Mercurial > urweb
changeset 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 | be0c4e2e488a |
children | a8b273f1f7e3 |
files | include/urweb/urweb.h src/c/urweb.c src/mysql.sml src/postgres.sml src/sqlite.sml tests/timestamp.ur tests/timestamp.urp |
diffstat | 7 files changed, 34 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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;
--- 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
--- 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 = \"\";",
--- 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\";",
--- 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 = \"\";",
--- /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 :: [])}) +