comparison src/c/urweb.c @ 1834:690638bd9fef

Fix generation of timestamp literals for MySQL and SQLite
author Adam Chlipala <adam@chlipala.net>
date Fri, 30 Nov 2012 09:50:00 -0500
parents 5c51ae0d643b
children 79c0c22e13ae
comparison
equal deleted inserted replaced
1833:be0c4e2e488a 1834:690638bd9fef
2413 return "NULL"; 2413 return "NULL";
2414 else 2414 else
2415 return uw_Basis_sqlifyFloat(ctx, *n); 2415 return uw_Basis_sqlifyFloat(ctx, *n);
2416 } 2416 }
2417 2417
2418 int uw_Estrings = 1; 2418 int uw_Estrings = 1, uw_sql_type_annotations = 1;
2419 char *uw_sqlsuffixString = "::text"; 2419 char *uw_sqlsuffixString = "::text";
2420 char *uw_sqlsuffixChar = "::char"; 2420 char *uw_sqlsuffixChar = "::char";
2421 2421
2422 uw_Basis_string uw_Basis_sqlifyString(uw_context ctx, uw_Basis_string s) { 2422 uw_Basis_string uw_Basis_sqlifyString(uw_context ctx, uw_Basis_string s) {
2423 char *r, *s2; 2423 char *r, *s2;
2632 stm.tm_isdst = -1; 2632 stm.tm_isdst = -1;
2633 2633
2634 if (localtime_r(&t.seconds, &stm)) { 2634 if (localtime_r(&t.seconds, &stm)) {
2635 s = uw_malloc(ctx, TIMES_MAX); 2635 s = uw_malloc(ctx, TIMES_MAX);
2636 len = strftime(s, TIMES_MAX, TIME_FMT_PG, &stm); 2636 len = strftime(s, TIMES_MAX, TIME_FMT_PG, &stm);
2637 if (t.microseconds) { 2637 if (uw_sql_type_annotations) {
2638 r = uw_malloc(ctx, len + 21); 2638 if (t.microseconds) {
2639 sprintf(r, "'%s.%06u'::timestamp", s, t.microseconds); 2639 r = uw_malloc(ctx, len + 21);
2640 sprintf(r, "'%s.%06u'::timestamp", s, t.microseconds);
2641 } else {
2642 r = uw_malloc(ctx, len + 14);
2643 sprintf(r, "'%s'::timestamp", s);
2644 }
2640 } else { 2645 } else {
2641 r = uw_malloc(ctx, len + 14); 2646 r = uw_malloc(ctx, len + 3);
2642 sprintf(r, "'%s'::timestamp", s); 2647 sprintf(r, "'%s'", s);
2643 } 2648 }
2644 return r; 2649 return r;
2645 } else 2650 } else
2646 return "<Invalid time>"; 2651 return "<Invalid time>";
2647 } 2652 }