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 | |
parent | 9d38076e9a1dc49faec13596a2f707269c2a0ad7 (diff) |
Fix generation of timestamp literals for MySQL and SQLite
Diffstat (limited to 'src')
-rw-r--r-- | src/c/urweb.c | 17 | ||||
-rw-r--r-- | src/mysql.sml | 2 | ||||
-rw-r--r-- | src/postgres.sml | 2 | ||||
-rw-r--r-- | src/sqlite.sml | 2 |
4 files changed, 17 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 diff --git a/src/mysql.sml b/src/mysql.sml index 1a641d57..999a9ea3 100644 --- a/src/mysql.sml +++ b/src/mysql.sml @@ -389,6 +389,8 @@ fun init {dbstring, prepared = ss, tables, views, sequences} = newline, string "uw_Estrings = 0;", newline, + string "uw_sql_type_annotations = 0;", + newline, string "uw_sqlsuffixString = \"\";", newline, string "uw_sqlsuffixChar = \"\";", diff --git a/src/postgres.sml b/src/postgres.sml index e555c565..ce7a78dd 100644 --- a/src/postgres.sml +++ b/src/postgres.sml @@ -380,6 +380,8 @@ fun init {dbstring, prepared = ss, tables, views, sequences} = newline, string "uw_Estrings = 1;", newline, + string "uw_sql_type_annotations = 1;", + newline, string "uw_sqlsuffixString = \"::text\";", newline, string "uw_sqlsuffixChar = \"::char\";", diff --git a/src/sqlite.sml b/src/sqlite.sml index 0f83c967..4ec64788 100644 --- a/src/sqlite.sml +++ b/src/sqlite.sml @@ -164,6 +164,8 @@ fun init {dbstring, prepared = ss, tables, views, sequences} = newline, string "uw_Estrings = 0;", newline, + string "uw_sql_type_annotations = 0;", + newline, string "uw_sqlsuffixString = \"\";", newline, string "uw_sqlsuffixChar = \"\";", |