# HG changeset patch # User Adam Chlipala # Date 1220806606 14400 # Node ID 1afa94582275dc23f4532c2544a23441791946f4 # Parent df02b09ff1ed74d319e75b48b2c540f115e0f3ec Reading ints and floats from SQL diff -r df02b09ff1ed -r 1afa94582275 include/types.h --- a/include/types.h Sun Sep 07 12:19:36 2008 -0400 +++ b/include/types.h Sun Sep 07 12:56:46 2008 -0400 @@ -17,3 +17,7 @@ typedef enum { SUCCESS, FATAL, BOUNDED_RETRY, UNLIMITED_RETRY } failure_kind; + + +#define INTS_MAX 50 +#define FLOATS_MAX 100 diff -r df02b09ff1ed -r 1afa94582275 src/c/urweb.c --- a/src/c/urweb.c Sun Sep 07 12:19:36 2008 -0400 +++ b/src/c/urweb.c Sun Sep 07 12:56:46 2008 -0400 @@ -225,9 +225,6 @@ } -#define INTS_MAX 50 -#define FLOATS_MAX 100 - char *lw_Basis_attrifyInt(lw_context ctx, lw_Basis_int n) { char *result; int len; diff -r df02b09ff1ed -r 1afa94582275 src/cjr_print.sml --- a/src/cjr_print.sml Sun Sep 07 12:19:36 2008 -0400 +++ b/src/cjr_print.sml Sun Sep 07 12:56:46 2008 -0400 @@ -390,12 +390,10 @@ 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 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 @@ 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 @@ 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, diff -r df02b09ff1ed -r 1afa94582275 tests/pquery.ur --- a/tests/pquery.ur Sun Sep 07 12:19:36 2008 -0400 +++ b/tests/pquery.ur Sun Sep 07 12:56:46 2008 -0400 @@ -1,11 +1,13 @@ table t1 : {A : int, B : string, C : float} fun lookup (inp : {B : string}) = - s <- query (SELECT t1.B FROM t1 WHERE t1.B = {inp.B}) - (fn fs _ => return fs.T1.B) - "Couldn't find it!"; + s <- query (SELECT * FROM t1 WHERE t1.B = {inp.B}) + (fn fs _ => return fs.T1) + {A = 0, B = "Couldn't find it!", C = 0.0}; return - Result: {cdata s} + A: {cdata (show _ s.A)}
+ B: {cdata (show _ s.B)}
+ C: {cdata (show _ s.C)}
fun main () : transaction page = return