Page 2 of 2
Posted: Thu Nov 06, 2008 1:03 pm
by pdwyer
I did an initial test of this with the code below in
unicode mode compile with unicode source. When I wrote the file I tried with pb_ascii and the default (which is utf8 in unicode mode)
The output was UTF8 text in default and CP932 in pb_ascii (which is what my system is set to use in the regional settings when not using unicode)
If you need to force a specific code page different from the user's default then you will need to use WideCharToMultiByte
Does this help at all or do you need to force a code page non standard to the system running the app?
Code: Select all
UseSQLiteDatabase()
Filename$ = "c:\utf.db"
If OpenFile(0, Filename$)
Debug "Database file created"
CloseFile(0)
EndIf
If OpenDatabase(0, Filename$, "", "")
Debug "Connected to PureBasic.sqlite"
If DatabaseUpdate(0, "CREATE TABLE info (test VARCHAR(255));")
Debug "Table created"
EndIf
DatabaseUpdate(0, "insert into info (test) values('日本語')") ;
DatabaseQuery(0, "SELECT * FROM info")
OpenFile(0,"c:\UTFOut2.txt")
While NextDatabaseRow(0)
WriteString(0, GetDatabaseString(0, 0));#PB_Ascii
Wend
CloseFile(0)
EndIf
Posted: Fri Nov 07, 2008 11:43 am
by silvercover
I did an initial test of this with the code below in unicode mode compile with unicode source. When I wrote the file I tried with pb_ascii and the default (which is utf8 in unicode mode)
The output was UTF8 text in default and CP932 in pb_ascii (which is what my system is set to use in the regional settings when not using unicode)
If you need to force a specific code page different from the user's default then you will need to use WideCharToMultiByte
Does this help at all or do you need to force a code page non standard to the system running the app?
I did the same last time but it didn't help. I think I need that WideCharToMultiByte .
I also have no problem receiving values from that app.
Thank you.
Posted: Fri Nov 07, 2008 1:23 pm
by pdwyer
can you post some text of the type we are talking about?
Posted: Fri Nov 07, 2008 2:45 pm
by pdwyer
Okay, I think this should solve it
The code page here is set to 932 so you need to change that to whatever.
Notes
1. I'm using writedata not writestring this time so as to be sure PB conversions are not effecting this
2. This must use unicode mode compile as otherwise the input to the WideCharToMultiByte_ function will not be in the right format.
3. I've just set an arbitrary buffer of len x 3 because japanese can take up 3 bytes per char in utf8, if you call WideCharToMultiByte_ with param 6 set to 0 then the function won't convert but rather return the size for you only so you can alloc the memory then call again with that memory size after allocation. Details are here
http://msdn.microsoft.com/en-us/library/ms776420.aspx
Code: Select all
UseSQLiteDatabase()
Filename$ = "c:\utf.db"
If OpenFile(0, Filename$)
Debug "Database file created"
CloseFile(0)
EndIf
If OpenDatabase(0, Filename$, "", "")
Debug "Connected to PureBasic.sqlite"
If DatabaseUpdate(0, "CREATE TABLE info (test VARCHAR(255));")
Debug "Table created"
EndIf
DatabaseUpdate(0, "insert into info (test) values('日本語')") ;
DatabaseQuery(0, "SELECT * FROM info")
OpenFile(0,"c:\UTFOut2.txt")
While NextDatabaseRow(0)
UTFChar.s = GetDatabaseString(0, 0)
*OutBuff = AllocateMemory(Len(UTFChar) * 3)
ActualSize = WideCharToMultiByte_(932, 0, @UTFChar, Len(UTFChar), *OutBuff, Len(UTFChar) * 3, 0, 0)
Debug ActualSize
WriteData(0,*OutBuff,ActualSize)
;WriteString(0, GetDatabaseString(0, 0));#PB_Ascii
Wend
CloseFile(0)
EndIf
Posted: Fri Nov 07, 2008 4:33 pm
by silvercover
THANK YOU very much pdwyer.
Now it's working and i can easily put my code page and get the right result.
You rock man!
Thank you all guys.
Posted: Fri Nov 07, 2008 4:40 pm
by pdwyer
Posted: Tue Nov 25, 2008 10:46 am
by silvercover
Hi again,
I have another problem on this issue. when I use pdwyer's code in executable application (Compiled with utf8) it works perfect, but when I put the code in a procedure to make my DLL(Compiled with utf8) file it does not work as expected!
I use ProcedureCDLL to make my procedures.
What's wrong?:?:
Thanks in advance.
Posted: Tue Nov 25, 2008 11:08 am
by pdwyer
was the app calling the dll unicode compiled?
Posted: Tue Nov 25, 2008 11:09 am
by silvercover
pdwyer wrote:was the app calling the dll unicode compiled?
Yes it does.
Posted: Tue Apr 14, 2009 9:40 am
by DaylightDreamer
Is there is a way to put data in SQLite database in ANSI already ?

Posted: Tue Apr 14, 2009 11:25 am
by pdwyer
Not sure what you mean