Page 1 of 1

[OCL]Is there any sample code for query/update BLOB data in OCL C++?

Posted: Tue 07 Aug 2007 06:16
by euca
As title, is there any sample code for querying/updating BLOB or LONG RAW data in Oracle database through OCL (Oracle Class Library for C++).

Thanks a lot.

ps. stored procedure samples would be better :)

Posted: Tue 07 Aug 2007 07:41
by Paul
Please see the following projects in OCL installation package
ocl\demos\clob\clob.cpp
ocl\demos\long\long.cpp

Work with CLOB and BLOB using OraLob type, work with LONG and LONG RAW using OraLong type.

Posted: Tue 07 Aug 2007 08:07
by euca
But as I looked into clob.cpp, I found the sample code is for file i/o using "loadFromFile(fileName)".

Is there any other sample code using something like "setBlob()" for stored procedure input parameter?

Thanks a lot!

Posted: Thu 09 Aug 2007 11:25
by Paul
We do not have such example. You can use the one of the following cases to update CLOB, BLOB field. You can find information how to use other methods of OraLob, CRLob classes in OCL documentation.

void loadFromFile(OraQuery& query)
{
int id;
string fileName, title;

cout > id;

cout > title;

cout > fileName;

if (query.isActive())
query.close();

query.setCommandText(insertSQL);

query.param("ID").setInt(id);
query.param("TITLE").setString(title);

query.param("VALUE").setDirection(pdInput);
//query.param("VALUE").getClob().loadFromFile(fileName);

OraLob *lob = &query.param("VALUE").getClob();
char *s1 = "string data";
lob->write(0, strlen(s1), s1);

char *s2 = "string data1";
lob->setChars(s2);

CRString s3 = "string data3";
lob->setString(s3);

//lob.set

query.execute();
}

Posted: Fri 10 Aug 2007 03:06
by euca
It works!!!

The sample codes you provided help me very much!
Thank you very very much!
:D

ps. but if the stored procedure has an input parameter type "BLOB", it'll said "unsupported datatype". After I turned to use "Long Raw" instead, it worked.