Skip to content

Commit 4125f2e

Browse files
authored
Merge pull request duckdb#113 from Mytherin/encoding
Set encoding using the mysql API method
2 parents 06d5de1 + fbf5d4d commit 4125f2e

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
@@ -260,11 +260,13 @@ MYSQL *MySQLUtils::Connect(const string &dsn) {
260260
// retry
261261
result =
262262
mysql_real_connect(mysql, "127.0.0.1", user, passwd, db, config.port, unix_socket, config.client_flag);
263-
if (result) {
264-
return result;
265-
}
266263
}
267-
throw IOException("Failed to connect to MySQL database with parameters \"%s\": %s", dsn, mysql_error(mysql));
264+
if (!result) {
265+
throw IOException("Failed to connect to MySQL database with parameters \"%s\": %s", dsn, mysql_error(mysql));
266+
}
267+
}
268+
if (mysql_set_character_set(result, "utf8mb4") != 0) {
269+
throw IOException("Failed to set MySQL character set");
268270
}
269271
D_ASSERT(mysql == result);
270272
return result;

0 commit comments

Comments
 (0)