I have a problem with the SQLite3 C API. I’m trying to read some information from the places.sqlite database that Firefox uses to store many things. What I’m interested in is to retrieve the last visited website and the window title associated.
I wrote this piece of code:
query = "SELECT `url`, `title` FROM `moz_places` WHERE `id`=(SELECT `place_id` FROM `moz_historyvisits` ORDER BY `id` DESC LIMIT 1)";
stmt = NULL;
if (sqlite3_prepare_v2(db, query.c_str(), strlen(query.c_str()) + 1, &stmt, NULL) != SQLITE_OK)
cerr << sqlite3_errmsg(db) << endl;
else
{
while ((ret = sqlite3_step(stmt)) == SQLITE_ROW)
cout << sqlite3_column_text(stmt, 0) << endl << sqlite3_column_text(stmt, 1) << endl;
if (ret != SQLITE_DONE)
cerr << sqlite3_errmsg(db) << endl;
}
When there are no special characters it works fine, but if the window title contains “é”, “è” or “•” for example, I get those wonderful characters “é”, “è” or “•”.
I did some research and found that some people actually got non-UTF8 encoded databases. So I checked the places.sqlite database encoding with both SQLite Manager and the “PRAGMA encoding” request, both say that it is UTF-8 encoded.
Then I created my own database, encoded in UTF-8, entered some special characters in a table and it didn’t work either. So I thought that maybe QtCreator (which I’m using) can’t show special characters, I tried to get the foreground window title with GetForegroundWindow() and print it in QtCreator application output. It successfully showed the special characters of some window titles.
What am I missing here ?
Thank you.
Weel, seems like I managed to fix that problem by using this function I wrote:
Still, I found it weird that with a function like
GetWindowText()I manage to correctly print “é” and other caracters from a simplechar *, but here I must use awchar_t *…Well, it works at least, let’s hope it was the best solution 🙂