Changeset: ecd7ad5a7094 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ecd7ad5a7094
Modified Files:
        clients/src/mapiclient/dump.c
        sql/src/sql/createdb.mx
        sql/src/sql/system.sql
Branch: Oct2010
Log Message:

Don't dump system-created User-defined Functions.
This fixes bug 2666.
The fix is to create a new table, called systemfunctions, which
contains the IDs of all system functions.  Dump will first check
whether the table exists (if it doesn't, it will use the old way of
dumping), and then not dump any functions that are mentioned in the
table.
The table is created and filled at the end of the createdb.sql script.


diffs (123 lines):

diff -r 260ac3b9c481 -r ecd7ad5a7094 clients/src/mapiclient/dump.c
--- a/clients/src/mapiclient/dump.c     Thu Sep 09 13:11:53 2010 +0200
+++ b/clients/src/mapiclient/dump.c     Thu Sep 09 14:14:14 2010 +0200
@@ -106,6 +106,42 @@
 }
 
 static int
+has_systemfunctions(Mapi mid)
+{
+       MapiHdl hdl;
+       int ret;
+
+       if ((hdl = mapi_query(mid,
+                             "SELECT \"t\".\"id\" "
+                             "FROM \"_tables\" \"t\", \"schemas\" \"s\" "
+                             "WHERE \"t\".\"name\" = 'systemfunctions' AND "
+                                   "\"t\".\"schema_id\" = \"s\".\"id\" AND "
+                                   "\"s\".\"name\" = 'sys'")) == NULL ||
+           mapi_error(mid))
+               goto bailout;
+       ret = mapi_get_row_count(hdl) == 1;
+       while ((mapi_fetch_row(hdl)) != 0) {
+               if (mapi_error(mid))
+                       goto bailout;
+       }
+       if (mapi_error(mid))
+               goto bailout;
+       mapi_close_handle(hdl);
+       return ret;
+
+  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 0;
+}
+
+static int
 dump_foreign_keys(Mapi mid, char *schema, char *tname, stream *toConsole)
 {
        MapiHdl hdl = NULL;
@@ -880,20 +916,19 @@
                     "\"sys\".\"functions\" \"f\" "
                "WHERE \"f\".\"id\" > 2000 AND "
                      "\"s\".\"id\" = \"f\".\"schema_id\""
-                     "%s%s%s "
+                     "%s%s%s%s "
                "ORDER BY \"f\".\"id\"";
        MapiHdl hdl;
        char *q;
+       size_t l;
 
-       if (sname != NULL) {
-               size_t l = sizeof(functions) + strlen(sname) + 20;
-
-               q = malloc(l);
-               snprintf(q, l, functions, " AND \"s\".\"name\" = '", sname, 
"'");
-       } else {
-               q = malloc(sizeof(functions));
-               snprintf(q, sizeof(functions), functions, "", "", "");
-       }
+       l = sizeof(functions) + (sname ? strlen(sname) : 0) + 100;
+       q = malloc(l);
+       snprintf(q, l, functions,
+                sname ? " AND \"s\".\"name\" = '" : "",
+                sname ? sname : "",
+                sname ? "'" : "",
+                has_systemfunctions(mid) ? " AND \"f\".\"id\" NOT IN (SELECT 
\"function_id\" FROM \"sys\".\"systemfunctions\")" : "");
        hdl = mapi_query(mid, q);
        free(q);
        if (hdl == NULL || mapi_error(mid))
@@ -1046,6 +1081,7 @@
                             "\"sys\".\"functions\" \"f\" "
                        "WHERE \"f\".\"sql\" = TRUE AND "
                              "\"s\".\"id\" = \"f\".\"schema_id\" "
+                             "%s"
                        "UNION "
                        "SELECT \"s\".\"name\" AS \"sname\", "
                               "\"t\".\"name\" AS \"name\", "
@@ -1073,6 +1109,7 @@
        MapiHdl hdl;
        int create_hash_func = 0;
        int rc = 0;
+       char query[1024];
 
        /* start a transaction for the dump */
        if (!describe)
@@ -1230,7 +1267,9 @@
        mapi_close_handle(hdl);
 
        /* dump tables */
-       if ((hdl = mapi_query(mid, tables_and_functions)) == NULL ||
+       snprintf(query, sizeof(query), tables_and_functions,
+                has_systemfunctions(mid) ? "AND \"f\".\"id\" NOT IN (SELECT 
\"function_id\" FROM \"sys\".\"systemfunctions\") " : "");
+       if ((hdl = mapi_query(mid, query)) == NULL ||
            mapi_error(mid))
                goto bailout;
 
diff -r 260ac3b9c481 -r ecd7ad5a7094 sql/src/sql/createdb.mx
--- a/sql/src/sql/createdb.mx   Thu Sep 09 13:11:53 2010 +0200
+++ b/sql/src/sql/createdb.mx   Thu Sep 09 14:14:14 2010 +0200
@@ -90,4 +90,6 @@
 parts.sql      -- testing only
 replication.sql        -- testing only
 @sql
+...@include system.sql
+
 commit;
diff -r 260ac3b9c481 -r ecd7ad5a7094 sql/src/sql/system.sql
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sql/src/sql/system.sql    Thu Sep 09 14:14:14 2010 +0200
@@ -0,0 +1,6 @@
+create table systemfunctions (function_id)
+       as (select id from functions) with data;
+update _tables
+       set system = true
+       where name = 'systemfunctions'
+               and schema_id = (select id from schemas where name = 'sys');
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to