Home » U++ Library support » U++ SQL » How to read a Blob from a SQLite3 DB (I can write a blob with a string but i can't read it )
How to read a Blob from a SQLite3 DB [message #43970] |
Tue, 02 December 2014 05:03  |
lmsp
Messages: 2 Registered: December 2014
|
Junior Member |
|
|
I have the next code to write a BLOB in a SQLite3 DB:
My .sch file:
TABLE_(BLOBS_TABLE)
INT_ (NUMBER)
BLOB_ (DATA)
END_TABLE
And C++ write(I omit the code of creation an open the DB):
S_BLOBS_TABLE row;
row.NUMBER = 1;
row.DATA = String(blob.GetBuffer(), blob.GetBufferLength());
SQL * Insert(FILES_BLOBS_TABLE)(row);
The class blob.GetBuffer() returns a char* and blob.GetBufferLength() the size of the buffer in bytes.
My problem comes when I try to read the data. I have tried:
SQL.Execute("select DATA from BLOBS_TABLE WHERE NUMBER=" +AsString(1) );
if(SQL.Fetch())
{
StringBuffer data( SQL[0] );
char* pBuffer = new char[data.GetLength()];
memcpy( pBuffer, data, data.GetLength() );
}
And:
SQL.Execute("select DATA from BLOBS_TABLE WHERE NUMBER=" +AsString(1) );
if(SQL.Fetch())
{
String data = SQL[0];
char* pBuffer = new char[data.GetLength()];
memcpy( pBuffer, (const char*)data, data.GetLength() );
}
But any solution doesn't work. Any help?
|
|
|
|
|
Goto Forum:
Current Time: Fri Apr 25 11:54:45 CEST 2025
Total time taken to generate the page: 0.00970 seconds
|