Specifying encoding on database creation
[hcoop/domtool2.git] / src / plugins / mysql.sml
index 7f55e5f..a10fbbc 100644 (file)
@@ -31,38 +31,38 @@ fun adduser {user, passwd} =
        NONE => SOME "No password given"
       | SOME passwd =>
        if validPasswd passwd then
-           if Slave.shell [Config.MySQL.adduser, user, " ", passwd] then
-               NONE
-           else
-               SOME "Error executing CREATE USER script"
+           Option.map (fn s => "Error executing CREATE USER script:\n" ^ s)
+                      (Slave.shellOutput [Config.MySQL.adduser, user, " ", passwd])
        else
            SOME "Password contains characters besides letters, digits, and !.-_"
 
 fun passwd {user, passwd} =
     if validPasswd passwd then
-       if Slave.shell [Config.MySQL.passwd, user, " ", passwd] then
-           NONE
-       else
-           SOME "Error executing SET PASSWORD script"
+       Option.map (fn s => "Error executing SET PASSWORD script:\n" ^ s)
+                  (Slave.shellOutput [Config.MySQL.passwd, user, " ", passwd])
     else
        SOME "Password contains characters besides letters, digits, and !.-_"
 
-fun createdb {user, dbname} =
-    if Slave.shell [Config.MySQL.createdb, user, " ", dbname] then
-       NONE
-    else
-       SOME "Error executing CREATE DATABASE script"
+fun createdb {user, dbname, encoding} =
+    case encoding of
+       SOME _ => SOME "MySQL doesn't support specifying encodings"
+      | NONE =>
+       Option.map (fn s => "Error executing CREATE DATABASE script:\n" ^ s)
+                  (Slave.shellOutput [Config.MySQL.createdb, user, " ", dbname])
 
 fun dropdb {user, dbname} =
-    if Slave.shell [Config.MySQL.dropdb, user, " ", dbname] then
-       NONE
-    else
-       SOME "Error executing DROP DATABASE script"
+    Option.map (fn s => "Error executing DROP DATABASE script:\n" ^ s)
+              (Slave.shellOutput [Config.MySQL.dropdb, user, " ", dbname])
+
+fun grant {user, dbname} =
+    Option.map (fn s => "Error executing GRANT script:\n" ^ s)
+              (Slave.shellOutput [Config.MySQL.grant, user, " ", dbname])
 
 val _ = Dbms.register ("mysql", {getpass = SOME Client.getpass,
                                 adduser = adduser,
                                 passwd = passwd,
                                 createdb = createdb,
-                                dropdb = dropdb})
+                                dropdb = dropdb,
+                                grant = grant})
 
 end