diff src/cjr_print.sml @ 424:b10132434adc

Transactions seem to be working
author Adam Chlipala <adamc@hcoop.net>
date Fri, 24 Oct 2008 16:47:18 -0400
parents ad7e854a518c
children 7009b0ac1501
line wrap: on
line diff
--- a/src/cjr_print.sml	Fri Oct 24 16:13:53 2008 -0400
+++ b/src/cjr_print.sml	Fri Oct 24 16:47:18 2008 -0400
@@ -1268,6 +1268,75 @@
                             string "PQfinish(uw_get_db(ctx));",
                             newline,
                             string "}",
+                            newline,
+                            newline,
+
+                            string "int uw_db_begin(uw_context ctx) {",
+                            newline,
+                            string "PGconn *conn = uw_get_db(ctx);",
+                            newline,
+                            string "PGresult *res = PQexec(conn, \"BEGIN\");",
+                            newline,
+                            newline,
+                            string "if (res == NULL) return 1;",
+                            newline,
+                            newline,
+                            string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {",
+                            box [string "PQclear(res);",
+                                 newline,
+                                 string "return 1;",
+                                 newline],
+                            string "}",
+                            newline,
+                            string "return 0;",
+                            newline,
+                            string "}",
+                            newline,
+                            newline,
+
+                            string "int uw_db_commit(uw_context ctx) {",
+                            newline,
+                            string "PGconn *conn = uw_get_db(ctx);",
+                            newline,
+                            string "PGresult *res = PQexec(conn, \"COMMIT\");",
+                            newline,
+                            newline,
+                            string "if (res == NULL) return 1;",
+                            newline,
+                            newline,
+                            string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {",
+                            box [string "PQclear(res);",
+                                 newline,
+                                 string "return 1;",
+                                 newline],
+                            string "}",
+                            newline,
+                            string "return 0;",
+                            newline,
+                            string "}",
+                            newline,
+                            newline,
+
+                            string "int uw_db_rollback(uw_context ctx) {",
+                            newline,
+                            string "PGconn *conn = uw_get_db(ctx);",
+                            newline,
+                            string "PGresult *res = PQexec(conn, \"ROLLBACK\");",
+                            newline,
+                            newline,
+                            string "if (res == NULL) return 1;",
+                            newline,
+                            newline,
+                            string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {",
+                            box [string "PQclear(res);",
+                                 newline,
+                                 string "return 1;",
+                                 newline],
+                            string "}",
+                            newline,
+                            string "return 0;",
+                            newline,
+                            string "}",
                             newline]
 
       | DPreparedStatements ss =>
@@ -2158,6 +2227,12 @@
              else
                  box [newline,
                       string "void uw_db_init(uw_context ctx) { };",
+                      newline,
+                      string "int uw_db_begin(uw_context ctx) { return 0; };",
+                      newline,
+                      string "int uw_db_commit(uw_context ctx) { return 0; };",
+                      newline,
+                      string "int uw_db_rollback(uw_context ctx) { return 0; };",
                       newline]]
     end