Page 1 of 1

Sqlite with PB 4.20 b6. UTF8

Posted: Mon May 19, 2008 11:59 pm
by mcsalsa
Dear All,

I'm migrating an Access Application to Sqlite.
In MS Access I had a Memo field which now is Sqlite is a clob (datatype)

With the Access ODBC I can insert a text like this: "

Posted: Tue May 20, 2008 12:40 am
by pdwyer
I'm not 100% sure I'm understanding the question but you can insert using hex if you want to using the X'<hex goes here>' format.

http://www.purebasic.fr/english/viewtop ... qlite+blob (ignore the rest of th code on this link but the insert part and hex data.)

There's a Bin2Hex() function there too, you can pass a string pointer there I guess

Posted: Tue May 20, 2008 6:49 am
by mcsalsa
Thanks pdwyer for the answer.

My question goes about inserting and retrieving strings in which some of the characters are with ascii codes lower that 21.

One option I'm thinking is if it possible to inform SQlite to convert the string to UTF8 once you make the insert, because I can retrieve without problems.

Regards,

Posted: Tue May 20, 2008 9:43 am
by srod
SQLite automatically stores all of it's text data in utf-8 format.

Posted: Tue May 20, 2008 11:12 am
by pdwyer
if you use blobs, hex and pointers it will just hold whatever you put in it however you put it in and you can get it out the same way. (get a pointer back when you select out of a blob and peeks() it to your string) you can even have chr(0) in there up till the point that you use PB string functions at which time they will concaternate

BUT

I haven't really looked into the PB SQLite implementation stuff to see if all the commands are available or usable, its not my intention to use it till it's out of beta, I'm on 4.10 still

Posted: Tue May 20, 2008 3:02 pm
by mcsalsa
All right, I will put an example, in order to explain my problem better.

If you create a string like this:
s$=Chr(15)+Chr(8)+Chr(134)

then make the insert into a database. string1 is a varchar of 1200 chars

ssql.s="insert into table1 (string1) values ('" + s$ + "')"
DatabaseUpdate(0,ssql)

then if you retrieve the string back and do something like this

ssql.s="Select string1 from table1"
If DatabaseQuery(0,auxs)
If NextDatabaseRow(0)
cadena$=GetDatabaseString(0,0)
For i=1 To Len(cadena$)
Debug Asc(Mid(cadena$,i,1))
Next
EndIf
EndIf


The values that i get are: 15, 8, 194, 134. What am I doing wrong in order to get that "194", that is an extra value.


Thanks for your understanding.