comparison src/postgres.sml @ 879:b2a175a0f2ef

Demo working with MySQL
author Adam Chlipala <adamc@hcoop.net>
date Thu, 16 Jul 2009 18:10:29 -0400
parents a8952047e1d3
children 8e9f2d247dba
comparison
equal deleted inserted replaced
878:a8952047e1d3 879:b2a175a0f2ef
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 "void uw_client_init(void) { }", 250 box [string "void uw_client_init(void) {",
251 newline,
252 box [string "uw_sqlfmtInt = \"%lld::int8%n\";",
253 newline,
254 string "uw_sqlfmtFloat = \"%g::float8%n\";",
255 newline,
256 string "uw_Estrings = 1;",
257 newline,
258 string "uw_sqlsuffixString = \"::text\";",
259 newline,
260 string "uw_sqlsuffixBlob = \"::bytea\";",
261 newline,
262 string "uw_sqlfmtUint4 = \"%u::int4%n\";",
263 newline],
264 string "}",
251 newline, 265 newline,
252 newline, 266 newline,
253 267
254 string "static void uw_db_validate(uw_context ctx) {", 268 string "static void uw_db_validate(uw_context ctx) {",
255 newline, 269 newline,
637 e, 651 e,
638 string " == NULL ? NULL : ", 652 string " == NULL ? NULL : ",
639 p_ensql t (box [string "(*", e, string ")"]), 653 p_ensql t (box [string "(*", e, string ")"]),
640 string ")"] 654 string ")"]
641 655
642 fun queryPrepared {loc, id, query, inputs, cols, doCols} = 656 fun queryPrepared {loc, id, query, inputs, cols, doCols, nested = _} =
643 box [string "PGconn *conn = uw_get_db(ctx);", 657 box [string "PGconn *conn = uw_get_db(ctx);",
644 newline, 658 newline,
645 string "const int paramFormats[] = { ", 659 string "const int paramFormats[] = { ",
646 p_list_sep (box [string ",", space]) 660 p_list_sep (box [string ",", space])
647 (fn t => if isBlob t then string "1" else string "0") inputs, 661 (fn t => if isBlob t then string "1" else string "0") inputs,
780 newline], 794 newline],
781 string "}", 795 string "}",
782 newline, 796 newline,
783 newline, 797 newline,
784 798
785 string "uw_end_region(ctx);",
786 newline,
787 string "n = PQntuples(res);", 799 string "n = PQntuples(res);",
788 newline, 800 newline,
789 string "if (n != 1) {", 801 string "if (n != 1) {",
790 newline, 802 newline,
791 box [string "PQclear(res);", 803 box [string "PQclear(res);",
809 821
810 fun nextval {loc, seqE, seqName} = 822 fun nextval {loc, seqE, seqName} =
811 let 823 let
812 val query = case seqName of 824 val query = case seqName of
813 SOME s => 825 SOME s =>
814 string ("SELECT NEXTVAL('" ^ s ^ "')") 826 string ("\"SELECT NEXTVAL('" ^ s ^ "')\"")
815 | _ => box [string "uw_Basis_strcat(ctx, \"SELECT NEXTVAL('\", uw_Basis_strcat(ctx, ", 827 | _ => box [string "uw_Basis_strcat(ctx, \"SELECT NEXTVAL('\", uw_Basis_strcat(ctx, ",
816 seqE, 828 seqE,
817 string ", \"')\"))"] 829 string ", \"')\"))"]
818 in 830 in
819 box [string "char *query = ", 831 box [string "char *query = ",
876 p_cast = p_cast, 888 p_cast = p_cast,
877 p_blank = p_blank, 889 p_blank = p_blank,
878 supportsDeleteAs = true, 890 supportsDeleteAs = true,
879 createSequence = fn s => "CREATE SEQUENCE " ^ s, 891 createSequence = fn s => "CREATE SEQUENCE " ^ s,
880 textKeysNeedLengths = false, 892 textKeysNeedLengths = false,
881 supportsNextval = true} 893 supportsNextval = true,
894 supportsNestedPrepared = true}
882 895
883 val () = setDbms "postgres" 896 val () = setDbms "postgres"
884 897
885 end 898 end