Fall back on sqlite's default non-unicode aware LIKE when we couldn't load the sqlite symbols. Fixes problems for slackware users (one of their problems anyway...).
This commit is contained in:
parent
ba8f57fcbd
commit
70b6ba8c39
@ -44,11 +44,15 @@ sqlite_int64 (*LibraryBackend::_sqlite3_value_int64) (sqlite3_value*) = NULL;
|
|||||||
const uchar* (*LibraryBackend::_sqlite3_value_text) (sqlite3_value*) = NULL;
|
const uchar* (*LibraryBackend::_sqlite3_value_text) (sqlite3_value*) = NULL;
|
||||||
void (*LibraryBackend::_sqlite3_result_int64) (sqlite3_context*, sqlite_int64) = NULL;
|
void (*LibraryBackend::_sqlite3_result_int64) (sqlite3_context*, sqlite_int64) = NULL;
|
||||||
|
|
||||||
|
bool LibraryBackend::sStaticInitDone = false;
|
||||||
|
bool LibraryBackend::sLoadedSqliteSymbols = false;
|
||||||
|
|
||||||
bool LibraryBackend::StaticInit() {
|
|
||||||
if (_sqlite3_create_function) {
|
void LibraryBackend::StaticInit() {
|
||||||
return true;
|
if (sStaticInitDone) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
sStaticInitDone = true;
|
||||||
|
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
// We statically link libqsqlite.dll on windows so these symbols are already
|
// We statically link libqsqlite.dll on windows so these symbols are already
|
||||||
@ -65,7 +69,7 @@ bool LibraryBackend::StaticInit() {
|
|||||||
QLibrary library(plugin_path);
|
QLibrary library(plugin_path);
|
||||||
if (!library.load()) {
|
if (!library.load()) {
|
||||||
qDebug() << "QLibrary::load() failed for " << plugin_path;
|
qDebug() << "QLibrary::load() failed for " << plugin_path;
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_sqlite3_create_function = reinterpret_cast<Sqlite3CreateFunc>(
|
_sqlite3_create_function = reinterpret_cast<Sqlite3CreateFunc>(
|
||||||
@ -79,15 +83,16 @@ bool LibraryBackend::StaticInit() {
|
|||||||
_sqlite3_result_int64 = reinterpret_cast<void (*) (sqlite3_context*, sqlite_int64)>(
|
_sqlite3_result_int64 = reinterpret_cast<void (*) (sqlite3_context*, sqlite_int64)>(
|
||||||
library.resolve("sqlite3_result_int64"));
|
library.resolve("sqlite3_result_int64"));
|
||||||
|
|
||||||
if (_sqlite3_create_function &&
|
if (!_sqlite3_create_function ||
|
||||||
_sqlite3_value_type &&
|
!_sqlite3_value_type ||
|
||||||
_sqlite3_value_int64 &&
|
!_sqlite3_value_int64 ||
|
||||||
_sqlite3_value_text &&
|
!_sqlite3_value_text ||
|
||||||
_sqlite3_result_int64) {
|
!_sqlite3_result_int64) {
|
||||||
return true;
|
|
||||||
}
|
|
||||||
qDebug() << "Couldn't resolve sqlite symbols";
|
qDebug() << "Couldn't resolve sqlite symbols";
|
||||||
return false;
|
sLoadedSqliteSymbols = false;
|
||||||
|
} else {
|
||||||
|
sLoadedSqliteSymbols = true;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,12 +174,10 @@ QSqlDatabase LibraryBackend::Connect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find Sqlite3 functions in the Qt plugin.
|
// Find Sqlite3 functions in the Qt plugin.
|
||||||
if (!StaticInit()) {
|
StaticInit();
|
||||||
emit Error("LibraryBackend: StaticInit() failed.");
|
|
||||||
return db;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We want Unicode aware LIKE clauses.
|
// We want Unicode aware LIKE clauses if possible
|
||||||
|
if (sLoadedSqliteSymbols) {
|
||||||
QVariant v = db.driver()->handle();
|
QVariant v = db.driver()->handle();
|
||||||
if (v.isValid() && qstrcmp(v.typeName(), "sqlite3*") == 0) {
|
if (v.isValid() && qstrcmp(v.typeName(), "sqlite3*") == 0) {
|
||||||
sqlite3* handle = *static_cast<sqlite3**>(v.data());
|
sqlite3* handle = *static_cast<sqlite3**>(v.data());
|
||||||
@ -189,6 +192,7 @@ QSqlDatabase LibraryBackend::Connect() {
|
|||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (db.tables().count() == 0) {
|
if (db.tables().count() == 0) {
|
||||||
// Set up initial schema
|
// Set up initial schema
|
||||||
|
@ -189,7 +189,7 @@ class LibraryBackend : public LibraryBackendInterface {
|
|||||||
FRIEND_TEST(LibraryBackendTest, LikeUnicodeCaseInsensitive);
|
FRIEND_TEST(LibraryBackendTest, LikeUnicodeCaseInsensitive);
|
||||||
|
|
||||||
// Do static initialisation like loading sqlite functions.
|
// Do static initialisation like loading sqlite functions.
|
||||||
static bool StaticInit();
|
static void StaticInit();
|
||||||
// Custom LIKE() function for sqlite.
|
// Custom LIKE() function for sqlite.
|
||||||
static bool Like(const char* needle, const char* haystack);
|
static bool Like(const char* needle, const char* haystack);
|
||||||
static void SqliteLike(sqlite3_context* context, int argc, sqlite3_value** argv);
|
static void SqliteLike(sqlite3_context* context, int argc, sqlite3_value** argv);
|
||||||
@ -205,6 +205,9 @@ class LibraryBackend : public LibraryBackendInterface {
|
|||||||
static sqlite_int64 (*_sqlite3_value_int64) (sqlite3_value*);
|
static sqlite_int64 (*_sqlite3_value_int64) (sqlite3_value*);
|
||||||
static const uchar* (*_sqlite3_value_text) (sqlite3_value*);
|
static const uchar* (*_sqlite3_value_text) (sqlite3_value*);
|
||||||
static void (*_sqlite3_result_int64) (sqlite3_context*, sqlite_int64);
|
static void (*_sqlite3_result_int64) (sqlite3_context*, sqlite_int64);
|
||||||
|
|
||||||
|
static bool sStaticInitDone;
|
||||||
|
static bool sLoadedSqliteSymbols;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LIBRARYBACKEND_H
|
#endif // LIBRARYBACKEND_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user