Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of sqlite3_create_function() #4164

Merged
merged 2 commits into from
Jul 31, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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