# HG changeset patch # User Adam Chlipala # Date 1293229108 18000 # Node ID 0dec38af601c2b866c3dde2a87dad628de3bc901 # Parent 7dd8a67042652fee039e20c93086c10f6ef1a535 Fix Postgres date serialization diff -r 7dd8a6704265 -r 0dec38af601c include/urweb.h --- a/include/urweb.h Fri Dec 24 16:41:10 2010 -0500 +++ b/include/urweb.h Fri Dec 24 17:18:28 2010 -0500 @@ -165,6 +165,7 @@ 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 -r 7dd8a6704265 -r 0dec38af601c src/c/urweb.c --- a/src/c/urweb.c Fri Dec 24 16:41:10 2010 -0500 +++ b/src/c/urweb.c Fri Dec 24 17:18:28 2010 -0500 @@ -2513,7 +2513,7 @@ 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 @@ return ""; } +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 ""; +} + char *uw_Basis_sqlifyTimeN(uw_context ctx, uw_Basis_time *t) { if (t == NULL) return "NULL"; diff -r 7dd8a6704265 -r 0dec38af601c src/postgres.sml --- a/src/postgres.sml Fri Dec 24 16:41:10 2010 -0500 +++ b/src/postgres.sml Fri Dec 24 17:18:28 2010 -0500 @@ -654,7 +654,7 @@ | 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 ")"]