From f9ba242405fe4c47011e5881ada6352dad660ed8 Mon Sep 17 00:00:00 2001 From: Byungwook Kim Date: Tue, 24 May 2022 08:43:01 +0900 Subject: [PATCH 01/15] [CBRD-24240] migration tool for 11.0.x and 11.1.x --- migrate/Makefile | 19 + migrate/migrate.c | 1073 +++++++++++++++++++++++++++++++++++++++++++++ migrate/migrate.h | 74 ++++ 3 files changed, 1166 insertions(+) create mode 100644 migrate/Makefile create mode 100644 migrate/migrate.c create mode 100644 migrate/migrate.h diff --git a/migrate/Makefile b/migrate/Makefile new file mode 100644 index 0000000..fed9fbc --- /dev/null +++ b/migrate/Makefile @@ -0,0 +1,19 @@ +CC = gcc + +INCDIR=$(CUBRID)/include +BIN = migrate +OBJ = $(BIN).o +SRC = $(BIN).c +INC = $(BIN).h +CFLAG = -g + +all: $(BIN) + +$(BIN): $(OBJ) + $(CC) $(CFLAG) -o $(BIN) $(OBJ) -ldl + +$(OBJ): $(SRC) $(INC) + $(CC) $(CFLAG) -c $(SRC) -I$(INCDIR) + +clean: + rm -rf $(BIN) $(OBJ) diff --git a/migrate/migrate.c b/migrate/migrate.c new file mode 100644 index 0000000..9a1ce86 --- /dev/null +++ b/migrate/migrate.c @@ -0,0 +1,1073 @@ +/* + * Copyright 2016 CUBRID Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "migrate.h" + +#define VERSION_INFO 72 +#define DATABASES_ENVNAME "CUBRID_DATABASES" +#define DATABASES_FILENAME "databases.txt" +#define MAX_LINE 4096 +#define ENV_VAR_MAX 255 + +static const char *catalog_query[] = { + /* alter catalog to add column */ + "alter table _db_class add column unique_name varchar (255) after [class_of]", + "delete from _db_attribute where class_of.class_name = '_db_class' and rownum % 2 = 1", + + "alter table db_serial add column unique_name varchar first", + "delete from _db_attribute where class_of.class_name = 'db_serial' and rownum % 2 = 1 and attr_name <> 'unique_name'", + + "alter table db_trigger add column unique_name varchar after owner", + "delete from _db_attribute where class_of.class_name = 'db_trigger' and rownum % 2 = 1 and attr_name <> 'unique_name'", + + /* alter catalog to modify _db_index_key */ + "alter table _db_index_key modify column func varchar(1023)", + "delete from _db_attribute where class_of.class_name = '_db_index_key' and rownum % 2 = 1", + + /* alter catalog to add tables and views (_db_server, _db_synonym, db_server, db_synonym) */ + "create table [_db_server] ( \ + [link_name] character varying(255) not null, \ + [host] character varying(255), \ + [port] integer, \ + [db_name] character varying(255), \ + [user_name] character varying(255), \ + [password] character varying(1073741823), \ + [properties] character varying(2048), \ + [owner] [db_user] not null, \ + [comment] character varying(1024), \ + constraint [pk__db_server_link_name_owner] primary key ([link_name], [owner]) \ + ) dont_reuse_oid", + + "create view [db_server] ( \ + [link_name] character varying(255), \ + [host] character varying(255), \ + [port] integer, \ + [db_name] character varying(255), \ + [user_name] character varying(255), \ + [properties] character varying(2048), \ + [owner] character varying(256), \ + [comment] character varying(1024) \ + ) as \ + select \ + [ds].[link_name], \ + [ds].[host], \ + [ds].[port], \ + [ds].[db_name], \ + [ds].[user_name], \ + [ds].[properties], \ + [ds].[owner].[name], \ + [ds].[comment] \ + from \ + [_db_server] [ds] \ + where \ + current_user = 'DBA' \ + or { [ds].[owner].[name] } subseteq ( \ + select set {current_user} + coalesce (sum (set {[t].[g].[name]}), set { }) \ + from [db_user] [u], table([groups]) as [t]([g]) \ + where [u].[name] = current_user \ + ) \ + or { [ds] } subseteq ( \ + select sum (set {[au].[class_of]}) \ + from [_db_auth] [au] \ + where {[au].[grantee].[name]} subseteq ( \ + select set {current_user} + coalesce (sum (set {[t].[g].[name]}), set { }) \ + from [db_user] [u], table([groups]) as [t]([g]) \ + where [u].[name] = current_user \ + ) \ + and [au].[auth_type] = 'SELECT' \ + )", + + "CREATE TABLE [_db_synonym] ( \ + [unique_name] CHARACTER VARYING(255) NOT NULL, \ + [name] CHARACTER VARYING(255) NOT NULL, \ + [owner] [db_user] NOT NULL, \ + [is_public] INTEGER DEFAULT 0 NOT NULL, \ + [target_unique_name] CHARACTER VARYING(255) NOT NULL, \ + [target_name] CHARACTER VARYING(255) NOT NULL, \ + [target_owner] [db_user] NOT NULL, [comment] CHARACTER VARYING(2048), \ + CONSTRAINT [pk__db_synonym_unique_name] PRIMARY KEY ([unique_name]), \ + INDEX [i__db_synonym_name_owner_is_public] ([name], [owner], [is_public]) \ + ) DONT_REUSE_OID", + + "create view [db_synonym] ( \ + [synonym_name] CHARACTER VARYING(255), \ + [synonym_owner_name] CHARACTER VARYING(255), \ + [is_public_synonym] CHARACTER VARYING(3), \ + [target_name] CHARACTER VARYING(255), \ + [target_owner_name] CHARACTER VARYING(255), \ + [comment] CHARACTER VARYING(2048) \ + ) as \ + SELECT \ + [s].[name] AS [synonym_name], \ + CAST ([s].[owner].[name] AS VARCHAR(255)) AS [synonym_owner_name], \ + CASE WHEN [s].[is_public] = 1 THEN 'YES' ELSE 'NO' END AS [is_public_synonym], \ + [s].[target_name] AS [target_name], \ + CAST ([s].[target_owner].[name] AS VARCHAR(255)) AS [target_owner_name], \ + [s].[comment] AS [comment] \ + FROM \ + [_db_synonym] [s] \ + WHERE \ + CURRENT_USER = 'DBA' \ + OR [s].[is_public] = 1 \ + OR ( \ + [s].[is_public] = 0 \ + AND { [s].[owner].[name] } SUBSETEQ ( \ + SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET { }) \ + FROM [db_user] [u], TABLE([groups]) AS [t]([g]) \ + WHERE [u].[name] = CURRENT_USER \ + ) \ + )", + + /* set system class for newly added tables and views */ + "update _db_class set is_system_class = 1 where class_name in ('_db_server', 'db_server', '_db_synonym', 'db_synonym')" +}; + +static char *rename_query = "select \ + case \ + when class_type = 0 then \ + 'rename table [' || class_name || '] to [' || lower (owner.name) || '.' || class_name || '] ' \ + else \ + 'rename view [' || class_name || '] to [' || lower (owner.name) || '.' || class_name || '] ' \ + end as q \ + from \ + _db_class \ + where \ + is_system_class % 8 = 0"; + +/* update class_name and unique_name except for system classes. */ +static char *update_db_class_not_for_system_classes = + "update _db_class set class_name = substring_index (class_name, '.', -1), unique_name = class_name where is_system_class % 8 = 0"; + +static char *serial_query = "select \ + 'call change_serial_owner (''' || name || ''', ''' || substring_index (class_name, '.', 1) || ''') \ + on class db_serial' as q \ + from db_serial \ + where class_name is not null"; + +static char *update_serial[] = { + "update db_serial set name = substring_index (name, '.', -1)", + "update db_serial set unique_name = lower (owner.name) || '.' || name" +}; + +static char *update_trigger = "update db_trigger set unique_name = lower (owner.name) || '.' || name"; + +static char *index_query[] = { + "create unique index u_db_serial_name_owner ON db_serial (name, owner)", + "alter table db_serial drop constraint pk_db_serial_name", + "alter table db_serial add constraint pk_db_serial_unique_name primary key (unique_name)", + + "create index i__db_class_unique_name on _db_class (unique_name)", + "create index i__db_class_class_name_owner on _db_class (class_name, owner)", + + "drop index i__db_class_class_name on _db_class" +}; + +/* only system classes update unique_name. */ +static char *update_db_class_for_system_classes = + "update _db_class set unique_name = class_name where is_system_class % 8 != 0"; + +static char db_path[PATH_MAX]; + +FILE *out = NULL; +int verbose = 0; + +static void +print_errmsg (const char *err_msg) +{ + fprintf (stderr, "ERROR: %s\n", err_msg); + + return; +} + +static void +print_log (const char *log_fmt, ...) +{ + char log_msg[BUF_LEN]; + time_t t; + struct tm *tm; + va_list ap; + + t = time (NULL); + tm = localtime (&t); + + snprintf (log_msg, BUF_LEN, "%d-%02d-%02d %02d:%02d:%02d\t", + tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); + + va_start (ap, log_fmt); + + vsnprintf (log_msg + strlen (log_msg), BUF_LEN - strlen (log_msg), log_fmt, ap); + + va_end (ap); + + snprintf (log_msg + strlen (log_msg), BUF_LEN - strlen (log_msg), "\n"); + + fprintf (stderr, "ERROR : %s\n", log_msg); + + return; +} + +static int +char_isspace (int c) +{ + return ((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n' || (c) == '\f' || (c) == '\v'); +} + +static char * +next_char (char *str_p) +{ + char *p; + + p = str_p; + while (char_isspace ((int) *p) && *p != '\0') + { + p++; + } + + return (p); +} + +static char * +get_token (char *str_p, char **token_p) +{ + char *p, *end, *token = NULL; + int length; + + p = str_p; + while (char_isspace ((int) *p) && *p != '\0') + { + p++; + } + end = p; + while (!char_isspace ((int) *end) && *end != '\0') + { + end++; + } + + length = (int) (end - p); + if (length > 0) + { + token = (char *) malloc (length + 1); + if (token != NULL) + { + strncpy (token, p, length); + token[length] = '\0'; + } + } + + *token_p = token; + return (end); +} + +static int +get_directory_path (char *buffer) +{ + const char *env_name; + + env_name = getenv (DATABASES_ENVNAME); + if (env_name == NULL || strlen (env_name) == 0) + { + fprintf (out, "migrate: env variable %s is not set\n", DATABASES_ENVNAME); + return -1; + } + else + { + if (env_name[strlen (env_name) - 1] == '/') + { + sprintf (buffer, "%s%s", env_name, DATABASES_FILENAME); + } + else + { + sprintf (buffer, "%s/%s", env_name, DATABASES_FILENAME); + } + } + + return 0; +} + +static int +get_db_path (char *dbname, char **pathname) +{ + FILE *file_p = NULL; + char line[MAX_LINE]; + char filename[PATH_MAX]; + char *vol_path = NULL; + char *name = NULL; + char *host = NULL; + char *str = NULL; + + if (get_directory_path (filename) < 0) + { + return -1; + } + + file_p = fopen (filename, "r"); + + while (fgets (line, MAX_LINE - 1, file_p) != NULL) + { + str = next_char (line); + if (*str != '\0' && *str != '#') + { + str = get_token (str, &name); + str = get_token (str, &vol_path); + str = get_token (str, &host); + + if (vol_path == NULL) + { + fclose (file_p); + fprintf (out, "migrate: %s is invalid for %s\n", filename, dbname); + return -1; + } + + if (strcmp (host, "localhost") == 0 && strcmp (name, dbname) == 0) + { + str = get_token (str, pathname); + if (*pathname == NULL || *pathname == (char *) '\0') + { + *pathname = vol_path; + } + else + { + free (vol_path); + } + + free (name); + free (host); + + fclose (file_p); + + return 0; + } + + free (vol_path); + free (name); + free (host); + } + } + + fclose (file_p); + + fprintf (out, "migrate: can not find database, %s\n", dbname); + + return -1; +} + +static int +migrate_get_db_path (char *dbname) +{ + char *path; + int error; + + error = get_db_path (dbname, &path); + + if (error < 0) + { + return -1; + } + + sprintf (db_path, "%s/%s_lgat", path, dbname); +} + +static int +migrate_check_log_volume (char *dbname) +{ + char *version = cub_db_get_database_version (); + char *path; + int fd; + float log_ver; + + if (version) + { + if ((strncmp (version, "11.0", 4) != 0 && strncmp (version, "11.1", 4) != 0)) // build number¿©¼­ 11.X.X-XXXX ·Î Ç¥½ÃµÊ + { + fprintf (out, "CUBRID version %s, should be 11.0.x or 11.1.x\n", version); + return -1; + } + + fprintf (out, "%s\n", version); + } + else + { + fprintf (out, "migrate: can not get version info.\n"); + return -1; + } + + fd = open (db_path, O_RDONLY); + + if (fd < 0) + { + fprintf (out, "migrate: can not open the log file\n"); + return -1; + } + + if (lseek (fd, VERSION_INFO, SEEK_SET) < 0) + { + fprintf (out, "migrate: can not seek the version info.\n"); + close (fd); + return -1; + } + + if (read (fd, &log_ver, 4) < 0) + { + fprintf (out, "migrate: can not read the version info.\n"); + close (fd); + return -1; + } + + if (log_ver < 11.0f || log_ver >= 11.2f) + { + fprintf (out, "migrate: the database volume %2.1f is not a migratable version\n", log_ver); + close (fd); + return -1; + } + + close (fd); + + return 0; +} + +static int +migrate_backup_log_volume (char *dbname) +{ + char backup_path[PATH_MAX]; + int fd; + + int backup; + off_t copied = 0; + struct stat fileinfo = { 0 }; + + fd = open (db_path, O_RDWR); + + /* open log volume file and seek version info */ + if (fd < 0) + { + fprintf (out, "migrate: can not open the log file for upgrade\n"); + return -1; + } + + /* creating backup log file */ + sprintf (backup_path, "%s.bak", db_path); + backup = open (backup_path, O_RDWR | O_CREAT | O_TRUNC, 0666); + if (backup < 0) + { + fprintf (out, "migrate: can not create backup log file, %s\n", backup_path); + close (fd); + return -1; + } + + /* copying to backup log file */ + fstat (fd, &fileinfo); + ssize_t bytes = sendfile (backup, fd, &copied, fileinfo.st_size); + + if (bytes != copied) + { + fprintf (out, "migrate: cant not copy the backup log file\n"); + close (fd); + close (backup); + return -1; + } + + fprintf (out, "\tbackup volume, %s created\n", backup_path); + + close (fd); + close (backup); + + return 0; +} + +static void +migrate_update_log_volume (char *dbname) +{ + float version = 11.2; + int fd; + + fd = open (db_path, O_RDWR); + + /* open log volume file and seek version info */ + if (fd < 0) + { + fprintf (out, "migrate: can not open the log file for upgrade\n"); + return; + } + + if (lseek (fd, VERSION_INFO, SEEK_SET) < 0) + { + fprintf (out, "migrate: can not seek the version info. for upgrade\n"); + close (fd); + return; + } + + /* updating volumne info. */ + if (write (fd, &version, 4) < 0) + { + fprintf (out, "migrate: can not write the version info. for upgrade\n"); + close (fd); + return; + } + + fsync (fd); + + close (fd); + + fprintf (out, "migration done\n"); +} + +static int +cub_db_execute_query (const char *str, DB_QUERY_RESULT ** result) +{ + DB_SESSION *session = NULL; + STATEMENT_ID stmt_id; + int error = NO_ERROR; + + session = cub_db_open_buffer (str); + if (session == NULL) + { + error = cub_er_errid (); + goto exit; + } + + stmt_id = cub_db_compile_statement (session); + if (stmt_id < 0) + { + error = cub_er_errid (); + goto exit; + } + + error = cub_db_execute_statement_local (session, stmt_id, result); + + if (error >= 0) + { + return error; + } + +exit: + if (session != NULL) + { + cub_db_close_session (session); + } + + return error; +} + +static int +migrate_initialize (char *dbname) +{ + char libcubridsa_path[BUF_LEN]; + int error = 0; + + CUBRID_ENV = getenv ("CUBRID"); + if (CUBRID_ENV == NULL) + { + print_errmsg ("$CUBRID environment variable is not defined."); + error = -1; + } + + if (getenv ("CUBRID_DATABASES") == NULL) + { + print_errmsg ("$CUBRID_DATABASES environment variable is not defined."); + error = -1; + } + + snprintf (libcubridsa_path, BUF_LEN, "%s/lib/libcubridsa.so", CUBRID_ENV); + + if (migrate_get_db_path (dbname) < 0) + { + return -1; + } + + fprintf (out, "%s reading\n", db_path); + + /* dynamic loading (libcubridsa.so) */ + dl_handle = dlopen (libcubridsa_path, RTLD_LAZY); + if (dl_handle == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_db_get_database_version = dlsym (dl_handle, "db_get_database_version"); + if (cub_db_get_database_version == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_au_disable_passwords = dlsym (dl_handle, "au_disable_passwords"); + if (cub_au_disable_passwords == NULL) + { + cub_au_disable_passwords = dlsym (dl_handle, "_Z20au_disable_passwordsv"); + if (cub_au_disable_passwords == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + } + + cub_db_restart_ex = dlsym (dl_handle, "db_restart_ex"); + if (cub_db_restart_ex == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_er_errid = dlsym (dl_handle, "er_errid"); + if (cub_er_errid == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_db_open_buffer = dlsym (dl_handle, "db_open_buffer"); + if (cub_db_open_buffer == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_db_compile_statement = dlsym (dl_handle, "db_compile_statement"); + if (cub_db_compile_statement == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_db_execute_statement_local = dlsym (dl_handle, "db_execute_statement_local"); + if (cub_db_execute_statement_local == NULL) + { + cub_db_execute_statement_local = + dlsym (dl_handle, "_Z26db_execute_statement_localP10db_sessioniPP15db_query_result"); + if (cub_db_execute_statement_local == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + } + + cub_db_query_get_tuple_value = dlsym (dl_handle, "db_query_get_tuple_value"); + if (cub_db_query_get_tuple_value == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_db_query_first_tuple = dlsym (dl_handle, "db_query_first_tuple"); + if (cub_db_query_first_tuple == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_db_query_next_tuple = dlsym (dl_handle, "db_query_next_tuple"); + if (cub_db_query_next_tuple == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_db_close_session = dlsym (dl_handle, "db_close_session"); + if (cub_db_close_session == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_db_query_end = dlsym (dl_handle, "db_query_end"); + if (cub_db_query_end == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_db_commit_transaction = dlsym (dl_handle, "db_commit_transaction"); + if (cub_db_commit_transaction == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_db_abort_transaction = dlsym (dl_handle, "db_abort_transaction"); + if (cub_db_abort_transaction == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_db_shutdown = dlsym (dl_handle, "db_shutdown"); + if (cub_db_shutdown == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_db_error_string = dlsym (dl_handle, "db_error_string"); + if (cub_db_error_string == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_Au_disable = dlsym (dl_handle, "Au_disable"); + if (cub_Au_disable == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + return error; +} + +static int +migrate_execute_query (const char *query) +{ + DB_QUERY_RESULT *result; + int error; + + error = cub_db_execute_query (query, &result); + + if (verbose) + { + fprintf (out, "\tmigrate: execute query: %s\n", query); + } + + if (error < 0) + { + fprintf (out, "migrate: execute query failed \"%s\"\n", query); + return -1; + } + cub_db_query_end (result); +} + +static int +migrate_generated (const char *generated, int col_num) +{ + DB_QUERY_RESULT *gen_result; + DB_QUERY_RESULT *result; + const char *query; + int error; + + error = cub_db_execute_query (generated, &gen_result); + if (error < 0) + { + fprintf (out, "generated: execute query failed\n \"%s\"\n", generated); + return -1; + } + + if ((error = cub_db_query_first_tuple (gen_result)) == DB_CURSOR_SUCCESS) + { + do + { + int i; + DB_VALUE value; + + for (i = 0; i < col_num; i++) + { + /* from query */ + error = cub_db_query_get_tuple_value (gen_result, i, &value); + if (error < 0) + { + fprintf (out, "generated: can not get a tuple for \"%s\"\n", generated); + return -1; + } + + query = value.data.ch.medium.buf; + if (query == NULL) + { + goto end; + } + + /* from generated result */ + error = migrate_execute_query (query); + if (error < 0) + { + return error; + } + } + error = cub_db_query_next_tuple (gen_result); + } + while (error != DB_CURSOR_END && error != DB_CURSOR_ERROR); + } + +end: + cub_db_query_end (gen_result); + + if (error < 0) + { + fprintf (out, "generated: can not get a next tuple for \"%s\"\n", generated); + return -1; + } + + return 0; +} + +static int +migrate_queries () +{ + DB_QUERY_RESULT *result; + DB_VALUE value; + int i, error; + + /* generated query */ + error = migrate_generated (rename_query, 1); + if (error < 0) + { + fprintf (out, "migrate: execute query failed \"%s\"\n", rename_query); + return -1; + } + + /* catalog query */ + for (i = 0; i < sizeof (catalog_query) / sizeof (const char *); i++) + { + error = migrate_execute_query (catalog_query[i]); + if (error < 0) + { + return -1; + } + } + + error = migrate_execute_query (update_db_class_not_for_system_classes); + if (error < 0) + { + return -1; + } + + error = migrate_generated (serial_query, 1); + if (error < 0) + { + fprintf (out, "migrate: execute query failed \"%s\"\n", serial_query); + return -1; + } + + for (i = 0; i < sizeof (update_serial) / sizeof (const char *); i++) + { + error = migrate_execute_query (update_serial[i]); + if (error < 0) + { + return -1; + } + } + + error = migrate_execute_query (update_trigger); + if (error < 0) + { + return -1; + } + + /* index query */ + for (i = 0; i < sizeof (index_query) / sizeof (const char *); i++) + { + error = migrate_execute_query (index_query[i]); + if (error < 0) + { + return -1; + } + } + + error = migrate_execute_query (update_db_class_for_system_classes); + if (error < 0) + { + return -1; + } + + return 0; +} + +static void +print_usage (void) +{ + printf ("usage: migrate [options] db-name\n\n"); + printf ("valid options\n"); + printf (" -v:\t\tverbose detailed\n"); + printf (" -o FILE:\tredirect output to FILE\n"); +} + +static char * +parse_args (int argc, char *argv[]) +{ + int i; + char *dbname = NULL; + char *outfile = { 0 }; + + out = stdout; + + for (i = 1; i < argc; i++) + { + if (argv[i][0] == '-') + { + switch (argv[i][1]) + { + case 'v': + verbose = 1; + break; + case 'o': + if (argc > i + 1) + { + outfile = argv[++i]; + if (*outfile == '-') + { + printf ("error: missing output file\n\n"); + goto error_exit; + } + else + { + out = fopen (outfile, "w"); + if (out == NULL) + { + printf ("error: can not open out file\n\n"); + goto error_exit; + } + } + } + else + { + printf ("error: missing out file\n\n"); + goto error_exit; + } + break; + default: + printf ("error: no such option\n\n"); + goto error_exit; + } + } + else + { + if (dbname == NULL) + { + dbname = argv[i]; + } + else + { + printf ("error: not allowed multi DB\n\n"); + goto error_exit; + } + } + } + + if (dbname == NULL) + { + printf ("error: missing db-name\n\n"); + goto error_exit; + } + + return dbname; + +error_exit: + print_usage (); + return NULL; +} + +int +main (int argc, char *argv[]) +{ + int status, error; + char *dbname; + + if (argc < 2) + { + print_usage (); + return -1; + } + else + { + dbname = parse_args (argc, argv); + if (dbname == NULL) + { + return -1; + } + } + + printf ("\n"); + printf ("Phase 1: Initializing\n"); + + error = migrate_initialize (dbname); + if (error < 0) + { + fprintf (out, "migrate: error encountered while initializing\n"); + return -1; + } + + printf ("\n"); + printf ("Phase 2: Checking log volume\n"); + + status = migrate_check_log_volume (dbname); + + if (status < 0) + { + printf ("migrate: encountered error while checking the log volume\n"); + return -1; + } + + printf ("\n"); + printf ("Phase 3: Backup the log volume\n"); + + /* backup first before upating catalog */ + if (migrate_backup_log_volume (dbname) < 0) + { + printf ("migrate: encountered error while backup the log volume\n"); + return -1; + } + + printf ("\n"); + printf ("Phase 4: Executing the mirgate queries\n"); + + cub_au_disable_passwords (); + + error = cub_db_restart_ex ("migrate", dbname, "DBA", NULL, NULL, DB_CLIENT_TYPE_ADMIN_UTILITY); + if (error) + { + PRINT_LOG ("migrate: db_restart_ex () call failed [err_code: %d, err_msg: %s]", error, cub_db_error_string (1)); + return -1; + } + + *cub_Au_disable = 1; + + error = migrate_queries (); + if (error < 0) + { + printf ("migrate: error encountered while executing quries\n"); + error = cub_db_abort_transaction (); + if (error < 0) + { + printf ("migrate: error encountered while aborting\n"); + } + error = cub_db_shutdown (); + goto end; + } + + error = cub_db_commit_transaction (); + if (error < 0) + { + printf ("migrate: error encountered while committing\n"); + error = cub_db_shutdown (); + goto end; + } + + error = cub_db_shutdown (); + +end: + if (error < 0) + { + printf ("migrate: error encountered while shutdown db\n"); + return -1; + } + + printf ("\n"); + printf ("Phase 5: Updating version info for log volume\n"); + + /* finalizing: update volume info. to 11.2 */ + migrate_update_log_volume (dbname); + + return 0; +} diff --git a/migrate/migrate.h b/migrate/migrate.h new file mode 100644 index 0000000..605f7a9 --- /dev/null +++ b/migrate/migrate.h @@ -0,0 +1,74 @@ +/* + * Copyright 2016 CUBRID Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef _CUB_MIGRATE_ +#define _CUB_MIGRATE_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define VERSION "1.0" + +#define BUF_LEN 2048 +#define DB_CLIENT_TYPE_ADMIN_UTILITY 7 + +#define PRINT_LOG(fmt, ...) print_log (fmt "\tin %s () from %s:%d", __VA_ARGS__, __func__, __FILE__, __LINE__) + +/* global variable */ +const char *PRO_NAME = NULL; +const char *CUBRID_ENV = NULL; + +void *dl_handle = NULL; + +/* CUBRID function pointer */ +void (*cub_au_disable_passwords) (void); +int (*cub_db_restart_ex) (const char *, const char *, const char *, const char *, const char *, int); +int (*cub_er_errid) (void); +DB_SESSION *(*cub_db_open_buffer) (const char *); +int (*cub_db_compile_statement) (DB_SESSION *); +int (*cub_db_execute_statement_local) (DB_SESSION *, int, DB_QUERY_RESULT **); +void (*cub_db_close_session) (DB_SESSION *); +int (*cub_db_query_end) (DB_QUERY_RESULT *); +int (*cub_db_commit_transaction) (void); +int (*cub_db_abort_transaction) (void); +int (*cub_db_query_get_tuple_value) (DB_QUERY_RESULT * result, int tuple_index, DB_VALUE * value); +int (*cub_db_query_next_tuple) (DB_QUERY_RESULT * result); +int (*cub_db_query_first_tuple) (DB_QUERY_RESULT * result); +char *(*cub_db_get_database_version) (void); +int (*cub_db_shutdown) (void); +const char *(*cub_db_error_string) (int); + +/* CUBRID global variable */ +int *cub_Au_disable; +bool *cub_Au_sysadm; + +#endif From 79e5601cfc42edaf6e3edd05cdfc479e23dfdcd1 Mon Sep 17 00:00:00 2001 From: Byungwook Kim Date: Tue, 24 May 2022 09:08:55 +0900 Subject: [PATCH 02/15] fix license --- migrate/migrate.c | 2 +- migrate/migrate.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/migrate/migrate.c b/migrate/migrate.c index 9a1ce86..e588c68 100644 --- a/migrate/migrate.c +++ b/migrate/migrate.c @@ -1,5 +1,5 @@ /* - * Copyright 2016 CUBRID Corporation + * Copyright 2022 CUBRID Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/migrate/migrate.h b/migrate/migrate.h index 605f7a9..355bac0 100644 --- a/migrate/migrate.h +++ b/migrate/migrate.h @@ -1,5 +1,5 @@ /* - * Copyright 2016 CUBRID Corporation + * Copyright 2022 CUBRID Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 588b68fee6f076c441392a5334e684d1102efa6a Mon Sep 17 00:00:00 2001 From: Byungwook Kim Date: Fri, 22 Jul 2022 16:31:58 +0900 Subject: [PATCH 03/15] fix: rename first --- migrate/migrate.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/migrate/migrate.c b/migrate/migrate.c index e588c68..bcc21a0 100644 --- a/migrate/migrate.c +++ b/migrate/migrate.c @@ -25,7 +25,8 @@ static const char *catalog_query[] = { /* alter catalog to add column */ - "alter table _db_class add column unique_name varchar (255) after [class_of]", + "alter table _db_class rename column class_name to unique_name", + "alter table _db_class add column class_name varchar (255) after [unique_name]", "delete from _db_attribute where class_of.class_name = '_db_class' and rownum % 2 = 1", "alter table db_serial add column unique_name varchar first", @@ -169,11 +170,13 @@ static char *index_query[] = { "create unique index u_db_serial_name_owner ON db_serial (name, owner)", "alter table db_serial drop constraint pk_db_serial_name", "alter table db_serial add constraint pk_db_serial_unique_name primary key (unique_name)", - +#if 0 "create index i__db_class_unique_name on _db_class (unique_name)", - "create index i__db_class_class_name_owner on _db_class (class_name, owner)", - - "drop index i__db_class_class_name on _db_class" +#endif + "create index i__db_class_class_name_owner on _db_class (class_name, owner)" +#if 0 + "drop index i__db_class_class_name on _db_class" +#endif }; /* only system classes update unique_name. */ @@ -836,13 +839,13 @@ migrate_queries () return -1; } } - +#if 0 error = migrate_execute_query (update_db_class_not_for_system_classes); if (error < 0) { return -1; } - +#endif error = migrate_generated (serial_query, 1); if (error < 0) { @@ -874,13 +877,20 @@ migrate_queries () return -1; } } - +#if 0 error = migrate_execute_query (update_db_class_for_system_classes); if (error < 0) { return -1; } + error = migrate_execute_query (select_db_class_for_system_update); + if (error < 0) + { + return -1; + } +#endif + return 0; } @@ -1037,12 +1047,11 @@ main (int argc, char *argv[]) if (error < 0) { printf ("migrate: error encountered while executing quries\n"); - error = cub_db_abort_transaction (); - if (error < 0) + if (cub_db_abort_transaction () < 0) { printf ("migrate: error encountered while aborting\n"); } - error = cub_db_shutdown (); + cub_db_shutdown (); goto end; } @@ -1050,16 +1059,15 @@ main (int argc, char *argv[]) if (error < 0) { printf ("migrate: error encountered while committing\n"); - error = cub_db_shutdown (); + cub_db_shutdown (); goto end; } - error = cub_db_shutdown (); + cub_db_shutdown (); end: if (error < 0) { - printf ("migrate: error encountered while shutdown db\n"); return -1; } From fab59bc5c8439b1a697277cddc0f668d76a9507c Mon Sep 17 00:00:00 2001 From: Byungwook Kim Date: Tue, 6 Sep 2022 16:37:30 +0900 Subject: [PATCH 04/15] add: drop view --- migrate/Makefile | 2 +- migrate/migrate.c | 749 ++++++++++++++++++++++++++++++++++++++-------- migrate/migrate.h | 99 ++++-- 3 files changed, 700 insertions(+), 150 deletions(-) diff --git a/migrate/Makefile b/migrate/Makefile index fed9fbc..683dc50 100644 --- a/migrate/Makefile +++ b/migrate/Makefile @@ -1,4 +1,4 @@ -CC = gcc +CC = g++ INCDIR=$(CUBRID)/include BIN = migrate diff --git a/migrate/migrate.c b/migrate/migrate.c index bcc21a0..8617149 100644 --- a/migrate/migrate.c +++ b/migrate/migrate.c @@ -15,6 +15,7 @@ * */ +#include "extract_schema.hpp" #include "migrate.h" #define VERSION_INFO 72 @@ -23,23 +24,13 @@ #define MAX_LINE 4096 #define ENV_VAR_MAX 255 -static const char *catalog_query[] = { - /* alter catalog to add column */ - "alter table _db_class rename column class_name to unique_name", - "alter table _db_class add column class_name varchar (255) after [unique_name]", - "delete from _db_attribute where class_of.class_name = '_db_class' and rownum % 2 = 1", - - "alter table db_serial add column unique_name varchar first", - "delete from _db_attribute where class_of.class_name = 'db_serial' and rownum % 2 = 1 and attr_name <> 'unique_name'", - - "alter table db_trigger add column unique_name varchar after owner", - "delete from _db_attribute where class_of.class_name = 'db_trigger' and rownum % 2 = 1 and attr_name <> 'unique_name'", - - /* alter catalog to modify _db_index_key */ - "alter table _db_index_key modify column func varchar(1023)", - "delete from _db_attribute where class_of.class_name = '_db_index_key' and rownum % 2 = 1", +static const char *view_query = "select class_name \ + from _db_class \ + where is_system_class = 0 and class_type = 1"; +static const char *catalog_query[] = { /* alter catalog to add tables and views (_db_server, _db_synonym, db_server, db_synonym) */ + /* _db_server */ "create table [_db_server] ( \ [link_name] character varying(255) not null, \ [host] character varying(255), \ @@ -53,91 +44,327 @@ static const char *catalog_query[] = { constraint [pk__db_server_link_name_owner] primary key ([link_name], [owner]) \ ) dont_reuse_oid", - "create view [db_server] ( \ + /* _db_synonym */ + "CREATE TABLE [_db_synonym] ( \ + [unique_name] character varying(255) not null, \ + [name] character varying(255) not null, \ + [owner] [db_user] not null, \ + [is_public] integer default 0 not null, \ + [target_unique_name] character varying(255) not null, \ + [target_name] character varying(255) not null, \ + [target_owner] [db_user] not null, [comment] character varying(2048), \ + constraint [pk__db_synonym_unique_name] primary key ([unique_name]), \ + index [i__db_synonym_name_owner_is_public] ([name], [owner], [is_public]) \ + ) DONT_REUSE_OID", + + /* db_class */ + "CREATE OR REPLACE VIEW [db_class] ( \ + [class_name] varchar(255), \ + [owner_name] varchar(255), \ + [class_type] varchar(6), \ + [is_system_class] varchar(3), \ + [tde_algorithm] varchar(32), \ + [partitioned] varchar(3), \ + [is_reuse_oid_class] varchar(3), \ + [collation] varchar(32), \ + [comment] varchar(2048) \ + ) as \ + SELECT [c].[class_name] AS [class_name], CAST ([c].[owner].[name] AS VARCHAR(255)) AS [owner_name], CASE [c].[class_type] WHEN 0 THEN 'CLASS' WHEN 1 THEN 'VCLASS' ELSE 'UNKNOW' END AS [class_type], CASE WHEN MOD([c].[is_system_class], 2) = 1 THEN 'YES' ELSE 'NO' END AS [is_system_class], CASE [c].[tde_algorithm] WHEN 0 THEN 'NONE' WHEN 1 THEN 'AES' WHEN 2 THEN 'ARIA' END AS [tde_algorithm], CASE WHEN [c].[sub_classes] IS NULL THEN 'NO' ELSE NVL ((SELECT 'YES' FROM [_db_partition] AS [p] WHERE [p].[class_of] = [c] AND [p].[pname] IS NULL), 'NO') END AS [partitioned], CASE WHEN MOD ([c].[is_system_class] / 8, 2) = 1 THEN 'YES' ELSE 'NO' END AS [is_reuse_oid_class], [coll].[coll_name] AS [collation], [c].[comment] AS [comment] FROM [_db_class] AS [c], [_db_collation] AS [coll] WHERE [c].[collation_id] = [coll].[coll_id] AND (CURRENT_USER = 'DBA' OR {[c].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[c]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT'))", + + /* db_direct_super_class */ + "CREATE OR REPLACE VIEW [db_direct_super_class] ( \ + [class_name] varchar(255), \ + [owner_name] varchar(255), \ + [super_class_name] varchar(255), \ + [super_owner_name] varchar(255) \ + ) as \ +SELECT [c].[class_name] AS [class_name], CAST ([c].[owner].[name] AS VARCHAR(255)) AS [owner_name], [s].[class_name] AS [super_class_name], CAST ([s].[owner].[name] AS VARCHAR(255)) AS [super_owner_name] FROM [_db_class] AS [c], TABLE ([c].[super_classes]) AS [t] ([s]) WHERE CURRENT_USER = 'DBA' OR {[c].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[c]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT')", + + /* db_vclass */ + "CREATE OR REPLACE VIEW [db_vclass] ( \ + [vclass_name] varchar(255), \ + [owner_name] varchar(255), \ + [vclass_def] varchar(1073741823), \ + [comment] varchar(2048) \ + ) as \ +SELECT [q].[class_of].[class_name] AS [vclass_name], CAST ([q].[class_of].[owner].[name] AS VARCHAR(255)) AS [owner_name], [q].[spec] AS [vclass_def], [c].[comment] AS [comment] FROM [_db_query_spec] AS [q], [_db_class] AS [c] WHERE [q].[class_of] = [c] AND (CURRENT_USER = 'DBA' OR {[q].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[q].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT'))", + + /* db_attribute */ + "CREATE OR REPLACE VIEW [db_attribute] ( \ + [attr_name] varchar(255), \ + [class_name] varchar(255), \ + [owner_name] varchar(255), \ + [attr_type] varchar(8), \ + [def_order] integer, \ + [from_class_name] varchar(255), \ + [from_owner_name] varchar(255), \ + [from_attr_name] varchar(255), \ + [data_type] varchar(9), \ + [prec] integer, \ + [scale] integer, \ + [charset] varchar(32), \ + [collation] varchar(32), \ + [domain_class_name] varchar(255), \ + [domain_owner_name] varchar(255), \ + [default_value] varchar(255), \ + [is_nullable] varchar(3), \ + [comment] varchar(1024) \ + ) as \ +SELECT [a].[attr_name] AS [attr_name], [c].[class_name] AS [class_name], CAST ([c].[owner].[name] AS VARCHAR(255)) AS [owner_name], CASE [a].[attr_type] WHEN 0 THEN 'INSTANCE' WHEN 1 THEN 'CLASS' ELSE 'SHARED' END AS [attr_type], [a].[def_order] AS [def_order], [a].[from_class_of].[class_name] AS [from_class_name], CAST ([a].[from_class_of].[owner].[name] AS VARCHAR(255)) AS [from_owner_name], [a].[from_attr_name] AS [from_attr_name], [t].[type_name] AS [data_type], [d].[prec] AS [prec], [d].[scale] AS [scale], IF ([a].[data_type] IN (4, 25, 26, 27, 35), (SELECT [ch].[charset_name] FROM [_db_charset] AS [ch] WHERE [d].[code_set] = [ch].[charset_id]), 'Not applicable') AS [charset], IF ([a].[data_type] IN (4, 25, 26, 27, 35), (SELECT [coll].[coll_name] FROM [_db_collation] AS [coll] WHERE [d].[collation_id] = [coll].[coll_id]), 'Not applicable') AS [collation], [d].[class_of].[class_name] AS [domain_class_name], CAST ([d].[class_of].[owner].[name] AS VARCHAR(255)) AS [domain_owner_name], [a].[default_value] AS [default_value], CASE WHEN [a].[is_nullable] = 1 THEN 'YES' ELSE 'NO' END AS [is_nullable], [a].[comment] AS [comment] FROM [_db_class] AS [c], [_db_attribute] AS [a], [_db_domain] AS [d], [_db_data_type] AS [t] WHERE [a].[class_of] = [c] AND [d].[object_of] = [a] AND [d].[data_type] = [t].[type_id] AND (CURRENT_USER = 'DBA' OR {[c].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[c]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT'))", + + /* db_attr_setdomain_elm */ + "CREATE OR REPLACE VIEW [db_attr_setdomain_elm] ( \ + [attr_name] varchar(255), \ + [class_name] varchar(255), \ + [owner_name] varchar(255), \ + [attr_type] varchar(8), \ + [data_type] varchar(9), \ + [prec] integer, \ + [scale] integer, \ + [code_set] integer, \ + [domain_class_name] varchar(255), \ + [domain_owner_name] varchar(255) \ + ) as \ +SELECT [a].[attr_name] AS [attr_name], [c].[class_name] AS [class_name], CAST ([c].[owner].[name] AS VARCHAR(255)) AS [owner_name], CASE [a].[attr_type] WHEN 0 THEN 'INSTANCE' WHEN 1 THEN 'CLASS' ELSE 'SHARED' END AS [attr_type], [et].[type_name] AS [data_type], [e].[prec] AS [prec], [e].[scale] AS [scale], [e].[code_set] AS [code_set], [e].[class_of].[class_name] AS [domain_class_name], CAST ([e].[class_of].[owner].[name] AS VARCHAR(255)) AS [domain_owner_name] FROM [_db_class] AS [c], [_db_attribute] AS [a], [_db_domain] AS [d], TABLE ([d].[set_domains]) AS [t] ([e]), [_db_data_type] AS [et] WHERE [a].[class_of] = [c] AND [d].[object_of] = [a] AND [e].[data_type] = [et].[type_id] AND (CURRENT_USER = 'DBA' OR {[c].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[c]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT'))", + + /* db_method */ + "CREATE OR REPLACE VIEW [db_method] ( \ + [meth_name] varchar(255), \ + [class_name] varchar(255), \ + [owner_name] varchar(255), \ + [meth_type] varchar(8), \ + [from_class_name] varchar(255), \ + [from_owner_name] varchar(255), \ + [from_meth_name] varchar(255), \ + [func_name] varchar(255) \ + ) AS \ +SELECT [m].[meth_name] AS [meth_name], [m].[class_of].[class_name] AS [class_name], CAST ([m].[class_of].[owner].[name] AS VARCHAR(255)) AS [owner_name], CASE [m].[meth_type] WHEN 0 THEN 'INSTANCE' ELSE 'CLASS' END AS [meth_type], [m].[from_class_of].[class_name] AS [from_class_name], CAST ([m].[from_class_of].[owner].[name] AS VARCHAR(255)) AS [from_owner_name], [m].[from_meth_name] AS [from_meth_name], [s].[func_name] AS [func_name] FROM [_db_method] AS [m], [_db_meth_sig] AS [s] WHERE [s].[meth_of] = [m] AND (CURRENT_USER = 'DBA' OR {[m].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[m].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT'))", + + /* db_meth_arg */ + "CREATE OR REPLACE VIEW [db_meth_arg] ( \ + [meth_name] varchar(255), \ + [class_name] varchar(255), \ + [owner_name] varchar(255), \ + [meth_type] varchar(8), \ + [index_of] integer, \ + [data_type] varchar(9), \ + [prec] integer, \ + [scale] integer, \ + [code_set] integer, \ + [domain_class_name] varchar(255), \ + [domain_owner_name] varchar(255) \ + ) AS \ +SELECT [s].[meth_of].[meth_name] AS [meth_name], [s].[meth_of].[class_of].[class_name] AS [class_name], CAST ([s].[meth_of].[class_of].[owner].[name] AS VARCHAR(255)) AS [owner_name], CASE [s].[meth_of].[meth_type] WHEN 0 THEN 'INSTANCE' ELSE 'CLASS' END AS [meth_type], [a].[index_of] AS [index_of], [t].[type_name] AS [data_type], [d].[prec] AS [prec], [d].[scale] AS [scale], [d].[code_set] AS [code_set], [d].[class_of].[class_name] AS [domain_class_name], CAST ([d].[class_of].[owner].[name] AS VARCHAR(255)) AS [domain_owner_name] FROM [_db_meth_sig] AS [s], [_db_meth_arg] AS [a], [_db_domain] AS [d], [_db_data_type] AS [t] WHERE [a].[meth_sig_of] = [s] AND [d].[object_of] = [a] AND [d].[data_type] = [t].[type_id] AND (CURRENT_USER = 'DBA' OR {[s].[meth_of].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[s].[meth_of].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT'))", + + /* db_meth_arg_setdomain_elm */ + "CREATE OR REPLACE VIEW [db_meth_arg_setdomain_elm] ( \ + [meth_name] varchar(255), \ + [class_name] varchar(255), \ + [owner_name] varchar(255), \ + [meth_type] varchar(8), \ + [index_of] integer, \ + [data_type] varchar(9), \ + [prec] integer, \ + [scale] integer, \ + [code_set] integer, \ + [domain_class_name] varchar(255), \ + [domain_owner_name] varchar(255) \ + ) AS \ +SELECT [s].[meth_of].[meth_name] AS [meth_name], [s].[meth_of].[class_of].[class_name] AS [class_name], CAST ([s].[meth_of].[class_of].[owner].[name] AS VARCHAR(255)) AS [owner_name], CASE [s].[meth_of].[meth_type] WHEN 0 THEN 'INSTANCE' ELSE 'CLASS' END AS [meth_type], [a].[index_of] AS [index_of], [et].[type_name] AS [data_type], [e].[prec] AS [prec], [e].[scale] AS [scale], [e].[code_set] AS [code_set], [e].[class_of].[class_name] AS [domain_class_name], CAST ([e].[class_of].[owner].[name] AS VARCHAR(255)) AS [domain_owner_name] FROM [_db_meth_sig] AS [s], [_db_meth_arg] AS [a], [_db_domain] AS [d], TABLE ([d].[set_domains]) AS [t] ([e]), [_db_data_type] AS [et] WHERE [a].[meth_sig_of] = [s] AND [d].[object_of] = [a] AND [e].[data_type] = [et].[type_id] AND (CURRENT_USER = 'DBA' OR {[s].[meth_of].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[s].[meth_of].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT'))", + + /* db_meth_file */ + "CREATE OR REPLACE VIEW [db_meth_file] ( \ + [class_name] varchar(255), \ + [owner_name] varchar(255), \ + [path_name] varchar(255), \ + [from_class_name] varchar(255), \ + [from_owner_name] varchar(255) \ + ) AS \ +SELECT [f].[class_of].[class_name] AS [class_name], CAST ([f].[class_of].[owner].[name] AS VARCHAR(255)) AS [owner_name], [f].[path_name] AS [path_name], [f].[from_class_of].[class_name] AS [from_class_name], CAST ([f].[from_class_of].[owner].[name] AS VARCHAR(255)) AS [from_owner_name] FROM [_db_meth_file] AS [f] WHERE CURRENT_USER = 'DBA' OR {[f].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[f].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT')", + + /* db_index */ + "CREATE OR REPLACE VIEW [db_index] ( \ + [index_name] varchar(255), \ + [is_unique] varchar(3), \ + [is_reverse] varchar(3), \ + [class_name] varchar(255), \ + [owner_name] varchar(255), \ + [key_count] integer, \ + [is_primary_key] varchar(3), \ + [is_foreign_key] varchar(3), \ + [filter_expression] varchar(255), \ + [have_function] varchar(3), \ + [comment] varchar(1024), \ + [status] varchar(255) \ + ) AS \ +SELECT [i].[index_name] AS [index_name], CASE [i].[is_unique] WHEN 0 THEN 'NO' ELSE 'YES' END AS [is_unique], CASE [i].[is_reverse] WHEN 0 THEN 'NO' ELSE 'YES' END AS [is_reverse], [i].[class_of].[class_name] AS [class_name], CAST ([i].[class_of].[owner].[name] AS VARCHAR(255)) AS [owner_name], [i].[key_count] AS [key_count], CASE [i].[is_primary_key] WHEN 0 THEN 'NO' ELSE 'YES' END AS [is_primary_key], CASE [i].[is_foreign_key] WHEN 0 THEN 'NO' ELSE 'YES' END AS [is_foreign_key], [i].[filter_expression] AS [filter_expression], CASE [i].[have_function] WHEN 0 THEN 'NO' ELSE 'YES' END AS [have_function], [i].[comment] AS [comment], CASE [i].[status] WHEN 0 THEN 'NO_INDEX' WHEN 1 THEN 'NORMAL INDEX' WHEN 2 THEN 'INVISIBLE INDEX' WHEN 3 THEN 'INDEX IS IN ONLINE BUILDING' ELSE 'NULL' END AS [status] FROM [_db_index] AS [i] WHERE CURRENT_USER = 'DBA' OR {[i].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[i].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT')", + + /* db_index_key */ + "CREATE OR REPLACE VIEW [db_index_key] ( \ + [index_name] varchar(255), \ + [class_name] varchar(255), \ + [owner_name] varchar(255), \ + [key_attr_name] varchar(255), \ + [key_order] integer, \ + [asc_desc] varchar(4), \ + [key_prefix_length] integer, \ + [func] varchar(1023) \ + ) as \ +SELECT [k].[index_of].[index_name] AS [index_name], [k].[index_of].[class_of].[class_name] AS [class_name], CAST ([k].[index_of].[class_of].[owner].[name] AS VARCHAR(255)) AS [owner_name], [k].[key_attr_name] AS [key_attr_name], [k].[key_order] AS [key_order], CASE [k].[asc_desc] WHEN 0 THEN 'ASC' WHEN 1 THEN 'DESC' ELSE 'UNKN' END AS [asc_desc], [k].[key_prefix_length] AS [key_prefix_length], [k].[func] AS [func] FROM [_db_index_key] AS [k] WHERE CURRENT_USER = 'DBA' OR {[k].[index_of].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[k].[index_of].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT')", + + /* db_auth */ + "CREATE OR REPLACE VIEW [db_auth] ( \ + [grantor_name] varchar(255), \ + [grantee_name] varchar(255), \ + [class_name] varchar(255), \ + [owner_name] varchar(255), \ + [auth_type] varchar(7), \ + [is_grantable] varchar(3) \ + ) as \ +SELECT CAST ([a].[grantor].[name] AS VARCHAR(255)) AS [grantor_name], CAST ([a].[grantee].[name] AS VARCHAR(255)) AS [grantee_name], [a].[class_of].[class_name] AS [class_name], CAST ([a].[class_of].[owner].[name] AS VARCHAR(255)) AS [owner_name], [a].[auth_type] AS [auth_type], CASE [a].[is_grantable] WHEN 0 THEN 'NO' ELSE 'YES' END AS [is_grantable] FROM [_db_auth] AS [a] WHERE CURRENT_USER = 'DBA' OR {[a].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[a].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT')", + + /* db_trig */ + "CREATE OR REPLACE VIEW [db_trig] ( \ + [trigger_name] varchar(255), \ + [owner_name] varchar(255), \ + [target_class_name] varchar(255), \ + [target_owner_name] varchar(255), \ + [target_attr_name] varchar(255), \ + [target_attr_type] varchar(255), \ + [action_type] integer, \ + [action_time] integer, \ + [comment] varchar(1024) \ + ) as \ +SELECT CAST ([t].[name] AS VARCHAR (255)) AS [trigger_name], CAST ([t].[owner].[name] AS VARCHAR(255)) AS [owner_name], [c].[class_name] AS [target_class_name], CAST ([c].[owner].[name] AS VARCHAR(255)) AS [target_owner_name], CAST ([t].[target_attribute] AS VARCHAR (255)) AS [target_attr_name], CASE [t].[target_class_attribute] WHEN 0 THEN 'INSTANCE' ELSE 'CLASS' END AS [target_attr_type], [t].[action_type] AS [action_type], [t].[action_time] AS [action_time], [t].[comment] AS [comment] FROM [db_trigger] AS [t] LEFT OUTER JOIN [_db_class] AS [c] ON [t].[target_class] = [c].[class_of] WHERE CURRENT_USER = 'DBA' OR {[t].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[c]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT')", + + /* db_partition */ + "CREATE OR REPLACE VIEW [db_partition] ( \ + [class_name] varchar(255), \ + [owner_name] varchar(255), \ + [partition_name] varchar(255), \ + [partition_class_name] varchar(255), \ + [partition_type] varchar(32), \ + [partition_expr] varchar(2048), \ + [partition_values] sequence of, \ + [comment] varchar(1024) \ + ) as \ +SELECT [s].[class_name] AS [class_name], CAST ([s].[owner].[name] AS VARCHAR(255)) AS [owner_name], [p].[pname] AS [partition_name], CONCAT ([s].[class_name], '__p__', [p].[pname]) AS [partition_class_name], CASE [p].[ptype] WHEN 0 THEN 'HASH' WHEN 1 THEN 'RANGE' ELSE 'LIST' END AS [partition_type], TRIM (SUBSTRING ([pp].[pexpr] FROM 8 FOR (POSITION (' FROM ' IN [pp].[pexpr]) - 8))) AS [partition_expr], [p].[pvalues] AS [partition_values], [p].[comment] AS [comment] FROM [_db_partition] AS [p], [_db_class] AS [c], TABLE ([c].[super_classes]) AS [t] ([s]), [_db_class] AS [cc], TABLE ([cc].[partition]) AS [tt] ([pp]) WHERE [p].[class_of] = [c] AND [s] = [cc] AND (CURRENT_USER = 'DBA' OR {[p].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[p].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT'))", + + /* db_stored_procedure */ + "CREATE OR REPLACE VIEW [db_stored_procedure] ( \ + [sp_name] varchar(255), \ + [sp_type] varchar(16), \ + [return_type] varchar(16), \ + [arg_count] integer, \ + [lang] varchar(16), \ + [target] varchar(4096), \ + [owner] varchar(256), \ + [comment] varchar(1024) \ + ) as \ +SELECT [sp].[sp_name] AS [sp_name], CASE [sp].[sp_type] WHEN 1 THEN 'PROCEDURE' ELSE 'FUNCTION' END AS [sp_type], CASE [sp].[return_type] WHEN 0 THEN 'void' WHEN 28 THEN 'CURSOR' ELSE (SELECT [t].[type_name] FROM [_db_data_type] AS [t] WHERE [sp].[return_type] = [t].[type_id]) END AS [return_type], [sp].[arg_count] AS [arg_count], CASE [sp].[lang] WHEN 1 THEN 'JAVA' ELSE '' END AS [lang], [sp].[target] AS [target], CAST ([sp].[owner].[name] AS VARCHAR(255)) AS [owner], [sp].[comment] AS [comment] FROM [_db_stored_procedure] AS [sp]", + + /* db_stored_procedure_args */ + "create or replace view [db_stored_procedure_args] ( \ + [sp_name] varchar(255), \ + [index_of] integer, \ + [arg_name] varchar(255), \ + [data_type] varchar(16), \ + [mode] varchar(6), \ + [comment] varchar(1024) \ + ) as \ +SELECT [sp].[sp_name] AS [sp_name], [sp].[index_of] AS [index_of], [sp].[arg_name] AS [arg_name], CASE [sp].[data_type] WHEN 28 THEN 'CURSOR' ELSE (SELECT [t].[type_name] FROM [_db_data_type] AS [t] WHERE [sp].[data_type] = [t].[type_id]) END AS [data_type], CASE [sp].[mode] WHEN 1 THEN 'IN' WHEN 2 THEN 'OUT' ELSE 'INOUT' END AS [mode], [sp].[comment] AS [comment] FROM [_db_stored_procedure_args] AS [sp] ORDER BY [sp].[sp_name], [sp].[index_of]", + + /* db_collation */ + "CREATE OR REPLACE VIEW [db_collation] ( \ + [coll_id] integer, \ + [coll_name] varchar(32), \ + [charset_name] varchar(32), \ + [is_builtin] varchar(3), \ + [has_expansions] varchar(3), \ + [contractions] integer, \ + [uca_strength] varchar(255) \ + ) as \ +SELECT [coll].[coll_id] AS [coll_id], [coll].[coll_name] AS [coll_name], [ch].[charset_name] AS [charset_name], CASE [coll].[built_in] WHEN 0 THEN 'No' WHEN 1 THEN 'Yes' ELSE 'ERROR' END AS [is_builtin], CASE [coll].[expansions] WHEN 0 THEN 'No' WHEN 1 THEN 'Yes' ELSE 'ERROR' END AS [has_expansions], [coll].[contractions] AS [contractions], CASE [coll].[uca_strength] WHEN 0 THEN 'Not applicable' WHEN 1 THEN 'Primary' WHEN 2 THEN 'Secondary' WHEN 3 THEN 'Tertiary' WHEN 4 THEN 'Quaternary' WHEN 5 THEN 'Identity' ELSE 'Unknown' END AS [uca_strength] FROM [_db_collation] AS [coll] INNER JOIN [_db_charset] AS [ch] ON [coll].[charset_id] = [ch].[charset_id] ORDER BY [coll].[coll_id]", + + /* db_charset */ + "CREATE OR REPLACE VIEW [db_charset] ( \ + [charset_id] integer, \ + [charset_name] varchar(32), \ + [default_collation] varchar(32), \ + [char_size] integer \ + ) as \ +SELECT [ch].[charset_id] AS [charset_id], [ch].[charset_name] AS [charset_name], [coll].[coll_name] AS [default_collation], [ch].[char_size] AS [char_size] FROM [_db_charset] AS [ch], [_db_collation] AS [coll] WHERE [ch].[default_collation] = [coll].[coll_id] ORDER BY [ch].[charset_id]", + + /* db_server */ + "CREATE OR REPLACE VIEW [db_server] ( \ [link_name] character varying(255), \ [host] character varying(255), \ [port] integer, \ [db_name] character varying(255), \ [user_name] character varying(255), \ [properties] character varying(2048), \ - [owner] character varying(256), \ + [owner] character varying(255), \ [comment] character varying(1024) \ ) as \ - select \ - [ds].[link_name], \ - [ds].[host], \ - [ds].[port], \ - [ds].[db_name], \ - [ds].[user_name], \ - [ds].[properties], \ - [ds].[owner].[name], \ - [ds].[comment] \ - from \ - [_db_server] [ds] \ - where \ - current_user = 'DBA' \ - or { [ds].[owner].[name] } subseteq ( \ - select set {current_user} + coalesce (sum (set {[t].[g].[name]}), set { }) \ - from [db_user] [u], table([groups]) as [t]([g]) \ - where [u].[name] = current_user \ +SELECT [ds].[link_name] AS [link_name], [ds].[host] AS [host], [ds].[port] AS [port], [ds].[db_name] AS [db_name], [ds].[user_name] AS [user_name], [ds].[properties] AS [properties], CAST ([ds].[owner].[name] AS VARCHAR(255)) AS [owner], [ds].[comment] AS [comment] FROM [_db_server] AS [ds] WHERE CURRENT_USER = 'DBA' OR {[ds].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[ds]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT')", + + /* db_synonym */ + "CREATE OR REPLACE VIEW [db_synonym] ( \ + [synonym_name] character varying(255), \ + [synonym_owner_name] character varying(255), \ + [is_public_synonym] character varying(3), \ + [target_name] character varying(255), \ + [target_owner_name] character varying(255), \ + [comment] character varying(2048) \ + ) AS \ +SELECT [s].[name] AS [synonym_name], CAST ([s].[owner].[name] AS VARCHAR(255)) AS [synonym_owner_name], CASE [s].[is_public] WHEN 1 THEN 'YES' ELSE 'NO' END AS [is_public_synonym], [s].[target_name] AS [target_name], CAST ([s].[target_owner].[name] AS VARCHAR(255)) AS [target_owner_name], [s].[comment] AS [comment] FROM [_db_synonym] AS [s] WHERE CURRENT_USER = 'DBA' OR [s].[is_public] = 1 OR ([s].[is_public] = 0 AND {[s].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER))", + + /* set system class for newly added tables and views */ + "UPDATE [_db_class] \ + SET is_system_class = 1 \ + WHERE \ + class_name in ( \ + '_db_server', \ + '_db_synonym', \ + 'db_class', \ + 'db_direct_super_class', \ + 'db_vclass', \ + 'db_attribute', \ + 'db_attr_setdomain_elm', \ + 'db_method', \ + 'db_meth_arg', \ + 'db_meth_arg_setdomain_elm', \ + 'db_meth_file', \ + 'db_index', \ + 'db_index_key', \ + 'db_auth', \ + 'db_trig', \ + 'db_partition', \ + 'db_stored_procedure', \ + 'db_stored_procedure_args', \ + 'db_collation', \ + 'db_charset', \ + 'db_server', \ + 'db_synonym' \ ) \ - or { [ds] } subseteq ( \ - select sum (set {[au].[class_of]}) \ - from [_db_auth] [au] \ - where {[au].[grantee].[name]} subseteq ( \ - select set {current_user} + coalesce (sum (set {[t].[g].[name]}), set { }) \ - from [db_user] [u], table([groups]) as [t]([g]) \ - where [u].[name] = current_user \ - ) \ - and [au].[auth_type] = 'SELECT' \ - )", + AND is_system_class = 0", - "CREATE TABLE [_db_synonym] ( \ - [unique_name] CHARACTER VARYING(255) NOT NULL, \ - [name] CHARACTER VARYING(255) NOT NULL, \ - [owner] [db_user] NOT NULL, \ - [is_public] INTEGER DEFAULT 0 NOT NULL, \ - [target_unique_name] CHARACTER VARYING(255) NOT NULL, \ - [target_name] CHARACTER VARYING(255) NOT NULL, \ - [target_owner] [db_user] NOT NULL, [comment] CHARACTER VARYING(2048), \ - CONSTRAINT [pk__db_synonym_unique_name] PRIMARY KEY ([unique_name]), \ - INDEX [i__db_synonym_name_owner_is_public] ([name], [owner], [is_public]) \ - ) DONT_REUSE_OID", + /* alter catalog to add column */ + "alter table _db_class add column unique_name varchar (255) after [class_of]", + "delete from _db_attribute where class_of.class_name = '_db_class' and rownum % 2 = 1", - "create view [db_synonym] ( \ - [synonym_name] CHARACTER VARYING(255), \ - [synonym_owner_name] CHARACTER VARYING(255), \ - [is_public_synonym] CHARACTER VARYING(3), \ - [target_name] CHARACTER VARYING(255), \ - [target_owner_name] CHARACTER VARYING(255), \ - [comment] CHARACTER VARYING(2048) \ - ) as \ - SELECT \ - [s].[name] AS [synonym_name], \ - CAST ([s].[owner].[name] AS VARCHAR(255)) AS [synonym_owner_name], \ - CASE WHEN [s].[is_public] = 1 THEN 'YES' ELSE 'NO' END AS [is_public_synonym], \ - [s].[target_name] AS [target_name], \ - CAST ([s].[target_owner].[name] AS VARCHAR(255)) AS [target_owner_name], \ - [s].[comment] AS [comment] \ - FROM \ - [_db_synonym] [s] \ - WHERE \ - CURRENT_USER = 'DBA' \ - OR [s].[is_public] = 1 \ - OR ( \ - [s].[is_public] = 0 \ - AND { [s].[owner].[name] } SUBSETEQ ( \ - SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET { }) \ - FROM [db_user] [u], TABLE([groups]) AS [t]([g]) \ - WHERE [u].[name] = CURRENT_USER \ - ) \ - )", + "alter table db_serial add column unique_name varchar first", + "delete from _db_attribute where class_of.class_name = 'db_serial' and rownum % 2 = 1 and attr_name <> 'unique_name'", - /* set system class for newly added tables and views */ - "update _db_class set is_system_class = 1 where class_name in ('_db_server', 'db_server', '_db_synonym', 'db_synonym')" + "alter table db_trigger add column unique_name varchar after owner", + "delete from _db_attribute where class_of.class_name = 'db_trigger' and rownum % 2 = 1 and attr_name <> 'unique_name'", + + /* alter catalog to modify _db_index_key */ + "alter table _db_index_key modify column func varchar(1023)", + "delete from _db_attribute where class_of.class_name = '_db_index_key' and rownum % 2 = 1" }; -static char *rename_query = "select \ +static const char *rename_query = "select \ case \ when class_type = 0 then \ 'rename table [' || class_name || '] to [' || lower (owner.name) || '.' || class_name || '] ' \ @@ -150,37 +377,33 @@ static char *rename_query = "select \ is_system_class % 8 = 0"; /* update class_name and unique_name except for system classes. */ -static char *update_db_class_not_for_system_classes = +static const char *update_db_class_not_for_system_classes = "update _db_class set class_name = substring_index (class_name, '.', -1), unique_name = class_name where is_system_class % 8 = 0"; -static char *serial_query = "select \ +static const char *serial_query = "select \ 'call change_serial_owner (''' || name || ''', ''' || substring_index (class_name, '.', 1) || ''') \ on class db_serial' as q \ from db_serial \ where class_name is not null"; -static char *update_serial[] = { +static const char *update_serial[] = { "update db_serial set name = substring_index (name, '.', -1)", "update db_serial set unique_name = lower (owner.name) || '.' || name" }; -static char *update_trigger = "update db_trigger set unique_name = lower (owner.name) || '.' || name"; +static const char *update_trigger = "update db_trigger set unique_name = lower (owner.name) || '.' || name"; -static char *index_query[] = { +static const char *index_query[] = { "create unique index u_db_serial_name_owner ON db_serial (name, owner)", "alter table db_serial drop constraint pk_db_serial_name", "alter table db_serial add constraint pk_db_serial_unique_name primary key (unique_name)", -#if 0 + "drop index i__db_class_class_name on _db_class", "create index i__db_class_unique_name on _db_class (unique_name)", -#endif - "create index i__db_class_class_name_owner on _db_class (class_name, owner)" -#if 0 - "drop index i__db_class_class_name on _db_class" -#endif + "create index i__db_class_class_name_owner on _db_class (class_name, owner)", }; /* only system classes update unique_name. */ -static char *update_db_class_for_system_classes = +static const char *update_db_class_for_system_classes = "update _db_class set unique_name = class_name where is_system_class % 8 != 0"; static char db_path[PATH_MAX]; @@ -368,6 +591,60 @@ get_db_path (char *dbname, char **pathname) return -1; } +static int +migrate_extract_views (int view_cnt, char **class_name, const char *schema_file) +{ + int i, j, error, is_partition = 0; + DB_OBJECT *class_ = NULL; + MOP *sub_partitions = NULL; + extract_context unload_context; + LIST_MOPS *class_table; + DB_OBJECT **req_class_table; + + *cub_required_class_only = true; + *cub_do_schema = true; + *cub_include_references = false; + *cub_input_filename = (char *) schema_file; + + class_table = cub_locator_get_all_mops (*cub_sm_Root_class_mop, DB_FETCH_READ, NULL); + *cub_class_table = class_table; + + req_class_table = (DB_OBJECT **) malloc (DB_SIZEOF (void *) * class_table->num); + *cub_req_class_table = req_class_table; + + for (i = 0; i < class_table->num; ++i) + { + req_class_table[i] = NULL; + } + + i = 0; + while (i < view_cnt) + { + class_ = cub_locator_find_class (class_name[i]); + if (class_ != NULL) + { + req_class_table[i] = class_; + i++; + } + } + + for (i = 0; req_class_table[i]; i++) + { + cub_au_fetch_class (req_class_table[i], NULL, 0, 1); + } + + unload_context.do_auth = 1; + unload_context.storage_order = FOLLOW_STORAGE_ORDER; + unload_context.exec_name = "migrate"; + + if ((error = cub_extract_classes_to_file (unload_context, schema_file)) != 0) + { + return error; + } + + return NO_ERROR; +} + static int migrate_get_db_path (char *dbname) { @@ -382,6 +659,8 @@ migrate_get_db_path (char *dbname) } sprintf (db_path, "%s/%s_lgat", path, dbname); + + return NO_ERROR; } static int @@ -601,17 +880,17 @@ migrate_initialize (char *dbname) error = -1; } - cub_db_get_database_version = dlsym (dl_handle, "db_get_database_version"); + cub_db_get_database_version = (DB_GET_DATABASE_VERSION) dlsym (dl_handle, "db_get_database_version"); if (cub_db_get_database_version == NULL) { PRINT_LOG ("%s", dlerror ()); error = -1; } - cub_au_disable_passwords = dlsym (dl_handle, "au_disable_passwords"); + cub_au_disable_passwords = (AU_DISABLE_PASSWORDS) dlsym (dl_handle, "au_disable_passwords"); if (cub_au_disable_passwords == NULL) { - cub_au_disable_passwords = dlsym (dl_handle, "_Z20au_disable_passwordsv"); + cub_au_disable_passwords = (AU_DISABLE_PASSWORDS) dlsym (dl_handle, "_Z20au_disable_passwordsv"); if (cub_au_disable_passwords == NULL) { PRINT_LOG ("%s", dlerror ()); @@ -619,39 +898,40 @@ migrate_initialize (char *dbname) } } - cub_db_restart_ex = dlsym (dl_handle, "db_restart_ex"); + cub_db_restart_ex = (DB_RESTART_EX) dlsym (dl_handle, "db_restart_ex"); if (cub_db_restart_ex == NULL) { PRINT_LOG ("%s", dlerror ()); error = -1; } - cub_er_errid = dlsym (dl_handle, "er_errid"); + cub_er_errid = (ER_ERRID) dlsym (dl_handle, "er_errid"); if (cub_er_errid == NULL) { PRINT_LOG ("%s", dlerror ()); error = -1; } - cub_db_open_buffer = dlsym (dl_handle, "db_open_buffer"); + cub_db_open_buffer = (DB_OPEN_BUFFER) dlsym (dl_handle, "db_open_buffer"); if (cub_db_open_buffer == NULL) { PRINT_LOG ("%s", dlerror ()); error = -1; } - cub_db_compile_statement = dlsym (dl_handle, "db_compile_statement"); + cub_db_compile_statement = (DB_COMPILE_STATEMENT) dlsym (dl_handle, "db_compile_statement"); if (cub_db_compile_statement == NULL) { PRINT_LOG ("%s", dlerror ()); error = -1; } - cub_db_execute_statement_local = dlsym (dl_handle, "db_execute_statement_local"); + cub_db_execute_statement_local = (DB_EXECUTE_STATEMENT_LOCAL) dlsym (dl_handle, "db_execute_statement_local"); if (cub_db_execute_statement_local == NULL) { cub_db_execute_statement_local = - dlsym (dl_handle, "_Z26db_execute_statement_localP10db_sessioniPP15db_query_result"); + (DB_EXECUTE_STATEMENT_LOCAL) dlsym (dl_handle, + "_Z26db_execute_statement_localP10db_sessioniPP15db_query_result"); if (cub_db_execute_statement_local == NULL) { PRINT_LOG ("%s", dlerror ()); @@ -659,76 +939,164 @@ migrate_initialize (char *dbname) } } - cub_db_query_get_tuple_value = dlsym (dl_handle, "db_query_get_tuple_value"); + cub_db_query_get_tuple_value = (DB_QUERY_GET_TUPLE_VALUE) dlsym (dl_handle, "db_query_get_tuple_value"); if (cub_db_query_get_tuple_value == NULL) { PRINT_LOG ("%s", dlerror ()); error = -1; } - cub_db_query_first_tuple = dlsym (dl_handle, "db_query_first_tuple"); + cub_db_query_first_tuple = (DB_QUERY_TUPLE) dlsym (dl_handle, "db_query_first_tuple"); if (cub_db_query_first_tuple == NULL) { PRINT_LOG ("%s", dlerror ()); error = -1; } - cub_db_query_next_tuple = dlsym (dl_handle, "db_query_next_tuple"); + cub_db_query_next_tuple = (DB_QUERY_TUPLE) dlsym (dl_handle, "db_query_next_tuple"); if (cub_db_query_next_tuple == NULL) { PRINT_LOG ("%s", dlerror ()); error = -1; } - cub_db_close_session = dlsym (dl_handle, "db_close_session"); + cub_db_query_tuple_count = (DB_QUERY_TUPLE) dlsym (dl_handle, "db_query_tuple_count"); + if (cub_db_query_tuple_count == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_db_close_session = (DB_CLOSE_SESSION) dlsym (dl_handle, "db_close_session"); if (cub_db_close_session == NULL) { PRINT_LOG ("%s", dlerror ()); error = -1; } - cub_db_query_end = dlsym (dl_handle, "db_query_end"); + cub_db_query_end = (DB_QUERY_END) dlsym (dl_handle, "db_query_end"); if (cub_db_query_end == NULL) { PRINT_LOG ("%s", dlerror ()); error = -1; } - cub_db_commit_transaction = dlsym (dl_handle, "db_commit_transaction"); + cub_db_commit_transaction = (DB_COMMIT_TRANSACTION) dlsym (dl_handle, "db_commit_transaction"); if (cub_db_commit_transaction == NULL) { PRINT_LOG ("%s", dlerror ()); error = -1; } - cub_db_abort_transaction = dlsym (dl_handle, "db_abort_transaction"); + cub_db_abort_transaction = (DB_ABORT_TRANSACTION) dlsym (dl_handle, "db_abort_transaction"); if (cub_db_abort_transaction == NULL) { PRINT_LOG ("%s", dlerror ()); error = -1; } - cub_db_shutdown = dlsym (dl_handle, "db_shutdown"); + cub_db_shutdown = (DB_SHUTDOWN) dlsym (dl_handle, "db_shutdown"); if (cub_db_shutdown == NULL) { PRINT_LOG ("%s", dlerror ()); error = -1; } - cub_db_error_string = dlsym (dl_handle, "db_error_string"); + cub_db_error_string = (DB_ERROR_STRING) dlsym (dl_handle, "db_error_string"); if (cub_db_error_string == NULL) { PRINT_LOG ("%s", dlerror ()); error = -1; } - cub_Au_disable = dlsym (dl_handle, "Au_disable"); + cub_Au_disable = (int *) dlsym (dl_handle, "Au_disable"); if (cub_Au_disable == NULL) { PRINT_LOG ("%s", dlerror ()); error = -1; } + cub_req_class_table = (DB_OBJECT ***) dlsym (dl_handle, "req_class_table"); + if (cub_req_class_table == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_required_class_only = (bool *) dlsym (dl_handle, "required_class_only"); + if (cub_required_class_only == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_include_references = (bool *) dlsym (dl_handle, "include_references"); + if (cub_include_references == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_input_filename = (char **) dlsym (dl_handle, "input_filename"); + if (cub_input_filename == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_do_schema = (bool *) dlsym (dl_handle, "do_schema"); + if (cub_do_schema == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_class_table = (LIST_MOPS **) dlsym (dl_handle, "class_table"); + if (cub_class_table == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_sm_Root_class_mop = (MOP *) dlsym (dl_handle, "sm_Root_class_mop"); + if (cub_sm_Root_class_mop == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_locator_get_all_mops = + (LOCATOR_GET_ALL_MOPS) dlsym (dl_handle, + "_Z20locator_get_all_mopsP9db_object13DB_FETCH_MODEP21LC_FETCH_VERSION_TYPE"); + if (cub_locator_get_all_mops == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_locator_find_class = (LOCATOR_FIND_CLASS) dlsym (dl_handle, "_Z18locator_find_classPKc"); + if (cub_locator_find_class == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_au_fetch_class = + (AU_FETCH_CLASS) dlsym (dl_handle, "_Z14au_fetch_classP9db_objectPP8sm_class12au_fetchmode7DB_AUTH"); + if (cub_au_fetch_class == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_extract_classes_to_file = + (EXTRACT_CLASSES_TO_FILE) dlsym (dl_handle, "_Z23extract_classes_to_fileR15extract_contextPKc"); + if (cub_locator_find_class == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + return error; } @@ -751,6 +1119,67 @@ migrate_execute_query (const char *query) return -1; } cub_db_query_end (result); + + return NO_ERROR; +} + +static int +migrate_get_view_list (char ***view_list) +{ + DB_QUERY_RESULT *result; + int cnt = 0, error; + char **list; + + error = cub_db_execute_query (view_query, &result); + if (error < 0) + { + fprintf (out, "view query: execute query failed\n \"%s\"\n", view_query); + return -1; + } + + cnt = cub_db_query_tuple_count (result); + + if (cnt == 0) + { + *view_list = NULL; + return 0; + } + + list = (char **) malloc (cnt * sizeof (char *)); + *view_list = list; + + cnt = 0; + if ((error = cub_db_query_first_tuple (result)) == DB_CURSOR_SUCCESS) + { + do + { + DB_VALUE value; + + /* from query */ + error = cub_db_query_get_tuple_value (result, 0, &value); + if (error < 0) + { + fprintf (out, "view_list: can not get a tuple for \"%s\"\n", view_query); + return -1; + } + + list[cnt++] = strdup (value.data.ch.medium.buf); + + error = cub_db_query_next_tuple (result); + } + while (error != DB_CURSOR_END && error != DB_CURSOR_ERROR); + } + +end: + cub_db_query_end (result); + + if (error < 0) + { + fprintf (out, "generated: can not get a next tuple for \"%s\"\n", view_query); + return -1; + } + + return cnt; } static int @@ -839,13 +1268,13 @@ migrate_queries () return -1; } } -#if 0 + error = migrate_execute_query (update_db_class_not_for_system_classes); if (error < 0) { return -1; } -#endif + error = migrate_generated (serial_query, 1); if (error < 0) { @@ -877,19 +1306,12 @@ migrate_queries () return -1; } } -#if 0 - error = migrate_execute_query (update_db_class_for_system_classes); - if (error < 0) - { - return -1; - } - error = migrate_execute_query (select_db_class_for_system_update); + error = migrate_execute_query (update_db_class_for_system_classes); if (error < 0) { return -1; } -#endif return 0; } @@ -983,6 +1405,8 @@ main (int argc, char *argv[]) { int status, error; char *dbname; + char **view_list; + int view_cnt; if (argc < 2) { @@ -1029,9 +1453,6 @@ main (int argc, char *argv[]) return -1; } - printf ("\n"); - printf ("Phase 4: Executing the mirgate queries\n"); - cub_au_disable_passwords (); error = cub_db_restart_ex ("migrate", dbname, "DBA", NULL, NULL, DB_CLIENT_TYPE_ADMIN_UTILITY); @@ -1043,6 +1464,69 @@ main (int argc, char *argv[]) *cub_Au_disable = 1; + printf ("Phase 4: Extracting Viewws\n"); + + view_cnt = migrate_get_view_list (&view_list); + if (view_cnt < 0) + { + printf ("migrate: encountered error while get view list\n"); + return -1; + } + + if (view_list) + { + int i; + FILE *f_query, *f_view; + char sql[4096]; + char view_list_file[256]; + char view_query_file[256]; + + /* make view list file as like unload */ + sprintf (view_list_file, "%s_schema", dbname); + if (migrate_extract_views (view_cnt, view_list, view_list_file) < 0) + { + printf ("migrate: encountered error while extracting the views\n"); + return -1; + } + + /* make view query file for drop view queries */ + sprintf (view_query_file, "%s.view", dbname); + f_query = fopen (view_query_file, "w"); + if (f_query == NULL) + { + printf ("migrate: encountered error while opening view query file\n"); + return -1; + } + + /* readey to make queries to drop views */ + for (i = 0; i < view_cnt; i++) + { + fprintf (f_query, "DROP VIEW [%s];\n", view_list[i]); + } + fprintf (f_query, "\n"); + + /* concatenate view list file and view query file */ + f_view = fopen (view_list_file, "r"); + if (f_view == NULL) + { + printf ("migrate: encountered error while opening view list file\n"); + return -1; + } + + while (fgets (sql, 4096, f_view)) + { + fprintf (f_query, "%s", sql); + } + + fclose (f_query); + fclose (f_view); + + free (view_list); + } + + printf ("\n"); + printf ("Phase 5: Executing the mirgate queries\n"); + error = migrate_queries (); if (error < 0) { @@ -1072,10 +1556,11 @@ main (int argc, char *argv[]) } printf ("\n"); - printf ("Phase 5: Updating version info for log volume\n"); + printf ("Phase 6: Updating version info for log volume\n"); +#if 0 /* finalizing: update volume info. to 11.2 */ migrate_update_log_volume (dbname); - +#endif return 0; } diff --git a/migrate/migrate.h b/migrate/migrate.h index 355bac0..5df6a65 100644 --- a/migrate/migrate.h +++ b/migrate/migrate.h @@ -43,6 +43,29 @@ #define PRINT_LOG(fmt, ...) print_log (fmt "\tin %s () from %s:%d", __VA_ARGS__, __func__, __FILE__, __LINE__) +#define DB_SIZEOF(val) (sizeof(val)) + +#define free_and_init(ptr) \ + do { \ + free ((ptr)); \ + (ptr) = NULL; \ + } while (0) + +typedef struct list_mops LIST_MOPS; +struct list_mops +{ + int num; + MOP mops[1]; +}; + +typedef enum +{ + LC_FETCH_CURRENT_VERSION = 0x01, /* fetch current version */ + LC_FETCH_MVCC_VERSION = 0x02, /* fetch MVCC - visible version */ + LC_FETCH_DIRTY_VERSION = 0x03, /* fetch dirty version - S-locked */ + LC_FETCH_CURRENT_VERSION_NO_CHECK = 0x04, /* fetch current version and not check server side */ +} LC_FETCH_VERSION_TYPE; + /* global variable */ const char *PRO_NAME = NULL; const char *CUBRID_ENV = NULL; @@ -50,25 +73,67 @@ const char *CUBRID_ENV = NULL; void *dl_handle = NULL; /* CUBRID function pointer */ -void (*cub_au_disable_passwords) (void); -int (*cub_db_restart_ex) (const char *, const char *, const char *, const char *, const char *, int); -int (*cub_er_errid) (void); -DB_SESSION *(*cub_db_open_buffer) (const char *); -int (*cub_db_compile_statement) (DB_SESSION *); -int (*cub_db_execute_statement_local) (DB_SESSION *, int, DB_QUERY_RESULT **); -void (*cub_db_close_session) (DB_SESSION *); -int (*cub_db_query_end) (DB_QUERY_RESULT *); -int (*cub_db_commit_transaction) (void); -int (*cub_db_abort_transaction) (void); -int (*cub_db_query_get_tuple_value) (DB_QUERY_RESULT * result, int tuple_index, DB_VALUE * value); -int (*cub_db_query_next_tuple) (DB_QUERY_RESULT * result); -int (*cub_db_query_first_tuple) (DB_QUERY_RESULT * result); -char *(*cub_db_get_database_version) (void); -int (*cub_db_shutdown) (void); -const char *(*cub_db_error_string) (int); +typedef void (*AU_DISABLE_PASSWORDS) (void); +typedef int (*DB_RESTART_EX) (const char *, const char *, const char *, const char *, const char *, int); +typedef int (*ER_ERRID) (void); +typedef DB_SESSION *(*DB_OPEN_BUFFER) (const char *); +typedef int (*DB_COMPILE_STATEMENT) (DB_SESSION *); +typedef int (*DB_EXECUTE_STATEMENT_LOCAL) (DB_SESSION *, int, DB_QUERY_RESULT **); +typedef void (*DB_CLOSE_SESSION) (DB_SESSION *); +typedef int (*DB_QUERY_END) (DB_QUERY_RESULT *); +typedef int (*DB_COMMIT_TRANSACTION) (void); +typedef int (*DB_ABORT_TRANSACTION) (void); +typedef int (*DB_QUERY_GET_TUPLE_VALUE) (DB_QUERY_RESULT * result, int tuple_index, DB_VALUE * value); +typedef int (*DB_QUERY_TUPLE) (DB_QUERY_RESULT * result); +typedef int (*DB_QUERY_GET_TUPLE_OID) (DB_QUERY_RESULT * result, DB_VALUE * value); +typedef int (*DB_MAKE_STRING) (DB_VALUE * value, DB_CONST_C_CHAR str); +typedef DB_OBJECT *(*DB_GET_OBJECT) (DB_VALUE * value); +typedef int (*DB_PUT) (DB_OBJECT * obj, const char *name, DB_VALUE * value); +typedef char *(*DB_GET_DATABASE_VERSION) (void); +typedef int (*DB_SHUTDOWN) (void); +typedef const char *(*DB_ERROR_STRING) (int); +typedef MOP (*LOCATOR_FIND_CLASS) (const char *classname); +typedef int (*EXTRACT_CLASSES_TO_FILE) (extract_context & ctxt, const char *output_filename); +typedef LIST_MOPS *(*LOCATOR_GET_ALL_MOPS) (MOP class_mop, DB_FETCH_MODE class_purpose, + LC_FETCH_VERSION_TYPE * force_fetch_version_type); +typedef int (*AU_FETCH_CLASS) (MOP op, void **class_ptr, int fetchmode, int type); + +AU_DISABLE_PASSWORDS cub_au_disable_passwords; +DB_RESTART_EX cub_db_restart_ex; +ER_ERRID cub_er_errid; +DB_OPEN_BUFFER cub_db_open_buffer; +DB_COMPILE_STATEMENT cub_db_compile_statement; +DB_EXECUTE_STATEMENT_LOCAL cub_db_execute_statement_local; +DB_CLOSE_SESSION cub_db_close_session; +DB_QUERY_END cub_db_query_end; +DB_COMMIT_TRANSACTION cub_db_commit_transaction; +DB_ABORT_TRANSACTION cub_db_abort_transaction; +DB_QUERY_GET_TUPLE_VALUE cub_db_query_get_tuple_value; +DB_QUERY_TUPLE cub_db_query_next_tuple; +DB_QUERY_TUPLE cub_db_query_first_tuple; +DB_QUERY_TUPLE cub_db_query_tuple_count; +DB_QUERY_GET_TUPLE_OID cub_db_query_get_tuple_oid; +DB_MAKE_STRING cub_db_make_string; +DB_GET_OBJECT cub_db_get_object; +DB_PUT cub_db_put; +DB_GET_DATABASE_VERSION cub_db_get_database_version; +DB_SHUTDOWN cub_db_shutdown; +DB_ERROR_STRING cub_db_error_string; +LOCATOR_FIND_CLASS cub_locator_find_class; +EXTRACT_CLASSES_TO_FILE cub_extract_classes_to_file; +LOCATOR_GET_ALL_MOPS cub_locator_get_all_mops; +AU_FETCH_CLASS cub_au_fetch_class; /* CUBRID global variable */ int *cub_Au_disable; -bool *cub_Au_sysadm; + +DB_OBJECT ***cub_req_class_table; +bool *cub_required_class_only; +bool *cub_include_references; +bool *cub_do_schema; +LIST_MOPS **cub_class_table; +MOP *cub_sm_Root_class_mop; +char **cub_input_filename; +extract_context cub_unload_context; #endif From 88302f9d6d924227fa339f9f916a2d3a66c38f03 Mon Sep 17 00:00:00 2001 From: Byungwook Kim Date: Tue, 6 Sep 2022 16:40:46 +0900 Subject: [PATCH 05/15] slip --- migrate/migrate.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/migrate/migrate.c b/migrate/migrate.c index 8617149..d9f0e45 100644 --- a/migrate/migrate.c +++ b/migrate/migrate.c @@ -1558,9 +1558,8 @@ main (int argc, char *argv[]) printf ("\n"); printf ("Phase 6: Updating version info for log volume\n"); -#if 0 /* finalizing: update volume info. to 11.2 */ migrate_update_log_volume (dbname); -#endif + return 0; } From 45e05289e0cf7cbe550cec2c7c901a97a386ffa5 Mon Sep 17 00:00:00 2001 From: Byungwook Kim Date: Wed, 7 Sep 2022 09:11:22 +0900 Subject: [PATCH 06/15] add comments --- migrate/migrate.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/migrate/migrate.c b/migrate/migrate.c index d9f0e45..59ac246 100644 --- a/migrate/migrate.c +++ b/migrate/migrate.c @@ -1464,8 +1464,10 @@ main (int argc, char *argv[]) *cub_Au_disable = 1; + printf ("\n"); printf ("Phase 4: Extracting Viewws\n"); + /* get view list from database by query related to view */ view_cnt = migrate_get_view_list (&view_list); if (view_cnt < 0) { @@ -1481,7 +1483,7 @@ main (int argc, char *argv[]) char view_list_file[256]; char view_query_file[256]; - /* make view list file as like unload */ + /* make view list file as like unload schema */ sprintf (view_list_file, "%s_schema", dbname); if (migrate_extract_views (view_cnt, view_list, view_list_file) < 0) { @@ -1513,6 +1515,7 @@ main (int argc, char *argv[]) return -1; } + /* copy and concat from view schema */ while (fgets (sql, 4096, f_view)) { fprintf (f_query, "%s", sql); From d2eef0782260e1123ddb46d54dae2ed2fc07bb24 Mon Sep 17 00:00:00 2001 From: Byungwook Kim Date: Thu, 20 Oct 2022 10:57:27 +0900 Subject: [PATCH 07/15] add extract_schema.hpp --- migrate/extract_schema.hpp | 61 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 migrate/extract_schema.hpp diff --git a/migrate/extract_schema.hpp b/migrate/extract_schema.hpp new file mode 100644 index 0000000..e28d84d --- /dev/null +++ b/migrate/extract_schema.hpp @@ -0,0 +1,61 @@ +/* + * Copyright 2008 Search Solution Corporation + * Copyright 2016 CUBRID Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +/* + * extract_schema.hpp - + */ + +#ifndef _EXTRACT_SCHEMA_HPP_ +#define _EXTRACT_SCHEMA_HPP_ + +#include "dbtype_def.h" +#include + +typedef enum +{ + FOLLOW_STORAGE_ORDER = 0, + FOLLOW_ATTRIBUTE_ORDER = 1 +} EMIT_STORAGE_ORDER; + +struct extract_context +{ + /* input */ + int do_auth; + EMIT_STORAGE_ORDER storage_order; + const char *exec_name; + + /* working */ + int has_indexes; + DB_OBJLIST *classes; + DB_OBJLIST *vclass_list_has_using_index; + + extract_context (): + do_auth (0), + storage_order (FOLLOW_STORAGE_ORDER), + exec_name (NULL), + has_indexes (0), + classes (NULL), + vclass_list_has_using_index (NULL) + { + } + + void clear_schema_workspace (void); +}; + +#endif /* _EXTRACT_SCHEMA_HPP_ */ From c1725c2f6ce2d48e73251eab811147be25f8ce91 Mon Sep 17 00:00:00 2001 From: Byungwook Kim Date: Fri, 21 Oct 2022 08:30:48 +0900 Subject: [PATCH 08/15] fix: grant for system view --- migrate/migrate.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/migrate/migrate.c b/migrate/migrate.c index 59ac246..802833a 100644 --- a/migrate/migrate.c +++ b/migrate/migrate.c @@ -71,6 +71,8 @@ static const char *catalog_query[] = { ) as \ SELECT [c].[class_name] AS [class_name], CAST ([c].[owner].[name] AS VARCHAR(255)) AS [owner_name], CASE [c].[class_type] WHEN 0 THEN 'CLASS' WHEN 1 THEN 'VCLASS' ELSE 'UNKNOW' END AS [class_type], CASE WHEN MOD([c].[is_system_class], 2) = 1 THEN 'YES' ELSE 'NO' END AS [is_system_class], CASE [c].[tde_algorithm] WHEN 0 THEN 'NONE' WHEN 1 THEN 'AES' WHEN 2 THEN 'ARIA' END AS [tde_algorithm], CASE WHEN [c].[sub_classes] IS NULL THEN 'NO' ELSE NVL ((SELECT 'YES' FROM [_db_partition] AS [p] WHERE [p].[class_of] = [c] AND [p].[pname] IS NULL), 'NO') END AS [partitioned], CASE WHEN MOD ([c].[is_system_class] / 8, 2) = 1 THEN 'YES' ELSE 'NO' END AS [is_reuse_oid_class], [coll].[coll_name] AS [collation], [c].[comment] AS [comment] FROM [_db_class] AS [c], [_db_collation] AS [coll] WHERE [c].[collation_id] = [coll].[coll_id] AND (CURRENT_USER = 'DBA' OR {[c].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[c]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT'))", + "GRANT SELECT ON [db_class] TO PUBLIC", + /* db_direct_super_class */ "CREATE OR REPLACE VIEW [db_direct_super_class] ( \ [class_name] varchar(255), \ @@ -80,6 +82,8 @@ static const char *catalog_query[] = { ) as \ SELECT [c].[class_name] AS [class_name], CAST ([c].[owner].[name] AS VARCHAR(255)) AS [owner_name], [s].[class_name] AS [super_class_name], CAST ([s].[owner].[name] AS VARCHAR(255)) AS [super_owner_name] FROM [_db_class] AS [c], TABLE ([c].[super_classes]) AS [t] ([s]) WHERE CURRENT_USER = 'DBA' OR {[c].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[c]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT')", + "GRANT SELECT ON [db_direct_super_class] TO PUBLIC", + /* db_vclass */ "CREATE OR REPLACE VIEW [db_vclass] ( \ [vclass_name] varchar(255), \ @@ -89,6 +93,8 @@ SELECT [c].[class_name] AS [class_name], CAST ([c].[owner].[name] AS VARCHAR(255 ) as \ SELECT [q].[class_of].[class_name] AS [vclass_name], CAST ([q].[class_of].[owner].[name] AS VARCHAR(255)) AS [owner_name], [q].[spec] AS [vclass_def], [c].[comment] AS [comment] FROM [_db_query_spec] AS [q], [_db_class] AS [c] WHERE [q].[class_of] = [c] AND (CURRENT_USER = 'DBA' OR {[q].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[q].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT'))", + "GRANT SELECT ON [db_vclass] TO PUBLIC", + /* db_attribute */ "CREATE OR REPLACE VIEW [db_attribute] ( \ [attr_name] varchar(255), \ @@ -112,6 +118,8 @@ SELECT [q].[class_of].[class_name] AS [vclass_name], CAST ([q].[class_of].[owner ) as \ SELECT [a].[attr_name] AS [attr_name], [c].[class_name] AS [class_name], CAST ([c].[owner].[name] AS VARCHAR(255)) AS [owner_name], CASE [a].[attr_type] WHEN 0 THEN 'INSTANCE' WHEN 1 THEN 'CLASS' ELSE 'SHARED' END AS [attr_type], [a].[def_order] AS [def_order], [a].[from_class_of].[class_name] AS [from_class_name], CAST ([a].[from_class_of].[owner].[name] AS VARCHAR(255)) AS [from_owner_name], [a].[from_attr_name] AS [from_attr_name], [t].[type_name] AS [data_type], [d].[prec] AS [prec], [d].[scale] AS [scale], IF ([a].[data_type] IN (4, 25, 26, 27, 35), (SELECT [ch].[charset_name] FROM [_db_charset] AS [ch] WHERE [d].[code_set] = [ch].[charset_id]), 'Not applicable') AS [charset], IF ([a].[data_type] IN (4, 25, 26, 27, 35), (SELECT [coll].[coll_name] FROM [_db_collation] AS [coll] WHERE [d].[collation_id] = [coll].[coll_id]), 'Not applicable') AS [collation], [d].[class_of].[class_name] AS [domain_class_name], CAST ([d].[class_of].[owner].[name] AS VARCHAR(255)) AS [domain_owner_name], [a].[default_value] AS [default_value], CASE WHEN [a].[is_nullable] = 1 THEN 'YES' ELSE 'NO' END AS [is_nullable], [a].[comment] AS [comment] FROM [_db_class] AS [c], [_db_attribute] AS [a], [_db_domain] AS [d], [_db_data_type] AS [t] WHERE [a].[class_of] = [c] AND [d].[object_of] = [a] AND [d].[data_type] = [t].[type_id] AND (CURRENT_USER = 'DBA' OR {[c].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[c]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT'))", + "GRANT SELECT ON [db_attribute] TO PUBLIC", + /* db_attr_setdomain_elm */ "CREATE OR REPLACE VIEW [db_attr_setdomain_elm] ( \ [attr_name] varchar(255), \ @@ -127,6 +135,8 @@ SELECT [a].[attr_name] AS [attr_name], [c].[class_name] AS [class_name], CAST ([ ) as \ SELECT [a].[attr_name] AS [attr_name], [c].[class_name] AS [class_name], CAST ([c].[owner].[name] AS VARCHAR(255)) AS [owner_name], CASE [a].[attr_type] WHEN 0 THEN 'INSTANCE' WHEN 1 THEN 'CLASS' ELSE 'SHARED' END AS [attr_type], [et].[type_name] AS [data_type], [e].[prec] AS [prec], [e].[scale] AS [scale], [e].[code_set] AS [code_set], [e].[class_of].[class_name] AS [domain_class_name], CAST ([e].[class_of].[owner].[name] AS VARCHAR(255)) AS [domain_owner_name] FROM [_db_class] AS [c], [_db_attribute] AS [a], [_db_domain] AS [d], TABLE ([d].[set_domains]) AS [t] ([e]), [_db_data_type] AS [et] WHERE [a].[class_of] = [c] AND [d].[object_of] = [a] AND [e].[data_type] = [et].[type_id] AND (CURRENT_USER = 'DBA' OR {[c].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[c]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT'))", + "GRANT SELECT ON [db_attr_setdomain_elm] TO PUBLIC", + /* db_method */ "CREATE OR REPLACE VIEW [db_method] ( \ [meth_name] varchar(255), \ @@ -140,6 +150,8 @@ SELECT [a].[attr_name] AS [attr_name], [c].[class_name] AS [class_name], CAST ([ ) AS \ SELECT [m].[meth_name] AS [meth_name], [m].[class_of].[class_name] AS [class_name], CAST ([m].[class_of].[owner].[name] AS VARCHAR(255)) AS [owner_name], CASE [m].[meth_type] WHEN 0 THEN 'INSTANCE' ELSE 'CLASS' END AS [meth_type], [m].[from_class_of].[class_name] AS [from_class_name], CAST ([m].[from_class_of].[owner].[name] AS VARCHAR(255)) AS [from_owner_name], [m].[from_meth_name] AS [from_meth_name], [s].[func_name] AS [func_name] FROM [_db_method] AS [m], [_db_meth_sig] AS [s] WHERE [s].[meth_of] = [m] AND (CURRENT_USER = 'DBA' OR {[m].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[m].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT'))", + "GRANT SELECT ON [db_method] TO PUBLIC", + /* db_meth_arg */ "CREATE OR REPLACE VIEW [db_meth_arg] ( \ [meth_name] varchar(255), \ @@ -156,6 +168,8 @@ SELECT [m].[meth_name] AS [meth_name], [m].[class_of].[class_name] AS [class_nam ) AS \ SELECT [s].[meth_of].[meth_name] AS [meth_name], [s].[meth_of].[class_of].[class_name] AS [class_name], CAST ([s].[meth_of].[class_of].[owner].[name] AS VARCHAR(255)) AS [owner_name], CASE [s].[meth_of].[meth_type] WHEN 0 THEN 'INSTANCE' ELSE 'CLASS' END AS [meth_type], [a].[index_of] AS [index_of], [t].[type_name] AS [data_type], [d].[prec] AS [prec], [d].[scale] AS [scale], [d].[code_set] AS [code_set], [d].[class_of].[class_name] AS [domain_class_name], CAST ([d].[class_of].[owner].[name] AS VARCHAR(255)) AS [domain_owner_name] FROM [_db_meth_sig] AS [s], [_db_meth_arg] AS [a], [_db_domain] AS [d], [_db_data_type] AS [t] WHERE [a].[meth_sig_of] = [s] AND [d].[object_of] = [a] AND [d].[data_type] = [t].[type_id] AND (CURRENT_USER = 'DBA' OR {[s].[meth_of].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[s].[meth_of].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT'))", + "GRANT SELECT ON [db_meth_arg] TO PUBLIC", + /* db_meth_arg_setdomain_elm */ "CREATE OR REPLACE VIEW [db_meth_arg_setdomain_elm] ( \ [meth_name] varchar(255), \ @@ -172,6 +186,8 @@ SELECT [s].[meth_of].[meth_name] AS [meth_name], [s].[meth_of].[class_of].[class ) AS \ SELECT [s].[meth_of].[meth_name] AS [meth_name], [s].[meth_of].[class_of].[class_name] AS [class_name], CAST ([s].[meth_of].[class_of].[owner].[name] AS VARCHAR(255)) AS [owner_name], CASE [s].[meth_of].[meth_type] WHEN 0 THEN 'INSTANCE' ELSE 'CLASS' END AS [meth_type], [a].[index_of] AS [index_of], [et].[type_name] AS [data_type], [e].[prec] AS [prec], [e].[scale] AS [scale], [e].[code_set] AS [code_set], [e].[class_of].[class_name] AS [domain_class_name], CAST ([e].[class_of].[owner].[name] AS VARCHAR(255)) AS [domain_owner_name] FROM [_db_meth_sig] AS [s], [_db_meth_arg] AS [a], [_db_domain] AS [d], TABLE ([d].[set_domains]) AS [t] ([e]), [_db_data_type] AS [et] WHERE [a].[meth_sig_of] = [s] AND [d].[object_of] = [a] AND [e].[data_type] = [et].[type_id] AND (CURRENT_USER = 'DBA' OR {[s].[meth_of].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[s].[meth_of].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT'))", + "GRANT SELECT ON [db_meth_arg_setdomain_elm] TO PUBLIC", + /* db_meth_file */ "CREATE OR REPLACE VIEW [db_meth_file] ( \ [class_name] varchar(255), \ @@ -182,6 +198,8 @@ SELECT [s].[meth_of].[meth_name] AS [meth_name], [s].[meth_of].[class_of].[class ) AS \ SELECT [f].[class_of].[class_name] AS [class_name], CAST ([f].[class_of].[owner].[name] AS VARCHAR(255)) AS [owner_name], [f].[path_name] AS [path_name], [f].[from_class_of].[class_name] AS [from_class_name], CAST ([f].[from_class_of].[owner].[name] AS VARCHAR(255)) AS [from_owner_name] FROM [_db_meth_file] AS [f] WHERE CURRENT_USER = 'DBA' OR {[f].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[f].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT')", + "GRANT SELECT ON [db_meth_file] TO PUBLIC", + /* db_index */ "CREATE OR REPLACE VIEW [db_index] ( \ [index_name] varchar(255), \ @@ -199,6 +217,8 @@ SELECT [f].[class_of].[class_name] AS [class_name], CAST ([f].[class_of].[owner] ) AS \ SELECT [i].[index_name] AS [index_name], CASE [i].[is_unique] WHEN 0 THEN 'NO' ELSE 'YES' END AS [is_unique], CASE [i].[is_reverse] WHEN 0 THEN 'NO' ELSE 'YES' END AS [is_reverse], [i].[class_of].[class_name] AS [class_name], CAST ([i].[class_of].[owner].[name] AS VARCHAR(255)) AS [owner_name], [i].[key_count] AS [key_count], CASE [i].[is_primary_key] WHEN 0 THEN 'NO' ELSE 'YES' END AS [is_primary_key], CASE [i].[is_foreign_key] WHEN 0 THEN 'NO' ELSE 'YES' END AS [is_foreign_key], [i].[filter_expression] AS [filter_expression], CASE [i].[have_function] WHEN 0 THEN 'NO' ELSE 'YES' END AS [have_function], [i].[comment] AS [comment], CASE [i].[status] WHEN 0 THEN 'NO_INDEX' WHEN 1 THEN 'NORMAL INDEX' WHEN 2 THEN 'INVISIBLE INDEX' WHEN 3 THEN 'INDEX IS IN ONLINE BUILDING' ELSE 'NULL' END AS [status] FROM [_db_index] AS [i] WHERE CURRENT_USER = 'DBA' OR {[i].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[i].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT')", + "GRANT SELECT ON [db_index] TO PUBLIC", + /* db_index_key */ "CREATE OR REPLACE VIEW [db_index_key] ( \ [index_name] varchar(255), \ @@ -212,6 +232,8 @@ SELECT [i].[index_name] AS [index_name], CASE [i].[is_unique] WHEN 0 THEN 'NO' E ) as \ SELECT [k].[index_of].[index_name] AS [index_name], [k].[index_of].[class_of].[class_name] AS [class_name], CAST ([k].[index_of].[class_of].[owner].[name] AS VARCHAR(255)) AS [owner_name], [k].[key_attr_name] AS [key_attr_name], [k].[key_order] AS [key_order], CASE [k].[asc_desc] WHEN 0 THEN 'ASC' WHEN 1 THEN 'DESC' ELSE 'UNKN' END AS [asc_desc], [k].[key_prefix_length] AS [key_prefix_length], [k].[func] AS [func] FROM [_db_index_key] AS [k] WHERE CURRENT_USER = 'DBA' OR {[k].[index_of].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[k].[index_of].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT')", + "GRANT SELECT ON [db_index_key] TO PUBLIC", + /* db_auth */ "CREATE OR REPLACE VIEW [db_auth] ( \ [grantor_name] varchar(255), \ @@ -223,6 +245,8 @@ SELECT [k].[index_of].[index_name] AS [index_name], [k].[index_of].[class_of].[c ) as \ SELECT CAST ([a].[grantor].[name] AS VARCHAR(255)) AS [grantor_name], CAST ([a].[grantee].[name] AS VARCHAR(255)) AS [grantee_name], [a].[class_of].[class_name] AS [class_name], CAST ([a].[class_of].[owner].[name] AS VARCHAR(255)) AS [owner_name], [a].[auth_type] AS [auth_type], CASE [a].[is_grantable] WHEN 0 THEN 'NO' ELSE 'YES' END AS [is_grantable] FROM [_db_auth] AS [a] WHERE CURRENT_USER = 'DBA' OR {[a].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[a].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT')", + "GRANT SELECT ON [db_auth] TO PUBLIC", + /* db_trig */ "CREATE OR REPLACE VIEW [db_trig] ( \ [trigger_name] varchar(255), \ @@ -237,6 +261,8 @@ SELECT CAST ([a].[grantor].[name] AS VARCHAR(255)) AS [grantor_name], CAST ([a]. ) as \ SELECT CAST ([t].[name] AS VARCHAR (255)) AS [trigger_name], CAST ([t].[owner].[name] AS VARCHAR(255)) AS [owner_name], [c].[class_name] AS [target_class_name], CAST ([c].[owner].[name] AS VARCHAR(255)) AS [target_owner_name], CAST ([t].[target_attribute] AS VARCHAR (255)) AS [target_attr_name], CASE [t].[target_class_attribute] WHEN 0 THEN 'INSTANCE' ELSE 'CLASS' END AS [target_attr_type], [t].[action_type] AS [action_type], [t].[action_time] AS [action_time], [t].[comment] AS [comment] FROM [db_trigger] AS [t] LEFT OUTER JOIN [_db_class] AS [c] ON [t].[target_class] = [c].[class_of] WHERE CURRENT_USER = 'DBA' OR {[t].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[c]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT')", + "GRANT SELECT ON [db_trig] TO PUBLIC", + /* db_partition */ "CREATE OR REPLACE VIEW [db_partition] ( \ [class_name] varchar(255), \ @@ -250,6 +276,8 @@ SELECT CAST ([t].[name] AS VARCHAR (255)) AS [trigger_name], CAST ([t].[owner].[ ) as \ SELECT [s].[class_name] AS [class_name], CAST ([s].[owner].[name] AS VARCHAR(255)) AS [owner_name], [p].[pname] AS [partition_name], CONCAT ([s].[class_name], '__p__', [p].[pname]) AS [partition_class_name], CASE [p].[ptype] WHEN 0 THEN 'HASH' WHEN 1 THEN 'RANGE' ELSE 'LIST' END AS [partition_type], TRIM (SUBSTRING ([pp].[pexpr] FROM 8 FOR (POSITION (' FROM ' IN [pp].[pexpr]) - 8))) AS [partition_expr], [p].[pvalues] AS [partition_values], [p].[comment] AS [comment] FROM [_db_partition] AS [p], [_db_class] AS [c], TABLE ([c].[super_classes]) AS [t] ([s]), [_db_class] AS [cc], TABLE ([cc].[partition]) AS [tt] ([pp]) WHERE [p].[class_of] = [c] AND [s] = [cc] AND (CURRENT_USER = 'DBA' OR {[p].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[p].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT'))", + "GRANT SELECT ON [db_partition] TO PUBLIC", + /* db_stored_procedure */ "CREATE OR REPLACE VIEW [db_stored_procedure] ( \ [sp_name] varchar(255), \ @@ -263,6 +291,8 @@ SELECT [s].[class_name] AS [class_name], CAST ([s].[owner].[name] AS VARCHAR(255 ) as \ SELECT [sp].[sp_name] AS [sp_name], CASE [sp].[sp_type] WHEN 1 THEN 'PROCEDURE' ELSE 'FUNCTION' END AS [sp_type], CASE [sp].[return_type] WHEN 0 THEN 'void' WHEN 28 THEN 'CURSOR' ELSE (SELECT [t].[type_name] FROM [_db_data_type] AS [t] WHERE [sp].[return_type] = [t].[type_id]) END AS [return_type], [sp].[arg_count] AS [arg_count], CASE [sp].[lang] WHEN 1 THEN 'JAVA' ELSE '' END AS [lang], [sp].[target] AS [target], CAST ([sp].[owner].[name] AS VARCHAR(255)) AS [owner], [sp].[comment] AS [comment] FROM [_db_stored_procedure] AS [sp]", + "GRANT SELECT ON [db_stored_procedure] TO PUBLIC", + /* db_stored_procedure_args */ "create or replace view [db_stored_procedure_args] ( \ [sp_name] varchar(255), \ @@ -274,6 +304,8 @@ SELECT [sp].[sp_name] AS [sp_name], CASE [sp].[sp_type] WHEN 1 THEN 'PROCEDURE' ) as \ SELECT [sp].[sp_name] AS [sp_name], [sp].[index_of] AS [index_of], [sp].[arg_name] AS [arg_name], CASE [sp].[data_type] WHEN 28 THEN 'CURSOR' ELSE (SELECT [t].[type_name] FROM [_db_data_type] AS [t] WHERE [sp].[data_type] = [t].[type_id]) END AS [data_type], CASE [sp].[mode] WHEN 1 THEN 'IN' WHEN 2 THEN 'OUT' ELSE 'INOUT' END AS [mode], [sp].[comment] AS [comment] FROM [_db_stored_procedure_args] AS [sp] ORDER BY [sp].[sp_name], [sp].[index_of]", + "GRANT SELECT ON [db_stored_procedure_args] TO PUBLIC", + /* db_collation */ "CREATE OR REPLACE VIEW [db_collation] ( \ [coll_id] integer, \ @@ -286,6 +318,8 @@ SELECT [sp].[sp_name] AS [sp_name], [sp].[index_of] AS [index_of], [sp].[arg_nam ) as \ SELECT [coll].[coll_id] AS [coll_id], [coll].[coll_name] AS [coll_name], [ch].[charset_name] AS [charset_name], CASE [coll].[built_in] WHEN 0 THEN 'No' WHEN 1 THEN 'Yes' ELSE 'ERROR' END AS [is_builtin], CASE [coll].[expansions] WHEN 0 THEN 'No' WHEN 1 THEN 'Yes' ELSE 'ERROR' END AS [has_expansions], [coll].[contractions] AS [contractions], CASE [coll].[uca_strength] WHEN 0 THEN 'Not applicable' WHEN 1 THEN 'Primary' WHEN 2 THEN 'Secondary' WHEN 3 THEN 'Tertiary' WHEN 4 THEN 'Quaternary' WHEN 5 THEN 'Identity' ELSE 'Unknown' END AS [uca_strength] FROM [_db_collation] AS [coll] INNER JOIN [_db_charset] AS [ch] ON [coll].[charset_id] = [ch].[charset_id] ORDER BY [coll].[coll_id]", + "GRANT SELECT ON [db_collation] TO PUBLIC", + /* db_charset */ "CREATE OR REPLACE VIEW [db_charset] ( \ [charset_id] integer, \ @@ -295,6 +329,8 @@ SELECT [coll].[coll_id] AS [coll_id], [coll].[coll_name] AS [coll_name], [ch].[c ) as \ SELECT [ch].[charset_id] AS [charset_id], [ch].[charset_name] AS [charset_name], [coll].[coll_name] AS [default_collation], [ch].[char_size] AS [char_size] FROM [_db_charset] AS [ch], [_db_collation] AS [coll] WHERE [ch].[default_collation] = [coll].[coll_id] ORDER BY [ch].[charset_id]", + "GRANT SELECT ON [db_charset] TO PUBLIC", + /* db_server */ "CREATE OR REPLACE VIEW [db_server] ( \ [link_name] character varying(255), \ @@ -308,6 +344,8 @@ SELECT [ch].[charset_id] AS [charset_id], [ch].[charset_name] AS [charset_name], ) as \ SELECT [ds].[link_name] AS [link_name], [ds].[host] AS [host], [ds].[port] AS [port], [ds].[db_name] AS [db_name], [ds].[user_name] AS [user_name], [ds].[properties] AS [properties], CAST ([ds].[owner].[name] AS VARCHAR(255)) AS [owner], [ds].[comment] AS [comment] FROM [_db_server] AS [ds] WHERE CURRENT_USER = 'DBA' OR {[ds].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[ds]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT')", + "GRANT SELECT ON [db_server] TO PUBLIC", + /* db_synonym */ "CREATE OR REPLACE VIEW [db_synonym] ( \ [synonym_name] character varying(255), \ @@ -319,6 +357,8 @@ SELECT [ds].[link_name] AS [link_name], [ds].[host] AS [host], [ds].[port] AS [p ) AS \ SELECT [s].[name] AS [synonym_name], CAST ([s].[owner].[name] AS VARCHAR(255)) AS [synonym_owner_name], CASE [s].[is_public] WHEN 1 THEN 'YES' ELSE 'NO' END AS [is_public_synonym], [s].[target_name] AS [target_name], CAST ([s].[target_owner].[name] AS VARCHAR(255)) AS [target_owner_name], [s].[comment] AS [comment] FROM [_db_synonym] AS [s] WHERE CURRENT_USER = 'DBA' OR [s].[is_public] = 1 OR ([s].[is_public] = 0 AND {[s].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER))", + "GRANT SELECT ON [db_synonym] TO PUBLIC", + /* set system class for newly added tables and views */ "UPDATE [_db_class] \ SET is_system_class = 1 \ From 2f9bb960d454d5cef810d6869d854c968efaa80d Mon Sep 17 00:00:00 2001 From: Byungwook Kim Date: Fri, 21 Oct 2022 17:52:12 +0900 Subject: [PATCH 09/15] fix system class mark --- migrate/migrate.c | 147 ++++++++++++++++++++++++++++++++++++++-------- migrate/migrate.h | 132 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 254 insertions(+), 25 deletions(-) diff --git a/migrate/migrate.c b/migrate/migrate.c index 802833a..9889906 100644 --- a/migrate/migrate.c +++ b/migrate/migrate.c @@ -24,11 +24,34 @@ #define MAX_LINE 4096 #define ENV_VAR_MAX 255 +static const char *system_views[] = { + "db_class", + "db_direct_super_class", + "db_vclass", + "db_attribute", + "db_attr_setdomain_elm", + "db_method", + "db_meth_arg", + "db_meth_arg_setdomain_elm", + "db_meth_file", + "db_index", + "db_index_key", + "db_auth", + "db_trig", + "db_partition", + "db_stored_procedure", + "db_stored_procedure_args", + "db_collation", + "db_charset", + "db_server", + "db_synonym" +}; + static const char *view_query = "select class_name \ from _db_class \ where is_system_class = 0 and class_type = 1"; -static const char *catalog_query[] = { +static const char *system_view_query[] = { /* alter catalog to add tables and views (_db_server, _db_synonym, db_server, db_synonym) */ /* _db_server */ "create table [_db_server] ( \ @@ -57,6 +80,7 @@ static const char *catalog_query[] = { index [i__db_synonym_name_owner_is_public] ([name], [owner], [is_public]) \ ) DONT_REUSE_OID", + "REVOKE SELECT ON [db_class] FROM PUBLIC", /* db_class */ "CREATE OR REPLACE VIEW [db_class] ( \ [class_name] varchar(255), \ @@ -70,9 +94,9 @@ static const char *catalog_query[] = { [comment] varchar(2048) \ ) as \ SELECT [c].[class_name] AS [class_name], CAST ([c].[owner].[name] AS VARCHAR(255)) AS [owner_name], CASE [c].[class_type] WHEN 0 THEN 'CLASS' WHEN 1 THEN 'VCLASS' ELSE 'UNKNOW' END AS [class_type], CASE WHEN MOD([c].[is_system_class], 2) = 1 THEN 'YES' ELSE 'NO' END AS [is_system_class], CASE [c].[tde_algorithm] WHEN 0 THEN 'NONE' WHEN 1 THEN 'AES' WHEN 2 THEN 'ARIA' END AS [tde_algorithm], CASE WHEN [c].[sub_classes] IS NULL THEN 'NO' ELSE NVL ((SELECT 'YES' FROM [_db_partition] AS [p] WHERE [p].[class_of] = [c] AND [p].[pname] IS NULL), 'NO') END AS [partitioned], CASE WHEN MOD ([c].[is_system_class] / 8, 2) = 1 THEN 'YES' ELSE 'NO' END AS [is_reuse_oid_class], [coll].[coll_name] AS [collation], [c].[comment] AS [comment] FROM [_db_class] AS [c], [_db_collation] AS [coll] WHERE [c].[collation_id] = [coll].[coll_id] AND (CURRENT_USER = 'DBA' OR {[c].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[c]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT'))", - "GRANT SELECT ON [db_class] TO PUBLIC", + "REVOKE SELECT ON [db_direct_super_class] FROM PUBLIC", /* db_direct_super_class */ "CREATE OR REPLACE VIEW [db_direct_super_class] ( \ [class_name] varchar(255), \ @@ -81,9 +105,9 @@ static const char *catalog_query[] = { [super_owner_name] varchar(255) \ ) as \ SELECT [c].[class_name] AS [class_name], CAST ([c].[owner].[name] AS VARCHAR(255)) AS [owner_name], [s].[class_name] AS [super_class_name], CAST ([s].[owner].[name] AS VARCHAR(255)) AS [super_owner_name] FROM [_db_class] AS [c], TABLE ([c].[super_classes]) AS [t] ([s]) WHERE CURRENT_USER = 'DBA' OR {[c].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[c]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT')", - "GRANT SELECT ON [db_direct_super_class] TO PUBLIC", + "REVOKE SELECT ON [db_vclass] FROM PUBLIC", /* db_vclass */ "CREATE OR REPLACE VIEW [db_vclass] ( \ [vclass_name] varchar(255), \ @@ -92,9 +116,9 @@ SELECT [c].[class_name] AS [class_name], CAST ([c].[owner].[name] AS VARCHAR(255 [comment] varchar(2048) \ ) as \ SELECT [q].[class_of].[class_name] AS [vclass_name], CAST ([q].[class_of].[owner].[name] AS VARCHAR(255)) AS [owner_name], [q].[spec] AS [vclass_def], [c].[comment] AS [comment] FROM [_db_query_spec] AS [q], [_db_class] AS [c] WHERE [q].[class_of] = [c] AND (CURRENT_USER = 'DBA' OR {[q].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[q].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT'))", - "GRANT SELECT ON [db_vclass] TO PUBLIC", + "REVOKE SELECT ON [db_attribute] FROM PUBLIC", /* db_attribute */ "CREATE OR REPLACE VIEW [db_attribute] ( \ [attr_name] varchar(255), \ @@ -117,9 +141,9 @@ SELECT [q].[class_of].[class_name] AS [vclass_name], CAST ([q].[class_of].[owner [comment] varchar(1024) \ ) as \ SELECT [a].[attr_name] AS [attr_name], [c].[class_name] AS [class_name], CAST ([c].[owner].[name] AS VARCHAR(255)) AS [owner_name], CASE [a].[attr_type] WHEN 0 THEN 'INSTANCE' WHEN 1 THEN 'CLASS' ELSE 'SHARED' END AS [attr_type], [a].[def_order] AS [def_order], [a].[from_class_of].[class_name] AS [from_class_name], CAST ([a].[from_class_of].[owner].[name] AS VARCHAR(255)) AS [from_owner_name], [a].[from_attr_name] AS [from_attr_name], [t].[type_name] AS [data_type], [d].[prec] AS [prec], [d].[scale] AS [scale], IF ([a].[data_type] IN (4, 25, 26, 27, 35), (SELECT [ch].[charset_name] FROM [_db_charset] AS [ch] WHERE [d].[code_set] = [ch].[charset_id]), 'Not applicable') AS [charset], IF ([a].[data_type] IN (4, 25, 26, 27, 35), (SELECT [coll].[coll_name] FROM [_db_collation] AS [coll] WHERE [d].[collation_id] = [coll].[coll_id]), 'Not applicable') AS [collation], [d].[class_of].[class_name] AS [domain_class_name], CAST ([d].[class_of].[owner].[name] AS VARCHAR(255)) AS [domain_owner_name], [a].[default_value] AS [default_value], CASE WHEN [a].[is_nullable] = 1 THEN 'YES' ELSE 'NO' END AS [is_nullable], [a].[comment] AS [comment] FROM [_db_class] AS [c], [_db_attribute] AS [a], [_db_domain] AS [d], [_db_data_type] AS [t] WHERE [a].[class_of] = [c] AND [d].[object_of] = [a] AND [d].[data_type] = [t].[type_id] AND (CURRENT_USER = 'DBA' OR {[c].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[c]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT'))", - "GRANT SELECT ON [db_attribute] TO PUBLIC", + "REVOKE SELECT ON [db_attr_setdomain_elm] FROM PUBLIC", /* db_attr_setdomain_elm */ "CREATE OR REPLACE VIEW [db_attr_setdomain_elm] ( \ [attr_name] varchar(255), \ @@ -134,9 +158,9 @@ SELECT [a].[attr_name] AS [attr_name], [c].[class_name] AS [class_name], CAST ([ [domain_owner_name] varchar(255) \ ) as \ SELECT [a].[attr_name] AS [attr_name], [c].[class_name] AS [class_name], CAST ([c].[owner].[name] AS VARCHAR(255)) AS [owner_name], CASE [a].[attr_type] WHEN 0 THEN 'INSTANCE' WHEN 1 THEN 'CLASS' ELSE 'SHARED' END AS [attr_type], [et].[type_name] AS [data_type], [e].[prec] AS [prec], [e].[scale] AS [scale], [e].[code_set] AS [code_set], [e].[class_of].[class_name] AS [domain_class_name], CAST ([e].[class_of].[owner].[name] AS VARCHAR(255)) AS [domain_owner_name] FROM [_db_class] AS [c], [_db_attribute] AS [a], [_db_domain] AS [d], TABLE ([d].[set_domains]) AS [t] ([e]), [_db_data_type] AS [et] WHERE [a].[class_of] = [c] AND [d].[object_of] = [a] AND [e].[data_type] = [et].[type_id] AND (CURRENT_USER = 'DBA' OR {[c].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[c]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT'))", - "GRANT SELECT ON [db_attr_setdomain_elm] TO PUBLIC", + "REVOKE SELECT ON [db_method] FROM PUBLIC", /* db_method */ "CREATE OR REPLACE VIEW [db_method] ( \ [meth_name] varchar(255), \ @@ -149,9 +173,9 @@ SELECT [a].[attr_name] AS [attr_name], [c].[class_name] AS [class_name], CAST ([ [func_name] varchar(255) \ ) AS \ SELECT [m].[meth_name] AS [meth_name], [m].[class_of].[class_name] AS [class_name], CAST ([m].[class_of].[owner].[name] AS VARCHAR(255)) AS [owner_name], CASE [m].[meth_type] WHEN 0 THEN 'INSTANCE' ELSE 'CLASS' END AS [meth_type], [m].[from_class_of].[class_name] AS [from_class_name], CAST ([m].[from_class_of].[owner].[name] AS VARCHAR(255)) AS [from_owner_name], [m].[from_meth_name] AS [from_meth_name], [s].[func_name] AS [func_name] FROM [_db_method] AS [m], [_db_meth_sig] AS [s] WHERE [s].[meth_of] = [m] AND (CURRENT_USER = 'DBA' OR {[m].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[m].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT'))", - "GRANT SELECT ON [db_method] TO PUBLIC", + "REVOKE SELECT ON [db_meth_arg] FROM PUBLIC", /* db_meth_arg */ "CREATE OR REPLACE VIEW [db_meth_arg] ( \ [meth_name] varchar(255), \ @@ -167,9 +191,9 @@ SELECT [m].[meth_name] AS [meth_name], [m].[class_of].[class_name] AS [class_nam [domain_owner_name] varchar(255) \ ) AS \ SELECT [s].[meth_of].[meth_name] AS [meth_name], [s].[meth_of].[class_of].[class_name] AS [class_name], CAST ([s].[meth_of].[class_of].[owner].[name] AS VARCHAR(255)) AS [owner_name], CASE [s].[meth_of].[meth_type] WHEN 0 THEN 'INSTANCE' ELSE 'CLASS' END AS [meth_type], [a].[index_of] AS [index_of], [t].[type_name] AS [data_type], [d].[prec] AS [prec], [d].[scale] AS [scale], [d].[code_set] AS [code_set], [d].[class_of].[class_name] AS [domain_class_name], CAST ([d].[class_of].[owner].[name] AS VARCHAR(255)) AS [domain_owner_name] FROM [_db_meth_sig] AS [s], [_db_meth_arg] AS [a], [_db_domain] AS [d], [_db_data_type] AS [t] WHERE [a].[meth_sig_of] = [s] AND [d].[object_of] = [a] AND [d].[data_type] = [t].[type_id] AND (CURRENT_USER = 'DBA' OR {[s].[meth_of].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[s].[meth_of].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT'))", - "GRANT SELECT ON [db_meth_arg] TO PUBLIC", + "REVOKE SELECT ON [db_meth_arg_setdomain_elm] FROM PUBLIC", /* db_meth_arg_setdomain_elm */ "CREATE OR REPLACE VIEW [db_meth_arg_setdomain_elm] ( \ [meth_name] varchar(255), \ @@ -185,9 +209,9 @@ SELECT [s].[meth_of].[meth_name] AS [meth_name], [s].[meth_of].[class_of].[class [domain_owner_name] varchar(255) \ ) AS \ SELECT [s].[meth_of].[meth_name] AS [meth_name], [s].[meth_of].[class_of].[class_name] AS [class_name], CAST ([s].[meth_of].[class_of].[owner].[name] AS VARCHAR(255)) AS [owner_name], CASE [s].[meth_of].[meth_type] WHEN 0 THEN 'INSTANCE' ELSE 'CLASS' END AS [meth_type], [a].[index_of] AS [index_of], [et].[type_name] AS [data_type], [e].[prec] AS [prec], [e].[scale] AS [scale], [e].[code_set] AS [code_set], [e].[class_of].[class_name] AS [domain_class_name], CAST ([e].[class_of].[owner].[name] AS VARCHAR(255)) AS [domain_owner_name] FROM [_db_meth_sig] AS [s], [_db_meth_arg] AS [a], [_db_domain] AS [d], TABLE ([d].[set_domains]) AS [t] ([e]), [_db_data_type] AS [et] WHERE [a].[meth_sig_of] = [s] AND [d].[object_of] = [a] AND [e].[data_type] = [et].[type_id] AND (CURRENT_USER = 'DBA' OR {[s].[meth_of].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[s].[meth_of].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT'))", - "GRANT SELECT ON [db_meth_arg_setdomain_elm] TO PUBLIC", + "REVOKE SELECT ON [db_meth_file] FROM PUBLIC", /* db_meth_file */ "CREATE OR REPLACE VIEW [db_meth_file] ( \ [class_name] varchar(255), \ @@ -197,9 +221,9 @@ SELECT [s].[meth_of].[meth_name] AS [meth_name], [s].[meth_of].[class_of].[class [from_owner_name] varchar(255) \ ) AS \ SELECT [f].[class_of].[class_name] AS [class_name], CAST ([f].[class_of].[owner].[name] AS VARCHAR(255)) AS [owner_name], [f].[path_name] AS [path_name], [f].[from_class_of].[class_name] AS [from_class_name], CAST ([f].[from_class_of].[owner].[name] AS VARCHAR(255)) AS [from_owner_name] FROM [_db_meth_file] AS [f] WHERE CURRENT_USER = 'DBA' OR {[f].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[f].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT')", - "GRANT SELECT ON [db_meth_file] TO PUBLIC", + "REVOKE SELECT ON [db_index] FROM PUBLIC", /* db_index */ "CREATE OR REPLACE VIEW [db_index] ( \ [index_name] varchar(255), \ @@ -216,9 +240,9 @@ SELECT [f].[class_of].[class_name] AS [class_name], CAST ([f].[class_of].[owner] [status] varchar(255) \ ) AS \ SELECT [i].[index_name] AS [index_name], CASE [i].[is_unique] WHEN 0 THEN 'NO' ELSE 'YES' END AS [is_unique], CASE [i].[is_reverse] WHEN 0 THEN 'NO' ELSE 'YES' END AS [is_reverse], [i].[class_of].[class_name] AS [class_name], CAST ([i].[class_of].[owner].[name] AS VARCHAR(255)) AS [owner_name], [i].[key_count] AS [key_count], CASE [i].[is_primary_key] WHEN 0 THEN 'NO' ELSE 'YES' END AS [is_primary_key], CASE [i].[is_foreign_key] WHEN 0 THEN 'NO' ELSE 'YES' END AS [is_foreign_key], [i].[filter_expression] AS [filter_expression], CASE [i].[have_function] WHEN 0 THEN 'NO' ELSE 'YES' END AS [have_function], [i].[comment] AS [comment], CASE [i].[status] WHEN 0 THEN 'NO_INDEX' WHEN 1 THEN 'NORMAL INDEX' WHEN 2 THEN 'INVISIBLE INDEX' WHEN 3 THEN 'INDEX IS IN ONLINE BUILDING' ELSE 'NULL' END AS [status] FROM [_db_index] AS [i] WHERE CURRENT_USER = 'DBA' OR {[i].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[i].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT')", - "GRANT SELECT ON [db_index] TO PUBLIC", + "REVOKE SELECT ON [db_index_key] FROM PUBLIC", /* db_index_key */ "CREATE OR REPLACE VIEW [db_index_key] ( \ [index_name] varchar(255), \ @@ -231,9 +255,9 @@ SELECT [i].[index_name] AS [index_name], CASE [i].[is_unique] WHEN 0 THEN 'NO' E [func] varchar(1023) \ ) as \ SELECT [k].[index_of].[index_name] AS [index_name], [k].[index_of].[class_of].[class_name] AS [class_name], CAST ([k].[index_of].[class_of].[owner].[name] AS VARCHAR(255)) AS [owner_name], [k].[key_attr_name] AS [key_attr_name], [k].[key_order] AS [key_order], CASE [k].[asc_desc] WHEN 0 THEN 'ASC' WHEN 1 THEN 'DESC' ELSE 'UNKN' END AS [asc_desc], [k].[key_prefix_length] AS [key_prefix_length], [k].[func] AS [func] FROM [_db_index_key] AS [k] WHERE CURRENT_USER = 'DBA' OR {[k].[index_of].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[k].[index_of].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT')", - "GRANT SELECT ON [db_index_key] TO PUBLIC", + "REVOKE SELECT ON [db_auth] FROM PUBLIC", /* db_auth */ "CREATE OR REPLACE VIEW [db_auth] ( \ [grantor_name] varchar(255), \ @@ -244,9 +268,9 @@ SELECT [k].[index_of].[index_name] AS [index_name], [k].[index_of].[class_of].[c [is_grantable] varchar(3) \ ) as \ SELECT CAST ([a].[grantor].[name] AS VARCHAR(255)) AS [grantor_name], CAST ([a].[grantee].[name] AS VARCHAR(255)) AS [grantee_name], [a].[class_of].[class_name] AS [class_name], CAST ([a].[class_of].[owner].[name] AS VARCHAR(255)) AS [owner_name], [a].[auth_type] AS [auth_type], CASE [a].[is_grantable] WHEN 0 THEN 'NO' ELSE 'YES' END AS [is_grantable] FROM [_db_auth] AS [a] WHERE CURRENT_USER = 'DBA' OR {[a].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[a].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT')", - "GRANT SELECT ON [db_auth] TO PUBLIC", + "REVOKE SELECT ON [db_trig] FROM PUBLIC", /* db_trig */ "CREATE OR REPLACE VIEW [db_trig] ( \ [trigger_name] varchar(255), \ @@ -260,9 +284,9 @@ SELECT CAST ([a].[grantor].[name] AS VARCHAR(255)) AS [grantor_name], CAST ([a]. [comment] varchar(1024) \ ) as \ SELECT CAST ([t].[name] AS VARCHAR (255)) AS [trigger_name], CAST ([t].[owner].[name] AS VARCHAR(255)) AS [owner_name], [c].[class_name] AS [target_class_name], CAST ([c].[owner].[name] AS VARCHAR(255)) AS [target_owner_name], CAST ([t].[target_attribute] AS VARCHAR (255)) AS [target_attr_name], CASE [t].[target_class_attribute] WHEN 0 THEN 'INSTANCE' ELSE 'CLASS' END AS [target_attr_type], [t].[action_type] AS [action_type], [t].[action_time] AS [action_time], [t].[comment] AS [comment] FROM [db_trigger] AS [t] LEFT OUTER JOIN [_db_class] AS [c] ON [t].[target_class] = [c].[class_of] WHERE CURRENT_USER = 'DBA' OR {[t].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[c]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT')", - "GRANT SELECT ON [db_trig] TO PUBLIC", + "REVOKE SELECT ON [db_partition] FROM PUBLIC", /* db_partition */ "CREATE OR REPLACE VIEW [db_partition] ( \ [class_name] varchar(255), \ @@ -275,9 +299,9 @@ SELECT CAST ([t].[name] AS VARCHAR (255)) AS [trigger_name], CAST ([t].[owner].[ [comment] varchar(1024) \ ) as \ SELECT [s].[class_name] AS [class_name], CAST ([s].[owner].[name] AS VARCHAR(255)) AS [owner_name], [p].[pname] AS [partition_name], CONCAT ([s].[class_name], '__p__', [p].[pname]) AS [partition_class_name], CASE [p].[ptype] WHEN 0 THEN 'HASH' WHEN 1 THEN 'RANGE' ELSE 'LIST' END AS [partition_type], TRIM (SUBSTRING ([pp].[pexpr] FROM 8 FOR (POSITION (' FROM ' IN [pp].[pexpr]) - 8))) AS [partition_expr], [p].[pvalues] AS [partition_values], [p].[comment] AS [comment] FROM [_db_partition] AS [p], [_db_class] AS [c], TABLE ([c].[super_classes]) AS [t] ([s]), [_db_class] AS [cc], TABLE ([cc].[partition]) AS [tt] ([pp]) WHERE [p].[class_of] = [c] AND [s] = [cc] AND (CURRENT_USER = 'DBA' OR {[p].[class_of].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[p].[class_of]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT'))", - "GRANT SELECT ON [db_partition] TO PUBLIC", + "REVOKE SELECT ON [db_stored_procedure] FROM PUBLIC", /* db_stored_procedure */ "CREATE OR REPLACE VIEW [db_stored_procedure] ( \ [sp_name] varchar(255), \ @@ -290,9 +314,9 @@ SELECT [s].[class_name] AS [class_name], CAST ([s].[owner].[name] AS VARCHAR(255 [comment] varchar(1024) \ ) as \ SELECT [sp].[sp_name] AS [sp_name], CASE [sp].[sp_type] WHEN 1 THEN 'PROCEDURE' ELSE 'FUNCTION' END AS [sp_type], CASE [sp].[return_type] WHEN 0 THEN 'void' WHEN 28 THEN 'CURSOR' ELSE (SELECT [t].[type_name] FROM [_db_data_type] AS [t] WHERE [sp].[return_type] = [t].[type_id]) END AS [return_type], [sp].[arg_count] AS [arg_count], CASE [sp].[lang] WHEN 1 THEN 'JAVA' ELSE '' END AS [lang], [sp].[target] AS [target], CAST ([sp].[owner].[name] AS VARCHAR(255)) AS [owner], [sp].[comment] AS [comment] FROM [_db_stored_procedure] AS [sp]", - "GRANT SELECT ON [db_stored_procedure] TO PUBLIC", + "REVOKE SELECT ON [db_stored_procedure_args] FROM PUBLIC", /* db_stored_procedure_args */ "create or replace view [db_stored_procedure_args] ( \ [sp_name] varchar(255), \ @@ -303,9 +327,9 @@ SELECT [sp].[sp_name] AS [sp_name], CASE [sp].[sp_type] WHEN 1 THEN 'PROCEDURE' [comment] varchar(1024) \ ) as \ SELECT [sp].[sp_name] AS [sp_name], [sp].[index_of] AS [index_of], [sp].[arg_name] AS [arg_name], CASE [sp].[data_type] WHEN 28 THEN 'CURSOR' ELSE (SELECT [t].[type_name] FROM [_db_data_type] AS [t] WHERE [sp].[data_type] = [t].[type_id]) END AS [data_type], CASE [sp].[mode] WHEN 1 THEN 'IN' WHEN 2 THEN 'OUT' ELSE 'INOUT' END AS [mode], [sp].[comment] AS [comment] FROM [_db_stored_procedure_args] AS [sp] ORDER BY [sp].[sp_name], [sp].[index_of]", - "GRANT SELECT ON [db_stored_procedure_args] TO PUBLIC", + "REVOKE SELECT ON [db_collation] FROM PUBLIC", /* db_collation */ "CREATE OR REPLACE VIEW [db_collation] ( \ [coll_id] integer, \ @@ -317,9 +341,9 @@ SELECT [sp].[sp_name] AS [sp_name], [sp].[index_of] AS [index_of], [sp].[arg_nam [uca_strength] varchar(255) \ ) as \ SELECT [coll].[coll_id] AS [coll_id], [coll].[coll_name] AS [coll_name], [ch].[charset_name] AS [charset_name], CASE [coll].[built_in] WHEN 0 THEN 'No' WHEN 1 THEN 'Yes' ELSE 'ERROR' END AS [is_builtin], CASE [coll].[expansions] WHEN 0 THEN 'No' WHEN 1 THEN 'Yes' ELSE 'ERROR' END AS [has_expansions], [coll].[contractions] AS [contractions], CASE [coll].[uca_strength] WHEN 0 THEN 'Not applicable' WHEN 1 THEN 'Primary' WHEN 2 THEN 'Secondary' WHEN 3 THEN 'Tertiary' WHEN 4 THEN 'Quaternary' WHEN 5 THEN 'Identity' ELSE 'Unknown' END AS [uca_strength] FROM [_db_collation] AS [coll] INNER JOIN [_db_charset] AS [ch] ON [coll].[charset_id] = [ch].[charset_id] ORDER BY [coll].[coll_id]", - "GRANT SELECT ON [db_collation] TO PUBLIC", + "REVOKE SELECT ON [db_charset] FROM PUBLIC", /* db_charset */ "CREATE OR REPLACE VIEW [db_charset] ( \ [charset_id] integer, \ @@ -328,7 +352,6 @@ SELECT [coll].[coll_id] AS [coll_id], [coll].[coll_name] AS [coll_name], [ch].[c [char_size] integer \ ) as \ SELECT [ch].[charset_id] AS [charset_id], [ch].[charset_name] AS [charset_name], [coll].[coll_name] AS [default_collation], [ch].[char_size] AS [char_size] FROM [_db_charset] AS [ch], [_db_collation] AS [coll] WHERE [ch].[default_collation] = [coll].[coll_id] ORDER BY [ch].[charset_id]", - "GRANT SELECT ON [db_charset] TO PUBLIC", /* db_server */ @@ -343,7 +366,6 @@ SELECT [ch].[charset_id] AS [charset_id], [ch].[charset_name] AS [charset_name], [comment] character varying(1024) \ ) as \ SELECT [ds].[link_name] AS [link_name], [ds].[host] AS [host], [ds].[port] AS [port], [ds].[db_name] AS [db_name], [ds].[user_name] AS [user_name], [ds].[properties] AS [properties], CAST ([ds].[owner].[name] AS VARCHAR(255)) AS [owner], [ds].[comment] AS [comment] FROM [_db_server] AS [ds] WHERE CURRENT_USER = 'DBA' OR {[ds].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) OR {[ds]} SUBSETEQ (SELECT SUM (SET {[au].[class_of]}) FROM [_db_auth] AS [au] WHERE {[au].[grantee].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER) AND [au].[auth_type] = 'SELECT')", - "GRANT SELECT ON [db_server] TO PUBLIC", /* db_synonym */ @@ -356,7 +378,6 @@ SELECT [ds].[link_name] AS [link_name], [ds].[host] AS [host], [ds].[port] AS [p [comment] character varying(2048) \ ) AS \ SELECT [s].[name] AS [synonym_name], CAST ([s].[owner].[name] AS VARCHAR(255)) AS [synonym_owner_name], CASE [s].[is_public] WHEN 1 THEN 'YES' ELSE 'NO' END AS [is_public_synonym], [s].[target_name] AS [target_name], CAST ([s].[target_owner].[name] AS VARCHAR(255)) AS [target_owner_name], [s].[comment] AS [comment] FROM [_db_synonym] AS [s] WHERE CURRENT_USER = 'DBA' OR [s].[is_public] = 1 OR ([s].[is_public] = 0 AND {[s].[owner].[name]} SUBSETEQ (SELECT SET {CURRENT_USER} + COALESCE (SUM (SET {[t].[g].[name]}), SET {}) FROM [db_user] AS [u], TABLE ([u].[groups]) AS [t] ([g]) WHERE [u].[name] = CURRENT_USER))", - "GRANT SELECT ON [db_synonym] TO PUBLIC", /* set system class for newly added tables and views */ @@ -387,8 +408,10 @@ SELECT [s].[name] AS [synonym_name], CAST ([s].[owner].[name] AS VARCHAR(255)) A 'db_server', \ 'db_synonym' \ ) \ - AND is_system_class = 0", + AND is_system_class = 0" +}; +static const char *catalog_query[] = { /* alter catalog to add column */ "alter table _db_class add column unique_name varchar (255) after [class_of]", "delete from _db_attribute where class_of.class_name = '_db_class' and rownum % 2 = 1", @@ -1114,6 +1137,24 @@ migrate_initialize (char *dbname) error = -1; } + cub_au_fetch_class_force = + (AU_FETCH_FORCE) dlsym (dl_handle, + "_Z20au_fetch_class_forceP9db_objectPP8sm_class12au_fetchmode"); + if (cub_au_fetch_class_force == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + + cub_locator_free_list_mops = + (LOCATOR_FREE_LIST) dlsym (dl_handle, + "_Z22locator_free_list_mopsP9list_mops"); + if (cub_locator_free_list_mops == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + cub_locator_find_class = (LOCATOR_FIND_CLASS) dlsym (dl_handle, "_Z18locator_find_classPKc"); if (cub_locator_find_class == NULL) { @@ -1137,6 +1178,14 @@ migrate_initialize (char *dbname) error = -1; } + cub_sm_mark_system_classes = + (SM_MARK_SYSTEM_CLASSES)dlsym (dl_handle, "_Z22sm_mark_system_classesv"); + if (cub_sm_mark_system_classes == NULL) + { + PRINT_LOG ("%s", dlerror ()); + error = -1; + } + return error; } @@ -1284,6 +1333,44 @@ migrate_generated (const char *generated, int col_num) return 0; } +int is_system_view(const char *name) +{ + int i; + + for (i = 0; i < sizeof(system_views) / sizeof(const char *); i++) + { + if (strstr((char *)name, system_views[i])) + { + return 1; + } + } + + return 0; +} + +void migrate_mark_system_classes_for_system_views(void) +{ + LIST_MOPS *lmops; + SM_CLASS *class_; + int i; + + lmops = cub_locator_get_all_mops (*cub_sm_Root_class_mop, DB_FETCH_QUERY_WRITE, NULL); + for (i = 0; i < lmops->num; i++) + { + if (lmops->mops[i] == *cub_sm_Root_class_mop) + { + continue; + } + if (cub_au_fetch_class_force (lmops->mops[i], &class_, AU_FETCH_UPDATE) == NO_ERROR + && is_system_view(class_->header.ch_name)) + { + class_->flags |= SM_CLASSFLAG_SYSTEM; + } + } + + cub_locator_free_list_mops (lmops); +} + static int migrate_queries () { @@ -1291,7 +1378,7 @@ migrate_queries () DB_VALUE value; int i, error; - /* generated query */ + /* generated query for rename */ error = migrate_generated (rename_query, 1); if (error < 0) { @@ -1299,6 +1386,20 @@ migrate_queries () return -1; } + /* system view query */ + for (i = 0; i < sizeof (system_view_query) / sizeof (const char *); i++) + { + error = migrate_execute_query (system_view_query[i]); + if (error < 0) + { + return -1; + } + } + + migrate_mark_system_classes_for_system_views(); + + error = cub_db_commit_transaction (); + /* catalog query */ for (i = 0; i < sizeof (catalog_query) / sizeof (const char *); i++) { diff --git a/migrate/migrate.h b/migrate/migrate.h index 5df6a65..2b58958 100644 --- a/migrate/migrate.h +++ b/migrate/migrate.h @@ -51,6 +51,129 @@ (ptr) = NULL; \ } while (0) +#define SM_CLASSFLAG_SYSTEM 1 + +typedef enum au_fetchmode +{ + AU_FETCH_READ, + AU_FETCH_SCAN, /* scan that does not allow write */ + AU_FETCH_EXCLUSIVE_SCAN, /* scan that does allow neither write nor other exclusive scan, i.e, scan for load + * index. */ + AU_FETCH_WRITE, + AU_FETCH_UPDATE +} AU_FETCHMODE; + +typedef enum +{ + SM_META_ROOT, /* the object is the root class */ + SM_META_CLASS /* the object is a normal class */ +} SM_METATYPE; + +typedef struct ws_object_header WS_OBJECT_HEADER; + +struct ws_object_header +{ + int chn; +}; + +typedef struct hfid HFID; /* FILE HEAP IDENTIFIER */ +struct hfid +{ + VFID vfid; /* Volume and file identifier */ + int hpgid; /* First page identifier (the header page) */ +}; + +typedef struct sm_class_header SM_CLASS_HEADER; +struct sm_class_header +{ + WS_OBJECT_HEADER ch_obj_header; /* always have the object header (chn) */ + + SM_METATYPE ch_type; /* doesn't need to be a full word */ + const char *ch_name; + + OID ch_rep_dir; /* representation directory record OID */ + HFID ch_heap; +}; + +typedef enum +{ + SM_CLASS_CT, /* default CSQL class */ + SM_VCLASS_CT, /* component db virtual class */ + SM_ADT_CT /* Abstract data type-pseudo class */ +} SM_CLASS_TYPE; + +typedef struct sm_class SM_CLASS; +struct sm_class +{ + SM_CLASS_HEADER header; + + void *users; /* immediate sub classes */ + SM_CLASS_TYPE class_type; /* what kind of class variant is this? */ + int repid; /* current representation id */ + + void *representations; /* list of old representations */ + + void *inheritance; /* immediate super classes */ + int object_size; /* memory size in bytes */ + int att_count; /* number of instance attributes */ + void *attributes; /* list of instance attribute definitions */ + void *shared; /* list of shared attribute definitions */ + int shared_count; /* number of shared attributes */ + int class_attribute_count; /* number of class attributes */ + void *class_attributes; /* list of class attribute definitions */ + + void *method_files; /* list of method files */ + const char *loader_commands; /* command string to the dynamic loader */ + + void *methods; /* list of method definitions */ + int method_count; /* number of instance methods */ + int class_method_count; /* number of class methods */ + void *class_methods; /* list of class method definitions */ + + void *resolutions; /* list of instance and class resolutions */ + + int fixed_count; /* number of fixed size attributes */ + int variable_count; /* number of variable size attributes */ + int fixed_size; /* byte size of fixed attributes */ + + int att_ids; /* attribute id counter */ + int method_ids; /* method id counter */ + int unused; /* formerly repid counter, delete */ + + void *query_spec; /* virtual class query_spec information */ + void *new_; /* temporary structure */ + void *stats; /* server statistics, loaded on demand */ + + MOP owner; /* authorization object */ + int collation_id; /* class collation */ + void *auth_cache; /* compiled cache */ + + void *ordered_attributes; /* see classobj_fixup_loaded_class () */ + void *properties; /* property list */ + struct parser_context *virtual_query_cache; + struct tr_schema_cache *triggers; /* Trigger cache */ + void *constraints; /* Constraint cache */ + const char *comment; /* table comment */ + void *fk_ref; /* fk ref cache */ + void *partition; /* partition information */ + + unsigned int flags; + unsigned int virtual_cache_local_schema_id; + unsigned int virtual_cache_global_schema_id; + unsigned int virtual_cache_snapshot_version; + + int tde_algorithm; + + unsigned methods_loaded:1; /* set when dynamic linking was performed */ + unsigned post_load_cleanup:1; /* set if post load cleanup has occurred */ + + unsigned triggers_validated:1; /* set when trigger cache is validated */ + unsigned has_active_triggers:1; /* set if trigger processing is required */ + unsigned dont_decache_constraints_or_flush:1; /* prevent decaching class constraint and flushing. */ + unsigned recache_constraints:1; /* class constraints need recache. */ + unsigned load_index_from_heap:1; /* load index from its heap if there are records. If false, create a new empty regardless of the heap when allocating an index. e.g. TRUNCATE */ +}; + typedef struct list_mops LIST_MOPS; struct list_mops { @@ -73,6 +196,8 @@ const char *CUBRID_ENV = NULL; void *dl_handle = NULL; /* CUBRID function pointer */ +typedef void (*LOCATOR_FREE_LIST) (LIST_MOPS * mops); +typedef void (*SM_MARK_SYSTEM_CLASSES) (void); typedef void (*AU_DISABLE_PASSWORDS) (void); typedef int (*DB_RESTART_EX) (const char *, const char *, const char *, const char *, const char *, int); typedef int (*ER_ERRID) (void); @@ -97,7 +222,11 @@ typedef int (*EXTRACT_CLASSES_TO_FILE) (extract_context & ctxt, const char *outp typedef LIST_MOPS *(*LOCATOR_GET_ALL_MOPS) (MOP class_mop, DB_FETCH_MODE class_purpose, LC_FETCH_VERSION_TYPE * force_fetch_version_type); typedef int (*AU_FETCH_CLASS) (MOP op, void **class_ptr, int fetchmode, int type); +typedef int (*AU_FETCH_FORCE) (MOP op, SM_CLASS ** class_, AU_FETCHMODE fetchmode); +SM_MARK_SYSTEM_CLASSES cub_sm_mark_system_classes; +AU_FETCH_FORCE cub_au_fetch_class_force; +LOCATOR_FREE_LIST cub_locator_free_list_mops; AU_DISABLE_PASSWORDS cub_au_disable_passwords; DB_RESTART_EX cub_db_restart_ex; ER_ERRID cub_er_errid; @@ -122,8 +251,7 @@ DB_ERROR_STRING cub_db_error_string; LOCATOR_FIND_CLASS cub_locator_find_class; EXTRACT_CLASSES_TO_FILE cub_extract_classes_to_file; LOCATOR_GET_ALL_MOPS cub_locator_get_all_mops; -AU_FETCH_CLASS cub_au_fetch_class; - +AU_FETCH_CLASS cub_au_fetch_class; /* CUBRID global variable */ int *cub_Au_disable; From 196e265af720499baaa52c624454d1a6060a5b85 Mon Sep 17 00:00:00 2001 From: cubridqa Date: Tue, 8 Nov 2022 08:41:10 +0900 Subject: [PATCH 10/15] slip --- migrate/migrate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrate/migrate.c b/migrate/migrate.c index 9889906..2589c74 100644 --- a/migrate/migrate.c +++ b/migrate/migrate.c @@ -1606,7 +1606,7 @@ main (int argc, char *argv[]) *cub_Au_disable = 1; printf ("\n"); - printf ("Phase 4: Extracting Viewws\n"); + printf ("Phase 4: Extracting Views\n"); /* get view list from database by query related to view */ view_cnt = migrate_get_view_list (&view_list); From c0beb8ca517af80e479de567d68b06a598c5982e Mon Sep 17 00:00:00 2001 From: beyondykk Date: Fri, 25 Nov 2022 16:13:51 +0900 Subject: [PATCH 11/15] fix: partition table --- migrate/migrate.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/migrate/migrate.c b/migrate/migrate.c index 2589c74..a7e48d0 100644 --- a/migrate/migrate.c +++ b/migrate/migrate.c @@ -435,9 +435,10 @@ static const char *rename_query = "select \ 'rename view [' || class_name || '] to [' || lower (owner.name) || '.' || class_name || '] ' \ end as q \ from \ - _db_class \ + _db_class c \ where \ - is_system_class % 8 = 0"; + c.is_system_class % 8 = 0 and [partition] is null \ + or exists (select pname from _db_partition p where p.class_of = c and p.pname is null)"; /* update class_name and unique_name except for system classes. */ static const char *update_db_class_not_for_system_classes = From 6d8b94645dde5f46c8687933a1706647308347f1 Mon Sep 17 00:00:00 2001 From: beyondykk Date: Thu, 8 Dec 2022 13:04:22 +0900 Subject: [PATCH 12/15] add synonym --- migrate/migrate.c | 88 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 2 deletions(-) diff --git a/migrate/migrate.c b/migrate/migrate.c index a7e48d0..484399f 100644 --- a/migrate/migrate.c +++ b/migrate/migrate.c @@ -470,6 +470,19 @@ static const char *index_query[] = { static const char *update_db_class_for_system_classes = "update _db_class set unique_name = class_name where is_system_class % 8 != 0"; +/* create synonym for granted table */ +static const char *synonym_query = "select 'create synonym ' || class_name || ' for [' || owner_name || '.' || class_name || '] \ + from db_class \ + where owner_name = 'PUBLIC' \ + union \ + select 'create synonym ' || class_name || ' for [' || grantor_name || '.' || class_name || ']' \ + from db_auth \ + where class_name in ( \ + select class_name \ + from db_class \ + where is_system_class = 'NO' \ + )"; + static char db_path[PATH_MAX]; FILE *out = NULL; @@ -1272,6 +1285,72 @@ migrate_get_view_list (char ***view_list) return cnt; } +static int +migrate_create_synonyms (char *dbname) +{ + DB_QUERY_RESULT *result; + const char *synonym; + int error; + FILE *f_synonym; + + char synonym_file[256]; + + /* make view list file as like unload schema */ + sprintf (synonym_file, "%s_synonym", dbname); + + error = cub_db_execute_query (synonym_query, &result); + if (error < 0) + { + fprintf (out, "synonym: execute query failed\n \"%s\"\n", synonym_query); + return -1; + } + + f_synonym = fopen (synonym_file, "w"); + if (f_synonym == NULL) + { + printf ("migrate: encountered error while opening synonym file\n"); + return -1; + } + + if ((error = cub_db_query_first_tuple (result)) == DB_CURSOR_SUCCESS) + { + do + { + DB_VALUE value; + + /* from query */ + error = cub_db_query_get_tuple_value (result, 0, &value); + if (error < 0) + { + fprintf (out, "synonym: can not get a tuple for \"%s\"\n", synonym_query); + return -1; + } + + synonym = value.data.ch.medium.buf; + if (synonym == NULL) + { + goto end; + } + + fprintf(f_synonym, "%s;\n", synonym); + + error = cub_db_query_next_tuple (result); + } + while (error != DB_CURSOR_END && error != DB_CURSOR_ERROR); + } + +end: + cub_db_query_end (result); + + if (error < 0) + { + fprintf (out, "synonym: can not get a next tuple for \"%s\"\n", synonym_query); + return -1; + } + + return 0; +} + static int migrate_generated (const char *generated, int col_num) { @@ -1670,7 +1749,12 @@ main (int argc, char *argv[]) } printf ("\n"); - printf ("Phase 5: Executing the mirgate queries\n"); + printf ("Phase 5: Creating synonyms\n"); + + error = migrate_create_synonyms (dbname); + + printf ("\n"); + printf ("Phase 6: Executing the mirgate queries\n"); error = migrate_queries (); if (error < 0) @@ -1701,7 +1785,7 @@ main (int argc, char *argv[]) } printf ("\n"); - printf ("Phase 6: Updating version info for log volume\n"); + printf ("Phase 7: Updating version info for log volume\n"); /* finalizing: update volume info. to 11.2 */ migrate_update_log_volume (dbname); From 2bbfea33955f9bf4be52df51b4656170e163121f Mon Sep 17 00:00:00 2001 From: beyondykk Date: Fri, 23 Dec 2022 14:37:16 +0900 Subject: [PATCH 13/15] fix: synonym --- migrate/migrate.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/migrate/migrate.c b/migrate/migrate.c index 484399f..8155846 100644 --- a/migrate/migrate.c +++ b/migrate/migrate.c @@ -471,17 +471,14 @@ static const char *update_db_class_for_system_classes = "update _db_class set unique_name = class_name where is_system_class % 8 != 0"; /* create synonym for granted table */ -static const char *synonym_query = "select 'create synonym ' || class_name || ' for [' || owner_name || '.' || class_name || '] \ - from db_class \ - where owner_name = 'PUBLIC' \ - union \ - select 'create synonym ' || class_name || ' for [' || grantor_name || '.' || class_name || ']' \ - from db_auth \ - where class_name in ( \ - select class_name \ - from db_class \ - where is_system_class = 'NO' \ - )"; +static const char *synonym_query = " \ + select 'create synonym [' \ + || grantee.name || '].[' \ + || c.class_name || '] for [' \ + || owner.name || '].[' || c.class_name || ']' \ + from _db_auth a, _db_class c \ + where a.class_of.class_name = c.class_name \ + and is_system_class = 0"; static char db_path[PATH_MAX]; @@ -1752,6 +1749,11 @@ main (int argc, char *argv[]) printf ("Phase 5: Creating synonyms\n"); error = migrate_create_synonyms (dbname); + if (error < 0) + { + printf ("migrate: error encountered while creating synonyms\n"); + return -1; + } printf ("\n"); printf ("Phase 6: Executing the mirgate queries\n"); From bb3547b448df03c9f53a1ff5c0ce656cb1290910 Mon Sep 17 00:00:00 2001 From: beyondykk Date: Mon, 26 Dec 2022 14:37:47 +0900 Subject: [PATCH 14/15] add README.md .gitignore and etc. --- migrate/.gitignore | 4 ++++ migrate/README.md | 55 ++++++++++++++++++++++++++++++++++++++++++++++ migrate/migrate.c | 2 +- 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 migrate/.gitignore create mode 100644 migrate/README.md diff --git a/migrate/.gitignore b/migrate/.gitignore new file mode 100644 index 0000000..2423b3f --- /dev/null +++ b/migrate/.gitignore @@ -0,0 +1,4 @@ +*.o +*.c~ +*.h~ +migrate diff --git a/migrate/README.md b/migrate/README.md new file mode 100644 index 0000000..3b9705d --- /dev/null +++ b/migrate/README.md @@ -0,0 +1,55 @@ +# migrate +The "migrate" is a utility tool for upgrading DB disk image from 11.0.x or 11.1.x to 11.2. + +# Supported version +- database disk image: 11.0.x +- engine version: 11.2.x + +# Prerequisites +You need to upgrade to 11.0.9 or later if you have a disk image of 11.0 version and you should upgrade your DBMS engine to 11.2.2 or later if you have CUBRID 11.2 engine. + +# Quick Start +You can get a upgrade tool by following the instructions. +```sh +$ git clone https://github.com/CUBRID/cubrid-contrib.git +$ cd cubrid-contrib/migrate +$ make migrate +$ ./migrate your-database-name +``` + +# Files +You can get a upgrade disk image which is 11.2 compatible. In addition, you can get the files as like view-file and synonym-file. A view-file is a kind of sql command script file to create view used at old version. A synonym-file is also a kind of sql command script to create synonym for convinience. The synonym only includes tables grated at old version. + +# Usage +```sh +usage: migrate [options] db-name + +valid options + -v: verbose detailed + -o FILE: redirect output to FILE +``` + +# Example +```sh +$ ./migrate mdb +Phase 1: Initializing +/home/cubrid/CUBRID/databases/mdb/mdb_lgat reading + +Phase 2: Checking log volume +11.0.10.0339 + +Phase 3: Backup the log volume + backup volume, /home/cubrid/CUBRID/databases/mdb/mdb_lgat.bak created + +Phase 4: Extracting Views + +Phase 5: Creating synonyms + +Phase 6: Executing the mirgate queries + +Phase 7: Updating version info for log volume +migration done + +$ ls mdb_* +mdb_schema mdb_synonym mdb_view +``` diff --git a/migrate/migrate.c b/migrate/migrate.c index 8155846..945063c 100644 --- a/migrate/migrate.c +++ b/migrate/migrate.c @@ -1710,7 +1710,7 @@ main (int argc, char *argv[]) } /* make view query file for drop view queries */ - sprintf (view_query_file, "%s.view", dbname); + sprintf (view_query_file, "%s_view", dbname); f_query = fopen (view_query_file, "w"); if (f_query == NULL) { From 9fb457e0172b5bc93dfc1b27a4dfdb85df10a222 Mon Sep 17 00:00:00 2001 From: beyondykk Date: Mon, 26 Dec 2022 14:53:34 +0900 Subject: [PATCH 15/15] slip --- migrate/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrate/README.md b/migrate/README.md index 3b9705d..d97d919 100644 --- a/migrate/README.md +++ b/migrate/README.md @@ -18,7 +18,7 @@ $ ./migrate your-database-name ``` # Files -You can get a upgrade disk image which is 11.2 compatible. In addition, you can get the files as like view-file and synonym-file. A view-file is a kind of sql command script file to create view used at old version. A synonym-file is also a kind of sql command script to create synonym for convinience. The synonym only includes tables grated at old version. +You can get a upgrade disk image which is 11.2 compatible. In addition, you can get the files as like view-file and synonym-file. A view-file is a kind of sql command script file to create view used at old version. A synonym-file is also a kind of sql command script to create synonym for convinience. The synonym only includes tables granted at old version. # Usage ```sh