diff src/c/urweb.c @ 1866:9fc086e3c95a

Add hex SQL syntax for blobs, such as X'0ABC12343'. Works with sqlite.
author Sergey Mironov <grrwlf@gmail.com>
date Fri, 13 Sep 2013 10:09:15 -0400
parents 79c0c22e13ae
children 216a3a67ebe3
line wrap: on
line diff
--- a/src/c/urweb.c	Mon Aug 19 12:38:43 2013 -0400
+++ b/src/c/urweb.c	Fri Sep 13 10:09:15 2013 -0400
@@ -2509,7 +2509,7 @@
 
 char *uw_sqlsuffixBlob = "::bytea";
 
-uw_Basis_string uw_Basis_sqlifyBlob(uw_context ctx, uw_Basis_blob b) {
+uw_Basis_string uw_Basis_sqlifyBlob_old(uw_context ctx, uw_Basis_blob b) {
   char *r, *s2;
   size_t i;
 
@@ -2556,6 +2556,29 @@
   return r;
 }
 
+int uw_Xstrings = 1;
+
+uw_Basis_string uw_Basis_sqlifyBlob(uw_context ctx, uw_Basis_blob b) {
+  char *r, *s2;
+  size_t i;
+
+  uw_check_heap(ctx, b.size * 2 + 3 + uw_Xstrings);
+
+  r = s2 = ctx->heap.front;
+  *s2++ = 'X';
+  *s2++ = '\'';
+
+  for (i = 0; i < b.size; ++i) {
+    char c = b.data[i];
+    sprintf(s2, "%02X", c);
+    s2 += 2;
+  }
+
+  *s2++ = '\'';
+  ctx->heap.front = s2 + 1;
+  return r;
+}
+
 char *uw_Basis_sqlifyChannel(uw_context ctx, uw_Basis_channel chn) {
   int len;
   char *r;