Hi,
I have pictures, that I need to insert into a SQLite database and then
retrieve later. I am using the following code, but it is not working.
//INSERTING INTO THE DATABASE
statement = "INSERT INTO photo_details VALUES(NULL,?,?);";//statement is
QString. Similar to string
err =
sqlite3_prepare(db,statement.toUtf8().data(),-1,&ppStmt,&tail);//toUtf8.data()
gives const char *
if(err == SQLITE_OK){
err = sqlite3_bind_int(ppStmt,1,currentNameId);
if(err != SQLITE_OK){
}
err =
sqlite3_bind_blob(ppStmt,2,bytes.constData(),bytes.size(),SQLITE_TRANSIENT);
//bytes.constData() return const char *
//bytes.size() = 98591
if(err != SQLITE_OK){
}
if(sqlite3_step(ppStmt) != SQLITE_DONE){
//error
}
}
//READING FROM THE DATABASE
int err = 0;
sqlite3_stmt *ppStmt;
const char *tail;
QString statement = "SELECT nameid,photo FROM photo_details WHERE "
"nameid = " + QString::number(currentNameId) +
";";//QString is similar
to string
err = sqlite3_prepare(db,statement.toUtf8().data(), -1, &ppStmt,
&tail);//toUtf8() and data() gives const char *
if(err == SQLITE_OK){
while(sqlite3_step(ppStmt) == SQLITE_ROW){
QByteArray bytes(QByteArray((const char
*)sqlite3_column_blob(ppStmt,1));
pixmap.loadFromData(bytes);//size of bytes is 8
}
}
sqlite3_finalize(ppStmt);
I tried searching the forum on how to do this but could not find anything
solid.
Can someone please help me get this working.
Thanks a lot!!
--
View this message in context:
http://www.nabble.com/BLOB-help-please-tf2573627.html#a7174510
Sent from the SQLite mailing list archive at Nabble.com.
-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------