Inserting UTF-16 characters (native,ODBC,JDBC)

Discussion forum about all things SqlBase or SqlTalk
gabriele
Italy
Posts: 5
Joined: 04 Nov 2019, 09:08
Location: Italy

Inserting UTF-16 characters (native,ODBC,JDBC)

Post by gabriele » 28 Apr 2020, 10:51

Good morning
How am I supposed to save UTF8/16 strings on SQLBASE 11.7.3 and 12.1?
I couldn't find any info about character sets outside some references to codepages.
Should I use NVARCHAR instead of VARCHAR? It doesn't seem to work.
Any suggestion is much appreciated

User avatar
Steve Leighton
Site Admin
Site Admin
New Zealand
Posts: 430
Joined: 05 Mar 2017, 20:57
Location: Stroud, England <--> Tauranga, New Zealand

Re: Inserting UTF-16 characters (native,ODBC,JDBC)

Post by Steve Leighton » 29 Apr 2020, 02:06

.
It doesn't seem to work
What does this mean ? You need to be more specific.
Have you declared the column you are saving to as nvarchar or varchar ?
Does your inserted string look something like this '〱䔠楤扮牵桧䰠湡e'
If so, convert your multi-byte string to a unicode string using SalStrToWideChar(). This works for me regardless of how the column is declared:

Code: Select all

Call SalStrToWideChar(sIn,sOut,ENC_UTF8)
If SqlPrepareAndExecute( hSql, 'Update COMPANY set address = :sOut, address_n = :sOut where company_id = 101' )
	Call SqlCommit(hSql)
Greetings from New Zealand
Steve Leighton

Bankside Systems Ltd.
UK ♦ Australia ♦ New Zealand

www.banksidesystems.co.uk

Image

gabriele
Italy
Posts: 5
Joined: 04 Nov 2019, 09:08
Location: Italy

Re: Inserting UTF-16 characters (native,ODBC,JDBC)

Post by gabriele » 29 Apr 2020, 09:43

I've made some progress

Code: Select all

CREATE TABLE TEST (
	COL VARCHAR(100),
	COL2 NVARCHAR(100)
);

Code: Select all

On SAM_AppStartup
	Set sName = 'Miękina'
	Call SalStrToWideChar( sName, sNameWide, ENC_UTF8)
	If SqlConnectEx( hSql, 'MYDB', 'SYSADM', 'SYSADM' )
		If SqlPrepareAndExecute(hSql, "insert into TEST values( :sNameWide, :sName )")
			If SqlCommit(hSql)
		Call SqlDisconnect(hSql)
result: M
result: Miękina
Only the nvarchar column works, and ONLY with bind variables:

Code: Select all

insert into TEST values('Miękina','Miękina')
doesn't work

Return to “SqlBase General Discussion”

Who is online

Users browsing this forum: [Ccbot] and 1 guest