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

Merge with Oct2010 branch.


diffs (truncated from 1517 to 300 lines):

diff -r 3183929efa1c -r f2322fcbbbcf clients/ChangeLog.Oct2010
--- a/clients/ChangeLog.Oct2010 Mon Sep 13 18:49:24 2010 +0200
+++ b/clients/ChangeLog.Oct2010 Tue Sep 14 09:33:20 2010 +0200
@@ -1,6 +1,9 @@
 # ChangeLog file for clients
 # This file is updated with Maddlog
 
+* Tue Sep 14 2010 Sjoerd Mullender <[email protected]>
+- Implemented dumping of "external" functions.  This fixes bug 2546.
+
 * Thu Aug 26 2010 Fabian Groffen <[email protected]>
 - Empty resultsets now show a header in mclient using SQL mode.
 
diff -r 3183929efa1c -r f2322fcbbbcf clients/src/mapiclient/dump.c
--- a/clients/src/mapiclient/dump.c     Mon Sep 13 18:49:24 2010 +0200
+++ b/clients/src/mapiclient/dump.c     Tue Sep 14 09:33:20 2010 +0200
@@ -143,7 +143,7 @@
 }
 
 static int
-dump_foreign_keys(Mapi mid, char *schema, char *tname, stream *toConsole)
+dump_foreign_keys(Mapi mid, const char *schema, const char *tname, const char 
*tid, stream *toConsole)
 {
        MapiHdl hdl = NULL;
        int cnt, i;
@@ -182,6 +182,35 @@
                               "\"fs\".\"name\" = '%s' AND "
                               "\"fkt\".\"name\" = '%s'"
                         "ORDER BY \"fkk\".\"name\", \"nr\"", schema, tname);
+       } else if (tid != NULL) {
+               maxquerylen = 1024;
+               query = malloc(maxquerylen);
+               snprintf(query, maxquerylen,
+                        "SELECT \"ps\".\"name\","              /* 0 */
+                               "\"pkt\".\"name\","             /* 1 */
+                               "\"pkkc\".\"column\","          /* 2 */
+                               "\"fkkc\".\"column\","          /* 3 */
+                               "\"fkkc\".\"nr\","              /* 4 */
+                               "\"fkk\".\"name\","             /* 5 */
+                               "\"fkk\".\"action\","           /* 6 */
+                               "0,"                            /* 7 */
+                               "\"fkt\".\"name\" "             /* 8 */
+                        "FROM \"sys\".\"_tables\" \"fkt\","
+                             "\"sys\".\"keycolumns\" \"fkkc\","
+                             "\"sys\".\"keys\" \"fkk\","
+                             "\"sys\".\"_tables\" \"pkt\","
+                             "\"sys\".\"keycolumns\" \"pkkc\","
+                             "\"sys\".\"keys\" \"pkk\","
+                             "\"sys\".\"schemas\" \"ps\""
+                        "WHERE \"fkt\".\"id\" = \"fkk\".\"table_id\" AND "
+                              "\"pkt\".\"id\" = \"pkk\".\"table_id\" AND "
+                              "\"fkk\".\"id\" = \"fkkc\".\"id\" AND "
+                              "\"pkk\".\"id\" = \"pkkc\".\"id\" AND "
+                              "\"fkk\".\"rkey\" = \"pkk\".\"id\" AND "
+                              "\"fkkc\".\"nr\" = \"pkkc\".\"nr\" AND "
+                              "\"pkt\".\"schema_id\" = \"ps\".\"id\" AND "
+                              "\"fkt\".\"id\" = %s"
+                        "ORDER BY \"fkk\".\"name\", \"nr\"", tid);
        } else {
                query = "SELECT \"ps\".\"name\","               /* 0 */
                               "\"pkt\".\"name\","              /* 1 */
@@ -244,35 +273,29 @@
                        pkeys[nkeys - 1] = mapi_fetch_field(hdl, 2);
                        fkeys[nkeys - 1] = mapi_fetch_field(hdl, 3);
                }
-               if (tname == NULL) {
-                       mnstr_printf(toConsole, "ALTER TABLE ");
-                       quoted_print(toConsole, c_fsname);
-                       mnstr_printf(toConsole, ".");
-                       quoted_print(toConsole, c_ftname);
-                       mnstr_printf(toConsole, " ADD ");
+               if (tname == NULL && tid == NULL) {
+                       mnstr_printf(toConsole,
+                                    "ALTER TABLE \"%s\".\"%s\" ADD ",
+                                    c_fsname, c_ftname);
                } else {
                        mnstr_printf(toConsole, ",\n\t");
                }
                if (c_fkname) {
-                       mnstr_printf(toConsole, "CONSTRAINT ");
-                       quoted_print(toConsole, c_fkname);
-                       mnstr_write(toConsole, " ", 1, 1);
+                       mnstr_printf(toConsole, "CONSTRAINT \"%s\" ",
+                               c_fkname);
                }
                mnstr_printf(toConsole, "FOREIGN KEY (");
                for (i = 0; i < nkeys; i++) {
-                       if (i > 0)
-                               mnstr_printf(toConsole, ", ");
-                       quoted_print(toConsole, fkeys[i]);
+                       mnstr_printf(toConsole, "%s\"%s\"",
+                                    i > 0 ? ", " : "", fkeys[i]);
                }
-               mnstr_printf(toConsole, ") REFERENCES ");
-               quoted_print(toConsole, c_psname);
-               mnstr_printf(toConsole, ".");
-               quoted_print(toConsole, c_ptname);
-               mnstr_printf(toConsole, " (");
+               mnstr_printf(toConsole, ") REFERENCES \"%s\".\"%s\" (",
+                            c_psname, c_ptname);
                for (i = 0; i < nkeys; i++) {
                        if (i > 0)
                                mnstr_printf(toConsole, ", ");
-                       quoted_print(toConsole, pkeys[i]);
+                       mnstr_printf(toConsole, "%s\"%s\"",
+                                    i > 0 ? ", " : "", pkeys[i]);
                }
                mnstr_printf(toConsole, ")");
                free(fkeys);
@@ -282,12 +305,18 @@
                        int on_update = (action >> 8) & 255;
                        int on_delete = action & 255;
 
-                       if (0 < on_delete && on_delete < NR_ACTIONS && 
on_delete != 2 /* RESTRICT -- default */)
-                               mnstr_printf(toConsole, " ON DELETE %s", 
actions[on_delete]);
-                       if (0 < on_update && on_update < NR_ACTIONS && 
on_delete != 2 /* RESTRICT -- default */)
-                               mnstr_printf(toConsole, " ON UPDATE %s", 
actions[on_update]);
+                       if (0 < on_delete &&
+                           on_delete < NR_ACTIONS &&
+                           on_delete != 2         /* RESTRICT -- default */)
+                               mnstr_printf(toConsole, " ON DELETE %s",
+                                            actions[on_delete]);
+                       if (0 < on_update &&
+                           on_update < NR_ACTIONS &&
+                           on_delete != 2         /* RESTRICT -- default */)
+                               mnstr_printf(toConsole, " ON UPDATE %s",
+                                            actions[on_update]);
                }
-               if (tname == NULL)
+               if (tname == NULL && tid == NULL)
                        mnstr_printf(toConsole, ";\n");
 
                if (mnstr_errnr(toConsole))
@@ -329,18 +358,372 @@
        return(_toupperbuf);
 }
 
+static int dump_column_definition(
+       Mapi mid,
+       stream *toConsole,
+       const char *schema,
+       const char *tname,
+       const char *tid,
+       int foreign);
+
+static int
+dump_type(Mapi mid, stream *toConsole, char *c_type, char *c_type_digits, char 
*c_type_scale)
+{
+       int space = 0;
+
+       /* map wrd type to something legal */
+       if (strcmp(c_type, "wrd") == 0) {
+               if (strcmp(c_type_scale, "32") == 0)
+                       c_type = "int";
+               else
+                       c_type = "bigint";
+       }
+       if (strcmp(c_type, "boolean") == 0) {
+               space = mnstr_printf(toConsole, "BOOLEAN");
+       } else if (strcmp(c_type, "int") == 0) {
+               space = mnstr_printf(toConsole, "INTEGER");
+       } else if (strcmp(c_type, "smallint") == 0) {
+               space = mnstr_printf(toConsole, "SMALLINT");
+       } else if (strcmp(c_type, "tinyint") == 0) {
+               space = mnstr_printf(toConsole, "TINYINT");
+       } else if (strcmp(c_type, "bigint") == 0) {
+               space = mnstr_printf(toConsole, "BIGINT");
+       } else if (strcmp(c_type, "date") == 0) {
+               space = mnstr_printf(toConsole, "DATE");
+       } else if (strcmp(c_type, "month_interval") == 0) {
+               if (strcmp(c_type_digits, "1") == 0)
+                       space = mnstr_printf(toConsole, "INTERVAL YEAR");
+               else if (strcmp(c_type_digits, "2") == 0)
+                       space = mnstr_printf(toConsole, "INTERVAL YEAR TO 
MONTH");
+               else if (strcmp(c_type_digits, "3") == 0)
+                       space = mnstr_printf(toConsole, "INTERVAL MONTH");
+               else
+                       fprintf(stderr, "Internal error: unrecognized month 
interval %s\n", c_type_digits);
+       } else if (strcmp(c_type, "sec_interval") == 0) {
+               if (strcmp(c_type_digits, "4") == 0)
+                       space = mnstr_printf(toConsole, "INTERVAL DAY");
+               else if (strcmp(c_type_digits, "5") == 0)
+                       space = mnstr_printf(toConsole, "INTERVAL DAY TO HOUR");
+               else if (strcmp(c_type_digits, "6") == 0)
+                       space = mnstr_printf(toConsole, "INTERVAL DAY TO 
MINUTE");
+               else if (strcmp(c_type_digits, "7") == 0)
+                       space = mnstr_printf(toConsole, "INTERVAL DAY TO 
SECOND");
+               else if (strcmp(c_type_digits, "8") == 0)
+                       space = mnstr_printf(toConsole, "INTERVAL HOUR");
+               else if (strcmp(c_type_digits, "9") == 0)
+                       space = mnstr_printf(toConsole, "INTERVAL HOUR TO 
MINUTE");
+               else if (strcmp(c_type_digits, "10") == 0)
+                       space = mnstr_printf(toConsole, "INTERVAL HOUR TO 
SECOND");
+               else if (strcmp(c_type_digits, "11") == 0)
+                       space = mnstr_printf(toConsole, "INTERVAL MINUTE");
+               else if (strcmp(c_type_digits, "12") == 0)
+                       space = mnstr_printf(toConsole, "INTERVAL MINUTE TO 
SECOND");
+               else if (strcmp(c_type_digits, "13") == 0)
+                       space = mnstr_printf(toConsole, "INTERVAL SECOND");
+               else
+                       fprintf(stderr, "Internal error: unrecognized second 
interval %s\n", c_type_digits);
+       } else if (strcmp(c_type, "clob") == 0) {
+               space = mnstr_printf(toConsole, "CHARACTER LARGE OBJECT");
+               if (strcmp(c_type_digits, "0") != 0)
+                       space += mnstr_printf(toConsole, "(%s)", c_type_digits);
+       } else if (strcmp(c_type, "blob") == 0) {
+               space = mnstr_printf(toConsole, "BINARY LARGE OBJECT");
+               if (strcmp(c_type_digits, "0") != 0)
+                       space += mnstr_printf(toConsole, "(%s)", c_type_digits);
+       } else if (strcmp(c_type, "timestamp") == 0 ||
+                  strcmp(c_type, "timestamptz") == 0) {
+               space = mnstr_printf(toConsole, "TIMESTAMP", c_type);
+               if (strcmp(c_type_digits, "7") != 0)
+                       space += mnstr_printf(toConsole, "(%d)", 
atoi(c_type_digits) - 1);
+               if (strcmp(c_type, "timestamptz") == 0)
+                       space += mnstr_printf(toConsole, " WITH TIME ZONE");
+       } else if (strcmp(c_type, "time") == 0 ||
+                  strcmp(c_type, "timetz") == 0) {
+               space = mnstr_printf(toConsole, "TIME", c_type);
+               if (strcmp(c_type_digits, "1") != 0)
+                       space += mnstr_printf(toConsole, "(%d)", 
atoi(c_type_digits) - 1);
+               if (strcmp(c_type, "timetz") == 0)
+                       space += mnstr_printf(toConsole, " WITH TIME ZONE");
+       } else if (strcmp(c_type, "real") == 0) {
+               if (strcmp(c_type_digits, "24") == 0 &&
+                   strcmp(c_type_scale, "0") == 0)
+                       space = mnstr_printf(toConsole, "REAL");
+               else if (strcmp(c_type_scale, "0") == 0)
+                       space = mnstr_printf(toConsole, "FLOAT(%s)", 
c_type_digits);
+               else
+                       space = mnstr_printf(toConsole, "FLOAT(%s,%s)",
+                                       c_type_digits, c_type_scale);
+       } else if (strcmp(c_type, "double") == 0) {
+               if (strcmp(c_type_digits, "53") == 0 &&
+                   strcmp(c_type_scale, "0") == 0)
+                       space = mnstr_printf(toConsole, "DOUBLE");
+               else if (strcmp(c_type_scale, "0") == 0)
+                       space = mnstr_printf(toConsole, "FLOAT(%s)", 
c_type_digits);
+               else
+                       space = mnstr_printf(toConsole, "FLOAT(%s,%s)",
+                                       c_type_digits, c_type_scale);
+       } else if (strcmp(c_type, "decimal") == 0 &&
+                  strcmp(c_type_digits, "1") == 0 &&
+                  strcmp(c_type_scale, "0") == 0) {
+               space = mnstr_printf(toConsole, "DECIMAL");
+       } else if (strcmp(c_type, "table") == 0) {
+               mnstr_printf(toConsole, "TABLE ");
+               dump_column_definition(mid, toConsole, NULL, NULL, 
c_type_digits, 1);
+       } else if (strcmp(c_type_digits, "0") == 0) {
+               space = mnstr_printf(toConsole, "%s", toUpper(c_type));
+       } else if (strcmp(c_type_scale, "0") == 0) {
+               space = mnstr_printf(toConsole, "%s(%s)",
+                               toUpper(c_type), c_type_digits);
+       } else {
+               space = mnstr_printf(toConsole, "%s(%s,%s)",
+                               toUpper(c_type), c_type_digits, c_type_scale);
+       }
+       return space;
+}
+
+static int
+dump_column_definition(Mapi mid, stream *toConsole, const char *schema, const 
char *tname, const char *tid, int foreign)
+{
+       MapiHdl hdl = NULL;
+       char *query;
+       size_t maxquerylen;
+       int cnt;
+       int slen;
+       int cap;
+#define CAP(X) ((cap = (int) (X)) < 0 ? 0 : cap)
+
+       maxquerylen = 1024;
+       if (tid == NULL)
+               maxquerylen += strlen(tname) + strlen(schema);
+       if ((query = malloc(maxquerylen)) == NULL)
+               goto bailout;
+
+       mnstr_printf(toConsole, "(\n");
+
+       if (tid)
+               snprintf(query, maxquerylen,
+                        "SELECT \"c\".\"name\","               /* 0 */
+                               "\"c\".\"type\","               /* 1 */
+                               "\"c\".\"type_digits\","        /* 2 */
+                               "\"c\".\"type_scale\","         /* 3 */
+                               "\"c\".\"null\","               /* 4 */
+                               "\"c\".\"default\","            /* 5 */
+                               "\"c\".\"number\" "             /* 6 */
+                        "FROM \"sys\".\"_columns\" \"c\" "
+                        "WHERE \"c\".\"table_id\" = %s "
+                        "ORDER BY \"number\"", tid);
+       else
+               snprintf(query, maxquerylen,
+                        "SELECT \"c\".\"name\","               /* 0 */
+                               "\"c\".\"type\","               /* 1 */
+                               "\"c\".\"type_digits\","        /* 2 */
+                               "\"c\".\"type_scale\","         /* 3 */
+                               "\"c\".\"null\","               /* 4 */
+                               "\"c\".\"default\","            /* 5 */
+                               "\"c\".\"number\" "             /* 6 */
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to