summaryrefslogtreecommitdiff
path: root/src/sqlite.sml
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2009-10-22 17:36:30 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2009-10-22 17:36:30 -0400
commit73b87d3545adf11b434837d0fee28500ef009bd6 (patch)
tree4b2eee33b6c42ab787f16df7b8bfc48e6f910b5a /src/sqlite.sml
parent4e7c75607f1c93d4d3fe983aede819d1da483f1b (diff)
Chars working with SQLite
Diffstat (limited to 'src/sqlite.sml')
-rw-r--r--src/sqlite.sml40
1 files changed, 28 insertions, 12 deletions
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