[Qt-interest] Qt Sqlite UserDefinedFunction
Bill KING
bill.king at trolltech.com
Thu Dec 11 02:48:50 CET 2008
Sylvain Pointeau wrote:
> Hello,
>
> How do I create a user defined function for SQLite using Qt?
> I would like to define the REGEXP using Qt behind.
>
> Thanks in advance for your help,
>
> Cheers,
> Sylvain
> ------------------------------------------------------------------------
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
Sorry for the delay, have been busy, but, a code snippet may lead you
down the right track, in this case, we're installing custom sorting, but
the steps are the same:
void installSorting( QSqlDatabase &db)
{
int sqliteLocaleAwareCompare(void *, int ll, const void *l, int
rl, const void *r);
QVariant v = db.driver()->handle();
if (v.isValid() && strcmp(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
int result = sqlite3_create_collation(
handle,
"localeAwareCompare",
SQLITE_UTF16, // ANY would be nice, but we only
encode in 16 anyway.
0,
sqliteLocaleAwareCompare);
if (result != SQLITE_OK)
qWarning() << "Could not add string collation
function: " << result;
} else {
qWarning() << "Could not get sqlite handle";
}
} else {
qWarning() << "handle variant returned typename " <<
v.typeName();
}
}
--
Bill King, Software Engineer
Qt Software, Nokia Pty Ltd
Brisbane Office
More information about the Qt-interest-old
mailing list