Page 1 of 1

ODBC DatabaseUpdate and Unicode

Posted: Mon Mar 16, 2015 3:55 am
by lethleant
I've hit a brick wall with updating an SQL database via the DatabaseUpdate routine where unicode characters are involved.

I'm able to read unicode text via DatabaseQuery thanks to information in other threads on the forum. I do have the Unicode compiler option turned on. I've debugged the strings retrieved via DatabaseQuery and they do contain the unicode text. Operating system is Windows Server 2008; database is on an SQL Server 2008R2 server.

However, when I build an SQL statement that includes unicode text and execute it via DatabaseUpdate, the "unicode text" that makes it into the database just contains a bunch of ?'s in place of non-ASCII characters. I've checked the database fields and they are the unicode-compatible nvarchar format.

Any tricks to using DatabaseUpdate with unicode text?

Thank you!
-Tim.

Re: ODBC DatabaseUpdate and Unicode

Posted: Mon Mar 16, 2015 8:52 am
by infratec
Hi,

first: are you sure that you use an ODBC driver which can handle unicode?

Then you can try to put an N before your text like:

Code: Select all

N'unicode text'
Bernd

Re: ODBC DatabaseUpdate and Unicode

Posted: Mon Mar 16, 2015 2:37 pm
by lethleant
That worked! Thanks for the help!

-Tim.

Re: ODBC DatabaseUpdate and Unicode

Posted: Mon Mar 16, 2015 2:53 pm
by Danilo
A public explanation of the magic 'N' could/would be helpful for educational purposes. References and links are welcome.

Re: ODBC DatabaseUpdate and Unicode

Posted: Mon Mar 16, 2015 5:37 pm
by infratec

Re: ODBC DatabaseUpdate and Unicode

Posted: Tue Mar 17, 2015 6:59 am
by Danilo
Thx infratec! I thought PB uses UTF8 strings with databases and Unicode.

Re: ODBC DatabaseUpdate and Unicode

Posted: Wed Mar 18, 2015 6:33 pm
by Num3
Interesting stuff!

BTW, link is dead, i read this article instead:

http://stackoverflow.com/questions/1002 ... statements

On a side note, purebasic works great with UTF8 + Mysql server out of the box, so this problem is specific to MSSQL.

Re: ODBC DatabaseUpdate and Unicode

Posted: Wed Mar 18, 2015 9:49 pm
by the.weavster
With Firebird >= 2.5 you specify what encoding your application will be sending as part of the DSN setup. Firebird then automatically transliterates between that and the charset of the database you're connecting to.