Changeset: c037e4ad579e for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c037e4ad579e
Modified Files:
clients/src/mapiclient/dump.c
Branch: Jun2010
Log Message:
If dumping fails (e.g. because of closed pipe in \|less), rollback our
transaction.
diffs (truncated from 405 to 300 lines):
diff -r ca44e0299890 -r c037e4ad579e clients/src/mapiclient/dump.c
--- a/clients/src/mapiclient/dump.c Wed Jul 07 14:12:50 2010 +0200
+++ b/clients/src/mapiclient/dump.c Wed Jul 07 14:38:33 2010 +0200
@@ -1109,32 +1109,20 @@
if (!describe)
stream_printf(toConsole, "START TRANSACTION;\n");
- if ((hdl = mapi_query(mid, start)) == NULL || mapi_error(mid)) {
- if (hdl) {
- mapi_explain_query(hdl, stderr);
- mapi_close_handle(hdl);
- } else
- mapi_explain(mid, stderr);
- return 1;
- }
+ if ((hdl = mapi_query(mid, start)) == NULL || mapi_error(mid))
+ goto bailout;
mapi_close_handle(hdl);
sname = get_schema(mid);
if (sname == NULL)
- return 1;
+ goto bailout2;
if (strcmp(sname, "sys") == 0 || strcmp(sname, "tmp") == 0) {
free(sname);
sname = NULL;
/* dump roles */
- if ((hdl = mapi_query(mid, roles)) == NULL || mapi_error(mid)) {
- if (hdl) {
- mapi_explain_query(hdl, stderr);
- mapi_close_handle(hdl);
- } else
- mapi_explain(mid, stderr);
- return 1;
- }
+ if ((hdl = mapi_query(mid, roles)) == NULL || mapi_error(mid))
+ goto bailout;
while (mapi_fetch_row(hdl) != 0) {
char *name = mapi_fetch_field(hdl, 0);
@@ -1143,46 +1131,26 @@
quoted_print(toConsole, name);
stream_printf(toConsole, ";\n");
}
- if (mapi_error(mid)) {
- mapi_explain_query(hdl, stderr);
- mapi_close_handle(hdl);
- return 1;
- }
+ if (mapi_error(mid))
+ goto bailout;
mapi_close_handle(hdl);
/* dump users, part 1 */
/* first make sure the password_hash function exists */
- if ((hdl = mapi_query(mid, chkhash)) == NULL ||
mapi_error(mid)) {
- if (hdl) {
- mapi_explain_query(hdl, stderr);
- mapi_close_handle(hdl);
- } else
- mapi_explain(mid, stderr);
- return 1;
- }
+ if ((hdl = mapi_query(mid, chkhash)) == NULL || mapi_error(mid))
+ goto bailout;
create_hash_func = mapi_rows_affected(hdl) == 0;
mapi_close_handle(hdl);
if (create_hash_func) {
- if ((hdl = mapi_query(mid, createhash)) == NULL ||
mapi_error(mid)) {
- if (hdl) {
- mapi_explain_query(hdl, stderr);
- mapi_close_handle(hdl);
- } else
- mapi_explain(mid, stderr);
- return 1;
- }
+ if ((hdl = mapi_query(mid, createhash)) == NULL ||
+ mapi_error(mid))
+ goto bailout;
mapi_close_handle(hdl);
}
- if ((hdl = mapi_query(mid, users1)) == NULL || mapi_error(mid))
{
- if (hdl) {
- mapi_explain_query(hdl, stderr);
- mapi_close_handle(hdl);
- } else
- mapi_explain(mid, stderr);
- return 1;
- }
+ if ((hdl = mapi_query(mid, users1)) == NULL || mapi_error(mid))
+ goto bailout;
while (mapi_fetch_row(hdl) != 0) {
char *uname = mapi_fetch_field(hdl, 0);
@@ -1193,35 +1161,22 @@
quoted_print(toConsole, uname);
stream_printf(toConsole, " WITH ENCRYPTED PASSWORD '%s'
NAME '%s' SCHEMA \"sys\";\n", pwhash, fullname);
}
- if (mapi_error(mid)) {
- mapi_explain_query(hdl, stderr);
- mapi_close_handle(hdl);
- return 1;
- }
+ if (mapi_error(mid))
+ goto bailout;
mapi_close_handle(hdl);
/* clean up -- not strictly necessary due to ROLLBACK */
if (create_hash_func) {
- if ((hdl = mapi_query(mid, drophash)) == NULL ||
mapi_error(mid)) {
- if (hdl) {
- mapi_explain_query(hdl, stderr);
- mapi_close_handle(hdl);
- } else
- mapi_explain(mid, stderr);
- return 1;
- }
+ if ((hdl = mapi_query(mid, drophash)) == NULL ||
+ mapi_error(mid))
+ goto bailout;
mapi_close_handle(hdl);
}
/* dump schemas */
- if ((hdl = mapi_query(mid, schemas)) == NULL ||
mapi_error(mid)) {
- if (hdl) {
- mapi_explain_query(hdl, stderr);
- mapi_close_handle(hdl);
- } else
- mapi_explain(mid, stderr);
- return 1;
- }
+ if ((hdl = mapi_query(mid, schemas)) == NULL ||
+ mapi_error(mid))
+ goto bailout;
while (mapi_fetch_row(hdl) != 0) {
char *sname = mapi_fetch_field(hdl, 0);
@@ -1235,22 +1190,13 @@
}
stream_printf(toConsole, ";\n");
}
- if (mapi_error(mid)) {
- mapi_explain_query(hdl, stderr);
- mapi_close_handle(hdl);
- return 1;
- }
+ if (mapi_error(mid))
+ goto bailout;
mapi_close_handle(hdl);
/* dump users, part 2 */
- if ((hdl = mapi_query(mid, users2)) == NULL || mapi_error(mid))
{
- if (hdl) {
- mapi_explain_query(hdl, stderr);
- mapi_close_handle(hdl);
- } else
- mapi_explain(mid, stderr);
- return 1;
- }
+ if ((hdl = mapi_query(mid, users2)) == NULL || mapi_error(mid))
+ goto bailout;
while (mapi_fetch_row(hdl) != 0) {
char *uname = mapi_fetch_field(hdl, 0);
@@ -1262,22 +1208,13 @@
quoted_print(toConsole, sname);
stream_printf(toConsole, ";\n");
}
- if (mapi_error(mid)) {
- mapi_explain_query(hdl, stderr);
- mapi_close_handle(hdl);
- return 1;
- }
+ if (mapi_error(mid))
+ goto bailout;
mapi_close_handle(hdl);
/* grant user privileges */
- if ((hdl = mapi_query(mid, grants)) == NULL || mapi_error(mid))
{
- if (hdl) {
- mapi_explain_query(hdl, stderr);
- mapi_close_handle(hdl);
- } else
- mapi_explain(mid, stderr);
- return 1;
- }
+ if ((hdl = mapi_query(mid, grants)) == NULL || mapi_error(mid))
+ goto bailout;
while (mapi_fetch_row(hdl) != 0) {
char *uname = mapi_fetch_field(hdl, 0);
@@ -1292,11 +1229,8 @@
server, so we can't dump them */
stream_printf(toConsole, ";\n");
}
- if (mapi_error(mid)) {
- mapi_explain_query(hdl, stderr);
- mapi_close_handle(hdl);
- return 1;
- }
+ if (mapi_error(mid))
+ goto bailout;
mapi_close_handle(hdl);
} else {
stream_printf(toConsole, "SET SCHEMA ");
@@ -1306,14 +1240,8 @@
}
/* dump sequences, part 1 */
- if ((hdl = mapi_query(mid, sequences1)) == NULL || mapi_error(mid)) {
- if (hdl) {
- mapi_explain_query(hdl, stderr);
- mapi_close_handle(hdl);
- } else
- mapi_explain(mid, stderr);
- return 1;
- }
+ if ((hdl = mapi_query(mid, sequences1)) == NULL || mapi_error(mid))
+ goto bailout;
while (mapi_fetch_row(hdl) != 0) {
char *schema = mapi_fetch_field(hdl, 0);
@@ -1327,22 +1255,14 @@
quoted_print(toConsole, name);
stream_printf(toConsole, " AS INTEGER;\n");
}
- if (mapi_error(mid)) {
- mapi_explain_query(hdl, stderr);
- mapi_close_handle(hdl);
- return 1;
- }
+ if (mapi_error(mid))
+ goto bailout;
mapi_close_handle(hdl);
/* dump tables */
- if ((hdl = mapi_query(mid, tables_and_functions)) == NULL ||
mapi_error(mid)) {
- if (hdl) {
- mapi_explain_query(hdl, stderr);
- mapi_close_handle(hdl);
- } else
- mapi_explain(mid, stderr);
- return 1;
- }
+ if ((hdl = mapi_query(mid, tables_and_functions)) == NULL ||
+ mapi_error(mid))
+ goto bailout;
while (rc == 0 &&
!stream_errnr(toConsole) &&
@@ -1354,7 +1274,7 @@
if (mapi_error(mid)) {
mapi_explain(mid, stderr);
mapi_close_handle(hdl);
- return 1;
+ goto bailout2;
}
if (sname != NULL && strcmp(schema, sname) != 0)
continue;
@@ -1386,28 +1306,20 @@
free(curschema);
curschema = strdup(sname ? sname : "sys");
}
- if (mapi_error(mid)) {
- mapi_explain_query(hdl, stderr);
- mapi_close_handle(hdl);
- return 1;
- }
+ if (mapi_error(mid))
+ goto bailout;
mapi_close_handle(hdl);
if (stream_errnr(toConsole))
- return 1;
+ goto bailout2;
if (!describe) {
if (dump_foreign_keys(mid, NULL, NULL, toConsole))
- return 1;
+ goto bailout2;
/* dump sequences, part 2 */
- if ((hdl = mapi_query(mid, sequences2)) == NULL ||
mapi_error(mid)) {
- if (hdl) {
- mapi_explain_query(hdl, stderr);
- mapi_close_handle(hdl);
- } else
- mapi_explain(mid, stderr);
- return 1;
- }
+ if ((hdl = mapi_query(mid, sequences2)) == NULL ||
+ mapi_error(mid))
+ goto bailout;
while (mapi_fetch_row(hdl) != 0) {
char *schema = mapi_fetch_field(hdl, 0);
@@ -1435,25 +1347,16 @@
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list