Changeset: 5cdf070153fa for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/5cdf070153fa
Modified Files:
        clients/mapiclient/dump.c
        sql/server/rel_dump.c
        sql/test/testdb/Tests/dump-nogeom.stable.out
        sql/test/testdb/Tests/dump.stable.out
Branch: label
Log Message:

Dump CHECK constraints.


diffs (139 lines):

diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c
--- a/clients/mapiclient/dump.c
+++ b/clients/mapiclient/dump.c
@@ -1119,7 +1119,9 @@ dump_column_definition(Mapi mid, stream 
                         "SELECT kc.name, "             /* 0 */
                                "kc.nr, "                       /* 1 */
                                "k.name, "                      /* 2 */
-                               "kc.id "                        /* 3 */
+                               "kc.id, "                       /* 3 */
+                               "k.type, "                      /* 4 */
+                           "case when k.type = 4 then 
sys.check_constraint(s.name, k.name) else null end " /* 5 */
                         "FROM sys.objects kc, "
                              "sys.keys k "
                         "WHERE kc.id = k.id "
@@ -1132,14 +1134,15 @@ dump_column_definition(Mapi mid, stream 
                                "kc.nr, "                       /* 1 */
                                "k.name, "                      /* 2 */
                                "kc.id, "                       /* 3 */
-                               "k.type "                       /* 4 */
+                               "k.type, "                      /* 4 */
+                           "case when k.type = 4 then 
sys.check_constraint(s.name, k.name) else null end " /* 5 */
                         "FROM sys.objects kc, "
                              "sys.keys k, "
                              "sys.schemas s, "
                              "sys._tables t "
                         "WHERE kc.id = k.id "
                           "AND k.table_id = t.id "
-                          "AND k.type in (1, 3) "
+                          "AND k.type in (1, 3, 4) "
                           "AND t.schema_id = s.id "
                           "AND s.name = '%s' "
                           "AND t.name = '%s' "
@@ -1158,16 +1161,28 @@ dump_column_definition(Mapi mid, stream 
                if (strcmp(kc_nr, "0") == 0) {
                        if (cnt)
                                mnstr_write(sqlf, ")", 1, 1);
+                       cnt = 0;
                        mnstr_printf(sqlf, ",\n\t");
                        if (k_name) {
                                mnstr_printf(sqlf, "CONSTRAINT ");
                                dquoted_print(sqlf, k_name, " ");
                        }
-                       mnstr_printf(sqlf, "UNIQUE%s (", strcmp(k_type, "1") == 
0 ? "" : " NULLS NOT DISTINCT");
-                       cnt = 1;
+                       if (strcmp(k_type, "4") == 0) {
+                               const char *k_check = mapi_fetch_field(hdl, 5);
+                               mnstr_printf(sqlf, "CHECK (%s)", k_check);
+                       } else {
+                               if (strcmp(k_type, "1") == 0) {
+                                       mnstr_printf(sqlf, "UNIQUE");
+                               } else {
+                                       mnstr_printf(sqlf, "UNIQUE NULLS NOT 
DISTINCT");
+                               }
+                               mnstr_printf(sqlf, " (");
+                               cnt = 1;
+                       }
                } else
                        mnstr_printf(sqlf, ", ");
-               dquoted_print(sqlf, c_column, NULL);
+               if (cnt)
+                       dquoted_print(sqlf, c_column, NULL);
                if (mnstr_errnr(sqlf) != MNSTR_NO__ERROR)
                        goto bailout;
        }
diff --git a/sql/server/rel_dump.c b/sql/server/rel_dump.c
--- a/sql/server/rel_dump.c
+++ b/sql/server/rel_dump.c
@@ -2525,6 +2525,29 @@ is_infix(sql_func *f)
        return false;
 }
 
+static void
+exp2sql_dquoted(stream *fout, const char *pref, const char *val, const char 
*suff)
+{
+       if (pref)
+               mnstr_printf(fout, "%s", pref);
+       mnstr_write(fout, "\"", 1, 1);
+       while (*val) {
+               const char *p = strchr(val, '"');
+               if (p) {
+                       if (p > val)
+                               mnstr_write(fout, val, 1, p - val);
+                       mnstr_write(fout, "\"\"", 1, 2);
+                       val = p + 1;
+               } else {
+                       mnstr_printf(fout, "%s", val);
+                       break;
+               }
+       }
+       mnstr_write(fout, "\"", 1, 1);
+       if (suff)
+               mnstr_printf(fout, "%s", suff);
+}
+
 /* only simple expressions, ie recursive no psm */
 static void
 exp2sql_print(mvc *sql, stream *fout, sql_exp *e)
@@ -2538,7 +2561,7 @@ exp2sql_print(mvc *sql, stream *fout, sq
                                mnstr_printf(fout, " %s ", sf->func->base.name);
                                exp2sql_print(sql, fout, args->h->next->data);
                        } else {
-                               mnstr_printf(fout, "%s(", sf->func->base.name);
+                               exp2sql_dquoted(fout, NULL, 
sf->func->base.name, "(");
                                if (args)
                                        for (node *n = args->h; n; n = n->next) 
{
                                                exp2sql_print(sql, fout, 
n->data);
@@ -2549,7 +2572,7 @@ exp2sql_print(mvc *sql, stream *fout, sq
                        }
                }       break;
                case e_column:
-                       mnstr_printf(fout, "%s", exp_name(e));
+                       exp2sql_dquoted(fout, NULL, exp_name(e), NULL);
                        break;
                case e_convert:
                        mnstr_printf(fout, "CAST (" );
diff --git a/sql/test/testdb/Tests/dump-nogeom.stable.out 
b/sql/test/testdb/Tests/dump-nogeom.stable.out
--- a/sql/test/testdb/Tests/dump-nogeom.stable.out
+++ b/sql/test/testdb/Tests/dump-nogeom.stable.out
@@ -101198,7 +101198,7 @@ CREATE TABLE "testschema"."nulls_not_dis
        CONSTRAINT "nulls_not_distinct_id_pkey" PRIMARY KEY ("id"),
        CONSTRAINT "nulls_not_distinct_unique1_unique" UNIQUE ("unique1"),
        CONSTRAINT "nulls_not_distinct_unique2_nndunique" UNIQUE NULLS NOT 
DISTINCT ("unique2"),
-       CONSTRAINT "nulls_not_distinct_check1_check" CHECK("check1" > 0)
+       CONSTRAINT "nulls_not_distinct_check1_check" CHECK ("check1" > 0)
 );
 COPY 1 RECORDS INTO "testschema"."nulls_not_distinct" FROM stdin USING 
DELIMITERS E'\t',E'\n','"';
 1      1       1       1
diff --git a/sql/test/testdb/Tests/dump.stable.out 
b/sql/test/testdb/Tests/dump.stable.out
--- a/sql/test/testdb/Tests/dump.stable.out
+++ b/sql/test/testdb/Tests/dump.stable.out
@@ -101198,7 +101198,7 @@ CREATE TABLE "testschema"."nulls_not_dis
        CONSTRAINT "nulls_not_distinct_id_pkey" PRIMARY KEY ("id"),
        CONSTRAINT "nulls_not_distinct_unique1_unique" UNIQUE ("unique1"),
        CONSTRAINT "nulls_not_distinct_unique2_nndunique" UNIQUE NULLS NOT 
DISTINCT ("unique2"),
-       CONSTRAINT "nulls_not_distinct_check1_check" CHECK("check1" > 0)
+       CONSTRAINT "nulls_not_distinct_check1_check" CHECK ("check1" > 0)
 );
 COPY 1 RECORDS INTO "testschema"."nulls_not_distinct" FROM stdin USING 
DELIMITERS E'\t',E'\n','"';
 1      1       1       1
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to