Changeset: 763df5150f0f for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=763df5150f0f Modified Files: clients/Tests/MAL-signatures.stable.out clients/Tests/MAL-signatures.stable.out.int128 clients/Tests/exports.stable.out monetdb5/optimizer/opt_prelude.c monetdb5/optimizer/opt_prelude.h sql/backends/monet5/rel_bin.c sql/backends/monet5/sql_cat.c sql/backends/monet5/sql_cat.h sql/backends/monet5/sql_statement.c sql/backends/monet5/sql_upgrades.c sql/backends/monet5/sqlcatalog.mal sql/include/sql_relation.h sql/scripts/97_comments.sql sql/server/rel_schema.c sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.int128 sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.powerpc64 sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.32bit sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.int128 sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.powerpc64 sql/test/emptydb-upgrade-hge/Tests/upgrade.stable.out.int128 sql/test/emptydb-upgrade/Tests/upgrade.stable.out sql/test/emptydb-upgrade/Tests/upgrade.stable.out.32bit sql/test/emptydb-upgrade/Tests/upgrade.stable.out.int128 sql/test/emptydb/Tests/check.stable.out sql/test/emptydb/Tests/check.stable.out.32bit sql/test/emptydb/Tests/check.stable.out.int128 sql/test/testdb-upgrade-chain-hge/Tests/upgrade.stable.out.int128 sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out.32bit sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out.int128 sql/test/testdb-upgrade-hge/Tests/upgrade.stable.out.int128 sql/test/testdb-upgrade/Tests/upgrade.stable.out sql/test/testdb-upgrade/Tests/upgrade.stable.out.32bit sql/test/testdb-upgrade/Tests/upgrade.stable.out.int128 Branch: default Log Message:
merged (again) with Mar2018 diffs (truncated from 3288 to 300 lines): diff --git a/clients/Tests/MAL-signatures.stable.out b/clients/Tests/MAL-signatures.stable.out --- a/clients/Tests/MAL-signatures.stable.out +++ b/clients/Tests/MAL-signatures.stable.out @@ -10948,6 +10948,7 @@ Ready. [ "sqlcatalog", "alter_set_table", "pattern sqlcatalog.alter_set_table(sname:str, tnme:str, access:int):void ", "SQLalter_set_table;", "Catalog operation alter_set_table" ] [ "sqlcatalog", "alter_table", "pattern sqlcatalog.alter_table(sname:str, tname:str, tbl:ptr, action:int):void ", "SQLalter_table;", "Catalog operation alter_table" ] [ "sqlcatalog", "alter_user", "pattern sqlcatalog.alter_user(sname:str, passwrd:str, enc:int, schema:str, oldpasswrd:str):void ", "SQLalter_user;", "Catalog operation alter_user" ] +[ "sqlcatalog", "comment_on", "pattern sqlcatalog.comment_on(objid:int, remark:str):void ", "SQLcomment_on;", "Catalog operation comment_on" ] [ "sqlcatalog", "create_function", "pattern sqlcatalog.create_function(sname:str, fname:str, fcn:ptr):void ", "SQLcreate_function;", "Catalog operation create_function" ] [ "sqlcatalog", "create_role", "pattern sqlcatalog.create_role(sname:str, role:str, grator:int):void ", "SQLcreate_role;", "Catalog operation create_role" ] [ "sqlcatalog", "create_schema", "pattern sqlcatalog.create_schema(sname:str, auth:str, ifnotexists:int, action:int):void ", "SQLcreate_schema;", "Catalog operation create_schema" ] diff --git a/clients/Tests/MAL-signatures.stable.out.int128 b/clients/Tests/MAL-signatures.stable.out.int128 --- a/clients/Tests/MAL-signatures.stable.out.int128 +++ b/clients/Tests/MAL-signatures.stable.out.int128 @@ -15161,6 +15161,7 @@ Ready. [ "sqlcatalog", "alter_set_table", "pattern sqlcatalog.alter_set_table(sname:str, tnme:str, access:int):void ", "SQLalter_set_table;", "Catalog operation alter_set_table" ] [ "sqlcatalog", "alter_table", "pattern sqlcatalog.alter_table(sname:str, tname:str, tbl:ptr, action:int):void ", "SQLalter_table;", "Catalog operation alter_table" ] [ "sqlcatalog", "alter_user", "pattern sqlcatalog.alter_user(sname:str, passwrd:str, enc:int, schema:str, oldpasswrd:str):void ", "SQLalter_user;", "Catalog operation alter_user" ] +[ "sqlcatalog", "comment_on", "pattern sqlcatalog.comment_on(objid:int, remark:str):void ", "SQLcomment_on;", "Catalog operation comment_on" ] [ "sqlcatalog", "create_function", "pattern sqlcatalog.create_function(sname:str, fname:str, fcn:ptr):void ", "SQLcreate_function;", "Catalog operation create_function" ] [ "sqlcatalog", "create_role", "pattern sqlcatalog.create_role(sname:str, role:str, grator:int):void ", "SQLcreate_role;", "Catalog operation create_role" ] [ "sqlcatalog", "create_schema", "pattern sqlcatalog.create_schema(sname:str, auth:str, ifnotexists:int, action:int):void ", "SQLcreate_schema;", "Catalog operation create_schema" ] diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out --- a/clients/Tests/exports.stable.out +++ b/clients/Tests/exports.stable.out @@ -2025,6 +2025,7 @@ ssize_t color_fromstr(const char *colorS ssize_t color_tostr(char **colorStr, size_t *len, const color *c); str columnBindRef; str columnRef; +str comment_onRef; str commitRef; str compileAllOptimizers(Client cntxt); str compileOptimizer(Client cntxt, const char *name); diff --git a/monetdb5/optimizer/opt_prelude.c b/monetdb5/optimizer/opt_prelude.c --- a/monetdb5/optimizer/opt_prelude.c +++ b/monetdb5/optimizer/opt_prelude.c @@ -72,6 +72,7 @@ str clear_tableRef; str closeRef; str columnBindRef; str columnRef; +str comment_onRef; str commitRef; str connectRef; str copy_fromRef; @@ -362,6 +363,7 @@ void optimizerInit(void) closeRef = putName("close"); columnRef = putName("column"); columnBindRef = putName("columnBind"); + comment_onRef = putName("comment_on"); commitRef = putName("commit"); connectRef = putName("connect"); countRef = putName("count"); diff --git a/monetdb5/optimizer/opt_prelude.h b/monetdb5/optimizer/opt_prelude.h --- a/monetdb5/optimizer/opt_prelude.h +++ b/monetdb5/optimizer/opt_prelude.h @@ -70,6 +70,7 @@ mal_export str clear_tableRef; mal_export str closeRef; mal_export str columnBindRef; mal_export str columnRef; +mal_export str comment_onRef; mal_export str commitRef; mal_export str connectRef; mal_export str copy_fromRef; diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c --- a/sql/backends/monet5/rel_bin.c +++ b/sql/backends/monet5/rel_bin.c @@ -4993,7 +4993,7 @@ rel2bin_ddl(backend *be, sql_rel *rel, l } else if (rel->flag <= DDL_ALTER_TABLE) { s = rel2bin_catalog_table(be, rel, refs); sql->type = Q_SCHEMA; - } else if (rel->flag <= DDL_ALTER_TABLE_SET_ACCESS) { + } else if (rel->flag <= DDL_COMMENT_ON) { s = rel2bin_catalog2(be, rel, refs); sql->type = Q_SCHEMA; } diff --git a/sql/backends/monet5/sql_cat.c b/sql/backends/monet5/sql_cat.c --- a/sql/backends/monet5/sql_cat.c +++ b/sql/backends/monet5/sql_cat.c @@ -1335,3 +1335,51 @@ SQLalter_set_table(Client cntxt, MalBlkP return msg; } + +str +SQLcomment_on(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) +{ + mvc *sql = NULL; + str msg; + int objid = *getArgReference_int(stk, pci, 1); + char *remark = *getArgReference_str(stk, pci, 2); + sql_trans *tx; + sql_schema *sys; + sql_table *comments; + sql_column *id_col, *remark_col; + oid rid; + + initcontext(); + + // Manually insert the rows to circumvent permission checks. + tx = sql->session->tr; + sys = mvc_bind_schema(sql, "sys"); + if (!sys) + throw(SQL, "sql.comment_on", SQLSTATE(3F000) "Internal error"); + comments = mvc_bind_table(sql, sys, "comments"); + if (!comments) + throw(SQL, "sql.comment_on", SQLSTATE(3F000) "no table sys.comments"); + id_col = mvc_bind_column(sql, comments, "id"); + remark_col = find_sql_column(comments, "remark"); + if (!id_col || !remark_col) + throw(SQL, "sql.comment_on", SQLSTATE(3F000) "no table sys.comments"); + rid = table_funcs.column_find_row(tx, id_col, &objid, NULL); + if (remark != NULL && *remark) { + if (!is_oid_nil(rid)) { + // have new remark and found old one, so update field + /* UPDATE sys.comments SET remark = %s WHERE id = %d */ + table_funcs.column_update_value(tx, remark_col, rid, remark); + } else { + // have new remark but found none so insert row + /* INSERT INTO sys.comments (id, remark) VALUES (%d, %s) */ + table_funcs.table_insert(tx, comments, &objid, remark); + } + } else { + if (!is_oid_nil(rid)) { + // have no remark but found one, so delete row + /* DELETE FROM sys.comments WHERE id = %d */ + table_funcs.table_delete(tx, comments, rid); + } + } + return MAL_SUCCEED; +} diff --git a/sql/backends/monet5/sql_cat.h b/sql/backends/monet5/sql_cat.h --- a/sql/backends/monet5/sql_cat.h +++ b/sql/backends/monet5/sql_cat.h @@ -63,6 +63,7 @@ sql5_export str SQLdrop_trigger(Client c sql5_export str SQLalter_add_table(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); sql5_export str SQLalter_del_table(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); sql5_export str SQLalter_set_table(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); +sql5_export str SQLcomment_on(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); sql5_export str UPGdrop_func(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); sql5_export str UPGcreate_func(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); diff --git a/sql/backends/monet5/sql_statement.c b/sql/backends/monet5/sql_statement.c --- a/sql/backends/monet5/sql_statement.c +++ b/sql/backends/monet5/sql_statement.c @@ -2334,6 +2334,7 @@ stmt_catalog(backend *be, int type, stmt case DDL_ALTER_TABLE_ADD_TABLE: q = newStmt(mb, sqlcatalogRef, alter_add_tableRef); break; case DDL_ALTER_TABLE_DEL_TABLE: q = newStmt(mb, sqlcatalogRef, alter_del_tableRef); break; case DDL_ALTER_TABLE_SET_ACCESS:q = newStmt(mb, sqlcatalogRef, alter_set_tableRef); break; + case DDL_COMMENT_ON: q = newStmt(mb, sqlcatalogRef, comment_onRef); break; default: showException(GDKout, SQL, "sql", "catalog operation unknown\n"); } diff --git a/sql/backends/monet5/sql_upgrades.c b/sql/backends/monet5/sql_upgrades.c --- a/sql/backends/monet5/sql_upgrades.c +++ b/sql/backends/monet5/sql_upgrades.c @@ -1411,10 +1411,6 @@ sql_update_mar2018(Client c, mvc *sql) " remark VARCHAR(65000) NOT NULL\n" ");\n" "GRANT SELECT ON sys.comments TO PUBLIC;\n" - "CREATE PROCEDURE sys.no_op()\n" - "BEGIN\n" - " DECLARE dummy INTEGER;\n" - "END;\n" "CREATE FUNCTION sys.function_type_keyword(ftype INT)\n" "RETURNS VARCHAR(20)\n" "BEGIN\n" @@ -1506,7 +1502,7 @@ sql_update_mar2018(Client c, mvc *sql) "INSERT INTO sys.systemfunctions\n" "SELECT id FROM sys.functions\n" "WHERE schema_id = (SELECT id FROM sys.schemas WHERE name = 'sys')\n" - "AND name IN ('function_type_keyword', 'no_op');\n" + "AND name = 'function_type_keyword';\n" "ALTER TABLE sys.keywords SET READ WRITE;\n" "INSERT INTO sys.keywords VALUES ('COMMENT'), ('CONTINUE'), ('START'), ('TRUNCATE');\n" "-- ALTER TABLE sys.keywords SET READ ONLY;\n" diff --git a/sql/backends/monet5/sqlcatalog.mal b/sql/backends/monet5/sqlcatalog.mal --- a/sql/backends/monet5/sqlcatalog.mal +++ b/sql/backends/monet5/sqlcatalog.mal @@ -147,3 +147,6 @@ pattern alter_set_table( sname:str, tnme address SQLalter_set_table comment "Catalog operation alter_set_table"; +pattern comment_on(objid:int, remark:str) +address SQLcomment_on +comment "Catalog operation comment_on"; diff --git a/sql/include/sql_relation.h b/sql/include/sql_relation.h --- a/sql/include/sql_relation.h +++ b/sql/include/sql_relation.h @@ -86,6 +86,7 @@ typedef struct expression { #define GET_PSM_LEVEL(level) (level>>8) /* todo make enum */ +/* ordering is important! see rel2bin_ddl() */ #define DDL_OUTPUT 1 #define DDL_LIST 2 #define DDL_PSM 3 @@ -133,6 +134,8 @@ typedef struct expression { #define DDL_ALTER_TABLE_DEL_TABLE 64 #define DDL_ALTER_TABLE_SET_ACCESS 65 +#define DDL_COMMENT_ON 66 + #define DDL_EMPTY 100 #define MAXOPS 22 diff --git a/sql/scripts/97_comments.sql b/sql/scripts/97_comments.sql --- a/sql/scripts/97_comments.sql +++ b/sql/scripts/97_comments.sql @@ -11,13 +11,6 @@ CREATE TABLE sys.comments ( GRANT SELECT ON sys.comments TO PUBLIC; -CREATE PROCEDURE sys.no_op() -BEGIN - DECLARE dummy INTEGER; -END; --- do not grant to public - - -- This table used to be in 99_system.sql but we need the systemfunctions table -- in sys.describe_all_objects and sys.commented_function_signatures defined below. CREATE TABLE sys.systemfunctions (function_id INTEGER NOT NULL); diff --git a/sql/server/rel_schema.c b/sql/server/rel_schema.c --- a/sql/server/rel_schema.c +++ b/sql/server/rel_schema.c @@ -2204,75 +2204,52 @@ rel_find_designated_routine(mvc *sql, sy } static sqlid -rel_find_designated_object(mvc *sql, symbol *sym, sql_schema **schema_out) { +rel_find_designated_object(mvc *sql, symbol *sym, sql_schema **schema_out) +{ sql_schema *dummy; if (schema_out == NULL) schema_out = &dummy; switch (sym->token) { - case SQL_SCHEMA: - return rel_find_designated_schema(sql, sym, schema_out); - case SQL_TABLE: - return rel_find_designated_table(sql, sym, schema_out); - case SQL_VIEW: - return rel_find_designated_table(sql, sym, schema_out); - case SQL_COLUMN: - return rel_find_designated_column(sql, sym, schema_out); - case SQL_INDEX: - return rel_find_designated_index(sql, sym, schema_out); - case SQL_SEQUENCE: - return rel_find_designated_sequence(sql, sym, schema_out); - case SQL_ROUTINE: - return rel_find_designated_routine(sql, sym, schema_out); - default: - sql_error(sql, 2, "42000!COMMENT ON %s is not supported", token2string(sym->token)); - return 0; + case SQL_SCHEMA: + return rel_find_designated_schema(sql, sym, schema_out); + case SQL_TABLE: + return rel_find_designated_table(sql, sym, schema_out); + case SQL_VIEW: + return rel_find_designated_table(sql, sym, schema_out); + case SQL_COLUMN: + return rel_find_designated_column(sql, sym, schema_out); + case SQL_INDEX: + return rel_find_designated_index(sql, sym, schema_out); + case SQL_SEQUENCE: + return rel_find_designated_sequence(sql, sym, schema_out); + case SQL_ROUTINE: + return rel_find_designated_routine(sql, sym, schema_out); + default: + sql_error(sql, 2, "42000!COMMENT ON %s is not supported", token2string(sym->token)); + return 0; } } static sql_rel * -rel_comment_on(mvc *sql, sqlid obj_id, sql_schema *schema, char *remark) { - sql_trans *tx; - sql_schema *sys; - sql_table *comments; - sql_column *id_col, *remark_col; - oid rid; +rel_comment_on(sql_allocator *sa, sqlid obj_id, const char *remark) +{ + sql_rel *rel = rel_create(sa); + list *exps = new_exp_list(sa); - // Check authorization - if (!mvc_schema_privs(sql, schema)) { - return sql_error(sql, 02, SQLSTATE(42000) "COMMENT ON: insufficient privileges for user '%s' in schema '%s'", stack_get_string(sql, "current_user"), schema->base.name); - } - - // Manually insert the rows to circumvent permission checks. - tx = sql->session->tr; - sys = find_sql_schema(tx, "sys"); - if (!sys) - return NULL; - comments = find_sql_table(sys, "comments"); - if (!comments) + if (rel == NULL || exps == NULL) return NULL; _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list