summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/urweb.h3
-rw-r--r--src/c/urweb.c37
-rw-r--r--src/mono_opt.sml6
3 files changed, 39 insertions, 7 deletions
diff --git a/include/urweb.h b/include/urweb.h
index fd8660e6..059cea0d 100644
--- a/include/urweb.h
+++ b/include/urweb.h
@@ -60,4 +60,7 @@ lw_Basis_bool lw_Basis_unurlifyBool(lw_context, char **);
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 --git a/src/c/urweb.c b/src/c/urweb.c
index 57caa03d..c37393f2 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -591,10 +591,33 @@ lw_Basis_string lw_Basis_strdup(lw_context ctx, lw_Basis_string s1) {
}
+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 @@ lw_Basis_string lw_Basis_sqlifyString(lw_context ctx, lw_Basis_string s) {
}
}
- *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 --git a/src/mono_opt.sml b/src/mono_opt.sml
index 3946684a..8be532aa 100644
--- a/src/mono_opt.sml
+++ b/src/mono_opt.sml
@@ -81,12 +81,12 @@ val urlifyString = String.translate (fn #" " => "+"
"%" ^ 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