static void qUpper(sqlite3_context *context, int argc, sqlite3_value **argv){ QByteArray ba = QString::fromUtf8((const char *)sqlite3_value_text(argv[0])).toUpper().toUtf8(); sqlite3_result_text(context, ba.constData(), ba.size(), NULL);}static void qLower(sqlite3_context *context, int argc, sqlite3_value **argv){ QByteArray ba = QString::fromUtf8((const char *)sqlite3_value_text(argv[0])).toLower().toUtf8(); sqlite3_result_text(context, ba.constData(), ba.size(), NULL);}
bool QSQLiteDriver::open(const QString & db, const QString &, const QString &, const QString &, int, const QString &conOpts){......... if (sqlite3_open16(db.constData(), &d->access) == SQLITE_OK) { sqlite3_busy_timeout(d->access, qGetSqliteTimeout(conOpts)); setOpen(true); setOpenError(false); sqlite3_create_function(d->access, "qupper", 1, SQLITE_UTF8, NULL, &qUpper, NULL, NULL); sqlite3_create_function(d->access, "qlower", 1, SQLITE_UTF8, NULL, &qLower, NULL, NULL); return true; } else {.......
select * from names where qupper(firstname) like 'АЛЕКС%'
bool QSQLiteDriver::open(const QString & db, const QString &, const QString &, const QString &, int, const QString &conOpts){ if (isOpen()) close(); if (db.isEmpty()) return false;if (sqlite3_open16(db.constData(), &d->access) == SQLITE_OK) { sqlite3_busy_timeout(d->access, qGetSqliteTimeout(conOpts)); setOpen(true); setOpenError(false); sqlite3_create_function(d->access, "qupper", 1, SQLITE_UTF8, NULL, &qUpper, NULL, NULL); sqlite3_create_function(d->access, "qlower", 1, SQLITE_UTF8, NULL, &qLower, NULL, NULL); return true; } else { //и весь остальной код метода обернутый в эти скобки }
static int qGetSqliteTimeout(QString opts){ enum { DefaultTimeout = 5000 }; opts.remove(QLatin1Char(' ')); if (opts.startsWith(QLatin1String("QSQLITE_BUSY_TIMEOUT="))) { bool ok; int nt = opts.mid(21).toInt(&ok); if (ok) return nt; } return DefaultTimeout;}
vb.netImports System.Data.SQLite <SQLiteFunction(Name:="lower", Arguments:=1, FuncType:=FunctionType.Scalar)> _Public Class LCase : Inherits SQLiteFunctionPublic Overrides Function Invoke(ByVal args() As Object) As ObjectIf (args.Length = 0) OrElse (args(0) Is Nothing) Then Return NothingReturn TryCast(args(0), String).ToLowerEnd FunctionEnd Class