• Welcome, Guest. Please login.
 
August 26, 2019, 12:31:17 am

News:

Welcome to the SQLitening support forums!


UTF-16

Started by Fim, May 19, 2018, 09:23:43 am

Previous topic - Next topic

Fim

How to put strings coded with UTF-16 in a SQLite databas using SQLItening?

This does not work:

DIM RAD_IN AS WSTRING
slExe(RAD_IN, "E2")

Parameter mismatches definition says the compiler.
/Fim W.
Fim W

cj


Fim

I know that SQLite can handle UTF-16.
I have tested it and it works as I whish.
In my example slExe(RAD_IN, "E2") I was doing wrong, I had declareted RAD_IN as WSTRING.
As far as I understand it should be like this:

DIM RAD_IN AS STRING
DIM NYTT AS WSTRING
NYTT = "ABCD"
RAD_IN = "INSERT INTO ORD (ORDET) VALUES(NYTT)"
SLEXE(RAD_IN, "E2")

Right??
/Fim W

Fim W

cj

May 21, 2018, 06:06:12 am #3 Last Edit: May 21, 2018, 01:59:19 pm by cj
I don't think it will preserve the unicode after following Bern's link.


#INCLUDE "sqlitening.inc"
FUNCTION PBMAIN () AS LONG
LOCAL ws AS WSTRING, s() AS STRING, x AS LONG
slopen "junk.db3","C"
slexe "create table if not exists t1(c1)"
FOR x = 1 TO 3
  ws = USING$("This is string number #",x)
  slexe USING$("insert into t1 values('&')",ws)
NEXT
slselary "select * from t1",s()
? JOIN$(s(),$CR)
END FUNCTION


cj

May 21, 2018, 06:18:01 am #4 Last Edit: May 21, 2018, 06:23:10 am by cj
DECLARE FUNCTION slExe LIB "SQLitening.Dll" ALIAS "slExe" (BYREF rsStatement AS STRING, OPTIONAL BYVAL rsModChars AS STRING) AS LONG

The whole statement would probably work with WSTRING, but SQLitening functions would have to be changed.

I am not sure if the WSTRING passed is being converted to STRING automatically by PowerBASIC!



Fim

Thanks, now I know.
/Fim W.
Fim W


cj

May 21, 2018, 12:26:44 pm #7 Last Edit: May 21, 2018, 12:28:25 pm by cj
Llink shows my method is wrong because unicode is changed to ansi before saving so when reading back it won't be unicode.
ws = STRING$(200,0)
s  = ws

cj

May 21, 2018, 01:57:03 pm #8 Last Edit: May 21, 2018, 02:01:31 pm by cj
I didn't see any tests
Test declare with WSTRING and also with using the two copy without conversion functions

#INCLUDE "sqlitening.inc"
DECLARE FUNCTION slBuildBindDatW LIB "SQLitening.Dll" ALIAS "slBuildBindDat" (BYREF rsData AS WSTRING, OPTIONAL BYVAL rsModChars AS STRING) AS STRING
DECLARE FUNCTION slFNW LIB "SQLitening.Dll" ALIAS "slFN" (BYREF rsColumnName AS STRING, OPTIONAL BYVAL rlSetNumber AS LONG) AS WSTRING
DECLARE FUNCTION slFNXW LIB "SQLitening.Dll" ALIAS "slFNX" (BYREF rsColumnName AS STRING, OPTIONAL BYVAL rsModChars AS STRING, OPTIONAL BYVAL rlSetNumber AS LONG) AS WSTRING

FUNCTION PBMAIN () AS LONG
LOCAL s  AS STRING
LOCAL ws AS WSTRING
slopen "junk.db3","C"
slexe "drop table if exists t1"
slexe "create table if not exists t1(c1)"

'New declare method
ws = "string 1"
slexeBind "insert into t1 values(?)", slBuildBindDatW(ws)   'slBuildBindDataW
IF slGetchangeCount = 0 THEN ? "Insert error":EXIT FUNCTION
slSel "select * from t1"
RESET ws
DO WHILE slGetRow
  ws+= slfnw("c1") + $CR
  ? ws,,"declare method"
LOOP

'Copy method
ws = "string 2"
s = CopyU2A(ws)                                              'new function
slexeBind "insert into t1 values(?)", slBuildBindDat(s)      'no new function
IF slGetchangeCount = 0 THEN ? "Insert error":EXIT FUNCTION
slSel "select * from t1"
RESET ws
DO WHILE slGetRow
  ws+= CopyA2U(slfn("c1")) + $CR
LOOP
? ws,,"copy method"
END FUNCTION

FUNCTION CopyA2U(rsA AS STRING) AS WSTRING
' This will copy the passed ANSI string to the retruning Unicode string without
' doing any conversion.

   LOCAL lspU AS WSTRING PTR

   lspU = VARPTR(rsA)
   FUNCTION = @lspU

END FUNCTION

FUNCTION CopyU2A(rsU AS WSTRING) AS STRING
' This will copy the passed Unicode string to the retruning ANSI string without
' doing any conversion.

   LOCAL lspA AS STRING PTR

   lspA = VARPTR(rsU)
   FUNCTION = @lspA

END FUNCTION



[font=courier]#INCLUDE "sqlitening.inc"
DECLARE FUNCTION slBuildBindDatW LIB "SQLitening.Dll" ALIAS "slBuildBindDat" (BYREF rsData AS WSTRING, OPTIONAL BYVAL rsModChars AS STRING) AS STRING
DECLARE FUNCTION slFNW LIB "SQLitening.Dll" ALIAS "slFN" (BYREF rsColumnName AS STRING, OPTIONAL BYVAL rlSetNumber AS LONG) AS WSTRING
DECLARE FUNCTION slFNXW LIB "SQLitening.Dll" ALIAS "slFNX" (BYREF rsColumnName AS STRING, OPTIONAL BYVAL rsModChars AS STRING, OPTIONAL BYVAL rlSetNumber AS LONG) AS WSTRING

FUNCTION PBMAIN () AS LONG
LOCAL s  AS STRING
LOCAL ws AS WSTRING
slopen "junk.db3","C"
slexe "drop table if exists t1"
slexe "create table if not exists t1(c1)"

'New declare method
ws = "string 1"
slexeBind "insert into t1 values(?)", slBuildBindDatW(ws)   'slBuildBindDataW
IF slGetchangeCount = 0 THEN ? "Insert error":EXIT FUNCTION
slSel "select * from t1"
RESET ws
DO WHILE slGetRow
  ws+= slfnw("c1") + $CR
  ? ws,,"declare method"
LOOP

'Copy method
ws = "string 2"
s = CopyU2A(ws)                                              'new function
slexeBind "insert into t1 values(?)", slBuildBindDat(s)      'no new function
IF slGetchangeCount = 0 THEN ? "Insert error":EXIT FUNCTION
slSel "select * from t1"
RESET ws
DO WHILE slGetRow
  ws+= CopyA2U(slfn("c1")) + $CR
LOOP
? ws,,"copy method"
END FUNCTION

FUNCTION CopyA2U(rsA AS STRING) AS WSTRING
' This will copy the passed ANSI string to the retruning Unicode string without
' doing any conversion.

   LOCAL lspU AS WSTRING PTR

   lspU = VARPTR(rsA)
   FUNCTION = @lspU

END FUNCTION

FUNCTION CopyU2A(rsU AS WSTRING) AS STRING
' This will copy the passed Unicode string to the retruning ANSI string without
' doing any conversion.

   LOCAL lspA AS STRING PTR

   lspA = VARPTR(rsU)
   FUNCTION = @lspA

END FUNCTION