diff --git a/src/windows/SQLite3-Win-RT/SQLite3/Statement.cpp b/src/windows/SQLite3-Win-RT/SQLite3/Statement.cpp index 50fdea13f..f50dc323c 100644 --- a/src/windows/SQLite3-Win-RT/SQLite3/Statement.cpp +++ b/src/windows/SQLite3-Win-RT/SQLite3/Statement.cpp @@ -45,7 +45,14 @@ namespace SQLite3 Platform::String^ Statement::ColumnText(int index) { - return ref new Platform::String(static_cast(sqlite3_column_text16(statement, index))); + // To preserve embedded nulls within text data and fix truncation on first null char, + // create platform string with corresponding length: + // (length is number of bytes in text column divided by size of one wide character. + // see https://bugs.chromium.org/p/chromium/issues/detail?id=422690 + // and https://www.sqlite.org/capi3ref.html#sqlite3_column_blob) + // Question: is this always correct in all conditions? + unsigned int length = sqlite3_column_bytes16(statement, index) / sizeof(wchar_t); + return ref new Platform::String(static_cast(sqlite3_column_text16(statement, index)), length); } int Statement::ColumnInt(int index) @@ -65,7 +72,14 @@ namespace SQLite3 int Statement::BindText(int index, Platform::String^ val) { - return sqlite3_bind_text16(statement, index, val->Data(), -1, SQLITE_TRANSIENT); + // To preserve embedded nulls within text data and fix truncation on first null char, + // pass number of text bytes to sqlite3_bind_text16() instead of -1 as third parameter: + // (number of bytes are calculated by multiplying string length with the size of one wide character. + // see https://bugs.chromium.org/p/chromium/issues/detail?id=422690 + // and https://www.sqlite.org/capi3ref.html#sqlite3_bind_blob) + // Question: is this always correct in all conditions? + int length = val->Length() * sizeof(wchar_t); + return sqlite3_bind_text16(statement, index, val->Begin(), length, SQLITE_TRANSIENT); } int Statement::BindInt(int index, int val)