diff src/c/urweb.c @ 280:fdd7a698be01

Compiling a parametrized query the inefficient way
author Adam Chlipala <adamc@hcoop.net>
date Tue, 02 Sep 2008 17:31:45 -0400
parents 137744c5b1ae
children 7d5860add50f
line wrap: on
line diff
--- a/src/c/urweb.c	Tue Sep 02 16:18:05 2008 -0400
+++ b/src/c/urweb.c	Tue Sep 02 17:31:45 2008 -0400
@@ -589,3 +589,41 @@
 
   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;
+}