comparison src/c/urweb.c @ 1364:0dec38af601c

Fix Postgres date serialization
author Adam Chlipala <adam@chlipala.net>
date Fri, 24 Dec 2010 17:18:28 -0500
parents 7dd8a6704265
children b02cb9da5686
comparison
equal deleted inserted replaced
1363:7dd8a6704265 1364:0dec38af601c
2511 char *r, *s; 2511 char *r, *s;
2512 struct tm stm; 2512 struct tm stm;
2513 2513
2514 if (localtime_r(&t, &stm)) { 2514 if (localtime_r(&t, &stm)) {
2515 s = uw_malloc(ctx, TIMES_MAX); 2515 s = uw_malloc(ctx, TIMES_MAX);
2516 len = strftime(s, TIMES_MAX, TIME_FMT, &stm); 2516 len = strftime(s, TIMES_MAX, TIME_FMT_PG, &stm);
2517 r = uw_malloc(ctx, len + 14); 2517 r = uw_malloc(ctx, len + 14);
2518 sprintf(r, "'%s'::timestamp", s); 2518 sprintf(r, "'%s'::timestamp", s);
2519 return r; 2519 return r;
2520 } else 2520 } else
2521 return "<Invalid time>"; 2521 return "<Invalid time>";
2528 2528
2529 if (localtime_r(&t, &stm)) { 2529 if (localtime_r(&t, &stm)) {
2530 uw_check_heap(ctx, TIMES_MAX); 2530 uw_check_heap(ctx, TIMES_MAX);
2531 r = ctx->heap.front; 2531 r = ctx->heap.front;
2532 len = strftime(r, TIMES_MAX, TIME_FMT, &stm); 2532 len = strftime(r, TIMES_MAX, TIME_FMT, &stm);
2533 ctx->heap.front += len+1;
2534 return r;
2535 } else
2536 return "<Invalid time>";
2537 }
2538
2539 char *uw_Basis_ensqlTime(uw_context ctx, uw_Basis_time t) {
2540 size_t len;
2541 char *r;
2542 struct tm stm;
2543
2544 if (localtime_r(&t, &stm)) {
2545 uw_check_heap(ctx, TIMES_MAX);
2546 r = ctx->heap.front;
2547 len = strftime(r, TIMES_MAX, TIME_FMT_PG, &stm);
2533 ctx->heap.front += len+1; 2548 ctx->heap.front += len+1;
2534 return r; 2549 return r;
2535 } else 2550 } else
2536 return "<Invalid time>"; 2551 return "<Invalid time>";
2537 } 2552 }