[Qt-interest] Sqlite3 handle
Neville Dastur
qt at dastur.me.uk
Sun Apr 4 05:38:26 CEST 2010
I am trying to us the sqlite3 handle passed back by QSqlDriver.
I have read the docs and have taken some code from there to obtain the
sqlite3 handle. However the snipet of code below consistently fails to
calling sqlite3_exec with a SIGSEGV. (Occurs on Linux + Mac)
Using a compiled version of 3.6.23-1. Also happens with statically
linked lib
Has anyone else successfully used the returned sqlite handle? Is there
something obvious I'm missing?
Thanking you
Neville
|Traceback
0 ?? 0 0x00000000
1 sqlite3_mutex_enter sqlite3.c 14549 0x08058072
code:
14547 SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex *p){
14548 if( p ){
14549 sqlite3GlobalConfig.mutex.xMutexEnter(p);
14550 }
14551 }
2 sqlite3_exec sqlite3.c 76821 0x080a0566
code:
sqlite3_mutex_enter(db->mutex);
3 main main.cpp 58 0x0804f477
code:
|| int rc = sqlite3_exec(handle, sql, 0, 0, &localError); // This is
line 58
|
Code that reproduces error
| QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("test.db");
if ( db.open() ) {
// If uncommented this works
//db.exec("CREATE TABLE normalMethod1 ( id INT(64), value
CHAR(32) )");
// This is taken from the Qt Docs
QVariant v = db.driver()->handle();
if (v.isValid() && qstrcmp(v.typeName(), "sqlite3*")==0) {
// v.data() returns a pointer to the handle
sqlite3 *handle = *static_cast<sqlite3 **>(v.data());
if (handle != 0) { // check that it is not NULL
qint64 id = sqlite3_last_insert_rowid((sqlite3 *)handle);
char* localError=0;
const char* sql = "CREATE TABLE tblOne (id int(32), name
char(16))";
int rc = sqlite3_exec(handle, sql, 0, 0, &localError);
// This is line 58
if (rc != SQLITE_OK) {
qFatal("Sqlite3 failed with %i", rc);
}
}
}
}|
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100404/673a36a1/attachment.html
More information about the Qt-interest-old
mailing list