I have some large data objects that have been serialized into a string/ostringstream using Boost. I would like to store these serialized objects in the database with the datatype CLOB via a procedure. In order to do so I am creating a CLOB-object but I don't know how to "put my data into the CLOB(myClob)".
I have seen some examples but all of them uses char-pointers and I would prefer not going down that alley...
Below is my c++ code so far. If you have any examples or good tips/links I would really appreciate any help.
Thx in advance
string qOracleDb::testRunStoredProc(const string& xId, const qTime date, const string& xUsage, int type, const std::ostringstream& data)
{
try
{
Clob myClob;
myClob.setEmpty();
myClob ?????
myStmt=myConn->createStatement("BEGIN DATA.SAVE_DATA_TEMP( :1, :2, :3, :4, :5); END;");
Date asofDate(myEnv, date.year(), date.month(), date.day(),0,0,0);
myStmt->setDate(1, asofDate);
myStmt->setString(2,xId);
myStmt->setString(3,xUsage);
myStmt->setInt(4, type);
myStmt->setClob(5, myClob);
myStmt->execute();
}
catch(SQLException ex)
{
// close nicely
myConn->terminateStatement (myStmt);
return "Exception thrown : "+ ex.getMessage()+", " + qStringUtils::toString(ex.getErrorCode());
}
// close nicely
myConn->terminateStatement (myStmt);
return "succes";
}
UPDATE: Since I have found code examples that have solved my problems I would like to share the solution since somebody else might also face this "challenge" one day. My data-variable has changed from a stream to a string and my code is as below:
/* Create dummy-clob in DB and insert data */
myStmt = myConn->createStatement("begin dbms_lob.createtemporary(:p1,FALSE);end;");
myStmt->registerOutParam(1,OCCICLOB);
myStmt->executeUpdate();
Clob resClob = myStmt->getClob(1);
resClob.write((unsigned int)data.size(), (unsigned char*)data.c_str(),(unsigned int)data.size());
myConn->terminateStatement (myStmt);
myStmt=myConn->createStatement("BEGIN DATA.SAVE_NOUVO_DATA( :1, :2, :3, :4, :5); END;");
Date asofDate(myEnv, date.year(), date.month(), date.day(),0,0,0);
myStmt->setDate(1, asofDate);
myStmt->setString(2,xId);
myStmt->setString(3,xUsage);
myStmt->setInt(4, type);
myStmt->setClob(5, resClob);
myStmt->execute();