comparison 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
comparison
equal deleted inserted replaced
1865:5144e03ef603 1866:9fc086e3c95a
2507 return r; 2507 return r;
2508 } 2508 }
2509 2509
2510 char *uw_sqlsuffixBlob = "::bytea"; 2510 char *uw_sqlsuffixBlob = "::bytea";
2511 2511
2512 uw_Basis_string uw_Basis_sqlifyBlob(uw_context ctx, uw_Basis_blob b) { 2512 uw_Basis_string uw_Basis_sqlifyBlob_old(uw_context ctx, uw_Basis_blob b) {
2513 char *r, *s2; 2513 char *r, *s2;
2514 size_t i; 2514 size_t i;
2515 2515
2516 uw_check_heap(ctx, b.size * 5 + 3 + uw_Estrings + strlen(uw_sqlsuffixBlob)); 2516 uw_check_heap(ctx, b.size * 5 + 3 + uw_Estrings + strlen(uw_sqlsuffixBlob));
2517 2517
2554 strcpy(s2, uw_sqlsuffixBlob); 2554 strcpy(s2, uw_sqlsuffixBlob);
2555 ctx->heap.front = s2 + 1 + strlen(uw_sqlsuffixBlob); 2555 ctx->heap.front = s2 + 1 + strlen(uw_sqlsuffixBlob);
2556 return r; 2556 return r;
2557 } 2557 }
2558 2558
2559 int uw_Xstrings = 1;
2560
2561 uw_Basis_string uw_Basis_sqlifyBlob(uw_context ctx, uw_Basis_blob b) {
2562 char *r, *s2;
2563 size_t i;
2564
2565 uw_check_heap(ctx, b.size * 2 + 3 + uw_Xstrings);
2566
2567 r = s2 = ctx->heap.front;
2568 *s2++ = 'X';
2569 *s2++ = '\'';
2570
2571 for (i = 0; i < b.size; ++i) {
2572 char c = b.data[i];
2573 sprintf(s2, "%02X", c);
2574 s2 += 2;
2575 }
2576
2577 *s2++ = '\'';
2578 ctx->heap.front = s2 + 1;
2579 return r;
2580 }
2581
2559 char *uw_Basis_sqlifyChannel(uw_context ctx, uw_Basis_channel chn) { 2582 char *uw_Basis_sqlifyChannel(uw_context ctx, uw_Basis_channel chn) {
2560 int len; 2583 int len;
2561 char *r; 2584 char *r;
2562 unsigned long long combo = ((unsigned long long)chn.cli << 32) | chn.chn; 2585 unsigned long long combo = ((unsigned long long)chn.cli << 32) | chn.chn;
2563 2586