Mercurial > urweb
comparison src/postgres.sml @ 874:3c7b48040dcf
MySQL demo/sql succeeds in reading no rows
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sun, 12 Jul 2009 15:05:40 -0400 |
parents | 41971801b62d |
children | 025806b3c014 |
comparison
equal
deleted
inserted
replaced
873:41971801b62d | 874:3c7b48040dcf |
---|---|
245 newline] | 245 newline] |
246 end | 246 end |
247 | 247 |
248 fun init {dbstring, prepared = ss, tables, views, sequences} = | 248 fun init {dbstring, prepared = ss, tables, views, sequences} = |
249 box [if #persistent (currentProtocol ()) then | 249 box [if #persistent (currentProtocol ()) then |
250 box [string "static void uw_db_validate(uw_context ctx) {", | 250 box [string "void uw_client_init() { }", |
251 newline, | |
252 newline, | |
253 | |
254 string "static void uw_db_validate(uw_context ctx) {", | |
251 newline, | 255 newline, |
252 string "PGconn *conn = uw_get_db(ctx);", | 256 string "PGconn *conn = uw_get_db(ctx);", |
253 newline, | 257 newline, |
254 string "PGresult *res;", | 258 string "PGresult *res;", |
255 newline, | 259 newline, |
507 string ") ? NULL : ", | 511 string ") ? NULL : ", |
508 case t of | 512 case t of |
509 String => getter t | 513 String => getter t |
510 | _ => box [string "({", | 514 | _ => box [string "({", |
511 newline, | 515 newline, |
512 string (p_sql_type t), | 516 string (p_sql_ctype t), |
513 space, | 517 space, |
514 string "*tmp = uw_malloc(ctx, sizeof(", | 518 string "*tmp = uw_malloc(ctx, sizeof(", |
515 string (p_sql_type t), | 519 string (p_sql_ctype t), |
516 string "));", | 520 string "));", |
517 newline, | 521 newline, |
518 string "*tmp = ", | 522 string "*tmp = ", |
519 getter t, | 523 getter t, |
520 string ";", | 524 string ";", |
526 | _ => | 530 | _ => |
527 box [string "(PQgetisnull(res, i, ", | 531 box [string "(PQgetisnull(res, i, ", |
528 string (Int.toString i), | 532 string (Int.toString i), |
529 string ") ? ", | 533 string ") ? ", |
530 box [string "({", | 534 box [string "({", |
531 string (p_sql_type t), | 535 string (p_sql_ctype t), |
532 space, | 536 space, |
533 string "tmp;", | 537 string "tmp;", |
534 newline, | 538 newline, |
535 string "uw_error(ctx, FATAL, \"Unexpectedly NULL field #", | 539 string "uw_error(ctx, FATAL, \"Unexpectedly NULL field #", |
536 string (Int.toString i), | 540 string (Int.toString i), |
826 newline, | 830 newline, |
827 nextvalCommon {loc = loc, query = box [string "\"", | 831 nextvalCommon {loc = loc, query = box [string "\"", |
828 string (String.toString query), | 832 string (String.toString query), |
829 string "\""]}] | 833 string "\""]}] |
830 | 834 |
835 fun sqlifyString s = "E'" ^ String.translate (fn #"'" => "\\'" | |
836 | #"\\" => "\\\\" | |
837 | ch => | |
838 if Char.isPrint ch then | |
839 str ch | |
840 else | |
841 "\\" ^ StringCvt.padLeft #"0" 3 | |
842 (Int.fmt StringCvt.OCT (ord ch))) | |
843 (String.toString s) ^ "'::text" | |
844 | |
845 fun p_cast (s, t) = s ^ "::" ^ p_sql_type t | |
846 | |
847 fun p_blank (n, t) = p_cast ("$" ^ Int.toString n, t) | |
848 | |
831 val () = addDbms {name = "postgres", | 849 val () = addDbms {name = "postgres", |
832 header = "postgresql/libpq-fe.h", | 850 header = "postgresql/libpq-fe.h", |
833 link = "-lpq", | 851 link = "-lpq", |
834 global_init = box [string "void uw_client_init() { }", | |
835 newline], | |
836 p_sql_type = p_sql_type, | 852 p_sql_type = p_sql_type, |
837 init = init, | 853 init = init, |
838 query = query, | 854 query = query, |
839 queryPrepared = queryPrepared, | 855 queryPrepared = queryPrepared, |
840 dml = dml, | 856 dml = dml, |
841 dmlPrepared = dmlPrepared, | 857 dmlPrepared = dmlPrepared, |
842 nextval = nextval, | 858 nextval = nextval, |
843 nextvalPrepared = nextvalPrepared} | 859 nextvalPrepared = nextvalPrepared, |
860 sqlifyString = sqlifyString, | |
861 p_cast = p_cast, | |
862 p_blank = p_blank, | |
863 supportsDeleteAs = true} | |
864 | |
844 val () = setDbms "postgres" | 865 val () = setDbms "postgres" |
845 | 866 |
846 end | 867 end |