/* * 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; }
/* * compactdb - compactdb main routine * return: 0 if successful, error code otherwise * arg(in): a map of command line arguments */ int compactdb (UTIL_FUNCTION_ARG * arg) { UTIL_ARG_MAP *arg_map = arg->arg_map; const char *exec_name = arg->command_name; int error; int i, status = 0; const char *database_name; bool verbose_flag = 0, delete_old_repr_flag = 0; char *input_filename = NULL; DB_OBJECT **req_class_table = NULL; LIST_MOPS *all_class_table = NULL; int maximum_processed_space = 10 * DB_PAGESIZE, pages; int instance_lock_timeout, class_lock_timeout; char **tables = NULL; int table_size = 0; database_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0); verbose_flag = utility_get_option_bool_value (arg_map, COMPACT_VERBOSE_S); input_filename = utility_get_option_string_value (arg_map, COMPACT_INPUT_CLASS_FILE_S, 0); pages = utility_get_option_int_value (arg_map, COMPACT_PAGES_COMMITED_ONCE_S); if (pages < COMPACT_MIN_PAGES || pages > COMPACT_MAX_PAGES) { fprintf (stderr, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_FAILURE)); fprintf (stderr, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_OUT_OF_RANGE_PAGES), COMPACT_MIN_PAGES, COMPACT_MAX_PAGES); return ER_GENERIC_ERROR; } if (database_name == NULL || database_name[0] == '\0' || utility_get_option_string_table_size (arg_map) < 1) { compactdb_usage (arg->argv0); return ER_GENERIC_ERROR; } table_size = utility_get_option_string_table_size (arg_map); if (table_size > 1 && input_filename != NULL) { compactdb_usage (arg->argv0); return ER_GENERIC_ERROR; } instance_lock_timeout = utility_get_option_int_value (arg_map, COMPACT_INSTANCE_LOCK_TIMEOUT_S); if (instance_lock_timeout < COMPACT_INSTANCE_MIN_LOCK_TIMEOUT || instance_lock_timeout > COMPACT_INSTANCE_MAX_LOCK_TIMEOUT) { fprintf (stderr, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_FAILURE)); fprintf (stderr, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_OUT_OF_RANGE_INSTANCE_LOCK_TIMEOUT), COMPACT_INSTANCE_MIN_LOCK_TIMEOUT, COMPACT_INSTANCE_MAX_LOCK_TIMEOUT); return ER_GENERIC_ERROR; } class_lock_timeout = utility_get_option_int_value (arg_map, COMPACT_CLASS_LOCK_TIMEOUT_S); if (class_lock_timeout < COMPACT_CLASS_MIN_LOCK_TIMEOUT || class_lock_timeout > COMPACT_CLASS_MAX_LOCK_TIMEOUT) { fprintf (stderr, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_FAILURE)); fprintf (stderr, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_OUT_OF_RANGE_CLASS_LOCK_TIMEOUT), COMPACT_CLASS_MIN_LOCK_TIMEOUT, COMPACT_CLASS_MAX_LOCK_TIMEOUT); return ER_GENERIC_ERROR; } delete_old_repr_flag = utility_get_option_bool_value (arg_map, COMPACT_DELETE_OLD_REPR_S); maximum_processed_space = pages * DB_PAGESIZE; if (table_size > 1) { tables = (char **) malloc (sizeof (char *) * table_size - 1); for (i = 1; i < table_size; i++) { tables[i - 1] = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, i); } } sysprm_set_force (PRM_NAME_JAVA_STORED_PROCEDURE, "no"); AU_DISABLE_PASSWORDS (); db_set_client_type (DB_CLIENT_TYPE_ADMIN_UTILITY); if ((error = db_login ("dba", NULL)) || (error = db_restart (arg->argv0, TRUE, database_name))) { fprintf (stderr, "%s: %s.\n\n", exec_name, db_error_string (3)); status = error; } else { status = db_set_isolation (TRAN_REP_CLASS_UNCOMMIT_INSTANCE); if (status == NO_ERROR) { status = compactdb_start (verbose_flag, delete_old_repr_flag, input_filename, tables, table_size - 1, maximum_processed_space, instance_lock_timeout, class_lock_timeout, TRAN_REP_CLASS_UNCOMMIT_INSTANCE); if (status == ER_FAILED) { fprintf (stderr, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_FAILURE)); } } db_shutdown (); } if (tables) { free (tables); tables = NULL; } return status; }
/* * ldr_exec_query_from_file - execute queries from file * return: 0 if successful, non-zero otherwise * file_name(in): file path * file(in): FILE * * start_line(in): start line * commit_period(in): commit period */ static int ldr_exec_query_from_file (const char *file_name, FILE * input_stream, int *start_line, int commit_period) { DB_SESSION *session = NULL; DB_QUERY_RESULT *res = NULL; int error = 0; int stmt_cnt, stmt_id = 0, stmt_type; int executed_cnt = 0; int parser_start_line_no; int parser_end_line_no = 1; int check_line_no = true; if ((*start_line) > 1) { int line_count = *start_line - 1; do { int c = fgetc (input_stream); if (c == EOF) { print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_UNREACHABLE_LINE), file_name, *start_line); error = ER_GENERIC_ERROR; goto end; } else if (c == '\n') { line_count--; } } while (line_count > 0); } check_line_no = false; session = db_make_session_for_one_statement_execution (input_stream); if (session == NULL) { print_log_msg (1, "ERROR: %s\n", db_error_string (3)); error = er_errid (); goto end; } util_arm_signal_handlers (&ldr_exec_query_interrupt_handler, &ldr_exec_query_interrupt_handler); while (1) { if (interrupt_query) { if (er_errid () != ER_INTERRUPTED) { er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_INTERRUPTED, 0); } error = er_errid (); db_close_session (session); goto end; } parser_start_line_no = parser_end_line_no; stmt_cnt = db_parse_one_statement (session); if (stmt_cnt > 0) { db_get_parser_line_col (session, &parser_end_line_no, NULL); stmt_id = db_compile_statement (session); } if (stmt_cnt <= 0 || stmt_id <= 0) { DB_SESSION_ERROR *session_error; int line, col; if ((session_error = db_get_errors (session)) != NULL) { do { session_error = db_get_next_error (session_error, &line, &col); if (line >= 0) { print_log_msg (1, "In %s line %d,\n", file_name, line + (*start_line)); print_log_msg (1, "ERROR: %s \n", db_error_string (3)); error = er_errid (); } } while (session_error); } db_close_session (session); break; } stmt_type = db_get_statement_type (session, stmt_id); res = (DB_QUERY_RESULT *) NULL; error = db_execute_statement (session, stmt_id, &res); if (error < 0) { print_log_msg (1, "ERROR: %s\n", db_error_string (3)); db_close_session (session); break; } executed_cnt++; error = db_query_end (res); if (error < 0) { print_log_msg (1, "ERROR: %s\n", db_error_string (3)); db_close_session (session); break; } if (stmt_type == CUBRID_STMT_COMMIT_WORK || (commit_period && (executed_cnt % commit_period == 0))) { db_commit_transaction (); print_log_msg (Verbose_commit, "%8d statements executed. Commit transaction at line %d\n", executed_cnt, parser_end_line_no); *start_line = parser_end_line_no + 1; } print_log_msg ((int) Verbose, "Total %8d statements executed.\r", executed_cnt); fflush (stdout); } end: if (error < 0) { db_abort_transaction (); } else { *start_line = parser_end_line_no + 1; print_log_msg (1, "Total %8d statements executed.\n", executed_cnt); fflush (stdout); db_commit_transaction (); } return error; }
int main (int argc, char *argv[]) { char *dbname, *uid, *passwd, *outfile, *errfile; FILE *fp; DB_OBJLIST *trigger_list, *temp; DB_OBJECT *trigger_obj; int errcode; if (argc < 6) { return 1; } putenv ((char *) "CUBRID_ERROR_LOG=NULL"); close (2); dbname = argv[1]; uid = argv[2]; passwd = argv[3]; outfile = argv[4]; errfile = argv[5]; db_login (uid, passwd); if (db_restart (argv[0], 0, dbname) < 0) { write_err_msg (errfile, (char *) db_error_string (1)); return 0; } fp = fopen (outfile, "w+"); if (fp == NULL) { db_shutdown (); return 0; } errcode = db_find_all_triggers (&trigger_list); if (errcode) { write_err_msg (errfile, (char *) db_error_string (1)); db_shutdown (); return 0; } fprintf (fp, MSGFMT, "open", "triggerlist"); temp = trigger_list; while (temp) { trigger_obj = temp->op; fprintf (fp, MSGFMT, "open", "triggerinfo"); get_trigger_information (fp, trigger_obj); fprintf (fp, MSGFMT, "close", "triggerinfo"); temp = temp->next; } fprintf (fp, MSGFMT, "close", "triggerlist"); fclose (fp); db_objlist_free (trigger_list); db_shutdown (); return 0; }
/* * error_message * * arguments: * * returns/side-effects: const char * * * description: */ const char * error_message () { return db_error_string (3); }
static int class_info (int argc, char *argv[], int opt_begin) { const char *dbname, *uid, *passwd, *outfile, *errfile; FILE *fp; DB_OBJLIST *objlist, *temp; DB_OBJECT *classobj; const char *ver_str; if (argc < 8) { return 1; } putenv ((char *) "CUBRID_ERROR_LOG=NULL"); close (2); dbname = argv[opt_begin++]; dbname = (dbname) ? dbname : ""; uid = argv[opt_begin++]; uid = (uid) ? uid : ""; passwd = argv[opt_begin++]; passwd = (passwd) ? passwd : ""; outfile = argv[opt_begin++]; outfile = (outfile) ? outfile : ""; errfile = argv[opt_begin++]; errfile = (errfile) ? errfile : ""; ver_str = argv[opt_begin++]; ver_str = (ver_str) ? ver_str : ""; db_login (uid, passwd); if (db_restart (argv[0], 0, dbname) < 0) { write_err_msg (errfile, (char *) db_error_string (1)); return 0; } fp = fopen (outfile, "w"); if (fp == NULL) { db_shutdown (); return 0; } fprintf (fp, MSGFMT, "open", "systemclass"); objlist = db_get_all_classes (); for (temp = objlist; temp != NULL; temp = temp->next) { classobj = temp->op; if (db_is_system_class (classobj)) write_class_info (fp, classobj); } db_objlist_free (objlist); fprintf (fp, MSGFMT, "close", "systemclass"); fprintf (fp, MSGFMT, "open", "userclass"); objlist = db_get_all_classes (); for (temp = objlist; temp != NULL; temp = temp->next) { classobj = temp->op; if (!db_is_system_class (classobj)) write_class_info (fp, classobj); } db_objlist_free (objlist); fprintf (fp, MSGFMT, "close", "userclass"); fclose (fp); db_shutdown (); return 0; }
static int dbmt_user_login (int argc, char *argv[], int opt_begin) { const char *outfile, *errfile, *dbname, *dbuser, *dbpasswd; FILE *outfp = NULL, *errfp = NULL; bool isdba = false; if (argc - opt_begin < 5) return -1; outfile = argv[opt_begin++]; outfile = (outfile) ? outfile : ""; errfile = argv[opt_begin++]; errfile = (errfile) ? errfile : ""; dbname = argv[opt_begin++]; dbname = (dbname) ? dbname : ""; dbuser = argv[opt_begin++]; dbuser = (dbuser) ? dbuser : ""; dbpasswd = argv[opt_begin++]; dbpasswd = (dbpasswd) ? dbpasswd : ""; outfp = fopen (outfile, "w"); errfp = fopen (errfile, "w"); if (outfp == NULL || errfp == NULL) { goto login_err; } db_login (dbuser, dbpasswd); if (db_restart (argv[0], 0, dbname) < 0) { fprintf (errfp, "%s", db_error_string (1)); goto login_err; } if (strcasecmp (dbuser, "DBA") == 0) { isdba = true; } else { DB_OBJECT *user, *obj; DB_VALUE v; DB_COLLECTION *col; int i; char *username; user = db_find_user (dbuser); if (user == NULL) { fprintf (errfp, "%s", db_error_string (1)); goto login_err; } db_get (user, "groups", &v); col = db_get_set (&v); for (i = 0; i < db_set_size (col); i++) { db_set_get (col, i, &v); obj = db_get_object (&v); db_get (obj, "name", &v); username = db_get_string (&v); if (username != NULL && strcasecmp (username, "DBA") == 0) { isdba = true; break; } } } if (isdba == true) fprintf (outfp, "isdba\n"); else fprintf (outfp, "isnotdba\n"); db_shutdown (); fclose (outfp); fclose (errfp); return 0; login_err: db_shutdown (); if (outfp != NULL) fclose (outfp); if (errfp != NULL) fclose (errfp); return -1; }
int main (int argc, char *argv[]) { float disk_compat_level = 0.0f; char *prog_name; const char *qp1 = "select db_user, password.password from db_user"; DB_VALUE user_val, password_val; MOP user_class; MOP user; char *db_name; char *password; char *decoded_str; char *encoded_str; int retval, error; DB_QUERY_RESULT *query_result; DB_QUERY_ERROR query_error; char out_buf[128]; if (argc < 2) { printf ("usage : %s databasename\n", argv[0]); return 1; } prog_name = argv[0]; db_name = argv[1]; AU_DISABLE_PASSWORDS (); db_set_client_type (DB_CLIENT_TYPE_ADMIN_UTILITY); db_login ("dba", NULL); db_restart (prog_name, 0, db_name); error = db_execute (qp1, &query_result, &query_error); if (error > 0) { error = db_query_first_tuple (query_result); while (error == NO_ERROR) { retval = db_query_get_tuple_value (query_result, 0, &user_val); if (retval != NO_ERROR) { printf ("%s\n", db_error_string (1)); return 1; } retval = db_query_get_tuple_value (query_result, 1, &password_val); if (retval != NO_ERROR) { printf ("%s\n", db_error_string (1)); return 1; } if (DB_IS_NULL (&user_val) || DB_IS_NULL (&password_val)) { error = db_query_next_tuple (query_result); continue; } user = db_get_object (&user_val); password = db_get_string (&password_val); retval = io_relseek_old (password, 1, out_buf); if (retval != NO_ERROR) { printf ("%s\n", db_error_string (1)); return 1; } retval = au_set_password (user, out_buf); if (retval != NO_ERROR) { printf ("%s\n", db_error_string (1)); return 1; } error = db_query_next_tuple (query_result); } db_query_end (query_result); } db_commit_transaction (); db_shutdown (); return 0; }