diff options
author | Adam Chlipala <adam@chlipala.net> | 2012-11-30 09:50:00 -0500 |
---|---|---|
committer | Adam Chlipala <adam@chlipala.net> | 2012-11-30 09:50:00 -0500 |
commit | 89be6e97ad713323aaf23f866a7fe08303e7180f (patch) | |
tree | 29698fd52bc17d2863f259f785f28699e1e20418 /src/c | |
parent | 9d38076e9a1dc49faec13596a2f707269c2a0ad7 (diff) |
Fix generation of timestamp literals for MySQL and SQLite
Diffstat (limited to 'src/c')
-rw-r--r-- | src/c/urweb.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c index 3a0af564..61fee786 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -2415,7 +2415,7 @@ char *uw_Basis_sqlifyFloatN(uw_context ctx, uw_Basis_float *n) { return uw_Basis_sqlifyFloat(ctx, *n); } -int uw_Estrings = 1; +int uw_Estrings = 1, uw_sql_type_annotations = 1; char *uw_sqlsuffixString = "::text"; char *uw_sqlsuffixChar = "::char"; @@ -2634,12 +2634,17 @@ char *uw_Basis_sqlifyTime(uw_context ctx, uw_Basis_time t) { if (localtime_r(&t.seconds, &stm)) { s = uw_malloc(ctx, TIMES_MAX); len = strftime(s, TIMES_MAX, TIME_FMT_PG, &stm); - if (t.microseconds) { - r = uw_malloc(ctx, len + 21); - sprintf(r, "'%s.%06u'::timestamp", s, t.microseconds); + if (uw_sql_type_annotations) { + if (t.microseconds) { + r = uw_malloc(ctx, len + 21); + sprintf(r, "'%s.%06u'::timestamp", s, t.microseconds); + } else { + r = uw_malloc(ctx, len + 14); + sprintf(r, "'%s'::timestamp", s); + } } else { - r = uw_malloc(ctx, len + 14); - sprintf(r, "'%s'::timestamp", s); + r = uw_malloc(ctx, len + 3); + sprintf(r, "'%s'", s); } return r; } else |