Mercurial > urweb
diff src/sqlite.sml @ 1014:ea9f03ac2710
Chars working with SQLite
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 22 Oct 2009 17:36:30 -0400 |
parents | 16f7cb0891b6 |
children | b2311dfb3158 |
line wrap: on
line diff
--- 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