Ejemplo n.º 1
0
int
reconnect_to_server (void)
{
#define MAX_SIZE_OTHER_COMMANDS 500
  int db_error = 0;

  int rval;

  db_error = db_restart (Program, 0, Db_name);

  if (db_error == ER_NET_CANT_CONNECT_SERVER)
    {

      char command[MAX_SIZE_OTHER_COMMANDS] = { 0 };

      strcpy (command, "cubrid server start ");
      strcat (command, Db_name);
      rval = system (command);
      if (rval)
	fprintf (stderr,
		 "qacsql: Line %d: system() failed on - %s, returned %08x\n",
		 __LINE__, command, rval);
      db_error = db_restart (Program, 0, Db_name);
    }

  return (db_error);

#undef MAX_SIZE_OTHER_COMMANDS
}
Ejemplo n.º 2
0
static int
cubrid_statdump_read ()
{
  char submit_name[256];

  /* Execution statistics for the file io */
  value_t file_num_creates[1];
  value_t file_num_removes[1];
  value_t file_num_ioreads[1];
  value_t file_num_iowrites[1];
  value_t file_num_iosynches[1];

  /* Execution statistics for the page buffer manager */
  value_t pb_num_fetches[1];
  value_t pb_num_dirties[1];
  value_t pb_num_ioreads[1];
  value_t pb_num_iowrites[1];
  value_t pb_num_victims[1];
  value_t pb_num_replacements[1];

  /* Execution statistics for the log manager */
  value_t log_num_ioreads[1];
  value_t log_num_iowrites[1];
  value_t log_num_appendrecs[1];
  value_t log_num_archives[1];
  value_t log_num_checkpoints[1];
  value_t log_num_wals[1];

  /* Execution statistics for the lock manager */
  value_t lk_num_acquired_on_pages[1];
  value_t lk_num_acquired_on_objects[1];
  value_t lk_num_converted_on_pages[1];
  value_t lk_num_converted_on_objects[1];
  value_t lk_num_re_requested_on_pages[1];
  value_t lk_num_re_requested_on_objects[1];
  value_t lk_num_waited_on_pages[1];
  value_t lk_num_waited_on_objects[1];

  /* Execution statistics for transactions */
  value_t tran_num_commits[1];
  value_t tran_num_rollbacks[1];
  value_t tran_num_savepoints[1];
  value_t tran_num_start_topops[1];
  value_t tran_num_end_topops[1];
  value_t tran_num_interrupts[1];

  /* Execution statistics for the btree manager */
  value_t bt_num_inserts[1];
  value_t bt_num_deletes[1];
  value_t bt_num_updates[1];

  /* Execution statistics for the query manger */
  value_t qm_num_selects[1];
  value_t qm_num_inserts[1];
  value_t qm_num_deletes[1];
  value_t qm_num_updates[1];
  value_t qm_num_sscans[1];
  value_t qm_num_iscans[1];
  value_t qm_num_lscans[1];
  value_t qm_num_setscans[1];
  value_t qm_num_methscans[1];
  value_t qm_num_nljoins[1];
  value_t qm_num_mjoins[1];
  value_t qm_num_objfetches[1];

  /* flush control */
  value_t fc_num_pages[1];
  value_t fc_num_log_pages[1];
  value_t fc_tokens[1];

  /* Execution statistics for network communication */
  value_t net_num_requests[1];

  MNT_SERVER_EXEC_GLOBAL_STATS *mystat;
  mystat = malloc (sizeof (MNT_SERVER_EXEC_GLOBAL_STATS));

  sprintf (submit_name, "statdump_%s", db);

  AU_DISABLE_PASSWORDS ();

  db_set_client_type (DB_CLIENT_TYPE_ADMIN_UTILITY);
  db_login ("dba", NULL);
  db_restart (db, TRUE, db);
  histo_start (true);

  mnt_server_copy_global_stats (mystat);

  file_num_creates[0].gauge = mystat->file_num_creates;
  file_num_removes[0].gauge = mystat->file_num_removes;
  file_num_ioreads[0].gauge = mystat->file_num_ioreads;
  file_num_iowrites[0].gauge = mystat->file_num_iowrites;
  file_num_iosynches[0].gauge = mystat->file_num_iosynches;

  pb_num_fetches[0].gauge = mystat->pb_num_fetches;
  pb_num_dirties[0].gauge = mystat->pb_num_dirties;
  pb_num_ioreads[0].gauge = mystat->pb_num_ioreads;
  pb_num_iowrites[0].gauge = mystat->pb_num_iowrites;
  pb_num_victims[0].gauge = mystat->pb_num_victims;
  pb_num_replacements[0].gauge = mystat->pb_num_replacements;

  log_num_ioreads[0].gauge = mystat->log_num_ioreads;
  log_num_iowrites[0].gauge = mystat->log_num_iowrites;
  log_num_appendrecs[0].gauge = mystat->log_num_appendrecs;
  log_num_archives[0].gauge = mystat->log_num_archives;
  log_num_checkpoints[0].gauge = mystat->log_num_checkpoints;
  log_num_wals[0].gauge = mystat->log_num_wals;

  lk_num_acquired_on_pages[0].gauge = mystat->lk_num_acquired_on_pages;
  lk_num_acquired_on_objects[0].gauge = mystat->lk_num_acquired_on_objects;
  lk_num_converted_on_pages[0].gauge = mystat->lk_num_converted_on_pages;
  lk_num_converted_on_objects[0].gauge = mystat->lk_num_converted_on_objects;
  lk_num_re_requested_on_pages[0].gauge =
    mystat->lk_num_re_requested_on_pages;
  lk_num_re_requested_on_objects[0].gauge =
    mystat->lk_num_re_requested_on_objects;
  lk_num_waited_on_pages[0].gauge = mystat->lk_num_waited_on_pages;
  lk_num_waited_on_objects[0].gauge = mystat->lk_num_waited_on_objects;

  tran_num_commits[0].gauge = mystat->tran_num_commits;
  tran_num_rollbacks[0].gauge = mystat->tran_num_rollbacks;
  tran_num_savepoints[0].gauge = mystat->tran_num_savepoints;
  tran_num_start_topops[0].gauge = mystat->tran_num_start_topops;
  tran_num_end_topops[0].gauge = mystat->tran_num_end_topops;
  tran_num_interrupts[0].gauge = mystat->tran_num_interrupts;

  bt_num_inserts[0].gauge = mystat->bt_num_inserts;
  bt_num_deletes[0].gauge = mystat->bt_num_deletes;
  bt_num_updates[0].gauge = mystat->bt_num_updates;

  qm_num_selects[0].gauge = mystat->qm_num_selects;
  qm_num_inserts[0].gauge = mystat->qm_num_inserts;
  qm_num_deletes[0].gauge = mystat->qm_num_deletes;
  qm_num_updates[0].gauge = mystat->qm_num_updates;
  qm_num_sscans[0].gauge = mystat->qm_num_sscans;
  qm_num_iscans[0].gauge = mystat->qm_num_iscans;
  qm_num_lscans[0].gauge = mystat->qm_num_lscans;
  qm_num_setscans[0].gauge = mystat->qm_num_setscans;
  qm_num_methscans[0].gauge = mystat->qm_num_methscans;
  qm_num_nljoins[0].gauge = mystat->qm_num_nljoins;
  qm_num_mjoins[0].gauge = mystat->qm_num_mjoins;
  qm_num_objfetches[0].gauge = mystat->qm_num_objfetches;

  fc_num_pages[0].gauge = mystat->fc_num_pages;
  fc_num_log_pages[0].gauge = mystat->fc_num_log_pages;
  fc_tokens[0].gauge = mystat->fc_tokens;

  net_num_requests[0].gauge = mystat->net_num_requests;

  submit ("file_num_creates", submit_name, file_num_creates, 1);
  submit ("file_num_removes", submit_name, file_num_removes, 1);
  submit ("file_num_ioreads", submit_name, file_num_ioreads, 1);
  submit ("file_num_iowrites", submit_name, file_num_iowrites, 1);
  submit ("file_num_iosynches", submit_name, file_num_iosynches, 1);

  submit ("pb_num_fetches", submit_name, pb_num_fetches, 1);
  submit ("pb_num_dirties", submit_name, pb_num_dirties, 1);
  submit ("pb_num_ioreads", submit_name, pb_num_ioreads, 1);
  submit ("pb_num_iowrites", submit_name, pb_num_iowrites, 1);
  submit ("pb_num_victims", submit_name, pb_num_victims, 1);
  submit ("pb_num_replacements", submit_name, pb_num_replacements, 1);

  submit ("log_num_ioreads", submit_name, log_num_ioreads, 1);
  submit ("log_num_iowrites", submit_name, log_num_iowrites, 1);
  submit ("log_num_appendrecs", submit_name, log_num_appendrecs, 1);
  submit ("log_num_archives", submit_name, log_num_archives, 1);
  submit ("log_num_checkpoints", submit_name, log_num_checkpoints, 1);
  submit ("log_num_wals", submit_name, log_num_wals, 1);

  submit ("lk_num_acquired_on_pages", submit_name, lk_num_acquired_on_pages,
	  1);
  submit ("lk_num_acquired_on_objects", submit_name,
	  lk_num_acquired_on_objects, 1);
  submit ("lk_num_converted_on_pages", submit_name, lk_num_converted_on_pages,
	  1);
  submit ("lk_num_converted_on_objects", submit_name,
	  lk_num_converted_on_objects, 1);
  submit ("lk_num_re_requested_on_pages", submit_name,
	  lk_num_re_requested_on_pages, 1);
  submit ("lk_num_re_requested_on_objects", submit_name,
	  lk_num_re_requested_on_objects, 1);
  submit ("lk_num_waited_on_pages", submit_name, lk_num_waited_on_pages, 1);
  submit ("lk_num_waited_on_objects", submit_name, lk_num_waited_on_objects,
	  1);

  submit ("tran_num_commits", submit_name, tran_num_commits, 1);
  submit ("tran_num_rollbacks", submit_name, tran_num_rollbacks, 1);
  submit ("tran_num_savepoints", submit_name, tran_num_savepoints, 1);
  submit ("tran_num_start_topops", submit_name, tran_num_start_topops, 1);
  submit ("tran_num_end_topops", submit_name, tran_num_end_topops, 1);
  submit ("tran_num_interrupts", submit_name, tran_num_interrupts, 1);

  submit ("bt_num_inserts", submit_name, bt_num_inserts, 1);
  submit ("bt_num_deletes", submit_name, bt_num_deletes, 1);
  submit ("bt_num_updates", submit_name, bt_num_updates, 1);

  submit ("qm_num_selects", submit_name, qm_num_selects, 1);
  submit ("qm_num_inserts", submit_name, qm_num_inserts, 1);
  submit ("qm_num_deletes", submit_name, qm_num_deletes, 1);
  submit ("qm_num_updates", submit_name, qm_num_updates, 1);
  submit ("qm_num_sscans", submit_name, qm_num_sscans, 1);
  submit ("qm_num_iscans", submit_name, qm_num_iscans, 1);
  submit ("qm_num_lscans", submit_name, qm_num_lscans, 1);
  submit ("qm_num_setscans", submit_name, qm_num_setscans, 1);
  submit ("qm_num_nljoins", submit_name, qm_num_nljoins, 1);
  submit ("qm_num_mjoins", submit_name, qm_num_mjoins, 1);
  submit ("qm_num_objfetches", submit_name, qm_num_objfetches, 1);

  submit ("fc_num_pages", submit_name, fc_num_pages, 1);
  submit ("fc_num_log_pages", submit_name, fc_num_log_pages, 1);
  submit ("fc_tokens", submit_name, fc_tokens, 1);

  submit ("net_num_requests", submit_name, net_num_requests, 1);

  histo_clear_global_stats ();
  histo_stop ();
  free (mystat);
  db_shutdown ();
  return 0;
}
Ejemplo n.º 3
0
/*
 * 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;
}
Ejemplo n.º 4
0
/* exe_one - execute one instruction */
void exe_one(void)
{
    /* get the opcode */
    opcode = getcbyte(pc); pc++;

    /* execute the instruction */
    switch (opcode) {
    case OP_CALL:
		*--sp = getboperand();
		*--sp = pc;
		*--sp = (int)(top - fp);
		fp = sp;
		pc = getafield(fp[fp[2]+3],A_CODE);
		break;
    case OP_SEND:
		*--sp = getboperand();
		*--sp = pc;
		*--sp = (int)(top - fp);
		fp = sp;
		if (p2 = fp[fp[2]+3])
		    p2 = getofield(p2,O_CLASS);
		else
		    p2 = fp[fp[2]+2];
		if (p2 && (p2 = getp(p2,fp[fp[2]+1]))) {
		    pc = getafield(p2,A_CODE);
		    break;
		}
		*sp = NIL;
		/* return NIL if there is no method for this message */
    case OP_RETURN:
		if (fp == top)
		    sts = CHAIN;
		else {
		    p2 = *sp;
		    sp = fp;
		    fp = top - *sp++;
		    pc = *sp++;
		    p3 = *sp++;
		    sp += p3;
		    *sp = p2;
		}
		break;
    case OP_TSPACE:
		sp -= getboperand();
		break;
    case OP_TMP:
		p2 = getboperand();
		*sp = fp[-p2-1];
		break;
    case OP_TSET:
		p2 = getboperand();
		fp[-p2-1] = *sp;
		break;
    case OP_ARG:
		p2 = getboperand();
		if (p2 >= fp[2])
		    error("too few arguments");
		*sp = fp[p2+3];
		break;
    case OP_ASET:
		p2 = getboperand();
		if (p2 >= fp[2])
		    error("too few arguments");
		fp[p2+3] = *sp;
		break;
    case OP_BRT:
		pc = (*sp ? getwoperand() : pc+2);
		break;
    case OP_BRF:
		pc = (*sp ? pc+2 : getwoperand());
		break;
    case OP_BR:
		pc = getwoperand();
		break;
    case OP_T:
		*sp = T;
		break;
    case OP_NIL:
		*sp = NIL;
		break;
    case OP_PUSH:
		*--sp = NIL;
		break;
    case OP_NOT:
		*sp = (*sp ? NIL : T);
		break;
    case OP_ADD:
		p2 = *sp++;
		*sp += p2;
		break;
    case OP_SUB:
		p2 = *sp++;
		*sp -= p2;
		break;
    case OP_MUL:
		p2 = *sp++;
		*sp *= p2;
		break;
    case OP_DIV:
		p2 = *sp++;
		*sp = (p2 == 0 ? 0 : *sp / p2);
		break;
    case OP_REM:
		p2 = *sp++;
		*sp = (p2 == 0 ? 0 : *sp % p2);
		break;
    case OP_BAND:
		p2 = *sp++;
		*sp &= p2;
		break;
    case OP_BOR:
		p2 = *sp++;
		*sp |= p2;
		break;
    case OP_BNOT:
		*sp = ~*sp;
		break;
    case OP_LT:
		p2 = *sp++;
		*sp = (*sp < p2 ? T : NIL);
		break;
    case OP_EQ:
		p2 = *sp++;
		*sp = (*sp == p2 ? T : NIL);
		break;
    case OP_GT:
		p2 = *sp++;
		*sp = (*sp > p2 ? T : NIL);
		break;
    case OP_LIT:
		*sp = getwoperand();
		break;
    case OP_SPLIT:
		*sp = getboperand();
		break;
    case OP_SNLIT:
		*sp = -getboperand();
		break;
    case OP_VAR:
		*sp = getvalue(getwoperand());
		break;
    case OP_SVAR:
		*sp = getvalue(getboperand());
		break;
    case OP_SET:
		setvalue(getwoperand(),*sp);
		break;
    case OP_SSET:
		setvalue(getboperand(),*sp);
		break;
    case OP_GETP:
		p2 = *sp++;
		*sp = getp(*sp,p2);
		break;
    case OP_SETP:
		p3 = *sp++;
		p2 = *sp++;
		*sp = setp(*sp,p2,p3);
		break;
    case OP_PRINT:
		print(*sp);
		break;
    case OP_PNUMBER:
    		pnumber(*sp);
    		break;
    case OP_PNOUN:
		show_noun(*sp);
		break;
    case OP_TERPRI:
		trm_chr('\n');
		break;
    case OP_FINISH:
		sts = FINISH;
		break;
    case OP_CHAIN:
		sts = CHAIN;
		break;
    case OP_ABORT:
		sts = ABORT;
		break;
    case OP_EXIT:
#ifdef MAC
		macpause();
#endif
		trm_done();
		exit();
		break;
    case OP_YORN:
		trm_get(line);
		*sp = (line[0] == 'Y' || line[0] == 'y' ? T : NIL);
    		break;
    case OP_CLASS:
		*sp = getofield(*sp,O_CLASS);
		break;
    case OP_MATCH:
		p2 = *sp++;
		*sp = (match(*sp,nouns[p2-1],adjectives[p2-1]) ? T : NIL);
		break;
    case OP_SAVE:
		*sp = db_save();
		break;
    case OP_RESTORE:
		*sp = db_restore();
		break;
    case OP_RESTART:
		*sp = db_restart();
		break;
    case OP_RAND:
		*sp = getrand(*sp);
		break;
    case OP_RNDMIZE:
		setrand(time(0L));
		*sp = NIL;
		break;
    default:
	    if (opcode >= OP_XVAR && opcode < OP_XSET)
		*sp = getvalue(opcode - OP_XVAR);
	    else if (opcode >= OP_XSET && opcode < OP_XPLIT)
		setvalue(opcode - OP_XSET,*sp);
	    else if (opcode >= OP_XPLIT && opcode < OP_XNLIT)
		*sp = opcode - OP_XPLIT;
	    else if (opcode >= OP_XNLIT && opcode < 256)
		*sp = OP_XNLIT - opcode;
	    else
		trm_str("Bad opcode\n");
	    break;
    }
}
Ejemplo n.º 5
0
/*
 * 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;
}
Ejemplo n.º 6
0
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;
}
Ejemplo n.º 7
0
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;
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
0
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;
}