Changeset: 5362367f63e5 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5362367f63e5
Modified Files:
        
Branch: default
Log Message:

Merge with Jun2010 branch.
Improve error reporting from SQL dump.


diffs (truncated from 521 to 300 lines):

diff -r ca9420679474 -r 5362367f63e5 clients/src/mapiclient/dump.c
--- a/clients/src/mapiclient/dump.c     Thu Jul 08 10:41:48 2010 +0200
+++ b/clients/src/mapiclient/dump.c     Thu Jul 08 15:26:11 2010 +0200
@@ -76,33 +76,32 @@
        char *sname = NULL;
        MapiHdl hdl;
 
-       if ((hdl = mapi_query(mid, "SELECT \"current_schema\"")) == NULL || 
mapi_error(mid)) {
-               if (hdl) {
-                       mapi_explain_query(hdl, stderr);
-                       mapi_close_handle(hdl);
-               } else
-                       mapi_explain(mid, stderr);
-               return NULL;
-       }
+       if ((hdl = mapi_query(mid, "SELECT \"current_schema\"")) == NULL || 
mapi_error(mid))
+               goto bailout;
        while ((mapi_fetch_row(hdl)) != 0) {
                sname = mapi_fetch_field(hdl, 0);
 
-               if (mapi_error(mid)) {
-                       mapi_explain_query(hdl, stderr);
-                       mapi_close_handle(hdl);
-                       return NULL;
-               }
+               if (mapi_error(mid))
+                       goto bailout;
        }
-       if (mapi_error(mid)) {
-               mapi_explain_query(hdl, stderr);
-               mapi_close_handle(hdl);
-               return NULL;
-       }
+       if (mapi_error(mid))
+               goto bailout;
        /* copy before closing the handle */
        if (sname)
                sname = strdup(sname);
        mapi_close_handle(hdl);
        return sname;
+
+  bailout:
+       if (hdl) {
+               if (mapi_result_error(hdl))
+                       mapi_explain_result(hdl, stderr);
+               else
+                       mapi_explain_query(hdl, stderr);
+               mapi_close_handle(hdl);
+       } else
+               mapi_explain(mid, stderr);
+       return NULL;
 }
 
 static int
@@ -112,7 +111,6 @@
        int cnt, i;
        char *query;
        size_t maxquerylen = 0;
-       int rc = 0;
 
        if (tname != NULL) {
                maxquerylen = 1024 + strlen(tname) + strlen(schema);
@@ -175,14 +173,8 @@
                        "ORDER BY \"fs\".\"name\",\"fkt\".\"name\","
                              "\"fkk\".\"name\", \"nr\"";
        }
-       if ((hdl = mapi_query(mid, query)) == NULL || mapi_error(mid)) {
-               if (hdl)
-                       mapi_explain_query(hdl, stderr);
-               else
-                       mapi_explain(mid, stderr);
-               rc = 1;
+       if ((hdl = mapi_query(mid, query)) == NULL || mapi_error(mid))
                goto bailout;
-       }
        cnt = mapi_fetch_row(hdl);
        while (cnt != 0) {
                char *c_psname = mapi_fetch_field(hdl, 0);
@@ -197,12 +189,8 @@
                char **fkeys, **pkeys;
                int nkeys = 0;
 
-               if (mapi_error(mid)) {
-                       mapi_explain_query(hdl, stderr);
-                       mapi_close_handle(hdl);
-                       rc = 1;
+               if (mapi_error(mid))
                        goto bailout;
-               }
                assert(strcmp(c_nr, "0") == 0);
                (void) c_nr;    /* pacify compilers in case assertions are 
disabled */
                nkeys = 1;
@@ -263,24 +251,29 @@
                if (tname == NULL)
                        stream_printf(toConsole, ";\n");
 
-               if (stream_errnr(toConsole)) {
-                       rc = 1;
+               if (stream_errnr(toConsole))
                        goto bailout;
-               }
        }
-       if (mapi_error(mid)) {
-               mapi_explain_query(hdl, stderr);
-               rc = 1;
-       }
+       if (mapi_error(mid))
+               goto bailout;
+       if (hdl)
+               mapi_close_handle(hdl);
+       return 0;
 
   bailout:
-       if (hdl)
+       if (hdl) {
+               if (mapi_result_error(hdl))
+                       mapi_explain_result(hdl, stderr);
+               else if (mapi_error(mid))
+                       mapi_explain_query(hdl, stderr);
                mapi_close_handle(hdl);
+       } else if (mapi_error(mid))
+               mapi_explain(mid, stderr);
 
        if (query != NULL && maxquerylen != 0)
                free(query);
 
-       return rc;
+       return 1;
 }
 
 int
@@ -296,7 +289,6 @@
        int cap;
 #define CAP(X) ((cap = (int) (X)) < 0 ? 0 : cap)
 
-
        if (schema == NULL) {
                if ((sname = strchr(tname, '.')) != NULL) {
                        size_t len = sname - tname;
@@ -322,20 +314,14 @@
                 "AND \"t\".\"name\" = '%s'",
                 schema, tname);
 
-       if ((hdl = mapi_query(mid, query)) == NULL || mapi_error(mid)) {
-               if (hdl)
-                       mapi_explain_query(hdl, stderr);
-               else
-                       mapi_explain(mid, stderr);
+       if ((hdl = mapi_query(mid, query)) == NULL || mapi_error(mid))
                goto bailout;
-       }
        cnt = 0;
        while ((mapi_fetch_row(hdl)) != 0) {
                cnt++;
                view = mapi_fetch_field(hdl, 1);
        }
        if (mapi_error(mid)) {
-               mapi_explain_query(hdl, stderr);
                view = NULL;
                goto bailout;
        }
@@ -383,13 +369,8 @@
                 "AND \"t\".\"schema_id\" = \"s\".\"id\" "
                 "AND \"s\".\"name\" = '%s' "
                 "ORDER BY \"number\"", tname, schema);
-       if ((hdl = mapi_query(mid, query)) == NULL || mapi_error(mid)) {
-               if (hdl)
-                       mapi_explain_query(hdl, stderr);
-               else
-                       mapi_explain(mid, stderr);
+       if ((hdl = mapi_query(mid, query)) == NULL || mapi_error(mid))
                goto bailout;
-       }
 
        slen = mapi_get_len(hdl, 0);
        cnt = 0;
@@ -402,10 +383,8 @@
                char *c_default = mapi_fetch_field(hdl, 5);
                int space = 0;
 
-               if (mapi_error(mid)) {
-                       mapi_explain_query(hdl, stderr);
+               if (mapi_error(mid))
                        goto bailout;
-               }
                if (cnt)
                        stream_printf(toConsole, ",\n");
 
@@ -521,10 +500,8 @@
                if (stream_errnr(toConsole))
                        goto bailout;
        }
-       if (mapi_error(mid)) {
-               mapi_explain_query(hdl, stderr);
+       if (mapi_error(mid))
                goto bailout;
-       }
        mapi_close_handle(hdl);
        hdl = NULL;
        /* presumably we don't need to order on id, since there should
@@ -547,22 +524,15 @@
                       "\"s\".\"name\" = '%s' AND "
                       "\"t\".\"name\" = '%s' "
                 "ORDER BY \"id\", \"nr\"", schema, tname);
-       if ((hdl = mapi_query(mid, query)) == NULL || mapi_error(mid)) {
-               if (hdl)
-                       mapi_explain_query(hdl, stderr);
-               else
-                       mapi_explain(mid, stderr);
+       if ((hdl = mapi_query(mid, query)) == NULL || mapi_error(mid))
                goto bailout;
-       }
        cnt = 0;
        while ((mapi_fetch_row(hdl)) != 0) {
                char *c_column = mapi_fetch_field(hdl, 0);
                char *k_name = mapi_fetch_field(hdl, 2);
 
-               if (mapi_error(mid)) {
-                       mapi_explain_query(hdl, stderr);
+               if (mapi_error(mid))
                        goto bailout;
-               }
                if (cnt == 0) {
                        stream_printf(toConsole, ",\n\t");
                        if (k_name) {
@@ -580,10 +550,8 @@
        }
        if (cnt)
                stream_printf(toConsole, ")");
-       if (mapi_error(mid)) {
-               mapi_explain_query(hdl, stderr);
+       if (mapi_error(mid))
                goto bailout;
-       }
        mapi_close_handle(hdl);
        hdl = NULL;
 
@@ -603,23 +571,16 @@
                       "\"s\".\"name\" = '%s' AND "
                       "\"t\".\"name\" = '%s' "
                 "ORDER BY \"id\", \"nr\"", schema, tname);
-       if ((hdl = mapi_query(mid, query)) == NULL || mapi_error(mid)) {
-               if (hdl)
-                       mapi_explain_query(hdl, stderr);
-               else
-                       mapi_explain(mid, stderr);
+       if ((hdl = mapi_query(mid, query)) == NULL || mapi_error(mid))
                goto bailout;
-       }
        cnt = 0;
        while ((mapi_fetch_row(hdl)) != 0) {
                char *c_column = mapi_fetch_field(hdl, 0);
                char *kc_nr = mapi_fetch_field(hdl, 1);
                char *k_name = mapi_fetch_field(hdl, 2);
 
-               if (mapi_error(mid)) {
-                       mapi_explain_query(hdl, stderr);
+               if (mapi_error(mid))
                        goto bailout;
-               }
                if (strcmp(kc_nr, "0") == 0) {
                        if (cnt)
                                stream_write(toConsole, ")", 1, 1);
@@ -639,10 +600,8 @@
        }
        if (cnt)
                stream_write(toConsole, ")", 1, 1);
-       if (mapi_error(mid)) {
-               mapi_explain_query(hdl, stderr);
+       if (mapi_error(mid))
                goto bailout;
-       }
        mapi_close_handle(hdl);
        hdl = NULL;
 
@@ -674,13 +633,8 @@
                       "\"s\".\"name\" = '%s' AND "
                       "\"t\".\"name\" = '%s' "
                 "ORDER BY \"i\".\"name\", \"kc\".\"nr\"", schema, tname);
-       if ((hdl = mapi_query(mid, query)) == NULL || mapi_error(mid)) {
-               if (hdl)
-                       mapi_explain_query(hdl, stderr);
-               else
-                       mapi_explain(mid, stderr);
+       if ((hdl = mapi_query(mid, query)) == NULL || mapi_error(mid))
                goto bailout;
-       }
        cnt = 0;
        while (mapi_fetch_row(hdl) != 0) {
                char *i_name = mapi_fetch_field(hdl, 0);
@@ -688,10 +642,8 @@
                char *kc_nr = mapi_fetch_field(hdl, 2);
                char *c_name = mapi_fetch_field(hdl, 3);
 
-               if (mapi_error(mid)) {
-                       mapi_explain_query(hdl, stderr);
+               if (mapi_error(mid))
                        goto bailout;
-               }
                if (k_name != NULL) {
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to