I just finished my code for inserting a blob in a oracle database.But for some while i am stoked at this problem. In order to insert a blob ,first i insert an empty blob then i update it whit the data.The insert is working but the update is not inserting the data . Also it gives no error ,and the functions returns are all as should be .
the code is :
try{
CString strSqlStat(szSqlStat);
CString strSqlStat2(szSqlStat2);
if(IsConnectionDead())
{
if(!Reconnect())
return ERR_RECONNECT_FAILED;
}
CFileException exFile;
CFile sourceFile;
if(!sourceFile.Open(szFilePath, CFile::modeRead | CFile::shareDenyNone, &exFile))
return ERR_BLOB_READFILE;
int nrBytesToRead = (int)sourceFile.GetLength();
char* pData = new char[nrBytesToRead+1];
DWORD nrBytesRead;
if(!ReadFile((HANDLE)sourceFile.m_hFile,pData,nrBytesToRead, &nrBytesRead, NULL))
{
delete pData;
return ERR_BLOB_READFILE;
}
sourceFile.Close();
if(nrBytesRead == 0)//file empty
{
delete pData;
return 0;
}
//variables
SQLRETURN retCode;
SDWORD cbTextSize, lbytes;
lbytes = (SDWORD)nrBytesRead;
cbTextSize = SQL_LEN_DATA_AT_EXEC(lbytes);
PTR pParmID;
SDWORD cbBatch = nrBytesRead;
int rgbValue = 1;
retcode = retCode = SQLExecDirect(hstmt,(SQLTCHAR*)szSqlStat2, SQL_NTS);
SQLRETURN ret;
SQLCHAR* SQLState;
SQLINTEGER NativeError;
SQLSMALLINT errmsglen;
SQLCHAR errmsg[255];
SQLCHAR errstate[50];
SQLGetDiagRec(SQL_HANDLE_STMT, hstmt, 1, (SQLCHAR*)errstate, &NativeError, (SQLCHAR*)errmsg, sizeof(errmsg), &errmsglen);
// Bind the parameter marker.
retCode = retcode = SQLBindParameter(hstmt, // hstmt
1, // ipar
SQL_PARAM_INPUT, // fParamType
SQL_C_BINARY, // fCType
SQL_LONGVARBINARY, // FSqlType
lbytes, // cbColDef
0, // ibScale
&rgbValue, // rgbValue
0, // cbValueMax
&cbTextSize); // pcbValue
SqlError(hstmt,SQL_HANDLE_STMT,_T("WriteBlob"), _T("CTLSqlConnection"), _T("SQLBindParameter"));
if(retCode != SQL_SUCCESS)
{
delete pData;
if(!EndTransaction(FALSE))
return ERR_ENDTRANSACTION_FAILED;
else
return -3;
}
//SQLExec
//SELECT Id FROM RH_Report WHERE Name = N'strName' strWhereLevel
retcode = retCode = SQLExecDirect(hstmt,(SQLTCHAR*)szSqlStat, SQL_NTS);
/*SQLRETURN ret;
SQLCHAR* SQLState;
SQLINTEGER NativeError;
SQLSMALLINT errmsglen;
SQLCHAR errmsg[255];
SQLCHAR errstate[50];*/
SQLGetDiagRec(SQL_HANDLE_STMT, hstmt, 1, (SQLCHAR*)errstate, &NativeError, (SQLCHAR*)errmsg, sizeof(errmsg), &errmsglen);
// retCode = SQLParamData(hstmt, &pParmID);
SQLGetDiagRec(SQL_HANDLE_STMT, hstmt, 1, (SQLCHAR*)errstate, &NativeError, (SQLCHAR*)errmsg, sizeof(errmsg), &errmsglen);
if(retCode == SQL_NEED_DATA)
{
// Put final batch.
SQLPutData(hstmt, pData, lbytes);
SQLGetDiagRec(SQL_HANDLE_STMT, hstmt, 1, (SQLCHAR*)errstate, &NativeError, (SQLCHAR*)errmsg, sizeof(errmsg), &errmsglen);
}
else
{
delete pData;
SqlError(hstmt,SQL_HANDLE_STMT,_T("WriteBlob"), _T("CTLSqlConnection"), _T("SQLExecDirect or SQLParamData"));
if(!EndTransaction(FALSE))
return ERR_ENDTRANSACTION_FAILED;
else
return -4;
}
delete pData;
// Make final SQLParamData call.
//retcode = retCode = SQLParamData(hstmt, &pParmID);
SQLGetDiagRec(SQL_HANDLE_STMT, hstmt, 1, (SQLCHAR*)errstate, &NativeError, (SQLCHAR*)errmsg, sizeof(errmsg), &errmsglen);
if(SqlError(hstmt,SQL_HANDLE_STMT,_T("WriteBlob"), _T("CTLSqlConnection"), _T("The last SQLParamData")))
if(!EndTransaction(FALSE))
return ERR_ENDTRANSACTION_FAILED;
else
return -5;
retcode = SQLCloseCursor(hstmt);
if(!EndTransaction(TRUE))
return ERR_ENDTRANSACTION_FAILED;
}catch(...){
return -10;
}
return 0;
I can't figure out what the problem could be .The statements look like :
"UPDATE "+ table_name +" SET "+ column_name +" = ? WHERE filename ='insert'")
and the insert statement:
INSERT INTO "+ table_name +" VALUES ('insert',EMPTY_BLOB())")
I hope you can help me . I am a c++ beginner.Waiting for your replys . Thanks.

New Topic/Question
Reply



MultiQuote






|