# HG changeset patch # User Adam Chlipala # Date 1220538441 14400 # Node ID 7d5860add50fc9b2703fb7a7bd1087b2fed87371 # Parent fdd7a698be012846c7e25c5574e44fcfa1c44bd4 Change sqlify[int|float|string] to annotate with SQL types diff -r fdd7a698be01 -r 7d5860add50f include/urweb.h --- a/include/urweb.h Tue Sep 02 17:31:45 2008 -0400 +++ b/include/urweb.h Thu Sep 04 10:27:21 2008 -0400 @@ -60,4 +60,7 @@ lw_Basis_string lw_Basis_strcat(lw_context, lw_Basis_string, lw_Basis_string); lw_Basis_string lw_Basis_strdup(lw_context, lw_Basis_string); +lw_Basis_int lw_Basis_sqlifyInt(lw_context, lw_Basis_int); +lw_Basis_float lw_Basis_sqlifyFloat(lw_context, lw_Basis_float); lw_Basis_string lw_Basis_sqlifyString(lw_context, lw_Basis_string); +lw_Basis_bool lw_Basis_sqlifyBool(lw_context, lw_Basis_bool); diff -r fdd7a698be01 -r 7d5860add50f src/c/urweb.c --- a/src/c/urweb.c Tue Sep 02 17:31:45 2008 -0400 +++ b/src/c/urweb.c Thu Sep 04 10:27:21 2008 -0400 @@ -591,10 +591,33 @@ } +char *lw_Basis_sqlifyInt(lw_context ctx, lw_Basis_int n) { + int len; + char *r; + + lw_check_heap(ctx, INTS_MAX + 6); + r = ctx->heap_front; + sprintf(r, "%lld::int8%n", n, &len); + ctx->heap_front += len+1; + return r; +} + +char *lw_Basis_sqlifyFloat(lw_context ctx, lw_Basis_float n) { + int len; + char *r; + + lw_check_heap(ctx, FLOATS_MAX + 8); + r = ctx->heap_front; + sprintf(r, "%g::float8%n", n, &len); + ctx->heap_front += len+1; + return r; +} + + lw_Basis_string lw_Basis_sqlifyString(lw_context ctx, lw_Basis_string s) { char *r, *s2; - lw_check_heap(ctx, strlen(s) * 2 + 4); + lw_check_heap(ctx, strlen(s) * 2 + 10); r = s2 = ctx->heap_front; *s2++ = 'E'; @@ -622,8 +645,14 @@ } } - *s2++ = '\''; - *s2++ = 0; - ctx->heap_front = s2; + strcpy(s2, "'::text"); + ctx->heap_front = s2 + 8; return r; } + +char *lw_Basis_sqlifyBool(lw_context ctx, lw_Basis_bool b) { + if (b == lw_Basis_False) + return "FALSE"; + else + return "TRUE"; +} diff -r fdd7a698be01 -r 7d5860add50f src/mono_opt.sml --- a/src/mono_opt.sml Tue Sep 02 17:31:45 2008 -0400 +++ b/src/mono_opt.sml Thu Sep 04 10:27:21 2008 -0400 @@ -81,12 +81,12 @@ "%" ^ hexIt ch) -val sqlifyInt = attrifyInt -val sqlifyFloat = attrifyFloat +fun sqlifyInt n = attrifyInt n ^ "::int8" +fun sqlifyFloat n = attrifyFloat n ^ "::float8" fun sqlifyString s = "E'" ^ String.translate (fn #"'" => "\\'" | ch => str ch) - (String.toString s) ^ "'" + (String.toString s) ^ "'::text" fun exp e = case e of