Mercurial > urweb
comparison src/postgres.sml @ 2270:1e3ba868f8bf
Merge.
author | Ziv Scully <ziv@mit.edu> |
---|---|
date | Mon, 19 Oct 2015 14:42:22 -0400 |
parents | 00cf8214c2e3 |
children | 251dd276f45f |
comparison
equal
deleted
inserted
replaced
2269:f7bc7c11a656 | 2270:1e3ba868f8bf |
---|---|
615 fun queryCommon {loc, query, cols, doCols} = | 615 fun queryCommon {loc, query, cols, doCols} = |
616 box [string "int n, i;", | 616 box [string "int n, i;", |
617 newline, | 617 newline, |
618 newline, | 618 newline, |
619 | 619 |
620 string "if (res == NULL) uw_error(ctx, FATAL, \"Out of memory allocating query result.\");", | 620 string "if (res == NULL) {", |
621 box [newline, | |
622 string "uw_try_reconnecting_and_restarting(ctx);", | |
623 newline, | |
624 string "uw_error(ctx, FATAL, \"Can't allocate query result; database server may be down.\");", | |
625 newline], | |
626 string "}", | |
621 newline, | 627 newline, |
622 newline, | 628 newline, |
623 | 629 |
624 string "if (PQresultStatus(res) != PGRES_TUPLES_OK) {", | 630 string "if (PQresultStatus(res) != PGRES_TUPLES_OK) {", |
625 newline, | 631 newline, |
780 queryCommon {loc = loc, cols = cols, doCols = doCols, query = box [string "\"", | 786 queryCommon {loc = loc, cols = cols, doCols = doCols, query = box [string "\"", |
781 string (Prim.toCString query), | 787 string (Prim.toCString query), |
782 string "\""]}] | 788 string "\""]}] |
783 | 789 |
784 fun dmlCommon {loc, dml, mode} = | 790 fun dmlCommon {loc, dml, mode} = |
785 box [string "if (res == NULL) uw_error(ctx, FATAL, \"Out of memory allocating DML result.\");", | 791 box [string "if (res == NULL) {", |
792 box [newline, | |
793 string "uw_try_reconnecting_and_restarting(ctx);", | |
794 newline, | |
795 string "uw_error(ctx, FATAL, \"Can't allocate DML result; database server may be down.\");", | |
796 newline], | |
797 string "}", | |
786 newline, | 798 newline, |
787 newline, | 799 newline, |
788 | 800 |
789 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {", | 801 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {", |
790 newline, | 802 newline, |
816 newline, | 828 newline, |
817 newline, | 829 newline, |
818 | 830 |
819 string "res = PQexec(conn, \"ROLLBACK TO s\");", | 831 string "res = PQexec(conn, \"ROLLBACK TO s\");", |
820 newline, | 832 newline, |
821 string "if (res == NULL) uw_error(ctx, FATAL, \"Out of memory allocating DML result.\");", | 833 string "if (res == NULL) {", |
834 box [newline, | |
835 string "uw_try_reconnecting_and_restarting(ctx);", | |
836 newline, | |
837 string "uw_error(ctx, FATAL, \"Can't allocate DML ROLLBACK result; database server may be down.\");", | |
838 newline], | |
839 string "}", | |
822 newline, | 840 newline, |
823 newline, | 841 newline, |
824 | 842 |
825 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {", | 843 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {", |
826 newline, | 844 newline, |
849 newline, | 867 newline, |
850 box [string "PQclear(res);", | 868 box [string "PQclear(res);", |
851 newline, | 869 newline, |
852 string "res = PQexec(conn, \"RELEASE s\");", | 870 string "res = PQexec(conn, \"RELEASE s\");", |
853 newline, | 871 newline, |
854 string "if (res == NULL) uw_error(ctx, FATAL, \"Out of memory allocating DML result.\");", | 872 string "if (res == NULL) {", |
873 box [newline, | |
874 string "uw_try_reconnecting_and_restarting(ctx);", | |
875 newline, | |
876 string "uw_error(ctx, FATAL, \"Can't allocate DML RELEASE result; database server may be down.\");", | |
877 newline], | |
878 string "}", | |
855 newline, | 879 newline, |
856 newline, | 880 newline, |
857 | 881 |
858 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {", | 882 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {", |
859 newline, | 883 newline, |
875 fun makeSavepoint mode = | 899 fun makeSavepoint mode = |
876 case mode of | 900 case mode of |
877 Error => box [] | 901 Error => box [] |
878 | None => box [string "res = PQexec(conn, \"SAVEPOINT s\");", | 902 | None => box [string "res = PQexec(conn, \"SAVEPOINT s\");", |
879 newline, | 903 newline, |
880 string "if (res == NULL) uw_error(ctx, FATAL, \"Out of memory allocating DML result.\");", | 904 string "if (res == NULL) {", |
905 box [newline, | |
906 string "uw_try_reconnecting_and_restarting(ctx);", | |
907 newline, | |
908 string "uw_error(ctx, FATAL, \"Can't allocate DML SAVEPOINT result; database server may be down.\");", | |
909 newline], | |
910 string "}", | |
881 newline, | 911 newline, |
882 newline, | 912 newline, |
883 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {", | 913 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {", |
884 box [newline, | 914 box [newline, |
885 string "PQclear(res);", | 915 string "PQclear(res);", |
936 dmlCommon {loc = loc, dml = box [string "\"", | 966 dmlCommon {loc = loc, dml = box [string "\"", |
937 string (Prim.toCString dml), | 967 string (Prim.toCString dml), |
938 string "\""], mode = mode}] | 968 string "\""], mode = mode}] |
939 | 969 |
940 fun nextvalCommon {loc, query} = | 970 fun nextvalCommon {loc, query} = |
941 box [string "if (res == NULL) uw_error(ctx, FATAL, \"Out of memory allocating nextval result.\");", | 971 box [string "if (res == NULL) {", |
972 box [newline, | |
973 string "uw_try_reconnecting_and_restarting(ctx);", | |
974 newline, | |
975 string "uw_error(ctx, FATAL, \"Can't allocate NEXTVAL result; database server may be down.\");", | |
976 newline], | |
977 string "}", | |
942 newline, | 978 newline, |
943 newline, | 979 newline, |
944 | 980 |
945 string "if (PQresultStatus(res) != PGRES_TUPLES_OK) {", | 981 string "if (PQresultStatus(res) != PGRES_TUPLES_OK) {", |
946 newline, | 982 newline, |
1018 nextvalCommon {loc = loc, query = box [string "\"", | 1054 nextvalCommon {loc = loc, query = box [string "\"", |
1019 string (Prim.toCString query), | 1055 string (Prim.toCString query), |
1020 string "\""]}] | 1056 string "\""]}] |
1021 | 1057 |
1022 fun setvalCommon {loc, query} = | 1058 fun setvalCommon {loc, query} = |
1023 box [string "if (res == NULL) uw_error(ctx, FATAL, \"Out of memory allocating setval result.\");", | 1059 box [string "if (res == NULL) {", |
1060 box [newline, | |
1061 string "uw_try_reconnecting_and_restarting(ctx);", | |
1062 newline, | |
1063 string "uw_error(ctx, FATAL, \"Can't allocate SETVAL result; database server may be down.\");", | |
1064 newline], | |
1065 string "}", | |
1024 newline, | 1066 newline, |
1025 newline, | 1067 newline, |
1026 | 1068 |
1027 string "if (PQresultStatus(res) != PGRES_TUPLES_OK) {", | 1069 string "if (PQresultStatus(res) != PGRES_TUPLES_OK) {", |
1028 newline, | 1070 newline, |