munna
3rd November 2006, 11:12
Hi,
I am trying to store and retrieve a picture from SQLite database in the following manner but it is not working
//To get the pixmap from database
QPixmap pixmap;
QString statement = "SELECT nameid,photo FROM photo_details WHERE "
"nameid = " + QString::number(currentNameId) + ";";
err = sqlite3_prepare(db,statement.toUtf8().data(), -1, &ppStmt, &tail);
if(err == SQLITE_OK){
while(sqlite3_step(ppStmt) == SQLITE_ROW){
pixmap.loadFromData(QByteArray((const char *)sqlite3_column_blob(ppStmt,1)));
}
}
//To store the picture in the database
QByteArray bytes;
QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly);
pixmap.save(&buffer, "PNG");
int err = 0;
//sqlite3_stmt *ppStmt;
char *errmsg;
sqlite3_stmt *ppStmt;
const char *tail;
statement = "INSERT INTO photo_details VALUES(NULL,?,?);";
err = sqlite3_prepare(db,statement.toUtf8().data(),-1,&ppStmt,&tail);
if(err == SQLITE_OK){
err = sqlite3_bind_int(ppStmt,1,currentNameId);
if(err != SQLITE_OK){
//Error
}
err = sqlite3_bind_blob(ppStmt,2,bytes.constData(),bytes .size(),SQLITE_TRANSIENT);
if(err != SQLITE_OK){
}
if(sqlite3_step(ppStmt) != SQLITE_DONE){
//error
}
}
While storing, the variable err does not throw any error, which means it is stored in the database. But when retrieve the picture back, the pixmap is not build because pixmap.isNull() returns true.
Can someone please tell me, what's wrong with my code ?
Thanks a lot.
I am trying to store and retrieve a picture from SQLite database in the following manner but it is not working
//To get the pixmap from database
QPixmap pixmap;
QString statement = "SELECT nameid,photo FROM photo_details WHERE "
"nameid = " + QString::number(currentNameId) + ";";
err = sqlite3_prepare(db,statement.toUtf8().data(), -1, &ppStmt, &tail);
if(err == SQLITE_OK){
while(sqlite3_step(ppStmt) == SQLITE_ROW){
pixmap.loadFromData(QByteArray((const char *)sqlite3_column_blob(ppStmt,1)));
}
}
//To store the picture in the database
QByteArray bytes;
QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly);
pixmap.save(&buffer, "PNG");
int err = 0;
//sqlite3_stmt *ppStmt;
char *errmsg;
sqlite3_stmt *ppStmt;
const char *tail;
statement = "INSERT INTO photo_details VALUES(NULL,?,?);";
err = sqlite3_prepare(db,statement.toUtf8().data(),-1,&ppStmt,&tail);
if(err == SQLITE_OK){
err = sqlite3_bind_int(ppStmt,1,currentNameId);
if(err != SQLITE_OK){
//Error
}
err = sqlite3_bind_blob(ppStmt,2,bytes.constData(),bytes .size(),SQLITE_TRANSIENT);
if(err != SQLITE_OK){
}
if(sqlite3_step(ppStmt) != SQLITE_DONE){
//error
}
}
While storing, the variable err does not throw any error, which means it is stored in the database. But when retrieve the picture back, the pixmap is not build because pixmap.isNull() returns true.
Can someone please tell me, what's wrong with my code ?
Thanks a lot.