PDA

View Full Version : QT library & ODBC



smrtak
27th February 2009, 08:03
Hello,
i try store utf8 strings with UPDATE, INSERT with QT application (ODBC driver) and characters not save propertly.
SET NAMES utf8; not work, any idea?

(libmysql work fine)

code:
query.bindValue(":name", (QString)m_name);
and i try new:
query.bindValue(":name", m_name.toUtf8());
with no effect, this look at problem in driver

but select * work fine...


input:

qpos 2b0c-2f54 ENTER SQLGetData
HSTMT 00C6A0E0
UWORD 2
SWORD -8 <SQL_C_WCHAR>
PTR 0x03B200B0
SQLLEN 102
SQLLEN * 0x0025F958

qpos 2b0c-2f54 EXIT SQLGetData with return code 0 (SQL_SUCCESS)
HSTMT 00C6A0E0
UWORD 2
SWORD -8 <SQL_C_WCHAR>
PTR 0x03B200B0 [ 24] "Petr Vom\ff\ffka"
SQLLEN 102
SQLLEN * 0x0025F958 (24)

result:


qpos 2b0c-2f54 ENTER SQLBindParameter
HSTMT 00C6A0E0
UWORD 1
SWORD 1 <SQL_PARAM_INPUT>
SWORD 1 <SQL_C_CHAR>
SWORD 12 <SQL_VARCHAR>
SQLULEN 14
SWORD 0
PTR 0x03E3BE68
SQLLEN 14
SQLLEN * 0x0025FA60

toroman
27th September 2009, 00:36
I think I might have the same problem...
I use Qt 4.5.2 and connect to MySQL database using ODBC.

I have a database which contains utf-8 data (accented characters, cyrillic...), and all the characters display correctly in tableView and lineEdit.

But when you insert/update the model/database it garbles the data showing "crazy" characters. It is regardles if the editing happened in the grid directly, or with setData() or with insertRecord, and regardles of providing the value as a string from code or from lineEdit. I was very puzzled with the fact that when I retreive a field from the database and put the retrieved value in a lineEdit, it is displayed correctly, and when I put lineEdit.text() with setData() back to the database (should be the same string?) it updates wrong.

Also trited .toUtf8 and similar.... no success?

Did you manage to solve your problem? Anyone?

P.S. using plain lineEdit.text() which is "abcd Å¡đčć" a get in the database something like "abcd šđčć"

toroman
27th September 2009, 14:32
I have done some investigation and here is what I have found.... funny

I enabled logging of the SQL from MyODBC driver (Windows) and here is what I get:

UPDATE `OBVEZ` SET `ID`=_latin1'634', `REGBR`=_latin1'', `NAZIV`=_latin1'Dragan Toroman', `IME`=_latin1'Dragan Toroman', `ADRESA`=_latin1'12 Å¡đ шђ', `MESTO`=_latin1'Some Place', `TACKA`=_latin1'13', `KOL`=_latin1'1', `IZBACI`=0, `PREBACEN`=0 WHERE `ID` = 634;

notice _latin1 :( :confused: WTF put that in there?

Investigating further....

toroman
27th September 2009, 21:14
I reverted to 3.51 instead of 5.1.5. myodbc, and everything works fine...

I have also asked the question about introducers (_latin1) on mysql forum... waiting for reply.
Funny there is a settion of charset in 3.51 which I have set to utf8, but no such setting in 5.1.5