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

(Windows) added fix to preserve embedded nulls within text data #709

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
18 changes: 16 additions & 2 deletions src/windows/SQLite3-Win-RT/SQLite3/Statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ namespace SQLite3

Platform::String^ Statement::ColumnText(int index)
{
return ref new Platform::String(static_cast<const wchar_t*>(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<const wchar_t*>(sqlite3_column_text16(statement, index)), length);
}

int Statement::ColumnInt(int index)
Expand All @@ -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)
Expand Down