# HG changeset patch # User Adam Chlipala # Date 1256247390 14400 # Node ID ea9f03ac2710ad544427723cf78706eb014cade3 # Parent d9483301ff0ec6ebaaf7ac911a1998507c46e3c2 Chars working with SQLite diff -r d9483301ff0e -r ea9f03ac2710 src/mono_opt.sml --- a/src/mono_opt.sml Thu Oct 22 17:04:37 2009 -0400 +++ b/src/mono_opt.sml Thu Oct 22 17:36:30 2009 -0400 @@ -323,9 +323,9 @@ | 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 -r d9483301ff0e -r ea9f03ac2710 src/monoize.sml --- a/src/monoize.sml Thu Oct 22 17:04:37 2009 -0400 +++ b/src/monoize.sml Thu Oct 22 17:36:30 2009 -0400 @@ -1876,7 +1876,8 @@ ], (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 -r d9483301ff0e -r ea9f03ac2710 src/mysql.sml --- a/src/mysql.sml Thu Oct 22 17:04:37 2009 -0400 +++ b/src/mysql.sml Thu Oct 22 17:36:30 2009 -0400 @@ -1539,6 +1539,8 @@ supportsNextval = false, supportsNestedPrepared = false, sqlPrefix = "SET storage_engine=InnoDB;\n\n", - supportsOctetLength = true} + supportsOctetLength = true, + trueString = "TRUE", + falseString = "FALSE"} end diff -r d9483301ff0e -r ea9f03ac2710 src/postgres.sml --- a/src/postgres.sml Thu Oct 22 17:04:37 2009 -0400 +++ b/src/postgres.sml Thu Oct 22 17:36:30 2009 -0400 @@ -902,7 +902,9 @@ supportsNextval = true, supportsNestedPrepared = true, sqlPrefix = "", - supportsOctetLength = true} + supportsOctetLength = true, + trueString = "TRUE", + falseString = "FALSE"} val () = setDbms "postgres" diff -r d9483301ff0e -r ea9f03ac2710 src/settings.sig --- a/src/settings.sig Thu Oct 22 17:04:37 2009 -0400 +++ b/src/settings.sig Thu Oct 22 17:36:30 2009 -0400 @@ -157,7 +157,9 @@ supportsNextval : bool, supportsNestedPrepared : bool, sqlPrefix : string, - supportsOctetLength : bool + supportsOctetLength : bool, + trueString : string, + falseString : string } val addDbms : dbms -> unit diff -r d9483301ff0e -r ea9f03ac2710 src/settings.sml --- a/src/settings.sml Thu Oct 22 17:04:37 2009 -0400 +++ b/src/settings.sml Thu Oct 22 17:36:30 2009 -0400 @@ -352,7 +352,9 @@ supportsNextval : bool, supportsNestedPrepared : bool, sqlPrefix : string, - supportsOctetLength : bool + supportsOctetLength : bool, + trueString : string, + falseString : string } val dbmses = ref ([] : dbms list) @@ -377,7 +379,9 @@ supportsNextval = false, supportsNestedPrepared = false, sqlPrefix = "", - supportsOctetLength = false} : dbms) + supportsOctetLength = false, + trueString = "", + falseString = ""} : dbms) fun addDbms v = dbmses := v :: !dbmses fun setDbms s = diff -r d9483301ff0e -r ea9f03ac2710 src/sqlite.sml --- a/src/sqlite.sml Thu Oct 22 17:04:37 2009 -0400 +++ b/src/sqlite.sml Thu Oct 22 17:36:30 2009 -0400 @@ -36,7 +36,7 @@ Int => "integer" | Float => "real" | String => "text" - | Char => "integer" + | Char => "text" | Bool => "integer" | Time => "text" | Blob => "blob" @@ -370,12 +370,12 @@ | 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 @@ 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 @@ 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 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 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 @@ supportsNextval = false, supportsNestedPrepared = false, sqlPrefix = "", - supportsOctetLength = false} + supportsOctetLength = false, + trueString = "1", + falseString = "0"} end