Skip to content

Commit

Permalink
Merge pull request #4164 from uklotzde/sqlite3_create_function
Browse files Browse the repository at this point in the history
Fix usage of  sqlite3_create_function()
  • Loading branch information
daschuer authored Jul 31, 2021
2 parents 69773ae + 3b7fbb2 commit 3272146
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/util/db/dbconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ const char kLexicographicalCollationFunc[] = "mixxxLexicographicalCollationFunc"
// The SQL statement 'A LIKE B' is implemented as 'like(B, A)', and if there is
// an escape character, say E, it is implemented as 'like(B, A, E)'
//static
void sqliteLike(sqlite3_context *context,
int aArgc,
sqlite3_value **aArgv) {
void sqliteLikeUtf8(sqlite3_context* context,
int aArgc,
sqlite3_value** aArgv) {
VERIFY_OR_DEBUG_ASSERT(aArgc == 2 || aArgc == 3) {
return;
}
Expand Down Expand Up @@ -277,27 +277,29 @@ bool initDatabase(const QSqlDatabase& database, StringCollator* pCollator) {
}

result = sqlite3_create_function(
handle,
"like",
2,
SQLITE_ANY,
nullptr,
sqliteLike,
nullptr, nullptr);
handle,
"like",
2,
SQLITE_UTF8 | SQLITE_DETERMINISTIC,
nullptr,
sqliteLikeUtf8,
nullptr,
nullptr);
VERIFY_OR_DEBUG_ASSERT(result == SQLITE_OK) {
kLogger.warning()
<< "Failed to install custom 2-arg LIKE function for SQLite3:"
<< result;
}

result = sqlite3_create_function(
handle,
"like",
3,
SQLITE_UTF8, // No conversion, Data is stored as UTF8
nullptr,
sqliteLike,
nullptr, nullptr);
handle,
"like",
3, // 3rd arg = ESCAPE
SQLITE_UTF8 | SQLITE_DETERMINISTIC,
nullptr,
sqliteLikeUtf8,
nullptr,
nullptr);
VERIFY_OR_DEBUG_ASSERT(result == SQLITE_OK) {
kLogger.warning()
<< "Failed to install custom 3-arg LIKE function for SQLite3:"
Expand Down

0 comments on commit 3272146

Please sign in to comment.