Skip to content

Commit fbf5d4d

Browse files
committed
Set encoding using the mysql API method
1 parent 360c933 commit fbf5d4d

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/mysql_connection.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ MySQLConnection MySQLConnection::Open(const string &connection_string) {
3030
MySQLConnection result;
3131
result.connection = make_shared_ptr<OwnedMySQLConnection>(MySQLUtils::Connect(connection_string));
3232
result.dsn = connection_string;
33-
result.Execute("SET character_set_results = 'utf8mb4';");
3433
return result;
3534
}
3635

src/mysql_utils.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,13 @@ MYSQL *MySQLUtils::Connect(const string &dsn) {
247247
// retry
248248
result =
249249
mysql_real_connect(mysql, "127.0.0.1", user, passwd, db, config.port, unix_socket, config.client_flag);
250-
if (result) {
251-
return result;
252-
}
253250
}
254-
throw IOException("Failed to connect to MySQL database with parameters \"%s\": %s", dsn, mysql_error(mysql));
251+
if (!result) {
252+
throw IOException("Failed to connect to MySQL database with parameters \"%s\": %s", dsn, mysql_error(mysql));
253+
}
254+
}
255+
if (mysql_set_character_set(result, "utf8mb4") != 0) {
256+
throw IOException("Failed to set MySQL character set");
255257
}
256258
D_ASSERT(mysql == result);
257259
return result;

0 commit comments

Comments
 (0)