-
Notifications
You must be signed in to change notification settings - Fork 190
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
[sqlite] not support utf8. #900
Comments
The offending line is: hxcpp/src/hx/libs/sqlite/Sqlite.cpp Line 239 in 652acae
@hughsando I'm not familiar enough hxcpp strings... what's the best way to fix this? Reduced example: class Test {
static function main() {
var cnx = sys.db.Sqlite.open(":memory:");
trace(cnx.request("SELECT '豪鬼' test").next());
cnx.close();
}
} Breakpoint on Breakpoint 1, sqlite3_prepare (db=0x5555557bc478, zSql=0x7ffff7958258 "SELECT '豪鬼' test",
nBytes=16, ppStmt=0x7fffffffdc38, pzTail=0x7fffffffdc40)
at /home/jonas/Code/hxcpp/project/thirdparty/sqlite-3.23.1/sqlite3.c:120119 |
@ConstNW, could you take look? |
Probably it's the same problem as #880 |
The problem isn't the string encoding, but rather that we're sending the number of characters; all Also, there should be no major advantage in sending the statement in UTF-16, even if that's the encoding internally used by hxcpp:
|
if there is no actual bytes length and the string is NULL-terminated then it can be calc by sqlite
|
I had disregarded that alternative because while maybe rare, null characters can be present in Unicode strings, including in Hxcpp and SQLite. SQLite does discourage their use in strings:
but that note is buried somewhat deep in the docs. Also, I imagine storage/retrieval of strings with nulls works fine (even if it's undefined behavior), which means that there might be some code using this after all.
Line 291 in 652acae
|
at haxe code string values with NULL are encoded to hex public function quote(s:String) {
if (s.indexOf("\000") >= 0) {
var hexChars = new Array<String>();
for (i in 0...s.length)
hexChars.push(StringTools.hex(StringTools.fastCodeAt(s, i), 2));
return "x'" + hexChars.join("") + "'";
}
return "'" + s.split("'").join("''") + "'";
} |
That's a good point! |
build.hxml
cpp version
I:\test\testcpp\bin>Main.exe
src/Main.hx:5: create table now
src/Main.hx:16: create table finish
src/Main.hx:19: INSERT INTO fa_customer (nickname) VALUES ('璞')
Error : ValueException
hl verion
I:\test\testcpp>hl test.hl
src/Main.hx:5: create table now
src/Main.hx:16: create table finish
src/Main.hx:19: INSERT INTO fa_customer (nickname) VALUES ('豪鬼')
src/Main.hx:22: sqlite init finish
The text was updated successfully, but these errors were encountered: