/* * pt_check_show_heap () - check table exists or not * return: PT_NODE pointer * * parser(in): * node(in): */ static PT_NODE * pt_check_table_in_show_heap (PARSER_CONTEXT * parser, PT_NODE * node) { int error = NO_ERROR; PT_NODE *show_args_node = NULL, *spec, *derived_table; PT_NODE *partition_node = NULL; SHOWSTMT_TYPE show_type; int partition_type = DB_NOT_PARTITIONED_CLASS; const char *table_name = NULL; MOP cls; SM_CLASS *sm_class = NULL; int save; if (node->node_type != PT_SELECT) { return node; } spec = node->info.query.q.select.from; assert (spec != NULL); derived_table = spec->info.spec.derived_table; assert (derived_table != NULL); show_type = derived_table->info.showstmt.show_type; assert (show_type == SHOWSTMT_HEAP_HEADER || show_type == SHOWSTMT_ALL_HEAP_HEADER || show_type == SHOWSTMT_HEAP_CAPACITY || show_type == SHOWSTMT_ALL_HEAP_CAPACITY); show_args_node = derived_table->info.showstmt.show_args; assert (show_args_node != NULL); assert (show_args_node->node_type == PT_VALUE); assert (show_args_node->type_enum == PT_TYPE_CHAR); table_name = (const char *) show_args_node->info.value.data_value.str->bytes; cls = sm_find_class (table_name); if (cls == NULL) { PT_ERRORmf (parser, show_args_node, MSGCAT_SET_ERROR, -(ER_LC_UNKNOWN_CLASSNAME), table_name); return node; } AU_DISABLE (save); error = au_fetch_class_force (cls, &sm_class, AU_FETCH_READ); AU_ENABLE (save); if (error == NO_ERROR) { if (sm_get_class_type (sm_class) != SM_CLASS_CT) { PT_ERRORm (parser, show_args_node, MSGCAT_SET_ERROR, -(ER_OBJ_NOT_A_CLASS)); return node; } } error = sm_partitioned_class_type (cls, &partition_type, NULL, NULL); if (error != NO_ERROR) { PT_ERRORc (parser, show_args_node, er_msg ()); return node; } partition_node = pt_make_integer_value (parser, partition_type); if (partition_node == NULL) { PT_INTERNAL_ERROR (parser, "allocate new node"); return node; } parser_append_node (partition_node, show_args_node); return node; }
/* * loaddb_internal - internal main loaddb function * return: NO_ERROR if successful, error code otherwise * argc(in): argc of main * argv(in): argv of main * dba_mode(in): */ static int loaddb_internal (UTIL_FUNCTION_ARG * arg, int dba_mode) { UTIL_ARG_MAP *arg_map = arg->arg_map; int error = NO_ERROR; /* set to static to avoid copiler warning (clobbered by longjump) */ static FILE *schema_file = NULL; static FILE *index_file = NULL; static FILE *object_file = NULL; FILE *error_file = NULL; int status = 0; int errors, objects, defaults; #if !defined (LDR_OLD_LOADDB) int lastcommit = 0; #endif /* !LDR_OLD_LOADDB */ char *passwd; /* set to static to avoid copiler warning (clobbered by longjump) */ static int interrupted = false; int au_save = 0; extern bool obt_Enable_autoincrement; char log_file_name[PATH_MAX]; LOADDB_INIT_DEBUG (); obt_Enable_autoincrement = false; Volume = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0); Input_file = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 1); User_name = utility_get_option_string_value (arg_map, LOAD_USER_S, 0); Password = utility_get_option_string_value (arg_map, LOAD_PASSWORD_S, 0); Syntax_check = utility_get_option_bool_value (arg_map, LOAD_CHECK_ONLY_S); Load_only = utility_get_option_bool_value (arg_map, LOAD_LOAD_ONLY_S); Estimated_size = utility_get_option_int_value (arg_map, LOAD_ESTIMATED_SIZE_S); Verbose = utility_get_option_bool_value (arg_map, LOAD_VERBOSE_S); Disable_statistics = utility_get_option_bool_value (arg_map, LOAD_NO_STATISTICS_S); Periodic_commit = utility_get_option_int_value (arg_map, LOAD_PERIODIC_COMMIT_S); Verbose_commit = Periodic_commit > 0 ? true : false; No_oid_hint = utility_get_option_bool_value (arg_map, LOAD_NO_OID_S); Schema_file = utility_get_option_string_value (arg_map, LOAD_SCHEMA_FILE_S, 0); Index_file = utility_get_option_string_value (arg_map, LOAD_INDEX_FILE_S, 0); Object_file = utility_get_option_string_value (arg_map, LOAD_DATA_FILE_S, 0); Error_file = utility_get_option_string_value (arg_map, LOAD_ERROR_CONTROL_FILE_S, 0); Ignore_logging = utility_get_option_bool_value (arg_map, LOAD_IGNORE_LOGGING_S); #if !defined (LDR_OLD_LOADDB) Ignore_class_file = utility_get_option_string_value (arg_map, LOAD_IGNORE_CLASS_S, 0); #endif Input_file = Input_file ? Input_file : ""; Schema_file = Schema_file ? Schema_file : ""; Index_file = Index_file ? Index_file : ""; Object_file = Object_file ? Object_file : ""; Error_file = Error_file ? Error_file : ""; if (ldr_validate_object_file (stderr, arg->argv0)) { goto error_return; } /* error message log file */ sprintf (log_file_name, "%s_%s.err", Volume, arg->command_name); er_init (log_file_name, ER_NEVER_EXIT); if (Index_file[0] != '\0' && PRM_SR_NBUFFERS < LOAD_INDEX_MIN_SORT_BUFFER_PAGES) { sysprm_set_force (PRM_NAME_SR_NBUFFERS, LOAD_INDEX_MIN_SORT_BUFFER_PAGES_STRING); } sysprm_set_force (PRM_NAME_JAVA_STORED_PROCEDURE, "no"); /* login */ if (User_name != NULL || !dba_mode) { (void) db_login (User_name, Password); if ((error = db_restart (arg->command_name, true, Volume))) { if (error == ER_AU_INVALID_PASSWORD) { /* prompt for password and try again */ error = NO_ERROR; passwd = getpass (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_PASSWORD_PROMPT)); if (!strlen (passwd)) passwd = NULL; (void) db_login (User_name, passwd); error = db_restart (arg->command_name, true, Volume); } } } else { /* if we're in the protected dba mode, just login without authorization */ AU_DISABLE_PASSWORDS (); db_set_client_type (DB_CLIENT_TYPE_ADMIN_UTILITY); (void) db_login ("dba", NULL); error = db_restart (arg->command_name, true, Volume); } /* open loaddb log file */ sprintf (log_file_name, "%s_loaddb.log", Volume); loaddb_log_file = fopen (log_file_name, "w+"); if (loaddb_log_file == NULL) { printf ("Cannot open log file %s\n", log_file_name); status = 2; goto error_return; } #if 0 #if !defined (LDR_OLD_LOADDB) /* Execute old loaddb if no optimization flag is set true * or LOADDB_NOPT is set, we must pass the argv except * -no option and invoke execvp() for no optimized loaddb */ if (No_optimization || envvar_get ("LOADDB_NOPT")) { char **tmp; char *lastslash, path[PATH_MAX]; int i = 1, j = 1; tmp = (char **) malloc (sizeof (char *) * (argc + 1)); tmp[0] = (char *) "loaddb"; while (j < argc) { if (!strcmp (argv[j], "-no")) j++; else tmp[i++] = argv[j++]; }; tmp[i] = 0; strcpy (path, argv[0]); lastslash = strrchr (path, (int) '/'); #if defined(WINDOWS) { char *p, exec_path[1024], cmd_line[1024 * 8]; int cp_len = 0; db_shutdown (); p = envvar_root (); if (p == NULL) { printf ("The `CUBRID' environment variable is not set.\n"); } else { sprintf (exec_path, "%s/migdb_o.exe", p); for (i = 0; tmp[i]; i++) { cp_len += sprintf (cmd_line + cp_len, "\"%s\" ", tmp[i]); } if (envvar_get ("FRONT_DEBUG") != NULL) { printf ("Executing:%s %s\n", exec_path, cmd_line); } run_proc (exec_path, cmd_line); } exit (0); } #else /* !WINDOWS */ if (lastslash != NULL) strcpy (lastslash + 1, "migdb_o"); else strcpy (path, "migdb_o"); if (execvp (path, tmp) == -1) { print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_NOPT_ERR)); exit (0); }; #endif /* WINDOWS */ } #endif /* !LDR_OLD_LOADDB */ #endif /* check if schema/index/object files exist */ ldr_check_file_name_and_line_no (); if (Schema_file[0] != 0) { schema_file = fopen (Schema_file, "r"); if (schema_file == NULL) { print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_BAD_INFILE), Schema_file); status = 2; goto error_return; } } if (Index_file[0] != 0) { index_file = fopen (Index_file, "r"); if (index_file == NULL) { print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_BAD_INFILE), Index_file); status = 2; goto error_return; } } if (Object_file[0] != 0) { object_file = fopen_ex (Object_file, "rb"); /* keep out ^Z */ if (object_file == NULL) { print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_BAD_INFILE), Object_file); status = 2; goto error_return; } } #if !defined (LDR_OLD_LOADDB) if (Ignore_class_file) { int retval; retval = get_ignore_class_list (Ignore_class_file); if (retval < 0) { status = 2; goto error_return; } } #endif /* Disallow syntax only and load only options together */ if (Load_only && Syntax_check) { print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_INCOMPATIBLE_ARGS), "--" LOAD_LOAD_ONLY_L, "--" LOAD_CHECK_ONLY_L); status = 1; /* parsing error */ goto error_return; } if (Error_file[0] != 0) { if (Syntax_check) { print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_INCOMPATIBLE_ARGS), "--" LOAD_ERROR_CONTROL_FILE_L, "--" LOAD_CHECK_ONLY_L); status = 1; /* parsing error */ goto error_return; } error_file = fopen_ex (Error_file, "rt"); if (error_file == NULL) { print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_BAD_INFILE), Error_file); status = 2; goto error_return; } er_filter_fileset (error_file); fclose (error_file); } /* check if no log option can be applied */ if (error || (Ignore_logging != 0 && locator_log_force_nologging () != NO_ERROR)) { /* couldn't log in */ print_log_msg (1, "%s\n", db_error_string (3)); status = 3; db_shutdown (); goto error_return; } /* change "print_key_value_on_unique_error" parameter */ sysprm_change_server_parameters ("print_key_value_on_unique_error=1"); /* if schema file is specified, do schema loading */ if (schema_file != NULL) { print_log_msg (1, "\nStart schema loading.\n"); /* * CUBRID 8.2 should be compatible with earlier versions of CUBRID. * Therefore, we do not perform user authentication when the loader * is executing by DBA group user. */ if (au_is_dba_group_member (Au_user)) { AU_DISABLE (au_save); } if (ldr_exec_query_from_file (Schema_file, schema_file, &schema_file_start_line, Periodic_commit) != 0) { print_log_msg (1, "\nError occurred during schema loading." "\nAborting current transaction..."); status = 3; db_shutdown (); print_log_msg (1, " done.\n\nRestart loaddb with '-%c %s:%d' option\n", LOAD_SCHEMA_FILE_S, Schema_file, schema_file_start_line); goto error_return; } if (au_is_dba_group_member (Au_user)) { AU_ENABLE (au_save); } print_log_msg (1, "Schema loading from %s finished.\n", Schema_file); /* update catalog statistics */ AU_DISABLE (au_save); sm_update_all_catalog_statistics (); AU_ENABLE (au_save); print_log_msg (1, "Statistics for Catalog classes have been updated.\n\n"); db_commit_transaction (); fclose (schema_file); schema_file = NULL; } /* if index file is specified, do index creation */ if (object_file != NULL) { #if defined (SA_MODE) locator_Dont_check_foreign_key = true; #endif print_log_msg (1, "\nStart object loading.\n"); ldr_init (Verbose); /* set the flag to indicate what type of interrupts to raise * If logging has been disabled set commit flag. * If logging is enabled set abort flag. */ if (Ignore_logging) Interrupt_type = LDR_STOP_AND_COMMIT_INTERRUPT; else Interrupt_type = LDR_STOP_AND_ABORT_INTERRUPT; if (Periodic_commit) { /* register the post commit function */ #if defined(LDR_OLD_LOADDB) ldr_register_post_commit_handler (&loaddb_report_num_of_commits); #else /* !LDR_OLD_LOADDB */ ldr_register_post_commit_handler (&loaddb_report_num_of_commits, NULL); #endif /* LDR_OLD_LOADDB */ } /* Check if we need to perform syntax checking. */ if (!Load_only) { print_log_msg ((int) Verbose, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_CHECKING)); do_loader_parse (object_file); #if defined(LDR_OLD_LOADDB) ldr_stats (&errors, &objects, &defaults); #else /* !LDR_OLD_LOADDB */ ldr_stats (&errors, &objects, &defaults, &lastcommit); #endif /* LDR_OLD_LOADDB */ } else errors = 0; if (errors) print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_ERROR_COUNT), errors); else if (!Syntax_check) { /* now do it for real if there were no errors and we aren't doing a simple syntax check */ ldr_start (Periodic_commit); fclose (object_file); object_file = fopen_ex (Object_file, "rb"); /* keep out ^Z */ if (object_file != NULL) { print_log_msg ((int) Verbose, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_INSERTING)); /* make sure signals are caught */ util_arm_signal_handlers (signal_handler, signal_handler); /* register function to call and jmp environment to longjmp to * after aborting or committing. */ ldr_register_post_interrupt_handler (&loaddb_get_num_of_inserted_objects, &loaddb_jmp_buf); if (setjmp (loaddb_jmp_buf) != 0) { /* We have had an interrupt, the transaction should have * been already been aborted or committed by the loader. * If Total_objects_loaded is -1 an error occurred during * rollback or commit. */ if (Total_objects_loaded != -1) print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_OBJECT_COUNT), Total_objects_loaded); #if !defined(LDR_OLD_LOADDB) ldr_stats (&errors, &objects, &defaults, &lastcommit); if (lastcommit > 0) print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_LAST_COMMITTED_LINE), lastcommit); #endif /* !LDR_OLD_LOADDB */ interrupted = true; } else { do_loader_parse (object_file); #if defined(LDR_OLD_LOADDB) ldr_stats (&errors, &objects, &defaults); #else /* !LDR_OLD_LOADDB */ ldr_stats (&errors, &objects, &defaults, &lastcommit); #endif /* LDR_OLD_LOADDB */ if (errors) { #if defined(LDR_OLD_LOADDB) print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_ERROR_COUNT), errors); #else /* !LDR_OLD_LOADDB */ if (lastcommit > 0) print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_LAST_COMMITTED_LINE), lastcommit); #endif /* LDR_OLD_LOADDB */ /* * don't allow the transaction to be committed at * this point, note that if we ever move to a scheme * where we write directly to the heap without the * transaction context, we will have to unwind the * changes made if errors are detected ! */ db_abort_transaction (); } else { if (objects) print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_OBJECT_COUNT), objects); if (defaults) print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_DEFAULT_COUNT), defaults); print_log_msg ((int) Verbose, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_COMMITTING)); /* commit the transaction and then update statistics */ if (!db_commit_transaction ()) { if (!Disable_statistics) { if (Verbose) print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_UPDATING_STATISTICS)); if (!ldr_update_statistics ()) { /* * would it be faster to update statistics * before the first commit and just have a * single commit ? */ print_log_msg ((int) Verbose, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_COMMITTING)); (void) db_commit_transaction (); } } } } } } } ldr_final (); if (object_file != NULL) { fclose (object_file); object_file = NULL; } } /* create index */ if (!interrupted && index_file != NULL) { print_log_msg (1, "\nStart index loading.\n"); if (ldr_exec_query_from_file (Index_file, index_file, &index_file_start_line, Periodic_commit) != 0) { print_log_msg (1, "\nError occurred during index loading." "\nAborting current transaction..."); status = 3; db_shutdown (); print_log_msg (1, " done.\n\nRestart loaddb with '-%c %s:%d' option\n", LOAD_INDEX_FILE_S, Index_file, index_file_start_line); goto error_return; } /* update catalog statistics */ AU_DISABLE (au_save); sm_update_catalog_statistics (CT_INDEX_NAME); sm_update_catalog_statistics (CT_INDEXKEY_NAME); AU_ENABLE (au_save); print_log_msg (1, "Index loading from %s finished.\n", Index_file); db_commit_transaction (); } print_log_msg ((int) Verbose, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_CLOSING)); (void) db_shutdown (); #if !defined (LDR_OLD_LOADDB) free_ignoreclasslist (); #endif return (status); error_return: if (schema_file != NULL) fclose (schema_file); if (object_file != NULL) fclose (object_file); if (index_file != NULL) fclose (index_file); #if !defined (LDR_OLD_LOADDB) free_ignoreclasslist (); #endif return status; }
/* * pt_check_show_index () - semantic check for show index. * return: * parser(in): * node(in): */ static PT_NODE * pt_check_show_index (PARSER_CONTEXT * parser, PT_NODE * node) { PT_NODE *show_args_node = NULL; MOP cls; const char *table_name = NULL; const char *index_name = NULL; SM_CLASS *sm_class = NULL; SM_CLASS_CONSTRAINT *sm_all_constraints = NULL; SM_CLASS_CONSTRAINT *sm_constraint = NULL; PT_NODE *entity = NULL; PT_NODE *derived_table = NULL; SHOWSTMT_TYPE show_type; int error = NO_ERROR; int save; int partition_type = DB_NOT_PARTITIONED_CLASS; PT_NODE *partition_node = NULL; if (node->node_type != PT_SELECT) { return node; } entity = node->info.query.q.select.from; assert (entity != NULL); derived_table = entity->info.spec.derived_table; assert (derived_table != NULL); show_type = derived_table->info.showstmt.show_type; assert (show_type == SHOWSTMT_INDEX_HEADER || show_type == SHOWSTMT_INDEX_CAPACITY || show_type == SHOWSTMT_ALL_INDEXES_HEADER || show_type == SHOWSTMT_ALL_INDEXES_CAPACITY); show_args_node = derived_table->info.showstmt.show_args; assert (show_args_node != NULL); assert (show_args_node->node_type == PT_VALUE); assert (show_args_node->type_enum == PT_TYPE_CHAR); assert (show_args_node->info.value.data_value.str->length < DB_MAX_IDENTIFIER_LENGTH); /* check table name */ table_name = (const char *) show_args_node->info.value.data_value.str->bytes; cls = sm_find_class (table_name); if (cls == NULL) { PT_ERRORmf (parser, show_args_node, MSGCAT_SET_ERROR, -(ER_LC_UNKNOWN_CLASSNAME), table_name); return node; } AU_DISABLE (save); error = au_fetch_class_force (cls, &sm_class, AU_FETCH_READ); AU_ENABLE (save); if (error == NO_ERROR) { if (sm_get_class_type (sm_class) != SM_CLASS_CT) { PT_ERRORm (parser, show_args_node, MSGCAT_SET_ERROR, -(ER_OBJ_NOT_A_CLASS)); return node; } } /* check index name */ if (show_type == SHOWSTMT_INDEX_HEADER || show_type == SHOWSTMT_INDEX_CAPACITY) { show_args_node = show_args_node->next; assert (show_args_node != NULL); assert (show_args_node->node_type == PT_VALUE); assert (show_args_node->type_enum == PT_TYPE_CHAR); assert (show_args_node->info.value.data_value.str->length < DB_MAX_IDENTIFIER_LENGTH); index_name = (const char *) show_args_node->info.value.data_value.str->bytes; sm_all_constraints = sm_class_constraints (cls); sm_constraint = classobj_find_constraint_by_name (sm_all_constraints, index_name); if (sm_all_constraints == NULL || sm_constraint == NULL) { PT_ERRORmf (parser, show_args_node, MSGCAT_SET_ERROR, -(ER_SM_NO_INDEX), index_name); return node; } } /* get partition type and pass it by args */ error = sm_partitioned_class_type (cls, &partition_type, NULL, NULL); if (error != NO_ERROR) { PT_ERRORc (parser, show_args_node, er_msg ()); return node; } partition_node = pt_make_integer_value (parser, partition_type); if (partition_node == NULL) { PT_INTERNAL_ERROR (parser, "allocate new node"); return node; } parser_append_node (partition_node, show_args_node); return node; }