ODBC DatabaseUpdate and Unicode

Just starting out? Need help? Post your questions and find answers here.
lethleant
New User
New User
Posts: 3
Joined: Thu Mar 12, 2015 8:23 pm

ODBC DatabaseUpdate and Unicode

Post 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.
infratec
Always Here
Always Here
Posts: 7836
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ODBC DatabaseUpdate and Unicode

Post 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
lethleant
New User
New User
Posts: 3
Joined: Thu Mar 12, 2015 8:23 pm

Re: ODBC DatabaseUpdate and Unicode

Post by lethleant »

That worked! Thanks for the help!

-Tim.
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: ODBC DatabaseUpdate and Unicode

Post by Danilo »

A public explanation of the magic 'N' could/would be helpful for educational purposes. References and links are welcome.
infratec
Always Here
Always Here
Posts: 7836
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ODBC DatabaseUpdate and Unicode

Post by infratec »

User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: ODBC DatabaseUpdate and Unicode

Post by Danilo »

Thx infratec! I thought PB uses UTF8 strings with databases and Unicode.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Re: ODBC DatabaseUpdate and Unicode

Post 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.
User avatar
the.weavster
Addict
Addict
Posts: 1583
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Re: ODBC DatabaseUpdate and Unicode

Post 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.
Post Reply