From ratkaisut at gmail.com Thu Aug 1 08:42:51 2019 From: ratkaisut at gmail.com (Sten Kultakangas) Date: Thu Aug 1 08:44:57 2019 Subject: [odb-users] inserting chinese characters into mysql error (utf8mb4 and utf8 are tried) In-Reply-To: References: Message-ID: Hi \xD6\xD0\xB9\xFA doesn't look like an UTF8-encoded ?? Please double check whether the strings in your source file are actually UTF-8 encoded, not e.g. big5-encoded. Use a hex viewer like builtin in notepad++ or Midnight Commander. UTF8 for ?? should be \xE4\xB8\xAD\xE5\x9B\xBD Best regards, Sten Kultakangas On Thu, Aug 1, 2019 at 2:57 PM ???? wrote: > When i insert some chinese characters into mysql via odb, i got the error > message "Incorrect string value: '\xD6\xD0\xB9\xFA' for column 'NATION' at > row 1", i know it's the wrong setting of character set, i tried my efforts > to fix the issue but all in vain. > firstly i used odb2.4, mysql 8.0 mysql connector c 6.1.11 and vs2015 in my > project, i tried using utf8mb4 charset, below is my configuration file: > [mysqld] character-set-server = utf8mb4 collation-server = > utf8mb4_general_ci init_connect='SET NAMES utf8mb4' > skip-character-set-client-handshake = true [mysql] > default-character-set=utf8mb4 [client] default-character-set=utf8mb4and it > seems nothing wrong with the mysql server: mysql> SHOW VARIABLES WHERE > Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%'; > +--------------------------+--------------------+ | Variable_name > | Value | > +--------------------------+--------------------+ | > character_set_client | utf8mb4 | | > character_set_connection | utf8mb4 | | > character_set_database | utf8mb4 | | > character_set_filesystem | binary | | > character_set_results | utf8mb4 | | character_set_server > | utf8mb4 | | character_set_system | utf8 > | | collation_connection | utf8mb4_general_ci | | > collation_database | utf8mb4_general_ci | | collation_server > | utf8mb4_general_ci | > +--------------------------+--------------------+ mysql> show > create table basininfo; > ------------------------------------------------------------------------------------------------+ > | basininfo | CREATE TABLE `basininfo` ( `ID` int(11) > NOT NULL AUTO_INCREMENT, `BASIN_NAME` varchar(1000) DEFAULT > NULL, `NATION` varchar(1000) DEFAULT NULL, PRIMARY > KEY (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 > the code piece induced the error is below: auto_ptr db( > new odb::mysql::database( "news" // database login > name , "news123" // database password , "newsdb" // > database name , "localhost" , 3306 , > nullptr ,"utf8mb4" )); transaction t(db->begin()); > BasinInfo binfo; binfo.setNation("??"); //chinese > character insert into column 'Nation' db->persist(binfo); > t.commit();after that, i changed the mysql server to 5.7, replace the > connector c to the libraray and include files that bundled with mysql 5.7, > and rebuild the odb-libmysql, but that effort does not do any help. finally > i changed the charset to utf8 and recreate the database, but problem > remains the same. i also start a post on stackoverflow at > https://stackoverflow.com/questions/57283107/problem-when-inserting-chinese-characters-into-mysql-via-c-odb, > for now i dont get the problem solved!do you have any idea about how to fix > it, thanks! From icewill9999 at vip.qq.com Thu Aug 1 21:02:45 2019 From: icewill9999 at vip.qq.com (=?gb18030?B?srvD99Xmz+A=?=) Date: Fri Aug 2 07:23:09 2019 Subject: =?gb18030?B?u9i4tKO6IFtvZGItdXNlcnNdIGluc2VydGluZyBj?= =?gb18030?B?aGluZXNlIGNoYXJhY3RlcnMgaW50byBteXNxbCBl?= =?gb18030?B?cnJvcih1dGY4bWI0IGFuZCB1dGY4IGFyZSB0cmll?= =?gb18030?B?ZCk=?= Message-ID: Hi, i double checked the visual studio settings of UTF-8, and found that the default setting is UTF-8 with signature, changed it to utf-8 without signature makes the problem gone, utf8mb4 is also ok, thanks a lot, a big help indeed! Best Regards wang haibo ------------------ ???? ------------------ ???: "Sten Kultakangas"; ????: 2019?8?1?(???) ??8:42 ???: "????"; ??: "odb-users"; ??: Re: [odb-users] inserting chinese characters into mysql error(utf8mb4 and utf8 are tried) Hi \xD6\xD0\xB9\xFA doesn't look like an UTF8-encoded ?? Please double check whether the strings in your source file are actually UTF-8 encoded, not e.g. big5-encoded. Use a hex viewer like builtin in notepad++ or Midnight Commander. UTF8 for ?? should be \xE4\xB8\xAD\xE5\x9B\xBD Best regards, Sten Kultakangas On Thu, Aug 1, 2019 at 2:57 PM ???? wrote: > When i insert some chinese characters into mysql via odb, i got the error > message "Incorrect string value: '\xD6\xD0\xB9\xFA' for column 'NATION' at > row 1", i know it's the wrong setting of character set, i tried my efforts > to fix the issue but all in vain. > firstly i used odb2.4, mysql 8.0 mysql connector c 6.1.11 and vs2015 in my > project, i tried using utf8mb4 charset, below is my configuration file: > [mysqld] character-set-server = utf8mb4 collation-server = > utf8mb4_general_ci init_connect='SET NAMES utf8mb4' > skip-character-set-client-handshake = true [mysql] > default-character-set=utf8mb4 [client] default-character-set=utf8mb4and it > seems nothing wrong with the mysql server: mysql> SHOW VARIABLES WHERE > Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%'; > +--------------------------+--------------------+ | Variable_name > | Value | > +--------------------------+--------------------+ | > character_set_client | utf8mb4 | | > character_set_connection | utf8mb4 | | > character_set_database | utf8mb4 | | > character_set_filesystem | binary | | > character_set_results | utf8mb4 | | character_set_server > | utf8mb4 | | character_set_system | utf8 > | | collation_connection | utf8mb4_general_ci | | > collation_database | utf8mb4_general_ci | | collation_server > | utf8mb4_general_ci | > +--------------------------+--------------------+ mysql> show > create table basininfo; > ------------------------------------------------------------------------------------------------+ > | basininfo | CREATE TABLE `basininfo` ( `ID` int(11) > NOT NULL AUTO_INCREMENT, `BASIN_NAME` varchar(1000) DEFAULT > NULL, `NATION` varchar(1000) DEFAULT NULL, PRIMARY > KEY (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 > the code piece induced the error is below: auto_ptr db( > new odb::mysql::database( "news" // database login > name , "news123" // database password , "newsdb" // > database name , "localhost" , 3306 , > nullptr ,"utf8mb4" )); transaction t(db->begin()); > BasinInfo binfo; binfo.setNation("??"); //chinese > character insert into column 'Nation' db->persist(binfo); > t.commit();after that, i changed the mysql server to 5.7, replace the > connector c to the libraray and include files that bundled with mysql 5.7, > and rebuild the odb-libmysql, but that effort does not do any help. finally > i changed the charset to utf8 and recreate the database, but problem > remains the same. i also start a post on stackoverflow at > https://stackoverflow.com/questions/57283107/problem-when-inserting-chinese-characters-into-mysql-via-c-odb, > for now i dont get the problem solved!do you have any idea about how to fix > it, thanks! From icewill9999 at vip.qq.com Thu Aug 15 03:37:18 2019 From: icewill9999 at vip.qq.com (=?gb18030?B?srvD99Xmz+A=?=) Date: Thu Aug 15 07:40:39 2019 Subject: [odb-users] the id value from the qcreator is inconsistent with the visual studio Message-ID: Hi all, i started to learn and use odb 2.4.0 in my project, my team members like to use qt creator to develop our application. and i remove all the qt features of the project and use the MSVC as the building tools. i defined a class with an id like this: class BasinInfo{ #pragma db id auto unsigned long id_; } then i code like this: shared_ptr binfo(new BasinInfo()); cout << "id " << binfo->Id() << endl; i get the result 3452816845, if i change the type of id to int, then i get -8421501541. all the results are not what i want, because if i run the code in visual studio i always get 0. the value of id is important to me is because i want to use the id value to decide the next operation. if (binfo->Id() > 0) { //binfo was a persistent object, update it! db->update(binfo); } else { //this is a transient object, need to persist into the db db->persist(binfo); } anyone knows how to fix it? thanks in advance! Best Regards From icewill9999 at vip.qq.com Thu Aug 15 20:51:41 2019 From: icewill9999 at vip.qq.com (=?gb18030?B?srvD99Xmz+A=?=) Date: Fri Aug 16 07:12:55 2019 Subject: =?gb18030?B?u9i4tKO6IFtvZGItdXNlcnNdIHRoZSBpZCB2YWx1?= =?gb18030?B?ZSBmcm9tIHRoZSBxY3JlYXRvciBpcyBpbmNvbnNp?= =?gb18030?B?c3RlbnQgd2l0aHRoZSB2aXN1YWwgc3R1ZGlv?= In-Reply-To: References: Message-ID: thanks? it's worked! Best Regards ------------------ ???? ------------------ ???: "Sten Kultakangas"; ????: 2019?8?15?(???) ??8:42 ???: "????"; ??: Re: [odb-users] the id value from the qcreator is inconsistent withthe visual studio Hi This is not related to OBC, but you should not rely on the undefined values of the variables. Some compilers automatically initialize undefined values to 0, others don't. Sometimes it depends on the command-line options of the compiler (e.g., whether the debugging information is to be placed into the object file) class BasinInfo{ #pragma db id auto unsigned long id_ = 0; } db->persist() ignores the value of the identity member variable. On Thu, Aug 15, 2019 at 2:38 PM ???? wrote: Hi all, i started to learn and use odb 2.4.0 in my project, my team members like to use qt creator to develop our application. and i remove all the qt features of the project and use the MSVC as the building tools. i defined a class with an id like this: class BasinInfo{ #pragma db id auto unsigned long id_; } then i code like this: shared_ptr binfo(new BasinInfo()); cout << "id " << binfo->Id() << endl; i get the result 3452816845, if i change the type of id to int, then i get -8421501541. all the results are not what i want, because if i run the code in visual studio i always get 0. the value of id is important to me is because i want to use the id value to decide the next operation. if (binfo->Id() > 0) { //binfo was a persistent object, update it! db->update(binfo); } else { //this is a transient object, need to persist into the db db->persist(binfo); } anyone knows how to fix it? thanks in advance! Best Regards