Skip to content

Commit 048e124

Browse files
author
Oscar Franco
authored
Merge pull request #70 from swittk/main
fix: made retrieving TEXT columns from SQLite with NULL values in-between strings work properly
2 parents b5d95b5 + 50ad59b commit 048e124

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

cpp/JSIHelper.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ jsi::Value createSequelQueryExecutionResult(jsi::Runtime &rt, SQLiteOPResult sta
154154
QuickValue value = entry.second;
155155
if (value.dataType == TEXT)
156156
{
157-
rowObject.setProperty(rt, columnName.c_str(), jsi::String::createFromUtf8(rt, value.textValue.c_str()));
157+
// using value.textValue (std::string) directly allows jsi::String to use length property of std::string (allowing strings with NULLs in them like SQLite does)
158+
rowObject.setProperty(rt, columnName.c_str(), jsi::String::createFromUtf8(rt, value.textValue));
158159
}
159160
else if (value.dataType == INTEGER)
160161
{

cpp/sqliteBridge.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,9 @@ SQLiteOPResult sqliteExecute(string const dbName, string const &query, vector<Qu
329329
case SQLITE_TEXT:
330330
{
331331
const char *column_value = reinterpret_cast<const char *>(sqlite3_column_text(statement, i));
332-
row[column_name] = createTextQuickValue(string(column_value));
332+
int byteLen = sqlite3_column_bytes(statement, i);
333+
// Specify length too; in case string contains NULL in the middle (which SQLite supports!)
334+
row[column_name] = createTextQuickValue(string(column_value, byteLen));
333335
break;
334336
}
335337

0 commit comments

Comments
 (0)