diff 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
line wrap: on
line diff
--- a/src/c/urweb.c	Wed Nov 28 16:56:45 2012 -0500
+++ b/src/c/urweb.c	Fri Nov 30 09:50:00 2012 -0500
@@ -2415,7 +2415,7 @@
     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 @@
   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