# HG changeset patch # User Adam Chlipala # Date 1354287000 18000 # Node ID 690638bd9fefec7b83eaa28d9ccca1ede9805d7a # Parent be0c4e2e488abb8620be8260c2b10c1d865c2301 Fix generation of timestamp literals for MySQL and SQLite diff -r be0c4e2e488a -r 690638bd9fef include/urweb/urweb.h --- a/include/urweb/urweb.h Wed Nov 28 16:56:45 2012 -0500 +++ b/include/urweb/urweb.h Fri Nov 30 09:50:00 2012 -0500 @@ -273,7 +273,7 @@ extern char *uw_sqlfmtInt; extern char *uw_sqlfmtFloat; -extern int uw_Estrings; +extern int uw_Estrings, uw_sql_type_annotations; extern char *uw_sqlsuffixString; extern char *uw_sqlsuffixChar; extern char *uw_sqlsuffixBlob; diff -r be0c4e2e488a -r 690638bd9fef src/c/urweb.c --- 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 diff -r be0c4e2e488a -r 690638bd9fef src/mysql.sml --- a/src/mysql.sml Wed Nov 28 16:56:45 2012 -0500 +++ b/src/mysql.sml Fri Nov 30 09:50:00 2012 -0500 @@ -389,6 +389,8 @@ newline, string "uw_Estrings = 0;", newline, + string "uw_sql_type_annotations = 0;", + newline, string "uw_sqlsuffixString = \"\";", newline, string "uw_sqlsuffixChar = \"\";", diff -r be0c4e2e488a -r 690638bd9fef src/postgres.sml --- a/src/postgres.sml Wed Nov 28 16:56:45 2012 -0500 +++ b/src/postgres.sml Fri Nov 30 09:50:00 2012 -0500 @@ -380,6 +380,8 @@ newline, string "uw_Estrings = 1;", newline, + string "uw_sql_type_annotations = 1;", + newline, string "uw_sqlsuffixString = \"::text\";", newline, string "uw_sqlsuffixChar = \"::char\";", diff -r be0c4e2e488a -r 690638bd9fef src/sqlite.sml --- a/src/sqlite.sml Wed Nov 28 16:56:45 2012 -0500 +++ b/src/sqlite.sml Fri Nov 30 09:50:00 2012 -0500 @@ -164,6 +164,8 @@ newline, string "uw_Estrings = 0;", newline, + string "uw_sql_type_annotations = 0;", + newline, string "uw_sqlsuffixString = \"\";", newline, string "uw_sqlsuffixChar = \"\";", diff -r be0c4e2e488a -r 690638bd9fef tests/timestamp.ur --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/timestamp.ur Fri Nov 30 09:50:00 2012 -0500 @@ -0,0 +1,11 @@ +table t : { A : time } + +fun many ls = + case ls of + [] => (WHERE TRUE) + | tm :: ls' => (WHERE t.A = {[tm]} AND {many ls'}) + +task initialize = fn () => + tm <- now; + dml (DELETE FROM t WHERE {many (tm :: [])}) + diff -r be0c4e2e488a -r 690638bd9fef tests/timestamp.urp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/timestamp.urp Fri Nov 30 09:50:00 2012 -0500 @@ -0,0 +1,5 @@ +database dbname=test +dbms mysql +sql timestamp.sql + +timestamp