changeset 1957:ef9fdbb05c73

MySQL: set character set when opening a new connection
author Adam Chlipala <adam@chlipala.net>
date Tue, 14 Jan 2014 19:22:53 -0500 (2014-01-15)
parents ac1be85e91ad
children 4ef0c6605b3a
files src/mysql.sml
diffstat 1 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/mysql.sml	Thu Jan 09 17:27:24 2014 -0500
+++ b/src/mysql.sml	Tue Jan 14 19:22:53 2014 -0500
@@ -551,6 +551,23 @@
              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;",