PDA

View Full Version : Reading umlaut letters from sqlite database



Djony
16th November 2006, 17:35
Hi!

I am trying to read some German names from my sqlite database, and I have problems getting exact umlaut letters (Qt cuts of some bits wiht umlaut). This is my piece of code, where I am executing query:

QString sStatement = "SELECT rp.id, rp.FirstName, rp.LastName, rp.Alias, rp.eMail, rp.Phone, "
"rp.division, rp.comment "
"FROM tbl_Responsible rp "
"WHERE id = "
"("
"SELECT responsible_id FROM rel_TestCase_has_Responsible "
"WHERE testcase_id = :currentTcId"
") "
"ORDER BY rp.LastName ASC";

m_ResponsibleQuery.prepare(sStatement);
m_ResponsibleQuery.bindValue(":currentTcId", uiId);
m_ResponsibleQuery.exec();
QTextCodec::setCodecForCStrings(QTextCodec::codecF orName("UTF-8"));

if (checkForErrors(&m_ResponsibleQuery, "Error while fetching the testcase rel. responsibles!",parent))
return vResponsibles;
else
{
while(m_ResponsibleQuery.next())
{


vResponsibles.push_back
(
new Responsible
(
m_ResponsibleQuery.value(0).toInt(), //id
m_ResponsibleQuery.value(1).toString(), //firstName
m_ResponsibleQuery.value(2).toString(), //lastName
m_ResponsibleQuery.value(3).toString(), //alias
m_ResponsibleQuery.value(4).toString(), //eMail
m_ResponsibleQuery.value(5).toString(), //phone
m_ResponsibleQuery.value(6).toString(), //division
m_ResponsibleQuery.value(7).toString(), //comment
DBM_getTestCaseRelResponsibleFunctions
(
m_ResponsibleQuery.value(0).toInt(),
uiId,
parent
) // function
)
);
}
return vResponsibles;
}

Does anyone have suggestions what I should use to get correct names? Any replies are welcome

Thanx

wysota
16th November 2006, 17:40
Which version of SQLITE? How did you enter the data into the database? Don't use a separate text codec, the driver for sqlite should convert the data for you.

Djony
16th November 2006, 17:53
version is sqlite 3. I have already received database with names inside, and saw with different sqlite browsers that names are there and are entered correctly.

wysota
16th November 2006, 19:22
Does removing the extra codec help?

Djony
17th November 2006, 10:32
No. Actually, the first code I recieved didn't have that extra codec call. I added it, but it made no diference. Any more ideas?

wysota
17th November 2006, 10:46
Are you sure the data in the database is encoded in UTF-8?

Djony
17th November 2006, 10:55
As far as I know, Sqlite operate with UTF-8 encoding. Is there any way I can check that, and can you suggest me ony other encoding I could try? (I think that that could be checked with changing codec call in my codec, by trial and error repeating).

wysota
17th November 2006, 10:58
I had problems with SQLite and Qt myself and in the end it proved that the SQLite database was not UTF-8 encoded after all. So try fetching the data with some other mechanism (but not the sqlite3 console, it doesn't convert between local and utf - that was the base of my problems) and see if they are utf-8 encoded.

Djony
17th November 2006, 11:04
Thank you for your fast reply, but I didn't understand completely what you wrote. Can you go in more detail please? Which other mechanism to fetch data? I'm a bit confused, sorry.

wysota
17th November 2006, 11:06
Which other mechanism to fetch data?

SQLite C API.

Djony
17th November 2006, 11:16
You mean, to use sqlite c api (in some simple application) to read data from database and see are they in UTF-8 encoded?

wysota
17th November 2006, 11:30
Yes. That's exactly what I mean.