Changeset: 1ee0a32b47c3 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/1ee0a32b47c3
Modified Files:
        clients/mapiclient/dump.c
        clients/mapiclient/mclient.c
        sql/test/emptydb/Tests/check.stable.out.int128
Branch: Jan2022
Log Message:

Merge with Jul2021 branch.


diffs (172 lines):

diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c
--- a/clients/mapiclient/dump.c
+++ b/clients/mapiclient/dump.c
@@ -1692,9 +1692,9 @@ dump_table_data(Mapi mid, const char *sc
                goto bailout;
        if (mapi_rows_affected(hdl) != 1) {
                if (mapi_rows_affected(hdl) == 0)
-                       fprintf(stderr, "table '%s.%s' does not exist\n", 
schema, tname);
+                       fprintf(stderr, "table %s.%s does not exist\n", schema, 
tname);
                else
-                       fprintf(stderr, "table '%s.%s' is not unique\n", 
schema, tname);
+                       fprintf(stderr, "table %s.%s is not unique\n", schema, 
tname);
                goto bailout;
        }
        while ((mapi_fetch_row(hdl)) != 0) {
@@ -1862,6 +1862,93 @@ bailout:
        return 1;
 }
 
+static int
+dump_table_alters(Mapi mid, const char *schema, const char *tname, stream 
*toConsole)
+{
+       char *sname = NULL;
+       char *query = NULL;
+       size_t maxquerylen;
+       MapiHdl hdl = NULL;
+       char *s = NULL;
+       char *t = NULL;
+       int rc = 1;
+
+       if (schema == NULL) {
+               if ((sname = strchr(tname, '.')) != NULL) {
+                       size_t len = sname - tname + 1;
+
+                       sname = malloc(len);
+                       if (sname == NULL)
+                               goto bailout;
+                       strcpy_len(sname, tname, len);
+                       tname += len;
+               } else if ((sname = get_schema(mid)) == NULL) {
+                       goto bailout;
+               }
+               schema = sname;
+       }
+
+       maxquerylen = 5120 + 2*strlen(tname) + 2*strlen(schema);
+       query = malloc(maxquerylen);
+       s = sescape(schema);
+       t = sescape(tname);
+       if (query == NULL || s == NULL || t == NULL)
+               goto bailout;
+
+       snprintf(query, maxquerylen,
+                        "SELECT t.access FROM sys._tables t, sys.schemas s "
+                        "WHERE s.name = '%s' AND t.schema_id = s.id AND t.name 
= '%s'",
+                        s, t);
+       if ((hdl = mapi_query(mid, query)) == NULL || mapi_error(mid))
+               goto bailout;
+       if (mapi_rows_affected(hdl) != 1) {
+               if (mapi_rows_affected(hdl) == 0)
+                       fprintf(stderr, "table %s.%s does not exist\n", schema, 
tname);
+               else
+                       fprintf(stderr, "table %s.%s is not unique\n", schema, 
tname);
+               goto bailout;
+       }
+       while ((mapi_fetch_row(hdl)) != 0) {
+               const char *access = mapi_fetch_field(hdl, 0);
+               if (access && *access == '1') {
+                       mnstr_printf(toConsole, "ALTER TABLE ");
+                       dquoted_print(toConsole, schema, ".");
+                       dquoted_print(toConsole, tname, " ");
+                       mnstr_printf(toConsole, "SET READ ONLY;\n");
+               }
+       }
+       mapi_close_handle(hdl);
+       snprintf(query, maxquerylen,
+                        "SELECT name, storage FROM sys._columns "
+                        "WHERE storage IS NOT NULL "
+                        "AND table_id = (SELECT id FROM sys._tables WHERE name 
= '%s' "
+                        "AND schema_id = (SELECT id FROM sys.schemas WHERE 
name = '%s'))",
+                        t, s);
+       if ((hdl = mapi_query(mid, query)) == NULL || mapi_error(mid))
+               goto bailout;
+       while ((mapi_fetch_row(hdl)) != 0) {
+               const char *cname = mapi_fetch_field(hdl, 0);
+               const char *storage = mapi_fetch_field(hdl, 1);
+               char *stg = sescape(storage);
+               if (stg == NULL)
+                       goto bailout;
+               mnstr_printf(toConsole, "ALTER TABLE ");
+               dquoted_print(toConsole, schema, ".");
+               dquoted_print(toConsole, tname, " ");
+               mnstr_printf(toConsole, "ALTER COLUMN ");
+               dquoted_print(toConsole, cname, " ");
+               mnstr_printf(toConsole, "SET STORAGE '%s';\n", stg);
+               free(stg);
+       }
+       rc = 0;                                         /* success */
+  bailout:
+       free(s);
+       free(t);
+       mapi_close_handle(hdl);         /* may be NULL */
+       free(sname);                            /* may be NULL */
+       return rc;
+}
+
 int
 dump_table(Mapi mid, const char *schema, const char *tname, stream *toConsole,
                   bool describe, bool foreign, bool useInserts, bool 
databaseDump,
@@ -1872,6 +1959,8 @@ dump_table(Mapi mid, const char *schema,
        rc = describe_table(mid, schema, tname, toConsole, foreign, 
databaseDump);
        if (rc == 0 && !describe)
                rc = dump_table_data(mid, schema, tname, toConsole, useInserts, 
noescape);
+       if (rc == 0)
+               rc = dump_table_alters(mid, schema, tname, toConsole);
        return rc;
 }
 
diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -2515,7 +2515,7 @@ doFile(Mapi mid, stream *fp, bool useins
                                                start_pager(&saveFD);
 #endif
                                                if (x & MD_TABLE || x & MD_VIEW)
-                                                       describe_table(mid, 
NULL, line, toConsole, 1, false);
+                                                       dump_table(mid, NULL, 
line, toConsole, true, true, false, false, false);
                                                if (x & MD_SEQ)
                                                        describe_sequence(mid, 
NULL, line, toConsole);
                                                if (x & MD_FUNC)
diff --git a/sql/test/emptydb/Tests/check.stable.out.int128 
b/sql/test/emptydb/Tests/check.stable.out.int128
--- a/sql/test/emptydb/Tests/check.stable.out.int128
+++ b/sql/test/emptydb/Tests/check.stable.out.int128
@@ -972,16 +972,22 @@ CREATE TABLE "sys"."comments" ("id" INTE
 CREATE TABLE "sys"."db_user_info" ("name" VARCHAR(1024), "fullname" 
VARCHAR(2048), "default_schema" INTEGER, "schema_path" CHARACTER LARGE OBJECT);
 CREATE TABLE "sys"."dependencies" ("id" INTEGER, "depend_id" INTEGER, 
"depend_type" SMALLINT);
 CREATE TABLE "sys"."dependency_types" ("dependency_type_id" SMALLINT NOT NULL, 
"dependency_type_name" VARCHAR(15) NOT NULL, CONSTRAINT 
"dependency_types_dependency_type_id_pkey" PRIMARY KEY ("dependency_type_id"), 
CONSTRAINT "dependency_types_dependency_type_name_unique" UNIQUE 
("dependency_type_name"));
+ALTER TABLE "sys"."dependency_types" SET READ ONLY;
 CREATE TABLE "sys"."dump_statements" ("o" INTEGER, "s" CHARACTER LARGE OBJECT);
 CREATE TABLE "sys"."fkey_actions" ("action_id" SMALLINT NOT NULL, 
"action_name" VARCHAR(15) NOT NULL, CONSTRAINT "fkey_actions_action_id_pkey" 
PRIMARY KEY ("action_id"));
 CREATE TABLE "sys"."function_languages" ("language_id" SMALLINT NOT NULL, 
"language_name" VARCHAR(20) NOT NULL, "language_keyword" VARCHAR(20), 
CONSTRAINT "function_languages_language_id_pkey" PRIMARY KEY ("language_id"), 
CONSTRAINT "function_languages_language_name_unique" UNIQUE ("language_name"));
+ALTER TABLE "sys"."function_languages" SET READ ONLY;
 CREATE TABLE "sys"."function_types" ("function_type_id" SMALLINT NOT NULL, 
"function_type_name" VARCHAR(30) NOT NULL, "function_type_keyword" VARCHAR(30) 
NOT NULL, CONSTRAINT "function_types_function_type_id_pkey" PRIMARY KEY 
("function_type_id"), CONSTRAINT "function_types_function_type_name_unique" 
UNIQUE ("function_type_name"));
+ALTER TABLE "sys"."function_types" SET READ ONLY;
 CREATE TABLE "sys"."functions" ("id" INTEGER, "name" VARCHAR(256), "func" 
VARCHAR(8196), "mod" VARCHAR(8196), "language" INTEGER, "type" INTEGER, 
"side_effect" BOOLEAN, "varres" BOOLEAN, "vararg" BOOLEAN, "schema_id" INTEGER, 
"system" BOOLEAN, "semantics" BOOLEAN);
 CREATE TABLE "sys"."idxs" ("id" INTEGER, "table_id" INTEGER, "type" INTEGER, 
"name" VARCHAR(1024));
 CREATE TABLE "sys"."index_types" ("index_type_id" SMALLINT NOT NULL, 
"index_type_name" VARCHAR(25) NOT NULL, CONSTRAINT 
"index_types_index_type_id_pkey" PRIMARY KEY ("index_type_id"), CONSTRAINT 
"index_types_index_type_name_unique" UNIQUE ("index_type_name"));
+ALTER TABLE "sys"."index_types" SET READ ONLY;
 CREATE TABLE "sys"."key_types" ("key_type_id" SMALLINT NOT NULL, 
"key_type_name" VARCHAR(15) NOT NULL, CONSTRAINT "key_types_key_type_id_pkey" 
PRIMARY KEY ("key_type_id"), CONSTRAINT "key_types_key_type_name_unique" UNIQUE 
("key_type_name"));
+ALTER TABLE "sys"."key_types" SET READ ONLY;
 CREATE TABLE "sys"."keys" ("id" INTEGER, "table_id" INTEGER, "type" INTEGER, 
"name" VARCHAR(1024), "rkey" INTEGER, "action" INTEGER);
 CREATE TABLE "sys"."keywords" ("keyword" VARCHAR(40) NOT NULL, CONSTRAINT 
"keywords_keyword_pkey" PRIMARY KEY ("keyword"));
+ALTER TABLE "sys"."keywords" SET READ ONLY;
 CREATE TABLE "sys"."netcdf_attrs" ("obj_name" VARCHAR(256), "att_name" 
VARCHAR(256), "att_type" VARCHAR(64), "value" CHARACTER LARGE OBJECT, "file_id" 
INTEGER, "gr_name" VARCHAR(256));
 CREATE TABLE "sys"."netcdf_dims" ("dim_id" INTEGER, "file_id" INTEGER, "name" 
VARCHAR(64), "length" INTEGER);
 CREATE TABLE "sys"."netcdf_files" ("file_id" INTEGER, "location" CHAR(256));
@@ -989,6 +995,7 @@ CREATE TABLE "sys"."netcdf_vardim" ("var
 CREATE TABLE "sys"."netcdf_vars" ("var_id" INTEGER, "file_id" INTEGER, "name" 
VARCHAR(64), "vartype" VARCHAR(64), "ndim" INTEGER, "coord_dim_id" INTEGER);
 CREATE TABLE "sys"."objects" ("id" INTEGER, "name" VARCHAR(1024), "nr" 
INTEGER, "sub" INTEGER);
 CREATE TABLE "sys"."privilege_codes" ("privilege_code_id" INTEGER NOT NULL, 
"privilege_code_name" VARCHAR(40) NOT NULL, CONSTRAINT 
"privilege_codes_privilege_code_id_pkey" PRIMARY KEY ("privilege_code_id"), 
CONSTRAINT "privilege_codes_privilege_code_name_unique" UNIQUE 
("privilege_code_name"));
+ALTER TABLE "sys"."privilege_codes" SET READ ONLY;
 CREATE TABLE "sys"."privileges" ("obj_id" INTEGER, "auth_id" INTEGER, 
"privileges" INTEGER, "grantor" INTEGER, "grantable" INTEGER);
 CREATE TABLE "sys"."range_partitions" ("table_id" INTEGER, "partition_id" 
INTEGER, "minimum" VARCHAR(2048), "maximum" VARCHAR(2048), "with_nulls" 
BOOLEAN);
 CREATE TABLE "sys"."schemas" ("id" INTEGER, "name" VARCHAR(1024), 
"authorization" INTEGER, "owner" INTEGER, "system" BOOLEAN);
@@ -998,6 +1005,7 @@ CREATE TABLE "sys"."statistics" ("column
 CREATE TABLE "sys"."storagemodelinput" ("schema" VARCHAR(1024) NOT NULL, 
"table" VARCHAR(1024) NOT NULL, "column" VARCHAR(1024) NOT NULL, "type" 
VARCHAR(1024) NOT NULL, "typewidth" INTEGER NOT NULL, "count" BIGINT NOT NULL, 
"distinct" BIGINT NOT NULL, "atomwidth" INTEGER NOT NULL, "reference" BOOLEAN 
NOT NULL DEFAULT false, "sorted" BOOLEAN, "unique" BOOLEAN, "isacolumn" BOOLEAN 
NOT NULL DEFAULT true);
 CREATE TABLE "sys"."table_partitions" ("id" INTEGER, "table_id" INTEGER, 
"column_id" INTEGER, "expression" VARCHAR(2048), "type" TINYINT);
 CREATE TABLE "sys"."table_types" ("table_type_id" SMALLINT NOT NULL, 
"table_type_name" VARCHAR(25) NOT NULL, CONSTRAINT 
"table_types_table_type_id_pkey" PRIMARY KEY ("table_type_id"), CONSTRAINT 
"table_types_table_type_name_unique" UNIQUE ("table_type_name"));
+ALTER TABLE "sys"."table_types" SET READ ONLY;
 CREATE TABLE "sys"."triggers" ("id" INTEGER, "name" VARCHAR(1024), "table_id" 
INTEGER, "time" SMALLINT, "orientation" SMALLINT, "event" SMALLINT, "old_name" 
VARCHAR(1024), "new_name" VARCHAR(1024), "condition" VARCHAR(2048), "statement" 
VARCHAR(2048));
 CREATE TABLE "sys"."types" ("id" INTEGER, "systemname" VARCHAR(256), "sqlname" 
VARCHAR(1024), "digits" INTEGER, "scale" INTEGER, "radix" INTEGER, "eclass" 
INTEGER, "schema_id" INTEGER);
 CREATE TABLE "sys"."user_role" ("login_id" INTEGER, "role_id" INTEGER);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to