Mercurial > urweb
diff src/c/urweb.c @ 1867:216a3a67ebe3
Tweak Sergey's patch to work with Postgres
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Fri, 13 Sep 2013 10:24:10 -0400 |
parents | 9fc086e3c95a |
children | 22b44fe822bf |
line wrap: on
line diff
--- a/src/c/urweb.c Fri Sep 13 10:09:15 2013 -0400 +++ b/src/c/urweb.c Fri Sep 13 10:24:10 2013 -0400 @@ -2509,46 +2509,45 @@ char *uw_sqlsuffixBlob = "::bytea"; -uw_Basis_string uw_Basis_sqlifyBlob_old(uw_context ctx, uw_Basis_blob b) { +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 * 5 + 3 + uw_Estrings + strlen(uw_sqlsuffixBlob)); + uw_check_heap(ctx, b.size * 5 + 4 + strlen(uw_sqlsuffixBlob)); r = s2 = ctx->heap.front; if (uw_Estrings) *s2++ = 'E'; + else + *s2++ = 'X'; *s2++ = '\''; for (i = 0; i < b.size; ++i) { - char c = b.data[i]; - - switch (c) { - case '\'': - if (uw_Estrings) + unsigned char c = b.data[i]; + + if (uw_Estrings) { + switch (c) { + case '\'': strcpy(s2, "\\'"); - else - strcpy(s2, "''"); - s2 += 2; - break; - case '\\': - if (uw_Estrings) { + s2 += 2; + break; + case '\\': strcpy(s2, "\\\\\\\\"); s2 += 4; - } else - *s2++ = '\\'; - break; - default: - if (isprint((int)c)) - *s2++ = c; - else if (uw_Estrings) { - sprintf(s2, "\\\\%03o", c); - s2 += 5; + break; + default: + if (isprint((int)c)) + *s2++ = c; + else { + sprintf(s2, "\\\\%03o", c); + s2 += 5; + } } - else - uw_error(ctx, FATAL, "Non-printable character %u in blob to SQLify", c); + } else { + sprintf(s2, "%02X", c); + s2 += 2; } - } + } *s2++ = '\''; strcpy(s2, uw_sqlsuffixBlob); @@ -2556,29 +2555,6 @@ 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;