Mercurial > urweb
comparison src/c/urweb.c @ 281:7d5860add50f
Change sqlify[int|float|string] to annotate with SQL types
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 04 Sep 2008 10:27:21 -0400 |
parents | fdd7a698be01 |
children | 0236d9412ad2 |
comparison
equal
deleted
inserted
replaced
280:fdd7a698be01 | 281:7d5860add50f |
---|---|
589 | 589 |
590 return s; | 590 return s; |
591 } | 591 } |
592 | 592 |
593 | 593 |
594 char *lw_Basis_sqlifyInt(lw_context ctx, lw_Basis_int n) { | |
595 int len; | |
596 char *r; | |
597 | |
598 lw_check_heap(ctx, INTS_MAX + 6); | |
599 r = ctx->heap_front; | |
600 sprintf(r, "%lld::int8%n", n, &len); | |
601 ctx->heap_front += len+1; | |
602 return r; | |
603 } | |
604 | |
605 char *lw_Basis_sqlifyFloat(lw_context ctx, lw_Basis_float n) { | |
606 int len; | |
607 char *r; | |
608 | |
609 lw_check_heap(ctx, FLOATS_MAX + 8); | |
610 r = ctx->heap_front; | |
611 sprintf(r, "%g::float8%n", n, &len); | |
612 ctx->heap_front += len+1; | |
613 return r; | |
614 } | |
615 | |
616 | |
594 lw_Basis_string lw_Basis_sqlifyString(lw_context ctx, lw_Basis_string s) { | 617 lw_Basis_string lw_Basis_sqlifyString(lw_context ctx, lw_Basis_string s) { |
595 char *r, *s2; | 618 char *r, *s2; |
596 | 619 |
597 lw_check_heap(ctx, strlen(s) * 2 + 4); | 620 lw_check_heap(ctx, strlen(s) * 2 + 10); |
598 | 621 |
599 r = s2 = ctx->heap_front; | 622 r = s2 = ctx->heap_front; |
600 *s2++ = 'E'; | 623 *s2++ = 'E'; |
601 *s2++ = '\''; | 624 *s2++ = '\''; |
602 | 625 |
620 s2 += 4; | 643 s2 += 4; |
621 } | 644 } |
622 } | 645 } |
623 } | 646 } |
624 | 647 |
625 *s2++ = '\''; | 648 strcpy(s2, "'::text"); |
626 *s2++ = 0; | 649 ctx->heap_front = s2 + 8; |
627 ctx->heap_front = s2; | 650 return r; |
628 return r; | 651 } |
629 } | 652 |
653 char *lw_Basis_sqlifyBool(lw_context ctx, lw_Basis_bool b) { | |
654 if (b == lw_Basis_False) | |
655 return "FALSE"; | |
656 else | |
657 return "TRUE"; | |
658 } |