summaryrefslogtreecommitdiff
path: root/src/c
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2008-09-02 17:31:45 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2008-09-02 17:31:45 -0400
commitab29ac3337d2be88ae3288652e999873be1dcf14 (patch)
treed3816565ec3c8518bb73979bd5957e8d324375f9 /src/c
parent5885d66bebeece6ba2f7b6a1b11f719086423114 (diff)
Compiling a parametrized query the inefficient way
Diffstat (limited to 'src/c')
-rw-r--r--src/c/urweb.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c
index f0e93e46..57caa03d 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -589,3 +589,41 @@ lw_Basis_string lw_Basis_strdup(lw_context ctx, lw_Basis_string s1) {
return s;
}
+
+
+lw_Basis_string lw_Basis_sqlifyString(lw_context ctx, lw_Basis_string s) {
+ char *r, *s2;
+
+ lw_check_heap(ctx, strlen(s) * 2 + 4);
+
+ r = s2 = ctx->heap_front;
+ *s2++ = 'E';
+ *s2++ = '\'';
+
+ for (; *s; s++) {
+ char c = *s;
+
+ switch (c) {
+ case '\'':
+ strcpy(s2, "\\'");
+ s2 += 2;
+ break;
+ case '\\':
+ strcpy(s2, "\\\\");
+ s2 += 2;
+ break;
+ default:
+ if (isprint(c))
+ *s2++ = c;
+ else {
+ sprintf(s2, "\\%3o", c);
+ s2 += 4;
+ }
+ }
+ }
+
+ *s2++ = '\'';
+ *s2++ = 0;
+ ctx->heap_front = s2;
+ return r;
+}