summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2010-12-24 17:18:28 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2010-12-24 17:18:28 -0500
commita6c580af25ee9e6112fcb116d9b0d2a09d2ea7cf (patch)
treeefe3e97abebe7dfe38aa2de03b5511d62c1d028c
parent466c2aa7a9c1f5bba2ad8630d55e2c2989216091 (diff)
Fix Postgres date serialization
-rw-r--r--include/urweb.h1
-rw-r--r--src/c/urweb.c17
-rw-r--r--src/postgres.sml2
3 files changed, 18 insertions, 2 deletions
diff --git a/include/urweb.h b/include/urweb.h
index c52e1c26..f0c14d85 100644
--- a/include/urweb.h
+++ b/include/urweb.h
@@ -165,6 +165,7 @@ uw_Basis_string uw_Basis_sqlifyBoolN(uw_context, uw_Basis_bool*);
uw_Basis_string uw_Basis_sqlifyTimeN(uw_context, uw_Basis_time*);
char *uw_Basis_ensqlBool(uw_Basis_bool);
+char *uw_Basis_ensqlTime(uw_context ctx, uw_Basis_time);
char *uw_Basis_jsifyString(uw_context, uw_Basis_string);
char *uw_Basis_jsifyChar(uw_context, uw_Basis_char);
diff --git a/src/c/urweb.c b/src/c/urweb.c
index 77d39ee7..4038c100 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -2513,7 +2513,7 @@ char *uw_Basis_sqlifyTime(uw_context ctx, uw_Basis_time t) {
if (localtime_r(&t, &stm)) {
s = uw_malloc(ctx, TIMES_MAX);
- len = strftime(s, TIMES_MAX, TIME_FMT, &stm);
+ len = strftime(s, TIMES_MAX, TIME_FMT_PG, &stm);
r = uw_malloc(ctx, len + 14);
sprintf(r, "'%s'::timestamp", s);
return r;
@@ -2536,6 +2536,21 @@ char *uw_Basis_attrifyTime(uw_context ctx, uw_Basis_time t) {
return "<Invalid time>";
}
+char *uw_Basis_ensqlTime(uw_context ctx, uw_Basis_time t) {
+ size_t len;
+ char *r;
+ struct tm stm;
+
+ if (localtime_r(&t, &stm)) {
+ uw_check_heap(ctx, TIMES_MAX);
+ r = ctx->heap.front;
+ len = strftime(r, TIMES_MAX, TIME_FMT_PG, &stm);
+ ctx->heap.front += len+1;
+ return r;
+ } else
+ return "<Invalid time>";
+}
+
char *uw_Basis_sqlifyTimeN(uw_context ctx, uw_Basis_time *t) {
if (t == NULL)
return "NULL";
diff --git a/src/postgres.sml b/src/postgres.sml
index 0acd1bf3..7209f34a 100644
--- a/src/postgres.sml
+++ b/src/postgres.sml
@@ -654,7 +654,7 @@ fun p_ensql t e =
| String => e
| Char => box [string "uw_Basis_attrifyChar(ctx, ", e, string ")"]
| Bool => box [string "(", e, string " ? \"TRUE\" : \"FALSE\")"]
- | Time => box [string "uw_Basis_attrifyTime(ctx, ", e, string ")"]
+ | Time => box [string "uw_Basis_ensqlTime(ctx, ", e, string ")"]
| Blob => box [e, string ".data"]
| Channel => box [string "uw_Basis_attrifyChannel(ctx, ", e, string ")"]
| Client => box [string "uw_Basis_attrifyClient(ctx, ", e, string ")"]