diff options
author | Adam Chlipala <adamc@hcoop.net> | 2009-10-22 17:36:30 -0400 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2009-10-22 17:36:30 -0400 |
commit | e2ffafb9cfaf0bb921bc9bca491214cb464a38d7 (patch) | |
tree | 4b2eee33b6c42ab787f16df7b8bfc48e6f910b5a | |
parent | fc3b6857ae9d41f0fa64dc53e135be6d27d85c76 (diff) |
Chars working with SQLite
-rw-r--r-- | src/mono_opt.sml | 4 | ||||
-rw-r--r-- | src/monoize.sml | 3 | ||||
-rw-r--r-- | src/mysql.sml | 4 | ||||
-rw-r--r-- | src/postgres.sml | 4 | ||||
-rw-r--r-- | src/settings.sig | 4 | ||||
-rw-r--r-- | src/settings.sml | 8 | ||||
-rw-r--r-- | src/sqlite.sml | 40 |
7 files changed, 47 insertions, 20 deletions
diff --git a/src/mono_opt.sml b/src/mono_opt.sml index 78754082..bb165770 100644 --- a/src/mono_opt.sml +++ b/src/mono_opt.sml @@ -323,9 +323,9 @@ fun exp e = | EFfiApp ("Basis", "sqlifyBool", [b as (_, loc)]) => optExp (ECase (b, [((PCon (Enum, PConFfi {mod = "Basis", datatyp = "bool", con = "True", arg = NONE}, NONE), loc), - (EPrim (Prim.String "TRUE"), loc)), + (EPrim (Prim.String (#trueString (Settings.currentDbms ()))), loc)), ((PCon (Enum, PConFfi {mod = "Basis", datatyp = "bool", con = "False", arg = NONE}, NONE), loc), - (EPrim (Prim.String "FALSE"), loc))], + (EPrim (Prim.String (#falseString (Settings.currentDbms ()))), loc))], {disc = (TFfi ("Basis", "bool"), loc), result = (TFfi ("Basis", "string"), loc)}), loc) | EFfiApp ("Basis", "sqlifyString", [(EPrim (Prim.String n), _)]) => diff --git a/src/monoize.sml b/src/monoize.sml index 6512eb1e..0a9f8e86 100644 --- a/src/monoize.sml +++ b/src/monoize.sml @@ -1876,7 +1876,8 @@ fun monoExp (env, st, fm) (all as (e, loc)) = ], (L'.ECase (gf "Having", - [((L'.PPrim (Prim.String "TRUE"), loc), + [((L'.PPrim (Prim.String + (#trueString (Settings.currentDbms ()))), loc), sc ""), ((L'.PWild, loc), strcat [sc " HAVING ", gf "Having"])], diff --git a/src/mysql.sml b/src/mysql.sml index f548b8d8..514a9257 100644 --- a/src/mysql.sml +++ b/src/mysql.sml @@ -1539,6 +1539,8 @@ val () = addDbms {name = "mysql", supportsNextval = false, supportsNestedPrepared = false, sqlPrefix = "SET storage_engine=InnoDB;\n\n", - supportsOctetLength = true} + supportsOctetLength = true, + trueString = "TRUE", + falseString = "FALSE"} end diff --git a/src/postgres.sml b/src/postgres.sml index 12142fe2..51e856db 100644 --- a/src/postgres.sml +++ b/src/postgres.sml @@ -902,7 +902,9 @@ val () = addDbms {name = "postgres", supportsNextval = true, supportsNestedPrepared = true, sqlPrefix = "", - supportsOctetLength = true} + supportsOctetLength = true, + trueString = "TRUE", + falseString = "FALSE"} val () = setDbms "postgres" diff --git a/src/settings.sig b/src/settings.sig index f07477e5..a207b207 100644 --- a/src/settings.sig +++ b/src/settings.sig @@ -157,7 +157,9 @@ signature SETTINGS = sig supportsNextval : bool, supportsNestedPrepared : bool, sqlPrefix : string, - supportsOctetLength : bool + supportsOctetLength : bool, + trueString : string, + falseString : string } val addDbms : dbms -> unit diff --git a/src/settings.sml b/src/settings.sml index 05a9e5da..b7bc02ff 100644 --- a/src/settings.sml +++ b/src/settings.sml @@ -352,7 +352,9 @@ type dbms = { supportsNextval : bool, supportsNestedPrepared : bool, sqlPrefix : string, - supportsOctetLength : bool + supportsOctetLength : bool, + trueString : string, + falseString : string } val dbmses = ref ([] : dbms list) @@ -377,7 +379,9 @@ val curDb = ref ({name = "", supportsNextval = false, supportsNestedPrepared = false, sqlPrefix = "", - supportsOctetLength = false} : dbms) + supportsOctetLength = false, + trueString = "", + falseString = ""} : dbms) fun addDbms v = dbmses := v :: !dbmses fun setDbms s = diff --git a/src/sqlite.sml b/src/sqlite.sml index f0ebac2f..8a61c25e 100644 --- a/src/sqlite.sml +++ b/src/sqlite.sml @@ -36,7 +36,7 @@ fun p_sql_type t = Int => "integer" | Float => "real" | String => "text" - | Char => "integer" + | Char => "text" | Bool => "integer" | Time => "text" | Blob => "blob" @@ -370,12 +370,12 @@ fun p_getcol {loc, wontLeakStrings, col = i, typ = t} = | Float => box [string "sqlite3_column_double(stmt, ", string (Int.toString i), string ")"] | String => if wontLeakStrings then - box [string "sqlite3_column_text(stmt, ", string (Int.toString i), string ")"] + box [string "(uw_Basis_string)sqlite3_column_text(stmt, ", string (Int.toString i), string ")"] else - box [string "uw_strdup(ctx, sqlite3_column_text(stmt, ", string (Int.toString i), string "))"] - | Char => box [string "sqlite3_column_int(stmt, ", string (Int.toString i), string ")"] + box [string "uw_strdup(ctx, (uw_Basis_string)sqlite3_column_text(stmt, ", string (Int.toString i), string "))"] + | Char => box [string "sqlite3_column_text(stmt, ", string (Int.toString i), string ")[0]"] | Bool => box [string "(uw_Basis_bool)sqlite3_column_int(stmt, ", string (Int.toString i), string ")"] - | Time => box [string "uw_Basis_stringToTime_error(ctx, sqlite3_column_text(stmt, ", string (Int.toString i), string "))"] + | Time => box [string "uw_Basis_stringToTime_error(ctx, (uw_Basis_string)sqlite3_column_text(stmt, ", string (Int.toString i), string "))"] | Blob => box [string "({", newline, string "char *data = (char *)sqlite3_column_blob(stmt, ", @@ -506,6 +506,18 @@ fun query {loc, cols, doCols} = string "uw_pop_cleanup(ctx);", newline] +val p_pre_inputs = + p_list_sepi (box []) + (fn i => fn t => + case t of + Char => box [string "char arg", + string (Int.toString (i + 1)), + string "s = {arg", + string (Int.toString (i + 1)), + string ", 0};", + newline] + | _ => box []) + fun p_inputs loc = p_list_sepi (box []) (fn i => fn t => @@ -521,17 +533,17 @@ fun p_inputs loc = string (Int.toString (i + 1)), string ", ", arg, - string ")"] + string ")"] | String => box [string "sqlite3_bind_text(stmt, ", string (Int.toString (i + 1)), string ", ", arg, string ", -1, SQLITE_TRANSIENT)"] - | Char => box [string "sqlite3_bind_int(stmt, ", - string (Int.toString (i + 1)), - string ", ", - arg, - string ")"] + | Char => box [string "sqlite3_bind_text(stmt, ", + string (Int.toString (i + 1)), + string ", ", + arg, + string "s, -1, SQLITE_TRANSIENT)"] | Bool => box [string "sqlite3_bind_int(stmt, ", string (Int.toString (i + 1)), string ", ", @@ -584,6 +596,7 @@ fun p_inputs loc = fun queryPrepared {loc, id, query, inputs, cols, doCols, nested} = box [string "uw_conn *conn = uw_get_db(ctx);", newline, + p_pre_inputs inputs, if nested then box [string "sqlite3_stmt *stmt;", newline] @@ -676,6 +689,7 @@ fun dml loc = fun dmlPrepared {loc, id, dml, inputs} = box [string "uw_conn *conn = uw_get_db(ctx);", newline, + p_pre_inputs inputs, string "sqlite3_stmt *stmt = conn->p", string (Int.toString id), string ";", @@ -779,6 +793,8 @@ val () = addDbms {name = "sqlite", supportsNextval = false, supportsNestedPrepared = false, sqlPrefix = "", - supportsOctetLength = false} + supportsOctetLength = false, + trueString = "1", + falseString = "0"} end |