Specifying encoding on database creation
[hcoop/domtool2.git] / src / main.sml
index 9530bcd..67e8dc0 100644 (file)
@@ -1365,18 +1365,22 @@ fun service () =
                                                   SOME ("Error adding user: " ^ msg)))
                                      (fn () => ())
 
                                                   SOME ("Error adding user: " ^ msg)))
                                      (fn () => ())
 
-                              | MsgCreateDb {dbtype, dbname} =>
+                              | MsgCreateDb {dbtype, dbname, encoding} =>
                                 doIt (fn () =>
                                          if Dbms.validDbname dbname then
                                              case Dbms.lookup dbtype of
                                                  NONE => ("Database creation request with unknown datatype type " ^ dbtype,
                                                           SOME ("Unknown database type " ^ dbtype))
                                                | SOME handler =>
                                 doIt (fn () =>
                                          if Dbms.validDbname dbname then
                                              case Dbms.lookup dbtype of
                                                  NONE => ("Database creation request with unknown datatype type " ^ dbtype,
                                                           SOME ("Unknown database type " ^ dbtype))
                                                | SOME handler =>
-                                                 case #createdb handler {user = user, dbname = dbname} of
-                                                     NONE => ("Created database " ^ user ^ "_" ^ dbname ^ ".",
-                                                              NONE)
-                                                   | SOME msg => ("Error creating database " ^ user ^ "_" ^ dbname ^ ": " ^ msg,
-                                                                  SOME ("Error creating database: " ^ msg))
+                                                 if not (Dbms.validEncoding encoding) then
+                                                     ("Invalid encoding " ^ valOf encoding ^ " requested for database creation.",
+                                                      SOME "Invalid encoding")
+                                                 else
+                                                     case #createdb handler {user = user, dbname = dbname, encoding = encoding} of
+                                                         NONE => ("Created database " ^ user ^ "_" ^ dbname ^ ".",
+                                                                  NONE)
+                                                       | SOME msg => ("Error creating database " ^ user ^ "_" ^ dbname ^ ": " ^ msg,
+                                                                      SOME ("Error creating database: " ^ msg))
                                          else
                                              ("Invalid database name " ^ user ^ "_" ^ dbname,
                                               SOME ("Invalid database name " ^ dbname)))
                                          else
                                              ("Invalid database name " ^ user ^ "_" ^ dbname,
                                               SOME ("Invalid database name " ^ dbname)))