Closed lightyears1998 closed 1 year ago
Hi @lightyears1998
Apologies for the delay! I've been quite busy with other things π
Am I correct in assuming that this fix would only work correctly when the database is encoded in UTF8? According to the SQLite documentation, it should also be possible to create a database that uses UTF16.
Unfortunately I seem to keep getting an out of memory
-error when I attempt to create a UTF16 database... (Which might be another problem entirely since I'm getting the same error on the gd-extension
-branch)
EDIT: It seems to work even with a UTF16 encoded database π
Never mind. You can certainly take your time. (BTW, thanks for the awesome project!) π
I think this fix should work no matter what the database text encoding is. I make the following test, and it seems to work correctly.
(I am not sure about the out-of-memory
error, but making a query before open_db()
could lead to such an error?)
As documented in sqlite3 document, sqlite3_errmsg
, sqlite3_expanded_sql
, sqlite3_column_text
and sqlite3_column_name
return a pointer to an UTF-8 string. (There are also UTF-16 variations of these functions, for example, sqlite3_column_name16
.) I guess that the database text encoding is processed interally in the db, and text is conveted to UTF-8 before returning from these functions. Godot editor use UTF-8 encoding by default, so the string literals in the source code is encoded in UTF-8 in most cases. (One has to re-compile the editor and export templates to change the text encoding of godot.) For the above reasons, I think the fix is feasible.
Unfortunately I seem to keep getting an out of memory-error when I attempt to create a UTF16 database... (Which might be another problem entirely since I'm getting the same error on the gd-extension-branch)
Another memory related issue is the one I issued in the godot-cpp repo. As that issue infects CharString
, perhaps it is somehow related to our issue, and we have to wait for upstream to fix the issue before ours can be resolved.
Hi @lightyears1998
As this fix also works for UTF-16, I do think it is ready to be merged π Thank you for your contribution!
This should fix #87.
I have tested the following cases on Windows:
import_from_json
andexport_to_json
with Unicode column names and values work.Note:
import_from_json
andexport_to_json
won't work with non-ASCII file paths on Windows. It is the expected behavior since we are using ifstream/ofstream directly. I notice thatopen_db
could work with the non-ASCII file path, probably becausesqlite3_open_v2
handles the file path for us. It seems that there is no easy solution for Unicode path handling on Windows.