Code:
mysqlpp::Query acc_query = connection->query("SELECT * FROM accounts;");
The following code produces:
_Gfirst = 0x00c67718 "SELECT * FROM accounts;ээээ««««««««юоюою"
As in Visual Studio debugger. It appears to cause my query to fail with weird results.
Has anyone else encountered it?
It's best to use UTF-8 encoding with MySQL. Code pages are a Windows-centric pre-Unicode concept. Your use of them instead of Unicode probably explains why you're having problems. While it's possible to make MySQL — and thus MySQL++ — work with Windows-style code pages, you shouldn't be doing that in 2010.
If you are using Unicode, it's probably UTF-16 encoding (Windows' native encoding in the NT derivatives), which again explains a lot.
Convert all string data into UTF-8 form before sending it to MySQL, and configure MySQL to use UTF-8 encoding in its tables.
Related
I'm trying to insert some UTF-8 strings into PostgreSQL database. I'm using Visual C++ and MFC (this bit probably not important) and a project setting "Use Multi-Byte Character Set" (trying to switch database in an old legacy app). So when I execute some INSERT command with some text in Cyrillic "АБВГ" I expect to see this text in database, but I'm seeing this instead (in DBeaver): "ÐБВГ". I insert this text by converting the string "\xC0\xC1\xC2\xC3" from code page 1251 to CP_UTF8.
When I change the system setting "Language for non-Unicode programs" from English to some Cyrillic, like Russian, the text that is actually inserted is no longer "ÐБВГ", but "АБВГ". Postgres ODBC driver apparently uses CP_ACP to interpret my multi-byte strings. Indeed, if I now try to insert "\xC0\xC1\xC2\xC3" directly (without conversion to UTF-8), I do see "АБВГ" in database. But I need to insert UTF-8 strings, not a subset from a code page.
How do I instruct the Postgres ODBC driver to interpret my strings as UTF-8, and ignore the "Language for non-Unicode programs" system setting?
In PSQL console both server_encoding and client_encoding are set to UTF8.
Change your ODBC DSN connection string to include this: ConnSettings=SET CLIENT_ENCODING TO 'UTF8';
I am going to write software in Qt. Its string literals should be written in native (non-English) language and they should support internationalization. The Qt docs advice to use tr() function for this http://doc.qt.io/qt-5/i18n-source-translation.html
So I try to write:
edit->setText(tr("Фильтр"));
and and I can see only question marks in running app
I replace it with QString::fromStdWString
edit->setText(QString::fromStdWString(L"Фильтр"));
and I can see correct text in my language
So the question is: How should I write non-ASCII strings to be able to correctly display them and translate using Qt Linguist
PS: I use UTF8 encoding for all source files, compiler is vs2013
PS2: I have found QTextCodec::setCodecForTr() function.. but It was removed from Qt 5.4
I think that the best option is to use some kind of Latin1 transliteration inside program source. Then, it's possible to implement both Russian and English versions as normal Qt translations.
BTW. It's possible, with some additional work, to use even plain numbers as translation-placeholders. Just like MFC did.
I found the strange solution for my problem:
By default VS saves files in UTF8 with BOM. In File -> Advanced save options I choose to save file in UTF without BOM and everything works like a charm:
edit->setText(tr("Фильтр"));
It looks like a VS compiler bug.. Interestingly MS claims that its compiler support Unicode only for UTF8 with BOM https://msdn.microsoft.com/en-us/library/xwy0e8f2.aspx
PS: length of "Фильтр" is 12 bytes, so it is really utf8 string
I wrote a C++ program to retrieve some text data from MS-Active Directory and save them into a Sqlite3 database, however I have a problem, the utf-8 encoding.
According to some readings, data from active directory is UTF-8 encoded, but when reading from C++, it treats as a “wide char” (wchar_t) that Sqlite3 (which is utf-8 default) does not accept as UTF-8 because it uses only “char” into the parameter of its “sqlite3_bind_text” unless I use sqlite3_bind_text16, but I do not wish to do it because it increases the size of database.
I tried to convert from "wchar_t" to "char" using the function "wcstombs_s", but resulting data are not correct.
I read that the only way would be to use MultiByteToWideChar or WideCharToMultiByte, but I didn’t give a try because I read that the cost of convertion is quite expensive.
I would like to know if anybody of you had a similar situation and found a clean and effective solution for this matter.
Many Thanks!
Using sqlite3_bind_text16 on a database created with the UTF-8 encoding doesn't increase its size, the strings are converted on the fly to UTF-8.
See the paragraph "Support for UTF-8 and UTF-16" on this page.
During working on one c++ project we decided to use MongoDB database for storing some data of our application. I have spent a week linking and compiling c++ driver, and its works now. But it is one trouble: strings like
bob.append("name", "some text with cyrilic symbols абвгд");
are added incorrectly and after extracting from database look like 4-5 chinese symbols.
I have found no documentation about unicode using in mongodb, so I can not understand how to write unicode to database.
Your example, and the example code in the C++ tutorial on mongodb.org work fine for me on Ubuntu 11.10. My locale is en_US.UTF-8, and I the source files I create are UTF-8.
MongoDB stores data in BSON, and BSON strings are UTF-8, and UTF-8 can handle any Unicode character (including Cyrillic). I think the C++ API assumes strings are UTF-8 encoded, but I'm not sure.
Here are some ideas:
If your code above (bob.append("name"... etc) is in a C++ source code file, try encoding that file as UTF-8.
Try inserting Unicode characters via the mongodb shell.
i use ATL macros like A2T and A2CW.
on the devel-computer everyhting works fine. when i use the application (visual studio 2008 pro) on another computer - the output of the ATL-macro-conversion is not readable.
i hope someone can help me to solve this problem. my application is finished - only the ATL conversion macros are the problem atm.
thanks in advance
The A2X macros use the current codepage to convert the strings. If you have literal strings (or some data you are distributing with the application) that you are converting, that were created with the codepage of the dev. computer in mind, and the other computer has a different codepage set, they will end up as gibberish. You can use APIs to explicitly specify the codepage you're converting from if this is the case. A2X macros should really only be used for content than comes as input from the user, where the codepage may vary, not for data where the codepage is known ahead of time.