PDA

View Full Version : Qt SQLite user functions



cevou
9th March 2009, 19:38
Hi,

i'm developing a program that can use multiple databases (PosgreSQL, MySQL, SQLite).
In some of the queries I need to use user functions like to_char, lpad ... which aren't supported by SQLite.
However I read that it's possible to add user functions to SQLite.
Is this also possiple in SQLite as used in Qt?

cevou
10th March 2009, 19:43
Well it works using SQLite extensions.
But - to enable the use of extensions I have to call sqlite3_enable_load_extension. This doesn't work. The app always crashes when calling sqlite3_enable_load_extension(handle,1).
Did I make a mistake?


QSqlDatabase db = QSqlDatabase::database();
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
sqlite3_enable_load_extension(handle,1);
}
}