From 1d2f9948f488cd4bb55b2434478726a59a3acce9 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Tue, 14 Jan 2014 19:22:53 -0500 Subject: MySQL: set character set when opening a new connection --- src/mysql.sml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/mysql.sml') diff --git a/src/mysql.sml b/src/mysql.sml index 472b72d1..e34efbd4 100644 --- a/src/mysql.sml +++ b/src/mysql.sml @@ -551,6 +551,23 @@ fun init {dbstring, prepared = ss, tables, views, sequences} = newline, string "}", newline, + newline, + string "if (mysql_set_character_set(mysql, \"utf8\")) {", + newline, + box [string "char msg[1024];", + newline, + string "strncpy(msg, mysql_error(mysql), 1024);", + newline, + string "msg[1023] = 0;", + newline, + string "mysql_close(mysql);", + newline, + string "uw_error(ctx, FATAL, ", + string "\"Error setting UTF-8 character set for MySQL connection: %s\", msg);"], + newline, + string "}", + newline, + newline, string "conn = calloc(1, sizeof(uw_conn));", newline, string "conn->conn = mysql;", -- cgit v1.2.3