From 09b9ebf63c7a41dc40a702832b9d103e85dcf297 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Sun, 7 Sep 2008 12:56:46 -0400 Subject: Reading ints and floats from SQL --- src/c/urweb.c | 3 --- src/cjr_print.sml | 33 ++++++++------------------------- 2 files changed, 8 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/c/urweb.c b/src/c/urweb.c index 47b45367..632dbf1e 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -225,9 +225,6 @@ void lw_write(lw_context ctx, const char* s) { } -#define INTS_MAX 50 -#define FLOATS_MAX 100 - char *lw_Basis_attrifyInt(lw_context ctx, lw_Basis_int n) { char *result; int len; diff --git a/src/cjr_print.sml b/src/cjr_print.sml index e9bc54de..24dedb6c 100644 --- a/src/cjr_print.sml +++ b/src/cjr_print.sml @@ -390,12 +390,10 @@ fun patConInfo env pc = fun p_unsql env (tAll as (t, loc)) e = case t of - TFfi ("Basis", "int") => box [string "*(lw_Basis_int *)", e] - | TFfi ("Basis", "float") => box [string "*(lw_Basis_float *)", e] + TFfi ("Basis", "int") => box [string "lw_Basis_stringToInt_error(ctx, ", e, string ")"] + | TFfi ("Basis", "float") => box [string "lw_Basis_stringToFloat_error(ctx, ", e, string ")"] | TFfi ("Basis", "string") => box [string "lw_Basis_strdup(ctx, ", e, string ")"] - | TFfi ("Basis", "bool") => box [string "(*(int *)", - e, - string " ? lw_Basis_True : lw_Basis_False)"] + | TFfi ("Basis", "bool") => box [string "lw_Basis_stringToBool_error(ctx, ", e, string ")"] | _ => (ErrorMsg.errorAt loc "Don't know how to unmarshal type from SQL"; Print.eprefaces' [("Type", p_typ env tAll)]; string "ERROR") @@ -427,10 +425,10 @@ fun getPargs (e, _) = fun p_ensql t e = case t of - Int => box [string "(char *)&", e] - | Float => box [string "(char *)&", e] + Int => box [string "lw_Basis_attrifyInt(ctx, ", e, string ")"] + | Float => box [string "lw_Basis_attrifyFloat(ctx, ", e, string ")"] | String => e - | Bool => box [string "lw_Basis_ensqlBool(", e, string ")"] + | Bool => box [string "(", e, string " ? \"TRUE\" : \"FALSE\")"] fun p_ensql_len t e = case t of @@ -751,21 +749,6 @@ fun p_exp' par env (e, loc) = ets, string " };", newline, - newline, - - string "const int paramLengths[] = { ", - p_list_sepi (box [string ",", space]) - (fn i => fn (_, t) => p_ensql_len t (box [string "arg", - string (Int.toString (i + 1))])) - ets, - string " };", - newline, - newline, - - string "const static int paramFormats[] = { ", - p_list_sep (box [string ",", space]) (fn _ => string "1") ets, - string " };", - newline, newline] end, string "int n, i;", @@ -781,12 +764,12 @@ fun p_exp' par env (e, loc) = newline, string "PGresult *res = ", case prepared of - NONE => string "PQexecParams(conn, query, 0, NULL, NULL, NULL, NULL, 1);" + NONE => string "PQexecParams(conn, query, 0, NULL, NULL, NULL, NULL, 0);" | SOME n => box [string "PQexecPrepared(conn, \"lw", string (Int.toString n), string "\", ", string (Int.toString (length (getPargs query))), - string ", paramValues, paramLengths, paramFormats, 1);"], + string ", paramValues, NULL, NULL, 0);"], newline, newline, -- cgit v1.2.3