SQLite Store: Fix storing strings with multi byte Unicode sequences

CQTexperiment
Christopher Snowhill 2021-12-24 15:46:31 -08:00
parent 2445cc94a9
commit a8a982d3a4
1 changed files with 5 additions and 2 deletions

View File

@ -661,10 +661,13 @@ static SQLiteStore *g_sharedStore = NULL;
return -1;
}
const char * str = [string UTF8String];
uint64_t len = strlen(str); // SQLite expects number of bytes, not characters
sqlite3_stmt *st = stmt[stmt_select_string];
if (sqlite3_reset(st) ||
sqlite3_bind_text64(st, select_string_in_id, [string UTF8String], [string length], SQLITE_STATIC, SQLITE_UTF8))
sqlite3_bind_text64(st, select_string_in_id, str, len, SQLITE_STATIC, SQLITE_UTF8))
{
return -1;
}
@ -691,7 +694,7 @@ static SQLiteStore *g_sharedStore = NULL;
st = stmt[stmt_add_string];
if (sqlite3_reset(st) ||
sqlite3_bind_text64(st, add_string_in_value, [string UTF8String], [string length], SQLITE_STATIC, SQLITE_UTF8) ||
sqlite3_bind_text64(st, add_string_in_value, str, len, SQLITE_STATIC, SQLITE_UTF8) ||
sqlite3_step(st) != SQLITE_DONE ||
sqlite3_reset(st))
{