CUBRID Engine  latest
db_admin.c
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 
20 /*
21  * db_admin.c - CUBRID Application Program Interface.
22  * Functions related to database creation and administration.
23  */
24 
25 #ident "$Id$"
26 
27 #include "config.h"
28 
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <stdarg.h>
32 #include <ctype.h>
33 #include <assert.h>
34 #include <signal.h>
35 
36 #include "authenticate.h"
37 #include "porting.h"
38 #include "system_parameter.h"
39 #include "storage_common.h"
40 #include "environment_variable.h"
41 #include "db.h"
42 #include "class_object.h"
43 #include "object_print.h"
44 #include "server_interface.h"
45 #include "boot_cl.h"
46 #include "locator_cl.h"
47 #include "schema_manager.h"
48 #include "schema_template.h"
49 #include "object_accessor.h"
50 #include "set_object.h"
51 #include "virtual_object.h"
52 #include "parser.h"
53 #include "memory_alloc.h"
54 #include "execute_schema.h"
55 #include "network_interface_cl.h"
56 #if defined(SA_MODE)
57 #include "jsp_sr.h"
58 #endif /* SA_MODE */
59 #include "jsp_cl.h"
60 #include "execute_statement.h"
61 #include "connection_support.h"
62 #include "trigger_manager.h"
63 #if !defined(CS_MODE)
64 #include "session.h"
65 #endif
66 #include "connection_cl.h"
67 #include "dbtype.h"
68 
69 #if !defined(WINDOWS)
70 void (*prev_sigfpe_handler) (int) = SIG_DFL;
71 #include "tcp.h"
72 #else
73 #include "wintcp.h"
74 #endif /* !WINDOWS */
75 
76 /* host status for marking abnormal host status */
79 {
81  int status;
82 };
83 
86 {
87  /* preferred_hosts + db-hosts */
91 };
92 
93 /* Some like to assume that the db_ layer is able to recognize that a
94  database has not been successfully restarted. For now, check every
95  time. We'll want another functional layer for esql that doesn't
96  do all this checking.
97  The macros for testing this variable were moved to db.h so the query
98  interface functions can use them as well. */
99 
101 char db_Program_name[PATH_MAX];
102 
103 static char *db_Preferred_hosts = NULL;
106 static int db_Delayed_hosts_count = 0;
107 
108 /* a list of abnormal host status */
110 
111 static DB_HOST_STATUS *db_add_host_status (char *hostname, int status);
113 
115 
116 static void install_static_methods (void);
117 static int fetch_set_internal (DB_SET * set, DB_FETCH_MODE purpose, int quit_on_error);
118 #if !defined(WINDOWS)
119 void sigfpe_handler (int sig);
120 #endif
121 
122 /*
123  * install_static_methods() - Installs the static method definitions for the
124  * system defined classes. This may change depending upon the product
125  * build configuration.
126  * return : none
127  *
128  */
129 static void
131 {
132  au_link_static_methods (); /* Authorization classes */
133 }
134 
135 /*
136  * db_init() - This will create a database file and associated log files and
137  * install the authorization objects and other required system objects.
138  * This is kept only for temporary compatibility. The creation of
139  * databases will ultimately be done only by a specially written utility
140  * function that will ensure all of the various configuration options are
141  * applied.
142  *
143  * return : Error Indicator.
144  * program(in) : the program name from argv[0]
145  * print_version(in): a flag enabling an initial "herald" message
146  * dbname(in) : the name of the database (server name)
147  * db_path(in) :
148  * vol_path(in) :
149  * log_path(in) :
150  * lob_path(in) :
151  * host_name(in) :
152  * overwrite(in) :
153  * comments(in) : additional comments to be added to the label
154  * addmore_vols_file(in):
155  * npages(in) : the initial page allocation
156  * desired_pagesize(in):
157  * log_npages(in):
158  * desired_log_page_size(in):
159  * lang_charset(in): string for language and charset (ko_KR.utf8)
160  *
161  */
162 
163 int
164 db_init (const char *program, int print_version, const char *dbname, const char *db_path, const char *vol_path,
165  const char *log_path, const char *lob_path, const char *host_name, const bool overwrite, const char *comments,
166  const char *addmore_vols_file, int npages, int desired_pagesize, int log_npages, int desired_log_page_size,
167  const char *lang_charset)
168 {
169 #if defined (CUBRID_DEBUG)
170  int value;
171  const char *env_value;
172  char more_vol_info_temp_file[L_tmpnam];
173 #endif
174  const char *more_vol_info_file = NULL;
175  int error = NO_ERROR;
176  BOOT_CLIENT_CREDENTIAL client_credential;
177  BOOT_DB_PATH_INFO db_path_info;
178 
180 
181 #if defined (CUBRID_DEBUG)
182  if (addmore_vols_file == NULL)
183  {
184  /* Added for debugging of multivols using old test programs/scripts What to do with volumes. */
185  env_value = envvar_get ("BOSR_SPLIT_INIT_VOLUME");
186  if (env_value != NULL)
187  {
188  value = atoi (env_value);
189  }
190  else
191  {
192  value = 0;
193  }
194 
195  if (value != 0)
196  {
197  FILE *more_vols_fp;
198  DKNPAGES db_npages;
199 
200  db_npages = npages / 4;
201 
202  if (tmpnam (more_vol_info_temp_file) != NULL && (more_vols_fp = fopen (more_vol_info_temp_file, "w")) != NULL)
203  {
204  fprintf (more_vols_fp, "%s %s %s %d", "PURPOSE", "DATA", "NPAGES", db_npages);
205  fprintf (more_vols_fp, "%s %s %s %d", "PURPOSE", "INDEX", "NPAGES", db_npages);
206  fprintf (more_vols_fp, "%s %s %s %d", "PURPOSE", "TEMP", "NPAGES", db_npages);
207  fclose (more_vols_fp);
208 
209  if ((db_npages * 4) != npages)
210  {
211  npages = npages - (db_npages * 4);
212  }
213  else
214  {
215  npages = db_npages;
216  }
217 
218  addmore_vols_file = more_vol_info_file = more_vol_info_temp_file;
219  }
220  }
221  }
222 #endif /* CUBRID_DEBUG */
223 
224  if (desired_pagesize > 0)
225  {
226  if (desired_pagesize < IO_MIN_PAGE_SIZE)
227  {
228  desired_pagesize = IO_MIN_PAGE_SIZE;
229  }
230  else if (desired_pagesize > IO_MAX_PAGE_SIZE)
231  {
232  desired_pagesize = IO_MAX_PAGE_SIZE;
233  }
234  }
235  else
236  {
237  desired_pagesize = IO_DEFAULT_PAGE_SIZE;
238  }
239 
240  if (desired_log_page_size > 0)
241  {
242  if (desired_log_page_size < IO_MIN_PAGE_SIZE)
243  {
244  desired_log_page_size = IO_MIN_PAGE_SIZE;
245  }
246  else if (desired_log_page_size > IO_MAX_PAGE_SIZE)
247  {
248  desired_log_page_size = IO_MAX_PAGE_SIZE;
249  }
250  }
251  else
252  {
253  desired_log_page_size = desired_pagesize;
254  }
255 
256  client_credential.client_type = DB_CLIENT_TYPE_ADMIN_UTILITY;
257  client_credential.db_name = dbname;
258  client_credential.program_name = program;
259  client_credential.process_id = -1;
260 
261  db_path_info.db_path = (char *) db_path;
262  db_path_info.vol_path = (char *) vol_path;
263  db_path_info.log_path = (char *) log_path;
264  db_path_info.lob_path = (char *) lob_path;
265  db_path_info.db_host = (char *) host_name;
266  db_path_info.db_comments = (char *) comments;
267 
268  error = boot_initialize_client (&client_credential, &db_path_info, (bool) overwrite, addmore_vols_file, npages,
269  (PGLENGTH) desired_pagesize, log_npages, (PGLENGTH) desired_log_page_size,
270  lang_charset);
271 
272  if (more_vol_info_file != NULL)
273  {
274  remove (more_vol_info_file);
275  }
276 
277  if (error != NO_ERROR)
278  {
280  }
281  else
282  {
284  /* should be part of boot_initialize_client when we figure out what this does */
286  }
287 
288  return (error);
289 }
290 
291 /*
292  * db_add_volume() - Add a volume extension to the database. The addition of
293  * the volume is a system operation that will be either aborted in case
294  * of failure or committed in case of success, independently on the
295  * destiny of the current transaction. The volume becomes immediately
296  * available to other transactions.
297  *
298  * return : Error code
299  * ext_path: Directory where the volume extension is created.
300  * If NULL, is given, it defaults to the system parameter.
301  * ext_name: Name of the volume extension
302  * If NULL, system generates one like "db".ext"volid" where
303  * "db" is the database name and "volid" is the volume
304  * identifier to be assigned to the volume extension.
305  * Most of the times, NULL is given by the application.
306  * ext_comments: Comments which are included in the volume extension
307  * header.
308  * ext_npages: Number of pages
309  * ext_purpose: The purpose of the volume extension. One of the following:
310  * - DB_PERMANENT_DATA_PURPOSE,
311  * - DB_TEMPORARY_DATA_PURPOSE
312  */
313 int
314 db_add_volume (const char *ext_path, const char *ext_name, const char *ext_comments, const int ext_npages,
315  const DB_VOLPURPOSE ext_purpose)
316 {
317  DBDEF_VOL_EXT_INFO ext_info;
318 
319  ext_info.path = ext_path;
320  ext_info.name = ext_name;
321  ext_info.comments = ext_comments;
322  ext_info.max_npages = ext_npages;
323  ext_info.max_writesize_in_sec = 0;
324  ext_info.purpose = ext_purpose;
325  ext_info.overwrite = false;
326 
327  return db_add_volume_ex (&ext_info);
328 }
329 
330 /*
331  * db_add_volume_ex() - Add a volume extension to the database. The addition of
332  * the volume is a system operation that will be either aborted in case
333  * of failure or committed in case of success, independently on the
334  * destiny of the current transaction. The volume becomes immediately
335  * available to other transactions.
336  *
337  * return : Error code
338  * ext_info : volume info
339  *
340  */
341 int
343 {
344  VOLID volid;
345  int error = NO_ERROR;
346 
348 
349  assert (ext_info != NULL);
350 
352  {
353  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_AU_DBA_ONLY, 1, "db_add_volume");
354  return er_errid ();
355  }
356 
357  ext_info->overwrite = false;
358  volid = boot_add_volume_extension (ext_info);
359  if (volid == NULL_VOLID)
360  {
361  assert (er_errid () != NO_ERROR);
362  error = er_errid ();
363  }
364 
365  return error;
366 }
367 
368 /*
369  * db_num_volumes() - Find the number of permanent volumes in the database.
370  *
371  * return : the number of permanent volumes in database.
372  */
373 int
375 {
376  int retval;
377 
379 
381 
382  return ((int) retval);
383 }
384 
385 /*
386  * db_last_volumes() - Find the last id of permanent volumes in the database.
387  *
388  * return : the number of permanent volumes in database.
389  */
390 int
392 {
393  int retval;
394 
396 
397  retval = boot_find_last_permanent ();
398 
399  return retval;
400 }
401 
402 /*
403  * db_vol_label() - Find the name of the volume associated with given volid.
404  * return : vol_fullname or NULL in case of failure.
405  * volid(in) : Permanent volume identifier.
406  * If NULL_VOLID is given, the total information of all
407  * volumes is requested.
408  * vol_fullname(out): Address where the name of the volume is placed. The size
409  * must be at least PATH_MAX (SET AS A SIDE EFFECT)
410  */
411 char *
412 db_vol_label (int volid, char *vol_fullname)
413 {
414  char *retval;
415 
416  CHECK_CONNECT_ZERO_TYPE (char *);
417 
418  retval = disk_get_fullname ((VOLID) volid, vol_fullname);
419 
420  return (retval);
421 }
422 
423 /*
424  * db_get_database_name() - Returns a C string containing the name of
425  * the active database.
426  * return : name of the currently active database.
427  *
428  * note : The string is copied and must be freed by the db_string_free()
429  * function when it is no longer required.
430  */
431 char *
433 {
434  const char *name = NULL;
435 
437 
438  if (strlen (db_Database_name))
439  {
440  name = ws_copy_string ((const char *) db_Database_name);
441  }
442 
443  return ((char *) name);
444 }
445 
446 /*
447  * db_get_database_version() - Returns a C string containing the version of
448  * the active database server.
449  * return : release version of the currently active server.
450  *
451  * note : The string is allocated and must be freed with the db_string_free()
452  * function when it is no longer required.
453  */
454 char *
456 {
457  char *name = NULL;
458  name = ws_copy_string (rel_build_number ());
459  return name;
460 }
461 
462 /*
463  * db_get_database_comments() - returns a C string containing the comments
464  * field of the database.
465  * return : comment string for currently active database.
466  *
467  * note : This string must be freed with db_string_free() function
468  * when no longer needed.
469  */
470 const char *
472 {
473  char *remarks = NULL;
474  const char *comment = NULL;
475 
477 
478  remarks = disk_get_remarks (0);
479  if (remarks != NULL)
480  {
481  comment = ws_copy_string (remarks);
482  free_and_init (remarks);
483  }
484 
485  return (comment);
486 }
487 
488 int
490 {
491  return db_Client_type;
492 }
493 
494 void
495 db_set_client_type (int client_type)
496 {
497  if (client_type > DB_CLIENT_TYPE_MAX || client_type < DB_CLIENT_TYPE_DEFAULT)
498  {
500  }
501  else
502  {
503  db_Client_type = client_type;
504  }
505 }
506 
507 void
508 db_set_preferred_hosts (const char *hosts)
509 {
510  if (db_Preferred_hosts)
511  {
513  }
514 
515  if (hosts)
516  {
517  db_Preferred_hosts = strdup (hosts);
518  }
519 }
520 
521 void
522 db_set_connect_order (int connect_order)
523 {
524  db_Connect_order = connect_order;
525 }
526 
527 void
528 db_set_max_num_delayed_hosts_lookup (int max_num_delayed_hosts_lookup)
529 {
530  db_Max_num_delayed_hosts_lookup = max_num_delayed_hosts_lookup;
531 }
532 
533 int
535 {
537 }
538 
539 int
541 {
542  return db_Delayed_hosts_count;
543 }
544 
545 void
547 {
549 }
550 
551 /*
552  * db_enable_trigger() - enable all trigger actions
553  * return : previous state
554  *
555  * NOTE: recommend to be called after db_restart is called
556  */
557 bool
559 {
560  return tr_set_execution_state (true);
561 }
562 
563 /*
564  * db_disable_trigger() - disable all trigger actions
565  * return :previous state
566  *
567  * NOTE: recommend to be called after db_restart is called
568  */
569 bool
571 {
572  return tr_set_execution_state (false);
573 }
574 
575 /*
576  * db_clear_host_status() - clear db_Host_status_list
577  * return :
578  */
579 void
581 {
582  for (size_t i = 0; i < DIM (db_Host_status_list.hostlist); i++)
583  {
584  db_Host_status_list.hostlist[i].hostname[0] = '\0';
585  db_Host_status_list.hostlist[i].status = DB_HS_NORMAL;
586  }
587  db_Host_status_list.connected_host_status = NULL;
588  db_Host_status_list.last_host_idx = -1;
589 
590  return;
591 }
592 
593 /*
594  * db_find_host_status() - Find host status with a given hostname
595  * in db_Host_status_list
596  * return : host status found
597  */
600 {
601  DB_HOST_STATUS *host_status;
602  int i;
603 
604  for (i = 0; i <= db_Host_status_list.last_host_idx; i++)
605  {
606  host_status = &db_Host_status_list.hostlist[i];
607  if (strcmp (hostname, host_status->hostname) == 0)
608  {
609  return host_status;
610  }
611  }
612 
613  return NULL;
614 }
615 
616 /*
617  * db_add_host_status() - add host status into db_Host_status_list
618  * return: added host status
619  *
620  * hostname(in) :
621  * status(in) :
622  */
625 {
626  DB_HOST_STATUS *host_status;
627  int idx;
628 
629  assert (db_Host_status_list.last_host_idx + 1 < (int) DIM (db_Host_status_list.hostlist));
630 
631  idx = ++db_Host_status_list.last_host_idx;
632  host_status = &db_Host_status_list.hostlist[idx];
633 
634  strncpy (host_status->hostname, hostname, sizeof (host_status->hostname) - 1);
635  host_status->status |= status;
636 
637  return host_status;
638 }
639 
640 /*
641  * db_set_host_status() - set host status to given status.
642  * it adds new host status if not exists.
643  * it adds status into existing one if exists.
644  * return :
645  * hostname(in) :
646  * status(in) :
647  */
648 void
650 {
651  DB_HOST_STATUS *host_status;
652 
653  host_status = db_find_host_status (hostname);
654 
655  if (host_status != NULL)
656  {
657  host_status->status |= status;
658  }
659  else
660  {
661  db_add_host_status (hostname, status);
662  }
663 
664  if (status & DB_HS_HA_DELAYED)
665  {
667  }
668 
669  return;
670 }
671 
672 /*
673  * db_set_host_connected() - set the currently connected host. if
674  * currently connected host does not exists, add it to host status list.
675  *
676  * return :
677  * host_connected(in): hostname that a client is currently connected to
678 
679  */
680 void
681 db_set_connected_host_status (char *host_connected)
682 {
683  DB_HOST_STATUS *connected_host_status;
684 
685  connected_host_status = db_find_host_status (host_connected);
686  if (connected_host_status != NULL)
687  {
688  db_Host_status_list.connected_host_status = connected_host_status;
689  }
690  else
691  {
692  db_Host_status_list.connected_host_status = db_add_host_status (host_connected, DB_HS_NORMAL);
693  }
694 
695  return;
696 }
697 
698 /*
699  * db_need_reconnect() - check if reconnection is required.
700  * return : whether reconnection is needed or not
701  *
702  * NOTE: it checks db_Host_status_list and determines whether to
703  * reconnect or not. if the currently connected host's status matches
704  * DB_HS_RECONNECT_INDICATOR, then reconnection is required.
705  * Also, if any hosts previously attempted to connect to were reported delayed,
706  * then reconnection is required.
707  */
708 bool
710 {
711  int i;
712  DB_HOST_STATUS *host_status;
713 
715  {
716  return true;
717  }
718 
719  /* if any previous attempt to connect failed due to HA replication delay */
720  for (i = 0; i <= db_Host_status_list.last_host_idx; i++)
721  {
722  host_status = &db_Host_status_list.hostlist[i];
723  if (host_status->status & DB_HS_HA_DELAYED)
724  {
725  return true;
726  }
727  }
728 
729  return false;
730 }
731 
732 /*
733  * db_need_ignore_repl_delay() - check if the current host's replication is delayed.
734  * return : whether to ignore HA delay or not.
735  *
736  * NOTE: it checks if the currently connected host is delayed. if it is true,
737  * it means that all the other hosts' replication is also delayed.
738  * Therefore, a client should notify a server that HA replication delay should be
739  * ignored when it is true. (if it is not notified, then the server will keep
740  * resetting the connection)
741  */
742 bool
744 {
745  if (db_Host_status_list.connected_host_status != NULL)
746  {
747  return ((db_Host_status_list.connected_host_status->status & DB_HS_HA_DELAYED) != 0);
748  }
749 
750  return false;
751 }
752 
753 
754 bool
756 {
757  if (db_Host_status_list.connected_host_status != NULL)
758  {
759  if (db_Host_status_list.connected_host_status->status & status)
760  {
761  return true;
762  }
763  }
764 
765  return false;
766 }
767 
768 /*
769  * db_get_host_list_with_given_status()
770  * - get a list of hostnames with a given status.
771  * return : the number of matching hosts
772  * hostlist(in/out): a resulting list of hostnames
773  * status(in): status that a caller is looking for
774  */
775 int
776 db_get_host_list_with_given_status (char **hostlist, int list_size, int status)
777 {
778  int i, num_hosts = 0;
779 
780  for (i = 0; i <= db_Host_status_list.last_host_idx && i < list_size; i++)
781  {
782  if (db_Host_status_list.hostlist[i].status & status)
783  {
784  hostlist[num_hosts++] = db_Host_status_list.hostlist[i].hostname;
785  }
786  }
787  hostlist[num_hosts] = NULL;
788 
789  return num_hosts;
790 }
791 
792 /*
793  * DATABASE ACCESS
794  */
795 
796 /*
797  * db_login() -
798  * return : Error code.
799  * name(in) : user name
800  * password(in): optional password
801  *
802  */
803 int
804 db_login (const char *name, const char *password)
805 {
806  int retval;
807 
808  retval = au_login (name, password, false);
809 
810  return (retval);
811 }
812 
813 #if !defined(WINDOWS)
814 /*
815  * sigfpe_handler() - The function is registered with the system to handle
816  * the SIGFPE signal. It will call the user function if one was set when
817  * the database was started.
818  * return : void
819  * sig : signal number.
820  */
821 void
822 sigfpe_handler (int sig)
823 {
824  void (*prev_sig) (int);
825  /* If the user had a SIGFPE handler, call it */
826  if ((prev_sigfpe_handler != SIG_IGN) &&
827 #if defined(SIG_ERR)
828  (prev_sigfpe_handler != SIG_ERR) &&
829 #endif
830 #if defined(SIG_HOLD)
831  (prev_sigfpe_handler != SIG_HOLD) &&
832 #endif
833  (prev_sigfpe_handler != SIG_DFL))
834  {
835  (*prev_sigfpe_handler) (sig);
836  }
837  /* If using reliable signals, the previous handler is this routine because it's been reestablished. In that case,
838  * don't change the value of the user's handler. */
839  prev_sig = os_set_signal_handler (SIGFPE, sigfpe_handler);
840  if (prev_sig != sigfpe_handler)
841  {
842  prev_sigfpe_handler = prev_sig;
843  }
844 }
845 #endif /* !WINDOWS */
846 
847 /*
848  * db_clear_host_connected() -
849  */
850 void
852 {
854 }
855 
856 /*
857  * db_restart() - This is the primary interface function for opening a
858  * database. The database must have already been created using the
859  * system defined generator tool.
860  *
861  * return : error code.
862  * program(in) : the program name from argv[0]
863  * print_version(in): flag to enable printing of an initial herald message
864  * volume(in) : the name of the database (server)
865  *
866  */
867 int
868 db_restart (const char *program, int print_version, const char *volume)
869 {
870  int error = NO_ERROR;
871  BOOT_CLIENT_CREDENTIAL client_credential;
872 
873  if (program == NULL || volume == NULL)
874  {
875  error = ER_OBJ_INVALID_ARGUMENTS;
877  }
878  else
879  {
880  strncpy_bufsize (db_Program_name, program);
881  db_Database_name[0] = '\0';
882 
883  /* authorization will need to access the database and call some db_ functions so assume connection will be ok
884  * until after boot_restart_client returns */
886 
887  client_credential.client_type = (BOOT_CLIENT_TYPE) db_Client_type;
888  client_credential.db_name = volume;
889  client_credential.program_name = program;
890  client_credential.process_id = -1;
891  client_credential.preferred_hosts = db_Preferred_hosts;
892  client_credential.connect_order = db_Connect_order;
893 
894  error = boot_restart_client (&client_credential);
895  if (error != NO_ERROR)
896  {
898  }
899  else
900  {
902  strncpy (db_Database_name, volume, DB_MAX_IDENTIFIER_LENGTH);
904 #if !defined(WINDOWS)
905 #if defined(SA_MODE) && (defined(LINUX) || defined(x86_SOLARIS))
906  if (!jsp_jvm_is_loaded ())
907  {
909  }
910 #else /* SA_MODE && (LINUX||X86_SOLARIS) */
912 #endif /* SA_MODE && (LINUX||X86_SOLARIS) */
913 #endif /* !WINDOWS */
914  }
915  }
916 
917  return (error);
918 }
919 
920 /*
921  * db_restart_ex() - extended db_restart()
922  *
923  * returns : error code.
924  *
925  * program(in) : the program name from argv[0]
926  * db_name(in) : the name of the database (server)
927  * db_user(in) : the database user name
928  * db_password(in) : the password
929  * client_type(in) : DB_CLIENT_TYPE_XXX in db.h
930  * preferred_hosts(in) : DO NOT USE IT, set it to NULL and
931  * use db_set_preferred_hosts instead
932  */
933 int
934 db_restart_ex (const char *program, const char *db_name, const char *db_user, const char *db_password,
935  const char *preferred_hosts, int client_type)
936 {
937  int retval;
938 
939  retval = au_login (db_user, db_password, false);
940  if (retval != NO_ERROR)
941  {
942  return retval;
943  }
944 
945  db_set_client_type (client_type);
946 
947  /* For backward compatibility. Do not use the parameter, preferred_hosts. A caller is supposed to use
948  * db_set_preferred_hosts before db_restart_ex is called. */
949  if (preferred_hosts != NULL)
950  {
951  db_set_preferred_hosts (preferred_hosts);
952  }
953 
954  return db_restart (program, false, db_name);
955 }
956 
957 /*
958  * db_shutdown() - This closes a database that was previously restarted.
959  * return : error code.
960  *
961  * note: This will ABORT the current transaction.
962  */
963 int
965 {
966  int error = NO_ERROR;
967 
968  error = boot_shutdown_client (true);
969  db_Database_name[0] = '\0';
971  db_Program_name[0] = '\0';
972 #if !defined(WINDOWS)
974 #endif
976 
978 
979  return (error);
980 }
981 
982 int
983 db_ping_server (int client_val, int *server_val)
984 {
985  int error = NO_ERROR;
986 
988 #if defined (CS_MODE)
989  error = net_client_ping_server (client_val, server_val, 5000);
990 #endif /* CS_MODE */
991  return error;
992 }
993 
994 /*
995  * db_disable_modification - Disable database modification operation
996  * return: error code
997  *
998  * NOTE: This function will change 'db_Disable_modifications'.
999  */
1000 int
1002 {
1003  /* CHECK_CONNECT_ERROR (); */
1005  return NO_ERROR;
1006 }
1007 
1008 /*
1009  * db_enable_modification - Enable database modification operation
1010  * return: error code
1011  *
1012  * NOTE: This function will change 'db_Disable_modifications'.
1013  */
1014 int
1016 {
1017  /* CHECK_CONNECT_ERROR (); */
1019  return NO_ERROR;
1020 }
1021 
1022 /*
1023  * db_end_session - end current session
1024  * return: error code
1025  *
1026  * NOTE: This function ends the session identified by 'db_Session_id'
1027  */
1028 int
1030 {
1031  int retval;
1032 
1034 
1036 
1037  return (retval);
1038 }
1039 
1040 /*
1041  * db_get_row_count - get affected row count
1042  * return: error code
1043  * row_count (out) : row count
1044  */
1045 int
1046 db_get_row_count (int *row_count)
1047 {
1049  return csession_get_row_count (row_count);
1050 }
1051 
1052 /*
1053  * db_get_last_insert_id - get the value of the last updated serial
1054  * return: error code
1055  * value (out) : the value of the last updated serial
1056  */
1057 int
1059 {
1061  return csession_get_last_insert_id (value, true);
1062 }
1063 
1064 
1065 /*
1066  * db_get_variable () - get the value of a session variable
1067  * return : error code or NO_ERROR
1068  * name (in) : name of the variable
1069  * value (out): value of the variable
1070  */
1071 int
1073 {
1075  return csession_get_variable (name, value);
1076 }
1077 
1078 /*
1079  * TRANSACTION MANAGEMENT
1080  */
1081 
1082 /*
1083  * db_commit_transaction() - Commits the current transaction.
1084  * You must call this function if you want changes to be made permanent.
1085  * return : error code.
1086  *
1087  * note : If you call db_shutdown without calling this function,
1088  * the transaction will be aborted and the changes lost.
1089  */
1090 int
1092 {
1093  int retval;
1094 
1096  /* CHECK_MODIFICATION_ERROR (); */
1097 
1098  /* API does not support RETAIN LOCK */
1099  retval = tran_commit (false);
1100 
1101  return (retval);
1102 }
1103 
1104 /*
1105  * db_abort_transaction() - Abort the current transaction.
1106  * This will throw away all changes that have been made since the last call
1107  * to db_commit_transaction.
1108  * Currently this will invoke a garbage collection because its a
1109  * convenient place to test this and is probably what we want anyway.
1110  *
1111  * return : error code.
1112  */
1113 int
1115 {
1116  int error;
1117 
1119  /* CHECK_MODIFICATION_ERROR (); */
1120 
1121  error = tran_abort ();
1122 
1123  return (error);
1124 }
1125 
1126 /*
1127  * db_reset_latest_query_status() - Reset latest query status.
1128  *
1129  * return : error code
1130  */
1131 int
1133 {
1135 
1137 
1138  return NO_ERROR;
1139 }
1140 
1141 /*
1142  * db_commit_is_needed() - This function can be used to test to see if there
1143  * are any dirty objects in the workspace that have not been flushed OR
1144  * if there are any objects on the server that have been flushed but have
1145  * not been committed during the current transaction. This could be used
1146  * to display a warning message or prompt window in interface utilities
1147  * that gives the user a last chance to commit a transaction before
1148  * exiting the process.
1149  *
1150  * return : non-zero if there objects need to be committed
1151  *
1152  */
1153 int
1155 {
1156  int retval;
1157 
1159 
1160  retval = (tran_has_updated ())? 1 : 0;
1161 
1162  return (retval);
1163 }
1164 
1165 int
1166 db_savepoint_transaction_internal (const char *savepoint_name)
1167 {
1168  int retval;
1169 
1170  retval = tran_savepoint_internal (savepoint_name, USER_SAVEPOINT);
1171 
1172  return (retval);
1173 }
1174 
1175 /*
1176  * db_savepoint_transaction() - see the note below.
1177  *
1178  * returns/side-effects: error code.
1179  * savepoint_name(in) : Name of the savepoint
1180  *
1181  * note: A savepoint is established for the current transaction, so
1182  * that future transaction operations can be rolled back to this
1183  * established savepoint. This operation is called a partial
1184  * abort (rollback). That is, all database actions affected by
1185  * the transaction after the savepoint are "undone", and all
1186  * effects of the transaction preceding the savepoint remain. The
1187  * transaction can then continue executing other database
1188  * statements. It is permissible to abort to the same savepoint
1189  * repeatedly within the same transaction.
1190  * If the same savepoint name is used in multiple savepoint
1191  * declarations within the same transaction, then only the latest
1192  * savepoint with that name is available for aborts and the
1193  * others are forgotten.
1194  * There is no limit on the number of savepoints that a
1195  * transaction can have.
1196  */
1197 int
1198 db_savepoint_transaction (const char *savepoint_name)
1199 {
1200  int retval;
1201 
1203 
1204  retval = db_savepoint_transaction_internal (savepoint_name);
1205 
1206  return (retval);
1207 }
1208 
1209 int
1210 db_abort_to_savepoint_internal (const char *savepoint_name)
1211 {
1212  int error;
1213 
1214  if (savepoint_name == NULL)
1215  {
1216  return db_abort_transaction ();
1217  }
1218 
1219  error = tran_abort_upto_user_savepoint (savepoint_name);
1220 
1221  return (error);
1222 }
1223 
1224 /*
1225  * db_abort_to_savepoint() - All the effects of the current transaction
1226  * after the given savepoint are undone and all effects of the transaction
1227  * preceding the given savepoint remain. After the partial abort the
1228  * transaction can continue its normal execution as if the
1229  * statements that were undone were never executed.
1230  *
1231  * return : error code
1232  * savepoint_name(in): Name of the savepoint or NULL
1233  *
1234  * note: If savepoint_name is NULL, the transaction is aborted.
1235  */
1236 int
1237 db_abort_to_savepoint (const char *savepoint_name)
1238 {
1239  int error;
1240 
1243 
1244  error = db_abort_to_savepoint_internal (savepoint_name);
1245 
1246  return (error);
1247 }
1248 
1249 /*
1250  * db_set_global_transaction_info() - Set the user information related with
1251  * the global transaction. The global transaction identified by the
1252  * 'global_transaction_id' should exist and should be the value returned by
1253  * 'db_2pc_start_transaction'. You can use this function to set the longer
1254  * format of global transaction identifier such as XID of XA interface.
1255  *
1256  * return : error code.
1257  * global_transaction_id(in): global transaction identifier
1258  * info(in) : pointer to the user information to be set
1259  * size(in) : size of the user information to be set
1260  */
1261 int
1262 db_set_global_transaction_info (int global_transaction_id, void *info, int size)
1263 {
1264  int retval;
1265 
1268 
1269  if (global_transaction_id <= 0 || info == NULL || size <= 0)
1270  {
1272  return ER_OBJ_INVALID_ARGUMENTS;
1273  }
1274 
1275  retval = tran_set_global_tran_info (global_transaction_id, info, size);
1276 
1277  return (retval);
1278 }
1279 
1280 /*
1281  * db_get_global_transaction_info() - Get the user information of the global
1282  * transaction identified by the 'global_transaction_id'. You can use this function to
1283  * get the longer format of global transaction identifier such as XID of
1284  * XA interface. This function is designed to use if you want to get XID
1285  * after calling 'db_2pc_prepared_transactions' to support xa_recover()
1286  * return : error code.
1287  *
1288  * global_transaction_id: global transaction identifier
1289  * buffer(out):
1290  * pointer to the buffer into which the user information is stored
1291  * size(in) : size of the buffer
1292  *
1293  */
1294 int
1295 db_get_global_transaction_info (int global_transaction_id, void *buffer, int size)
1296 {
1297  int retval;
1298 
1301 
1302  if (global_transaction_id <= 0 || buffer == NULL || size <= 0)
1303  {
1305  return ER_OBJ_INVALID_ARGUMENTS;
1306  }
1307 
1308  retval = tran_get_global_tran_info (global_transaction_id, buffer, size);
1309 
1310  return (retval);
1311 }
1312 
1313 /*
1314  * db_2pc_start_transaction() - Make current transaction as a part of a global
1315  * transaction by assigning a global transaction identifier(global_transaction_id). It is
1316  * recommended to call this function just after the end of a transaction
1317  * (commit or abort) before executing other works. This function is one way
1318  * of getting global_transaction_id of the transaction. The other way is to use
1319  * 'db_2pc_prepare_to_commit_transaction'. The function
1320  * 'db_2pc_prepare_transaction' should be used if this function is called.
1321  *
1322  * return : return global transaction identifier
1323  *
1324  */
1325 
1326 int
1328 {
1329  int global_transaction_id;
1330 
1333 
1334  global_transaction_id = tran_2pc_start ();
1335 
1336  return (global_transaction_id);
1337 }
1338 
1339 /*
1340  * db_2pc_prepare_transaction() - Prepare the current transaction for
1341  * commitment in 2PC. The transaction should be made as a part of a global
1342  * transaction before by 'db_2pc_start_transaction', a pair one of this
1343  * function. The system promises not to unilaterally abort the transaction.
1344  * After this function call, the only API functions that should be executed
1345  * are 'db_commit_transaction' & 'db_abort_transaction'.
1346  *
1347  * return : error code.
1348  *
1349  */
1350 int
1352 {
1353  int retval;
1354 
1357 
1358  retval = tran_2pc_prepare ();
1359 
1360  return (retval);
1361 }
1362 
1363 /*
1364  * db_2pc_prepared_transactions() - For restart recovery of global transactions
1365  * , this function returns gtrids of transactions in prepared state, which
1366  * was a part of a global transaction. If the return value is less than the
1367  * 'size', there's no more transactions to recover.
1368  * return : the number of ids copied into 'gtrids[]'
1369  * gtrids(out) : array into which global transaction identifiers are copied
1370  * size : size of 'gtrids[]' array
1371  */
1372 int
1373 db_2pc_prepared_transactions (int gtrids[], int size)
1374 {
1375  int count;
1376 
1379 
1380  if (gtrids == NULL || size <= 0)
1381  {
1383  return ER_OBJ_INVALID_ARGUMENTS;
1384  }
1385 
1386  count = tran_2pc_recovery_prepared (gtrids, size);
1387 
1388  return (count);
1389 } /* db_2pc_prepared_transactions() */
1390 
1391 /*
1392  * db_2pc_attach_transaction() - Attaches the user to the transaction that was
1393  * the local part of the specified global transaction. The current
1394  * transaction is aborted before the attachement takes place. The current
1395  * transaction must not be in the middle of a 2PC. It is recommended to
1396  * attach a client to a 2PC loose end transaction just after the client
1397  * restart or after a commit or abort.
1398  *
1399  * return : error code.
1400  * global_transaction_id(in): Global transaction identifier.
1401  */
1402 int
1403 db_2pc_attach_transaction (int global_transaction_id)
1404 {
1405  int retval;
1406 
1409 
1410  retval = tran_2pc_attach_global_tran (global_transaction_id);
1411 
1412  return (retval);
1413 }
1414 
1415 /*
1416  * db_2pc_prepare_to_commit_transaction() - This function prepares the
1417  * transaction identified by "global_transaction_id" for commitment. The system promises
1418  * not to unilaterally abort the transaction. After this function call, the
1419  * only API functions that should be executed are db_commit_transaction
1420  * & db_abort_transaction.
1421  * return : error code.
1422  * global_transaction_id(in): Identifier of the global transaction.
1423  *
1424  */
1425 int
1426 db_2pc_prepare_to_commit_transaction (int global_transaction_id)
1427 {
1428  int retval;
1429 
1432 
1433  retval = tran_2pc_prepare_global_tran (global_transaction_id);
1434 
1435  return (retval);
1436 }
1437 
1438 /*
1439  * db_set_interrupt: Set or clear a database interruption flags.
1440  * return : void
1441  * set(in): Set or clear an interruption
1442  *
1443  */
1444 void
1446 {
1447  CHECK_CONNECT_VOID ();
1449 }
1450 
1451 /*
1452  * db_set_suppress_repl_on_transaction : Suppress writing replication logs during
1453  * setting the flag on the transaction
1454  *
1455  * return : void
1456  * set(in): Set or clear the flag
1457  *
1458  */
1459 int
1461 {
1464 }
1465 
1466 /*
1467  * db_checkpoint: Set or clear a database interruption flags.
1468  * return : void
1469  * set(in): Set or clear an interruption
1470  *
1471  */
1472 int
1474 {
1476  return log_checkpoint ();
1477 }
1478 
1479 /*
1480  * db_set_lock_timeout() - This sets a timeout on the amount of time to spend
1481  * waiting to aquire a lock on an object. Normally the system will wait
1482  * forever for a lock to be granted. If you enable lock timeouts, you must
1483  * be prepared to handle lock failure errors at the return of any function
1484  * that performs an operation on a DB_OBJECT. A timeout value of zero
1485  * indicates that there is no timeout and the system will return immediately
1486  * if the lock cannot be granted. A positive integer indicates the maximum
1487  * number of seconds to wait. A value of -1 indicates an infinite timeout
1488  * where the system will wait forever to aquire the lock. Infinite timeout
1489  * is the default behavior.
1490  *
1491  * return : the old timeout value.
1492  * seconds(in) : the new timeout value
1493  *
1494  */
1495 int
1496 db_set_lock_timeout (int seconds)
1497 {
1498  int retval;
1499 
1502 
1503  if (seconds > 0)
1504  {
1505  retval = tran_reset_wait_times (seconds * 1000);
1506  }
1507  else
1508  {
1509  retval = tran_reset_wait_times (seconds);
1510  }
1511 
1512 
1513  return (retval);
1514 }
1515 
1516 /*
1517  * db_set_isolation() - Set the isolation level for present and future client
1518  * transactions to the given isolation level. It is recommended to set the
1519  * isolation level at the beginning of the client transaction. If the
1520  * isolation level is set in the middle of the client transaction, some
1521  * resources/locks acquired by the current transactions may be released at
1522  * this point according to the new isolation level. We say that the
1523  * transaction will see the given isolation level from this point on.
1524  * However, we should not call the transaction as one of that isolation
1525  * level.
1526  * For example, if a transaction with TRAN_READ_COMMITTED
1527  * is change to TRAN_REPEATABLE_READ, we cannot say that the
1528  * transaction has run with the last level of isolation...just that a part
1529  * of the transaction was run with that.
1530  *
1531  * return : error code.
1532  * isolation(in) : new Isolation level.
1533  */
1534 int
1536 {
1537  int retval;
1538 
1540 
1541  retval = tran_reset_isolation (isolation, TM_TRAN_ASYNC_WS ());
1542  return (retval);
1543 }
1544 
1545 /*
1546  * db_get_tran_settings() - Retrieve transaction settings.
1547  * return : none
1548  * lock_wait(out) : Transaction lock wait assigned to client transaction
1549  * (Set as a side effect)
1550  * tran_isolation(out) : Transaction isolation assigned to client transactions
1551  * (Set as a side effect)
1552  */
1553 void
1554 db_get_tran_settings (int *lock_wait, DB_TRAN_ISOLATION * tran_isolation)
1555 {
1556  bool dummy;
1557  int lock_timeout_in_msecs = -1;
1558 
1559  CHECK_CONNECT_VOID ();
1560  /* API does not support ASYNC WORKSPACE */
1561  tran_get_tran_settings (&lock_timeout_in_msecs, tran_isolation, &dummy /* async_ws */ );
1562  if (lock_timeout_in_msecs > 0)
1563  {
1564  *lock_wait = lock_timeout_in_msecs / 1000;
1565  }
1566  else
1567  {
1568  *lock_wait = lock_timeout_in_msecs;
1569  }
1570 }
1571 
1572 /*
1573  * db_synchronize_cache() - Decache any obsolete objects that were accessed by
1574  * the current transaction. This can happen when the client transaction
1575  * is not running with TRAN_REPEATABLE_READ isolation level.
1576  * That is some of the locks for accessed objects were relesed. CUBRID
1577  * tries to synchronize the client cache by decaching accessed objects
1578  * that have been updated by other transactions. This is done when
1579  * objects are fetched, as part of the fetch notification of
1580  * inconsistent objects are collected and brought to the client cache.
1581  *
1582  * return : nothing
1583  *
1584  */
1585 void
1587 {
1588  CHECK_CONNECT_VOID ();
1589 
1591 }
1592 
1593 /*
1594  * AUTHORIZATION
1595  */
1596 
1597 /*
1598  * db_find_user() - Returns the database object for a named user if that user
1599  * has been defined to the authorization system.
1600  * return : user object
1601  * name(in): user name
1602  *
1603  */
1604 
1605 DB_OBJECT *
1606 db_find_user (const char *name)
1607 {
1608  DB_OBJECT *retval;
1609 
1610  CHECK_CONNECT_NULL ();
1611  CHECK_1ARG_NULL (name);
1612 
1613  retval = au_find_user (name);
1614  return (retval);
1615 }
1616 
1617 /*
1618  * db_find_user_to_drop() - find the object by name user for dropping.
1619  *
1620  * return : error code
1621  * name(in): user name
1622  * user(out): user object
1623  *
1624  */
1625 int
1626 db_find_user_to_drop (const char *name, DB_OBJECT ** user)
1627 {
1629  CHECK_1ARG_ERROR (name);
1630 
1631  return au_find_user_to_drop (name, user);
1632 }
1633 
1634 /*
1635  * db_add_user() - This will add a new user to the database. Only the DBA can
1636  * add users. If the user already exists, its object pointer will be
1637  * returned and the exists flag will be set to non-zero. The exists
1638  * pointer can be NULL if the caller isn't interested in this value.
1639  *
1640  * return : new user object
1641  * name(in) : user name
1642  * exists(out): pointer to flag, set if user already exists
1643  *
1644  */
1645 DB_OBJECT *
1646 db_add_user (const char *name, int *exists)
1647 {
1648  DB_OBJECT *retval;
1649 
1650  CHECK_CONNECT_NULL ();
1651  CHECK_1ARG_NULL (name);
1653 
1654  retval = au_add_user (name, exists);
1655 
1656  return (retval);
1657 }
1658 
1659 /*
1660  * db_drop_user() - This will remove a user from the database. Only the DBA
1661  * can remove user objects. You should call this rather than db_drop so
1662  * that the internal system tables are updated correctly.
1663  * return : error code.
1664  * user(in): user object pointer
1665  *
1666  */
1667 int
1669 {
1670  int retval;
1671 
1673  CHECK_1ARG_ERROR (user);
1675 
1676  retval = au_drop_user (user);
1677 
1678  return (retval);
1679 }
1680 
1681 /*
1682  * db_add_member() - Adds a member to a user/group. Recall that users and
1683  * groups are exactly the same object, groups are just a convenient
1684  * nameing convention to refer to users with members. The member will
1685  * inherit all privilidges granted to the user either directly or
1686  * indirectly.
1687  *
1688  * return : error code
1689  * user(in/out) : user/group to get the new member
1690  * member(in/out): member user to add
1691  *
1692  */
1693 int
1695 {
1696  int retval;
1697 
1699  CHECK_2ARGS_ERROR (user, member);
1701 
1702  retval = au_add_member (user, member);
1703 
1704  return (retval);
1705 }
1706 
1707 /*
1708  * db_drop_member() - removes a member from a user/group. The removed member
1709  * loses all privilidges that were inherted directely or indirectely from
1710  * the group.
1711  *
1712  * return : error code
1713  * user(in/out) : user/group that needs member removed
1714  * member(in/out): member to remove
1715  *
1716  */
1717 
1718 int
1720 {
1721  int retval;
1722 
1724  CHECK_2ARGS_ERROR (user, member);
1726 
1727  retval = au_drop_member (user, member);
1728 
1729  return (retval);
1730 }
1731 
1732 /*
1733  * db_set_password() - This is used to change the password string for a user
1734  * object. The current password must be provided and match correctly before
1735  * the new one is assigned.
1736  * return : Error code
1737  * user(out) : user object
1738  * old_passwd(in) : the old password
1739  * new_passwd(in) : the new password
1740  *
1741  */
1742 int
1743 db_set_password (DB_OBJECT * user, const char *old_passwd, const char *new_passwd)
1744 {
1745  int retval;
1746 
1748  CHECK_1ARG_ERROR (user);
1750 
1751  /* should check old password ! */
1752  retval = au_set_password (user, new_passwd);
1753 
1754  return (retval);
1755 }
1756 
1757 /*
1758  * db_set_user_comment() - This is used to set the comment string for a user.
1759  * return : Error code
1760  * user(out) : user object
1761  * comment(in) : a comment string
1762  *
1763  */
1764 int
1765 db_set_user_comment (DB_OBJECT * user, const char *comment)
1766 {
1767  int retval;
1768 
1770  CHECK_1ARG_ERROR (user);
1772 
1773  retval = au_set_user_comment (user, comment);
1774 
1775  return (retval);
1776 }
1777 
1778 /*
1779  * db_grant() -This is the basic mechanism for passing permissions to other
1780  * users. The authorization type is one of the numeric values defined
1781  * by the DB_AUTH enumeration. If more than one authorization is to
1782  * be granted, the values in DB_AUTH can be combined using the C bitwise
1783  * "or" operator |. Errors are likely if the currently logged in user
1784  * was not the owner of the class and was not given the grant_option for
1785  * the desired authorization types.
1786  * return : error code
1787  * user(in) : a user object
1788  * class(in) : a class object
1789  * auth(in) : an authorization type
1790  * grant_option(in) : true if the grant option is to be added
1791  *
1792  */
1793 int
1794 db_grant (MOP user, MOP class_, AU_TYPE auth, int grant_option)
1795 {
1796  int retval;
1797 
1799  CHECK_2ARGS_ERROR (user, class_);
1801 
1803  if (!retval)
1804  {
1805  retval = au_grant (user, class_, auth, (bool) grant_option);
1806  }
1807 
1808  return (retval);
1809 }
1810 
1811 /*
1812  * db_revoke() - This is the basic mechanism for revoking previously granted
1813  * authorizations. A prior authorization must have been made.
1814  * returns : error code
1815  * user(in) : a user object
1816  * class_mop(in): a class object
1817  * auth(in) : the authorization type(s) to revoke
1818  *
1819  */
1820 int
1821 db_revoke (MOP user, MOP class_mop, AU_TYPE auth)
1822 {
1823  int retval;
1824 
1826  CHECK_2ARGS_ERROR (user, class_mop);
1828 
1829  retval = do_check_partitioned_class (class_mop, CHECK_PARTITION_SUBS, NULL);
1830  if (!retval)
1831  {
1832  retval = au_revoke (user, class_mop, auth);
1833  }
1834 
1835  return (retval);
1836 }
1837 
1838 /*
1839  * db_check_authorization() - This will check to see if a particular
1840  * authorization is available for a class. An error will be returned
1841  * if the authorization was not granted.
1842  * return : error status
1843  * op(in) : class or instance object
1844  * auth(in): authorization type
1845  *
1846  */
1847 int
1849 {
1850  SM_CLASS *class_;
1851  int retval;
1852 
1854  CHECK_1ARG_ERROR (op);
1855 
1856  /* should try to get a write lock on the class if the authorization type is AU_ALTER or AU_INDEX ? */
1857 
1858  retval = (au_fetch_class (op, &class_, AU_FETCH_READ, auth));
1859 
1860  return (retval);
1861 }
1862 
1863 /*
1864  * db_check_authorization() - same as db_check_authorization but also checks
1865  * for the grant option.
1866  * return : error status
1867  * op(in) : class or instance object
1868  * auth(in): authorization type
1869  *
1870  */
1871 int
1873 {
1874  SM_CLASS *class_;
1875  int retval;
1876 
1878  CHECK_1ARG_ERROR (op);
1879 
1880  retval = (au_fetch_class (op, &class_, AU_FETCH_READ, (DB_AUTH) (auth | (auth << AU_GRANT_SHIFT))));
1881 
1882  return (retval);
1883 }
1884 
1885 /*
1886  * db_get_owner() - returns the user object that owns the class.
1887  * return : owner object
1888  * class(in): class object
1889  *
1890  */
1891 DB_OBJECT *
1893 {
1894  DB_OBJECT *retval;
1895 
1896  CHECK_CONNECT_NULL ();
1897  CHECK_1ARG_NULL (class_obj);
1898 
1899  retval = au_get_class_owner (class_obj);
1900  return (retval);
1901 }
1902 
1903 /*
1904  * db_get_user_name() - This returns the name of the user that is currently
1905  * logged in. It simply makes a copy of the authorization name buffer.
1906  * The returned string must later be freed with db_string_free.
1907  *
1908  * return : name of current user
1909  */
1910 char *
1912 {
1913  const char *name;
1914 
1915  CHECK_CONNECT_NULL ();
1916 
1917  /* Kludge, twiddle the constness of this thing. It probably doesn't need to be const anyway, its just a copy of the
1918  * attribute value. */
1919  name = au_user_name ();
1920 
1921  return ((char *) name);
1922 }
1923 
1924 /*
1925  * db_get_user_and_host_name() - This returns the name of the user that is
1926  * currently logged in and the host name. Format for return value is
1927  * user_name@host_name
1928  *
1929  * return : user and host name
1930  */
1931 char *
1933 {
1934  char *user = NULL;
1935  char *username = NULL;
1937  int len;
1938 
1939  if (GETHOSTNAME (hostname, CUB_MAXHOSTNAMELEN) != 0)
1940  {
1941  return NULL;
1942  }
1943 
1944  username = db_get_user_name ();
1945  if (!username)
1946  {
1947  return NULL;
1948  }
1949 
1950  len = (int) strlen (hostname) + (int) strlen (username) + 2;
1951  user = (char *) db_private_alloc (NULL, len);
1952  if (!user)
1953  {
1954  db_string_free (username);
1956  return 0;
1957  }
1958 
1959  strcpy (user, username);
1960  strcat (user, "@");
1961  strcat (user, hostname);
1962  db_string_free (username);
1963 
1964  return user;
1965 }
1966 
1967 /*
1968  * db_get_user() - This returns the user object of the current user. If no user
1969  * has been logged in, it returns NULL. No error is set if NULL is returned,
1970  * it simply means that there is no active user.
1971  * return : name of current user
1972  */
1973 DB_OBJECT *
1975 {
1976  return Au_user;
1977 }
1978 
1979 /*
1980  * db_print_stats() - Debugging function for printing misc database statistics.
1981  * return : void.
1982  *
1983  */
1984 void
1986 {
1987  ws_dump (stdout);
1988 }
1989 
1990 /*
1991  * db_lock_read() - This function attempts to secure a read lock on a
1992  * particular object. If the lock could not be obtained an error is
1993  * returned. This should be used whenever there are a sequence of read
1994  * operations to be performed on an object. This allows the implementor
1995  * to check once for object availablity and then assume that subsequent
1996  * references will always succeed in locking.
1997  * return : error code
1998  * op(in) : object pointer
1999  */
2000 int
2002 {
2003  int retval;
2004 
2006  CHECK_1ARG_ERROR (op);
2007 
2008  retval = (obj_lock (op, 0));
2009 
2010  return (retval);
2011 }
2012 
2013 /*
2014  * db_lock_write() - This function attempts to secure a write lock on a
2015  * partiular object.If the lock could not be obtained, an error is returned.
2016  * This should be used whenever a sequence of write or read operations
2017  * is to be performed on an object. This allows the implementor to check
2018  * once for object availability and then assume that subsequent references
2019  * will always succeed in locking.
2020  * return : error code
2021  * op(in) : object pointer
2022  *
2023  * note: it is important that if an application knows that update/write
2024  * operations will be done to an object that a write lock be obtained BEFORE
2025  * obtaining a read lock or performing any operations that obtain read locks
2026  * Upgrading a read lock to a write lock incurrs some overhead so it is
2027  * beneficial to plan ahead and request the write lock at first.
2028  */
2029 int
2031 {
2032  int retval;
2033 
2035  CHECK_1ARG_ERROR (op);
2036 
2037  retval = (obj_lock (op, 1));
2038 
2039  return (retval);
2040 }
2041 
2042 /*
2043  * GENERAL INFORMATION FUNCTIONS
2044  */
2045 
2046 /*
2047  * db_freepgs() - Returns the number of free pages on a particular database
2048  * volume. The semantics of this function are a bit unclear currently
2049  * since support for multiple database volumes is still being defined.
2050  * return : the number of free pages
2051  * volume_label(in) : volume label name
2052  */
2053 int
2054 db_freepgs (const char *volume_label)
2055 {
2056  int retval;
2057 
2058  CHECK_CONNECT_ZERO ();
2059 
2060  retval = ((int) disk_get_free_numpages (NULL_VOLID));
2061 
2062  return (retval);
2063 }
2064 
2065 /*
2066  * db_totalpgs() - Returns the total number of pages on a volume. The semantics
2067  * of this function are unclear as support for multiple database volumes is
2068  * still being defined.
2069  * return : the number of total pages on a volume
2070  * volume_label(in) : volume name
2071  */
2072 int
2073 db_totalpgs (const char *volume_label)
2074 {
2075  int retval;
2076 
2077  CHECK_CONNECT_ZERO ();
2078 
2079  retval = ((int) disk_get_total_numpages (NULL_VOLID));
2080 
2081  return (retval);
2082 }
2083 
2084 /*
2085  * ERROR INTERFACE
2086  */
2087 
2088 const char *
2090 {
2091  const char *retval;
2092 
2093  retval = db_error_string (level);
2094  return (retval);
2095 }
2096 
2097 /*
2098  * db_error_string() - This is used to get a string describing the LAST error
2099  * that was detected in the database system.
2100  * Whenever a db_ function returns an negative error code or when they
2101  * return results such as NULL pointers that indicate error, the error will
2102  * have been stored in a global structure that can be examined to find out
2103  * more about the error.
2104  * The string returned will be overwritten when the next error is detected
2105  * so it may be necessary to copy it to a private area if you need to keep
2106  * it for some lenght of time. The level parameter controls the amount of
2107  * information to be included in the message, level 1 is for short messages,
2108  * level 3 is for longer error messages. Not all error conditions
2109  * (few in fact) have level 3 descriptions, all have level 1 descriptions.
2110  * If you ask for level 3 and there is no description present, you will be
2111  * returned the description at the next highest level.
2112  * return : string containing description of the error
2113  * level(in) : level of description
2114  */
2115 const char *
2116 db_error_string (int level)
2117 {
2118  /* this can be called when the database is not started */
2119  return er_msg ();
2120 }
2121 
2122 int
2124 {
2125  int retval;
2126 
2127  retval = db_error_code ();
2128  return (retval);
2129 }
2130 
2131 /*
2132  * db_error_code() - This is used to get an integer code identifying the LAST
2133  * error that was detected by the database. See the description under
2134  * db_error_string for more information on how error descriptions are
2135  * maintained. Normally, an application would use db_error_string
2136  * to display error messages to the user. It may be useful in some
2137  * cases to let an application examine the error code and conditionalize
2138  * execution to handle a particular event. In these cases, this function
2139  * can be used to get the error code.
2140  * return : a error code constant
2141  */
2142 int
2144 {
2145  int retval;
2146 
2147  /* can be called when the database is not started */
2148  retval = ((int) er_errid ());
2149  return (retval);
2150 }
2151 
2152 /*
2153  * db_error_init() - This is used to initialize the output log file for
2154  * database error messages. It should be used by tools that wish to
2155  * redirect error messages from the console.
2156  * If this routine is not called, all errors and warnings are printed
2157  * to stderr. This should be called Immediately after a database restart
2158  * and must be called again after a shutdown/restart sequence
2159  * (i.e. the specified file is closed) when the database is shut down).
2160  * return : true if successful, false if not successful
2161  * logfile(in) : pathname for log messages.
2162  */
2163 int
2164 db_error_init (const char *logfile)
2165 {
2166  /* can be called when the database is not started */
2168  return (1);
2169 }
2170 
2171 /*
2172  *
2173  * db_register_error_loghandler () - This function registers user supplied
2174  * error log handler function (db_error_log_handler_t type) which is called
2175  * whenever DBMS error message is to be logged.
2176  *
2177  * return : previously registered error log handler function (may be NULL)
2178  * f (in) : user supplied error log handler function
2179  *
2180  */
2181 
2184 {
2186 }
2187 
2188 /*
2189  * CLUSTER FETCH FUNCTIONS
2190  */
2191 
2192 /*
2193  * db_fetch_array() -
2194  * This function can be used to lock and fetch a collection of objects in a
2195  * single call to the server. This is provided only for performance reasons.
2196  * The objarray is a user allocated array of object pointers. The last
2197  * entry in the array must be NULL.
2198  * The purpose argument specifies for what type of operation the objects
2199  * are needed. Depending upon the operation the system will select the
2200  * needed lock.
2201  * If quit_on_error is zero, an attempt will be made to fetch all of the
2202  * objects in the array. If one of the objects could not be fetched with
2203  * the indicated lock, it will be ignored. In this case, an error code
2204  * will be returned only if there was another system error such as
2205  * unilateral abort due to a deadlock detection.
2206  * If quit_on_error is non-zero, the operation will stop the first time a
2207  * lock cannot be obtained on any object. The lock error will then be
2208  * returned by this function.
2209  * return : error condition
2210  * objects(out) : array of object pointers (NULL terminated)
2211  * purpose(in) : fetch purpose
2212  * quit_on_error(in): non-zero if operation quits at first error
2213  */
2214 
2215 int
2216 db_fetch_array (DB_OBJECT ** objects, DB_FETCH_MODE purpose, int quit_on_error)
2217 {
2218  int error = NO_ERROR;
2219  int count = 0;
2220  MOBJ obj;
2221 
2223  CHECK_1ARG_ERROR (objects);
2224 
2225  if (purpose != DB_FETCH_READ && purpose != DB_FETCH_WRITE)
2226  {
2227  purpose = DB_FETCH_READ;
2228  }
2229 
2230  for (count = 0; objects[count] != NULL; count++)
2231  {
2232  ;
2233  }
2234 
2235  obj = locator_fetch_set (count, objects, purpose, DB_FETCH_READ, quit_on_error);
2236  if (obj == NULL)
2237  {
2238  assert (er_errid () != NO_ERROR);
2239  error = er_errid ();
2240  }
2241  return (error);
2242 }
2243 
2244 /*
2245  * db_fetch_list() - This is a list interface to db_fetch_array. It simply
2246  * constructs an array of objects pointers given an object list.
2247  * return : error code
2248  * objects(in/out) : object list
2249  * purpose(in) : fetch purpose
2250  * quit_on_error(in): non-zero if operation quits after first error
2251  *
2252  */
2253 int
2254 db_fetch_list (DB_OBJLIST * objects, DB_FETCH_MODE purpose, int quit_on_error)
2255 {
2256  int error = NO_ERROR;
2257  DB_OBJECT **object_array;
2258  DB_OBJLIST *object_list;
2259  int len, i;
2260 
2261  len = db_list_length ((DB_LIST *) objects);
2262  if (len)
2263  {
2264  object_array = (DB_OBJECT **) malloc (sizeof (DB_OBJECT *) * (len + 1));
2265  if (object_array != NULL)
2266  {
2267  for (object_list = objects, i = 0; object_list != NULL; object_list = object_list->next, i++)
2268  {
2269  object_array[i] = object_list->op;
2270  }
2271  object_array[len] = NULL;
2272  error = db_fetch_array (object_array, purpose, quit_on_error);
2273 
2274  /* make sure we don't leave any GC roots around */
2275  for (i = 0; i < len; i++)
2276  object_array[i] = NULL;
2277  free_and_init (object_array);
2278  }
2279  }
2280  return (error);
2281 }
2282 
2283 /*
2284  * fetch_set_internal() -
2285  * This is used to fetch all of the objects contained in a set
2286  * in a single call to the server. It is a convenience function that
2287  * behaves similar to db_fetch_array().
2288  * If quit_on_error is zero, an attempt will be made to fetch all of the
2289  * objects in the array. If one of the objects could not be fetched with
2290  * the indicated lock, it will be ignored. In this case, an error code will
2291  * be returned only if there was another system error such as unilateral
2292  * abort due to a deadlock detection.
2293  * If quit_on_error is non-zero, the operation will stop the first time a
2294  * lock cannot be obtained on any object. The lock error will then be
2295  * returned by this function.
2296  * return : error code
2297  * set(in/out) : a set object
2298  * purpose(in) : fetch purpose
2299  * quit_on_error(in): non-zero if operation quits after first error
2300  */
2301 static int
2302 fetch_set_internal (DB_SET * set, DB_FETCH_MODE purpose, int quit_on_error)
2303 {
2304  int error = NO_ERROR;
2305  DB_VALUE value;
2306  MOBJ obj;
2307  int max, cnt, i;
2308  DB_OBJECT **mops;
2309  size_t buf_size;
2310 
2312  CHECK_1ARG_ERROR (set);
2313 
2314  if (purpose != DB_FETCH_READ && purpose != DB_FETCH_WRITE)
2315  {
2316  purpose = DB_FETCH_READ;
2317  }
2318 
2319  max = set_size (set);
2320  if (max)
2321  {
2322  buf_size = (max + 1) * sizeof (DB_OBJECT *);
2323  mops = (DB_OBJECT **) malloc (buf_size);
2324  if (mops == NULL)
2325  {
2326  error = ER_OUT_OF_VIRTUAL_MEMORY;
2328  return error;
2329  }
2330  cnt = 0;
2331 
2332  for (i = 0; i < max && error == NO_ERROR; i++)
2333  {
2334  error = set_get_element (set, i, &value);
2335  if (error == NO_ERROR)
2336  {
2337  if (DB_VALUE_TYPE (&value) == DB_TYPE_OBJECT && db_get_object (&value) != NULL)
2338  {
2339  mops[cnt] = db_get_object (&value);
2340  cnt++;
2341  }
2342  db_value_clear (&value);
2343  }
2344  }
2345  mops[cnt] = NULL;
2346  if (error == NO_ERROR && cnt)
2347  {
2348  obj = locator_fetch_set (cnt, mops, purpose, DB_FETCH_READ, quit_on_error);
2349  if (obj == NULL)
2350  {
2351  error = er_errid ();
2352  }
2353  }
2354 
2355  for (i = 0; i < max; i++)
2356  mops[i] = NULL;
2357 
2358  free_and_init (mops);
2359  }
2360 
2361  return (error);
2362 }
2363 
2364 /*
2365  * db_fetch_set() - see the function fetch_set_internal()
2366  * return : error code
2367  * set(in/out) : a set object
2368  * purpose(in) : fetch purpose
2369  * quit_on_error(in): non-zero if operation quits after first error
2370  */
2371 int
2372 db_fetch_set (DB_SET * set, DB_FETCH_MODE purpose, int quit_on_error)
2373 {
2374  int retval;
2375 
2376  retval = (fetch_set_internal (set, purpose, quit_on_error));
2377  return (retval);
2378 }
2379 
2380 /*
2381  * db_fetch_seq() - see the function fetch_set_internal()
2382  * return : error code
2383  * seq(in/out) : a seq object
2384  * purpose(in) : fetch purpose
2385  * quit_on_error(in): non-zero if operation quits after first error
2386  */
2387 int
2388 db_fetch_seq (DB_SEQ * seq, DB_FETCH_MODE purpose, int quit_on_error)
2389 {
2390  int retval;
2391 
2392  retval = (fetch_set_internal ((DB_SET *) seq, purpose, quit_on_error));
2393  return (retval);
2394 }
2395 
2396 /*
2397  * db_fetch_composition() -
2398  * This function locks and fetches a composition hierarchy in a single
2399  * call to the server. It is provided for performance only.
2400  * return : error code
2401  * object(in/out) : object that is the root of a composition hierarchy
2402  * purpose(in) : fetch purpose
2403  * max_level(in) : maximum composition depth
2404  * quit_on_error(in) : non-zero if operation quits after first error
2405  */
2406 int
2407 db_fetch_composition (DB_OBJECT * object, DB_FETCH_MODE purpose, int max_level, int quit_on_error)
2408 {
2409  int error = NO_ERROR;
2410  MOBJ obj = NULL;
2411 
2413  CHECK_1ARG_ERROR (object);
2414 
2415  if (purpose != DB_FETCH_READ && purpose != DB_FETCH_WRITE)
2416  {
2417  purpose = DB_FETCH_READ;
2418  }
2419 
2420  object = db_real_instance (object);
2421  if (object != NULL && !WS_ISVID (object))
2422  {
2423  obj = locator_fetch_nested (object, purpose, max_level, quit_on_error);
2424  }
2425  else
2426  {
2427  /* we don't do proxies, but probably should. This protects locator_fetch from virtual db_objects */
2429  }
2430  if (obj == NULL)
2431  {
2432  assert (er_errid () != NO_ERROR);
2433  error = er_errid ();
2434  }
2435 
2436  return (error);
2437 }
2438 
2439 /*
2440  * MISC UTILITIES
2441  */
2442 
2443 /*
2444  * db_warnspace() - Enables low storage warning messages for a particular
2445  * database volume. If enabled, when the number of free pages on a volume
2446  * falls below a certain threshold, warning messages will be sent to the
2447  * log or console.
2448  * This function currently has no effect.
2449  * volume_label(in) : volume name
2450  */
2451 void
2452 db_warnspace (const char *volume_label)
2453 {
2454  CHECK_CONNECT_VOID ();
2455 
2456 #if 0
2457  if (volume_label == NULL)
2458  {
2459  dk_warnspace (0);
2460  }
2461  else
2462  {
2463  dk_warnspace (fileio_find_volume_id_with_label (volume_label));
2464  }
2465 #endif
2466 }
2467 
2468 /*
2469  * db_preload_classes() - This can be used to preload the methods for a group
2470  * of classes at one time thereby avoiding repeated dynamic links as the
2471  * classes are fetched on demand.
2472  * return : void
2473  * names(in) : a "varargs" list of names terminated with NULL
2474  */
2475 void
2476 db_preload_classes (const char *name1, ...)
2477 {
2478  va_list variable_argument;
2479  DB_OBJLIST *classes = NULL;
2480  const char *name;
2481  MOP op;
2482 
2483  CHECK_CONNECT_VOID ();
2484 
2485  va_start (variable_argument, name1);
2486 
2487  name = name1;
2488  while (name != NULL)
2489  {
2490  op = sm_find_class (name);
2491  if (op != NULL)
2492  {
2493  if (ml_add (&classes, op, NULL))
2494  {
2495  return; /* memory error, abort */
2496  }
2497  }
2498  name = va_arg (variable_argument, const char *);
2499  }
2500  va_end (variable_argument);
2501 
2502  sm_prelink_methods (classes);
2503 }
2504 
2505 /*
2506  * db_link_static_methods() - This is used to specify the implementation
2507  * functions for methods that are statically linked with the application
2508  * program and do not need to be dynamically linked. The method link
2509  * strucutre contains a string that must match the implementation name for
2510  * a method and a function pointer that points to the actual function to be
2511  * used when the method is invoked. You can call this function any number
2512  * of times. The actual linkage information is kept in a global table and
2513  * will persist between restart/shutdown sequences of the database.
2514  * return : void
2515  * methods(in) : an array of method link structures
2516  *
2517  * note : This is one of the very few db_ functions that can be called before
2518  * a database is opened with db_restart.
2519  * If an entry for a particular function name was already made, it will
2520  * be replaced with the new function pointer.
2521  */
2522 void
2524 {
2526 
2527  if (methods != NULL)
2528  {
2529  for (method_link = methods; method_link->method != NULL; method_link++)
2530  sm_add_static_method (method_link->method, method_link->function);
2531  }
2532 }
2533 
2534 /*
2535  * db_unlink_static_methods() - This can be used to remove static linking
2536  * information for methods that were previously defined with
2537  * db_link_static_methods.
2538  * It not usually necessary to call this function. The static method
2539  * definitions generally persist for the duration of the application
2540  * program.
2541  * return : void
2542  * methods(in) : an array of method link structures
2543  */
2544 
2545 void
2547 {
2549 
2550  if (methods != NULL)
2551  {
2552  for (method_link = methods; method_link->method != NULL; method_link++)
2553  sm_delete_static_method (method_link->method);
2554  }
2555 }
2556 
2557 /*
2558  * db_flush_static_methods() - Removes ALL static link information from the
2559  * system. This could be used prior to database termination to make sure
2560  * that all system resources have been cleaned up.
2561  * return : void
2562  */
2563 void
2565 {
2567 }
2568 
2569 /*
2570  * db_force_method_reload() - This is strictly a debugging function that can
2571  * be used to force the dynamic linker to reload the methods for a class.
2572  * This would be done if the methods has already been linked, and a change
2573  * was made to the external .o file.
2574  * This probably should not be an exported db_ function.
2575  * return : void
2576  * obj(in) : class or instance
2577  */
2578 void
2580 {
2581  CHECK_CONNECT_VOID ();
2582 
2583  /* handles NULL */
2584  sm_force_method_link (obj);
2585 
2586 }
2587 
2588 /*
2589  * db_string_free() - Used to free strings that have been returned from any of
2590  * the db_ functions.
2591  * return : void
2592  * string(in): a string that was allocated within the workspace
2593  *
2594  */
2595 void
2596 db_string_free (char *string)
2597 {
2598  /* don't check connection here, we always allow things to be freed */
2599  if (string != NULL)
2600  {
2601  db_ws_free (string);
2602  }
2603 }
2604 
2605 /*
2606  * db_objlist_free() - free an object list that was returned by one of the
2607  * other db_ functions.
2608  * returns/side-effects: none
2609  * list(in): an object list
2610  */
2611 void
2613 {
2614  /* don't check connection here, we always allow things to be freed */
2615  /* the list must have been allocated with the ml_ext functions */
2616  if (list != NULL)
2617  {
2618  ml_ext_free (list);
2619  }
2620 }
2621 
2622 /*
2623  * db_identifier() - This function returns the permanent object identifier of
2624  * the given object.
2625  * return : Pointer to object identifier
2626  * obj(in): Object
2627  */
2628 DB_IDENTIFIER *
2630 {
2631  return ws_identifier_with_check (obj, true);
2632 }
2633 
2634 /*
2635  * db_object() - This function returns the object (MOP) associated with given
2636  * permanent object identifier.
2637  * return : Pointer to Object
2638  * oid(in): Permanent Object Identifier
2639  */
2640 DB_OBJECT *
2642 {
2643  DB_OBJECT *retval;
2644 
2645  retval = ws_mop (oid, NULL);
2646 
2647  return (retval);
2648 }
2649 
2650 /*
2651  * db_chn() - This function finds the cache coherency number of the given
2652  * object.
2653  * The cache coherency number of an object changes (increased by one) when
2654  * the object is flushed after the object is altered.
2655  * return : cache coherecy number
2656  * obj(in): Object
2657  * purpose(in): fetch purpose
2658  */
2659 int
2661 {
2662  int chn;
2663 
2664 #if 0 /* currently, unused */
2665  if (purpose != DB_FETCH_READ && purpose != DB_FETCH_WRITE)
2666  purpose = DB_FETCH_READ;
2667 #endif
2668 
2669  chn = locator_get_cache_coherency_number (obj); /* with DB_FETCH_READ */
2670 
2671  return chn;
2672 }
2673 
2674 /*
2675  * db_set_system_parameters () - set new values to system parameters
2676  *
2677  * return : error code
2678  * data (in) : string with new parameter values defined as:
2679  * "param1=new_val1; param2=new_val2; ..."
2680  */
2681 int
2682 db_set_system_parameters (const char *data)
2683 {
2684  SYSPRM_ERR rc;
2685  int error = NO_ERROR;
2686  SYSPRM_ASSIGN_VALUE *assignments = NULL;
2687 
2688  /* validate changes */
2689  rc = sysprm_validate_change_parameters (data, true, &assignments);
2690  /* If a server parameter is changed, user must belong to DBA group */
2692  {
2693  /* user is not authorized to do the changes */
2694  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_AU_DBA_ONLY, 1, "db_set_system_parameters");
2695  error = ER_AU_DBA_ONLY;
2696  goto cleanup;
2697  }
2699  {
2700  /* set system parameters on server */
2701  rc = sysprm_change_server_parameters (assignments);
2702  }
2703  if (rc == PRM_ERR_NO_ERROR)
2704  {
2705  /* values were successfully set on server, set them on client too */
2706  sysprm_change_parameter_values (assignments, true, true);
2707  }
2708 
2709  /* convert SYSPRM_ERR to error code */
2710  error = sysprm_set_error (rc, data);
2711 
2712 cleanup:
2713  /* clean up */
2714  sysprm_free_assign_values (&assignments);
2715  return error;
2716 }
2717 
2718 /*
2719  * db_set_system_parameters_for_ha_repl () - set new values for system
2720  * parameters for HA replication
2721  *
2722  * return : error code
2723  * data (in) : string with new parameter values defined as:
2724  * "param1=new_val1; param2=new_val2; ..."
2725  */
2726 int
2728 {
2729  return db_set_system_parameters (data);
2730 }
2731 
2732 /*
2733  * db_reset_system_parameters_from_assignments () - reset system parameter
2734  * values from a string containing list of assignments
2735  *
2736  * return : error code
2737  * data (in) : string with new parameter values defined as:
2738  * "param1=new_val1; param2=new_val2; ..."
2739  *
2740  */
2741 int
2743 {
2744  SYSPRM_ERR rc;
2745  int error = NO_ERROR;
2746  char buf[LINE_MAX];
2747 
2748  rc = sysprm_make_default_values (data, buf, sizeof (buf));
2749  if (rc == PRM_ERR_NO_ERROR)
2750  {
2751  return db_set_system_parameters (buf);
2752  }
2753 
2754  error = sysprm_set_error (rc, data);
2755 
2756  return error;
2757 }
2758 
2759 /*
2760  * db_get_system_parameters () - get system parameters values.
2761  *
2762  * return : error code.
2763  * data (in/out) : data (in) is a list of system parameters to get with next
2764  * format: "param1; param2; ...".
2765  * data (out) is a list of system parameters and their values
2766  * with the format: "param1=val1;param2=val2..."
2767  * len (in) : maximum allowed size of output.
2768  */
2769 int
2770 db_get_system_parameters (char *data, int len)
2771 {
2772  SYSPRM_ERR rc;
2773  int error = NO_ERROR;
2774  SYSPRM_ASSIGN_VALUE *prm_values = NULL;
2775 
2776  er_clear ();
2777 
2778  /* parse data and obtain the parameters required to print */
2779  rc = sysprm_obtain_parameters (data, &prm_values);
2780  if (rc == PRM_ERR_NOT_FOR_CLIENT)
2781  {
2782  /* obtain parameter values from server */
2783  rc = sysprm_obtain_server_parameters (&prm_values);
2784  }
2785 
2786  /* convert SYSPRM_ERR to error code */
2787  error = sysprm_set_error (rc, data);
2788 
2789  if (error == NO_ERROR)
2790  {
2791  /* print parameter values in data */
2792  memset (data, 0, len);
2793  (void) sysprm_print_assign_values (prm_values, data, len);
2794  }
2795 
2796  /* clean up */
2797  sysprm_free_assign_values (&prm_values);
2798  return error;
2799 }
2800 
2801 /*
2802  * db_get_host_connected() - return the host name connected
2803  * return : host name or NULL
2804  */
2805 char *
2807 {
2808  /* CHECK_CONNECT_NULL (); */
2809 
2810 #if defined(CS_MODE)
2811  return boot_get_host_connected ();
2812 #else
2813  return (char *) "localhost";
2814 #endif
2815 }
2816 
2817  /*
2818  * db_get_ha_server_state() - get the connected server's HA state
2819  * return : number defined in HA_SERVER_STATE
2820  * buffer(out) : buffer where the string of the HA state to be stored.
2821  * maxlen(in) : the length of 'buffer' argument.
2822  */
2823 int
2824 db_get_ha_server_state (char *buffer, int maxlen)
2825 {
2826  HA_SERVER_STATE ha_state;
2827 
2829 
2830 #if defined(CS_MODE)
2831  ha_state = boot_get_ha_server_state ();
2832 #else
2833  ha_state = HA_SERVER_STATE_NA;
2834 #endif
2835  if (buffer)
2836  {
2837  strncpy (buffer, css_ha_server_state_string (ha_state), maxlen);
2838  }
2839  return ha_state;
2840 }
2841 
2842 void
2843 db_set_server_session_key (const char *key)
2844 {
2846 }
2847 
2848 char *
2850 {
2851  return boot_get_server_session_key ();
2852 }
2853 
2854 /*
2855  * db_get_session_id () - get current session id
2856  * return : session id
2857  */
2858 SESSION_ID
2860 {
2861  return db_Session_id;
2862 }
2863 
2864 /*
2865  * db_set_session_id () - set current session id
2866  * return : void
2867  * session_id (in): session id
2868  */
2869 void
2870 db_set_session_id (const SESSION_ID session_id)
2871 {
2872  db_Session_id = session_id;
2873 }
2874 
2875 /*
2876  * db_find_or_create_session - check if current session is still active
2877  * if not, create a new session
2878  * return error code or NO_ERROR
2879  * db_user(in) :
2880  * program_name(in) :
2881  * Note: This function will check if the current session is active and will
2882  * create a new one if needed and save user access status in server
2883  */
2884 int
2885 db_find_or_create_session (const char *db_user, const char *program_name)
2886 {
2887  int err = NO_ERROR;
2888  SESSION_ID sess_id = db_get_session_id ();
2889  int row_count = DB_ROW_COUNT_NOT_SET;
2890  char *server_session_key;
2891  const char *host_name = boot_get_host_name ();
2892 
2893  server_session_key = db_get_server_session_key ();
2894  /* server_session_key is in/out parameter, it is replaced new key */
2895  err = csession_find_or_create_session (&sess_id, &row_count, server_session_key, db_user, host_name, program_name);
2896  if (err != NO_ERROR)
2897  {
2900  return err;
2901  }
2902 
2903  db_set_session_id (sess_id);
2904  db_update_row_count_cache (row_count);
2905 
2906  return NO_ERROR;
2907 }
2908 
2909 /*
2910  * db_get_row_count_cache () - get the cached value for row count
2911  * return : row count
2912  */
2913 int
2915 {
2916  return db_Row_count;
2917 }
2918 
2919 /*
2920 * db_update_row_count_cache () - update the cached value of row count
2921 * return : void
2922 */
2923 void
2924 db_update_row_count_cache (const int row_count)
2925 {
2926  db_Row_count = row_count;
2927 }
int tran_savepoint_internal(const char *savept_name, SAVEPOINT_TYPE savepoint_type)
DKNPAGES disk_get_total_numpages(VOLID volid)
db_error_log_handler_t db_register_error_log_handler(db_error_log_handler_t f)
Definition: db_admin.c:2183
int au_find_user_to_drop(const char *user_name, MOP *user)
void db_set_interrupt(int set)
Definition: db_admin.c:1445
int db_set_system_parameters_for_ha_repl(const char *data)
Definition: db_admin.c:2727
char db_Program_name[PATH_MAX]
Definition: db_admin.c:101
char * lob_path
Definition: boot.h:107
#define CHECK_MODIFICATION_ERROR()
Definition: db.h:121
void db_print_stats(void)
Definition: db_admin.c:1985
#define NO_ERROR
Definition: error_code.h:46
bool db_need_ignore_repl_delay(void)
Definition: db_admin.c:743
int db_check_authorization_and_grant_option(MOP op, DB_AUTH auth)
Definition: db_admin.c:1872
#define DB_ROW_COUNT_NOT_SET
Definition: dbtype_def.h:486
int db_2pc_prepare_to_commit_transaction(int global_transaction_id)
Definition: db_admin.c:1426
#define CHECK_CONNECT_FALSE()
Definition: db.h:103
void db_set_client_type(int client_type)
Definition: db_admin.c:495
char * db_path
Definition: boot.h:104
void tran_reset_latest_query_status(void)
void db_get_tran_settings(int *lock_wait, DB_TRAN_ISOLATION *tran_isolation)
Definition: db_admin.c:1554
MOP ws_mop(const OID *oid, MOP class_mop)
Definition: work_space.c:614
#define CHECK_2ARGS_ERROR(obj1, obj2)
Definition: db.h:195
int db_login(const char *name, const char *password)
Definition: db_admin.c:804
DB_OBJECT * db_get_owner(DB_OBJECT *class_obj)
Definition: db_admin.c:1892
void tran_get_tran_settings(int *lock_wait_in_msecs, TRAN_ISOLATION *tran_isolation, bool *async_ws)
DB_OBJECT * db_real_instance(DB_OBJECT *obj)
Definition: db_virt.c:247
DB_OBJECT * db_object(DB_IDENTIFIER *oid)
Definition: db_admin.c:2641
int db_set_password(DB_OBJECT *user, const char *old_passwd, const char *new_passwd)
Definition: db_admin.c:1743
char * MOBJ
Definition: work_space.h:174
MOBJ locator_fetch_set(int num_mops, MOP *mop_set, DB_FETCH_MODE inst_purpose, DB_FETCH_MODE class_purpose, int quit_on_errors)
Definition: locator_cl.c:2464
int db_Connect_status
Definition: db_macro.c:88
char * db_comments
Definition: boot.h:109
enum db_client_type BOOT_CLIENT_TYPE
void ws_dump(FILE *fpp)
Definition: work_space.c:3600
PAGEID DKNPAGES
int db_init(const char *program, int print_version, const char *dbname, const char *db_path, const char *vol_path, const char *log_path, const char *lob_path, const char *host_name, const bool overwrite, const char *comments, const char *addmore_vols_file, int npages, int desired_pagesize, int log_npages, int desired_log_page_size, const char *lang_charset)
Definition: db_admin.c:164
int db_totalpgs(const char *volume_label)
Definition: db_admin.c:2073
SESSION_ID db_get_session_id(void)
Definition: db_admin.c:2859
int tran_get_global_tran_info(int gtrid, void *buffer, int size)
#define AU_TYPE
Definition: authenticate.h:67
void(* prev_sigfpe_handler)(int)
Definition: db_admin.c:70
VOLID fileio_find_volume_id_with_label(THREAD_ENTRY *thread_p, const char *vol_label_p)
Definition: file_io.c:6319
int db_set_suppress_repl_on_transaction(int set)
Definition: db_admin.c:1460
void sm_delete_static_method(const char *name)
void db_clear_delayed_hosts_count(void)
Definition: db_admin.c:546
int sysprm_set_error(SYSPRM_ERR rc, const char *data)
DB_HOST_STATUS * connected_host_status
Definition: db_admin.c:89
int db_abort_to_savepoint_internal(const char *savepoint_name)
Definition: db_admin.c:1210
bool tran_has_updated(void)
int au_revoke(MOP user, MOP class_mop, DB_AUTH type)
int db_set_system_parameters(const char *data)
Definition: db_admin.c:2682
int do_check_partitioned_class(DB_OBJECT *classop, int check_map, char *keyattr)
int db_freepgs(const char *volume_label)
Definition: db_admin.c:2054
void db_clear_host_status(void)
Definition: db_admin.c:580
int db_shutdown(void)
Definition: db_admin.c:964
VOLID boot_find_last_permanent(void)
int tran_2pc_prepare_global_tran(int gtrid)
int db_reset_latest_query_status(void)
Definition: db_admin.c:1132
INT16 VOLID
bool au_is_dba_group_member(MOP user)
void db_free_execution_plan(void)
Definition: db_query.c:3638
DB_OBJECT * db_find_user(const char *name)
Definition: db_admin.c:1606
char * db_host
Definition: boot.h:108
int locator_get_cache_coherency_number(MOP mop)
Definition: locator_cl.c:2171
int db_2pc_prepared_transactions(int gtrids[], int size)
Definition: db_admin.c:1373
#define WS_ISVID(mop)
Definition: work_space.h:288
char * db_get_server_session_key(void)
Definition: db_admin.c:2849
char hostname[CUB_MAXHOSTNAMELEN]
Definition: db_admin.c:80
int csession_get_row_count(int *rows)
int db_fetch_seq(DB_SEQ *seq, DB_FETCH_MODE purpose, int quit_on_error)
Definition: db_admin.c:2388
void locator_synch_isolation_incons(void)
Definition: locator_cl.c:6171
char * db_vol_label(int volid, char *vol_fullname)
Definition: db_admin.c:412
int sm_prelink_methods(DB_OBJLIST *classes)
#define AU_GRANT_SHIFT
Definition: authenticate.h:94
int jsp_jvm_is_loaded(void)
Definition: jsp_sr.c:774
int er_errid(void)
void db_string_free(char *string)
Definition: db_admin.c:2596
int tran_abort(void)
static int db_Max_num_delayed_hosts_lookup
Definition: db_admin.c:105
void sysprm_free_assign_values(SYSPRM_ASSIGN_VALUE **assign_values_ptr)
int set_size(DB_COLLECTION *set)
Definition: set_object.c:3036
SYSPRM_ERR sysprm_obtain_parameters(char *data, SYSPRM_ASSIGN_VALUE **prm_values_ptr)
int db_Row_count
Definition: db_macro.c:81
void(* db_error_log_handler_t)(unsigned int)
Definition: dbi.h:125
int db_chn(DB_OBJECT *obj, DB_FETCH_MODE purpose)
Definition: db_admin.c:2660
void db_ws_free(void *ptr)
Definition: quick_fit.c:194
bool db_disable_trigger(void)
Definition: db_admin.c:570
#define DB_HS_HA_DELAYED
Definition: connection_cl.h:41
int db_set_lock_timeout(int seconds)
Definition: db_admin.c:1496
int er_init(const char *msglog_filename, int exit_ask)
int tran_2pc_start(void)
const char * rel_build_number(void)
int db_get_global_transaction_info(int global_transaction_id, void *buffer, int size)
Definition: db_admin.c:1295
int db_savepoint_transaction_internal(const char *savepoint_name)
Definition: db_admin.c:1166
void db_set_preferred_hosts(const char *hosts)
Definition: db_admin.c:508
int db_lock_read(DB_OBJECT *op)
Definition: db_admin.c:2001
const char * db_error_string_test(int level)
Definition: db_admin.c:2089
char * db_get_host_connected(void)
Definition: db_admin.c:2806
void db_force_method_reload(MOP obj)
Definition: db_admin.c:2579
int db_get_host_list_with_given_status(char **hostlist, int list_size, int status)
Definition: db_admin.c:776
int db_get_system_parameters(char *data, int len)
Definition: db_admin.c:2770
int csession_get_variable(DB_VALUE *name, DB_VALUE *value)
#define DB_HS_RECONNECT_INDICATOR
Definition: connection_cl.h:45
int boot_restart_client(BOOT_CLIENT_CREDENTIAL *client_credential)
Definition: boot_cl.c:738
#define DB_CONNECTION_STATUS_CONNECTED
Definition: db.h:47
INTL_CODESET lang_charset(void)
int db_lock_write(DB_OBJECT *op)
Definition: db_admin.c:2030
int tran_reset_wait_times(int wait_in_msecs)
MOP Au_dba_user
Definition: authenticate.c:334
int db_restart(const char *program, int print_version, const char *volume)
Definition: db_admin.c:868
static DB_HOST_STATUS * db_find_host_status(char *hostname)
Definition: db_admin.c:599
#define DB_CONNECT_ORDER_SEQ
Definition: connection_cl.h:33
void er_set(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
int db_restart_ex(const char *program, const char *db_name, const char *db_user, const char *db_password, const char *preferred_hosts, int client_type)
Definition: db_admin.c:934
Definition: db_set.h:35
db_client_type client_type
#define assert(x)
int boot_initialize_client(BOOT_CLIENT_CREDENTIAL *client_credential, BOOT_DB_PATH_INFO *db_path_info, bool db_overwrite, const char *file_addmore_vols, DKNPAGES npages, PGLENGTH db_desired_pagesize, DKNPAGES log_npages, PGLENGTH db_desired_log_page_size, const char *lang_charset)
Definition: boot_cl.c:290
int prm_get_integer_value(PARAM_ID prm_id)
MOP au_add_user(const char *name, int *exists)
int au_fetch_class(MOP op, SM_CLASS **class_ptr, AU_FETCHMODE fetchmode, DB_AUTH type)
char * db_get_database_name(void)
Definition: db_admin.c:432
int db_end_session(void)
Definition: db_admin.c:1029
int obj_lock(MOP op, int for_write)
DB_IDENTIFIER * db_identifier(DB_OBJECT *obj)
Definition: db_admin.c:2629
#define CHECK_MODIFICATION_NULL()
Definition: db.h:124
char * db_get_user_and_host_name(void)
Definition: db_admin.c:1932
int db_error_code(void)
Definition: db_admin.c:2143
static void install_static_methods(void)
Definition: db_admin.c:130
#define ER_OUT_OF_VIRTUAL_MEMORY
Definition: error_code.h:50
static int db_Delayed_hosts_count
Definition: db_admin.c:106
int tran_2pc_prepare(void)
#define CHECK_1ARG_ERROR(obj)
Definition: db.h:186
void db_objlist_free(DB_OBJLIST *list)
Definition: db_admin.c:2612
int au_set_password(MOP user, const char *password)
int db_error_code_test(void)
Definition: db_admin.c:2123
const char * css_ha_server_state_string(HA_SERVER_STATE state)
int tran_commit(bool retain_lock)
int db_get_ha_server_state(char *buffer, int maxlen)
Definition: db_admin.c:2824
void locator_set_sig_interrupt(int set)
Definition: locator_cl.c:193
int sysprm_print_assign_values(SYSPRM_ASSIGN_VALUE *prm_values, char *buffer, int length)
#define DB_MAX_IDENTIFIER_LENGTH
Definition: dbtype_def.h:495
int au_drop_member(MOP group, MOP member)
const char * db_error_string(int level)
Definition: db_admin.c:2116
DB_TRAN_ISOLATION
Definition: dbtran_def.h:26
void sm_flush_static_methods()
#define CHECK_1ARG_NULL(obj)
Definition: db.h:171
int db_Disable_modifications
Definition: db_macro.c:90
#define IO_MIN_PAGE_SIZE
int db_get_delayed_hosts_count(void)
Definition: db_admin.c:540
char * disk_get_remarks(VOLID volid)
DB_OBJECT * db_get_object(const DB_VALUE *value)
int db_abort_to_savepoint(const char *savepoint_name)
Definition: db_admin.c:1237
void sm_add_static_method(const char *name, void(*function)())
int db_fetch_set(DB_SET *set, DB_FETCH_MODE purpose, int quit_on_error)
Definition: db_admin.c:2372
int db_reset_system_parameters_from_assignments(const char *data)
Definition: db_admin.c:2742
int db_abort_transaction(void)
Definition: db_admin.c:1114
void db_link_static_methods(DB_METHOD_LINK *methods)
Definition: db_admin.c:2523
int db_grant(MOP user, MOP class_, AU_TYPE auth, int grant_option)
Definition: db_admin.c:1794
char * disk_get_fullname(VOLID volid, char *vol_fullname)
void db_update_row_count_cache(const int row_count)
Definition: db_admin.c:2924
static void cleanup(int signo)
Definition: broker.c:717
int au_add_member(MOP group, MOP member)
int db_drop_member(DB_OBJECT *user, DB_OBJECT *member)
Definition: db_admin.c:1719
#define NULL
Definition: freelistheap.h:34
#define strncpy_bufsize(buf, str)
Definition: porting.h:340
const char * er_msg(void)
char * vol_path
Definition: boot.h:105
MOP au_find_user(const char *user_name)
static char * dbname
void db_clear_host_connected(void)
Definition: db_admin.c:851
char * boot_get_server_session_key(void)
Definition: boot_cl.c:5792
#define DB_HS_NORMAL
Definition: connection_cl.h:37
int db_enable_modification(void)
Definition: db_admin.c:1015
SYSPRM_ERR sysprm_change_server_parameters(const SYSPRM_ASSIGN_VALUE *assignments)
#define err(fd,...)
Definition: porting.h:431
int db_savepoint_transaction(const char *savepoint_name)
Definition: db_admin.c:1198
int csession_get_last_insert_id(DB_VALUE *value, bool update_last_insert_id)
int boot_find_number_permanent_volumes(void)
bool db_need_reconnect(void)
Definition: db_admin.c:709
#define DB_EMPTY_SESSION
Definition: dbtype_def.h:483
SYSPRM_ERR sysprm_validate_change_parameters(const char *data, bool check, SYSPRM_ASSIGN_VALUE **assignments_ptr)
std::string program_name
MOBJ locator_fetch_nested(MOP mop, DB_FETCH_MODE purpose, int prune_level, int quit_on_errors)
Definition: locator_cl.c:2549
void boot_set_server_session_key(const char *key)
Definition: boot_cl.c:5801
int log_set_suppress_repl_on_transaction(int set)
#define db_private_alloc(thrd, size)
Definition: memory_alloc.h:227
int set_get_element(DB_COLLECTION *set, int index, DB_VALUE *value)
Definition: set_object.c:2575
int db_drop_user(DB_OBJECT *user)
Definition: db_admin.c:1668
struct db_objlist * next
Definition: dbtype_def.h:442
char * db_get_user_name(void)
Definition: db_admin.c:1911
char * db_name
int au_grant(MOP user, MOP class_mop, DB_AUTH type, bool grant_option)
int count(int &result, const cub_regex_object &reg, const std::string &src, const int position, const INTL_CODESET codeset)
#define IO_DEFAULT_PAGE_SIZE
DB_OBJECT * db_get_user(void)
Definition: db_admin.c:1974
int db_set_isolation(DB_TRAN_ISOLATION isolation)
Definition: db_admin.c:1535
int db_fetch_list(DB_OBJLIST *objects, DB_FETCH_MODE purpose, int quit_on_error)
Definition: db_admin.c:2254
int db_2pc_attach_transaction(int global_transaction_id)
Definition: db_admin.c:1403
int db_fetch_array(DB_OBJECT **objects, DB_FETCH_MODE purpose, int quit_on_error)
Definition: db_admin.c:2216
#define CHECK_CONNECT_ZERO_TYPE(TYPE)
Definition: db.h:97
#define max(a, b)
void db_set_connected_host_status(char *host_connected)
Definition: db_admin.c:681
static int db_Client_type
Definition: db_admin.c:114
void db_set_server_session_key(const char *key)
Definition: db_admin.c:2843
SYSPRM_ERR sysprm_make_default_values(const char *data, char *default_val_buf, const int buf_size)
int tran_reset_isolation(TRAN_ISOLATION isolation, bool async_ws)
struct db_object * op
Definition: dbtype_def.h:443
MOP Au_user
Definition: authenticate.c:343
const char * envvar_get(const char *name)
DB_VOLPURPOSE
Definition: dbtype_def.h:185
static void error(const char *msg)
Definition: gencat.c:331
const char * db_get_database_comments(void)
Definition: db_admin.c:471
static int rc
Definition: serial.c:50
int ml_add(DB_OBJLIST **list, MOP mop, int *added_ptr)
Definition: work_space.c:4493
int db_2pc_prepare_transaction(void)
Definition: db_admin.c:1351
#define CHECK_PARTITION_SUBS
void db_flush_static_methods(void)
Definition: db_admin.c:2564
MOP au_get_class_owner(MOP classmop)
#define CHECK_CONNECT_NULL()
Definition: db.h:91
DB_AUTH
Definition: dbtype_def.h:239
static int db_Connect_order
Definition: db_admin.c:104
#define ARG_FILE_LINE
Definition: error_manager.h:44
#define ER_AU_DBA_ONLY
Definition: error_code.h:204
SESSION_ID db_Session_id
Definition: db_macro.c:79
int db_add_volume_ex(DBDEF_VOL_EXT_INFO *ext_info)
Definition: db_admin.c:342
er_log_handler_t er_register_log_handler(er_log_handler_t handler)
int tran_2pc_attach_global_tran(int gtrid)
INT16 PGLENGTH
void db_set_max_num_delayed_hosts_lookup(int max_num_delayed_hosts_lookup)
Definition: db_admin.c:528
void au_link_static_methods(void)
int net_client_ping_server(int client_val, int *server_val, int timeout)
Definition: network_cl.c:3727
char * boot_get_host_name(void)
Definition: boot_cl.c:5725
#define CHECK_MODIFICATION_MINUSONE()
Definition: db.h:127
void db_unlink_static_methods(DB_METHOD_LINK *methods)
Definition: db_admin.c:2546
bool db_does_connected_host_have_status(int status)
Definition: db_admin.c:755
int sm_force_method_link(MOP obj)
int db_get_client_type(void)
Definition: db_admin.c:489
static char * db_Preferred_hosts
Definition: db_admin.c:103
int db_num_volumes(void)
Definition: db_admin.c:374
int db_disable_modification(void)
Definition: db_admin.c:1001
int boot_shutdown_client(bool is_er_final)
Definition: boot_cl.c:1396
void sysprm_change_parameter_values(const SYSPRM_ASSIGN_VALUE *assignments, bool check, bool set_flag)
#define free_and_init(ptr)
Definition: memory_alloc.h:147
char * db_get_database_version(void)
Definition: db_admin.c:455
#define strlen(s1)
Definition: intl_support.c:43
int csession_find_or_create_session(SESSION_ID *session_id, int *row_count, char *server_session_key, const char *db_user, const char *host, const char *program_name)
int tran_abort_upto_user_savepoint(const char *savepoint_name)
int db_fetch_composition(DB_OBJECT *object, DB_FETCH_MODE purpose, int max_level, int quit_on_error)
Definition: db_admin.c:2407
#define ER_OBJ_INVALID_ARGUMENTS
Definition: error_code.h:275
#define TM_TRAN_ASYNC_WS()
int log_checkpoint(void)
unsigned int SESSION_ID
Definition: dbtype_def.h:480
int db_get_row_count_cache(void)
Definition: db_admin.c:2914
int db_add_volume(const char *ext_path, const char *ext_name, const char *ext_comments, const int ext_npages, const DB_VOLPURPOSE ext_purpose)
Definition: db_admin.c:314
int db_set_user_comment(DB_OBJECT *user, const char *comment)
Definition: db_admin.c:1765
int db_last_volume(void)
Definition: db_admin.c:391
bool tr_set_execution_state(bool new_state)
void ml_ext_free(DB_OBJLIST *list)
Definition: work_space.c:4806
VOLID boot_add_volume_extension(DBDEF_VOL_EXT_INFO *ext_info)
int db_set_global_transaction_info(int global_transaction_id, void *info, int size)
Definition: db_admin.c:1262
void db_warnspace(const char *volume_label)
Definition: db_admin.c:2452
OID * ws_identifier_with_check(MOP mop, const bool check_non_referable)
Definition: work_space.c:2820
int db_get_variable(DB_VALUE *name, DB_VALUE *value)
Definition: db_admin.c:1072
static DB_HOST_STATUS * db_add_host_status(char *hostname, int status)
Definition: db_admin.c:624
void(* er_log_handler_t)(unsigned int)
DKNPAGES disk_get_free_numpages(VOLID volid)
void er_clear(void)
SYSPRM_ERR
bool db_enable_trigger(void)
Definition: db_admin.c:558
#define CHECK_CONNECT_ZERO()
Definition: db.h:94
int au_login(const char *name, const char *password, bool ignore_dba_privilege)
#define DB_VALUE_TYPE(value)
Definition: dbtype.h:72
int i
Definition: dynamic_load.c:954
static DB_HOST_STATUS_LIST db_Host_status_list
Definition: db_admin.c:109
int db_find_or_create_session(const char *db_user, const char *program_name)
Definition: db_admin.c:2885
DB_OBJECT * db_add_user(const char *name, int *exists)
Definition: db_admin.c:1646
char * strdup(const char *str)
Definition: porting.c:901
char db_Database_name[DB_MAX_IDENTIFIER_LENGTH+1]
Definition: db_admin.c:100
#define NULL_VOLID
const char * comments
DB_HOST_STATUS hostlist[MAX_NUM_DB_HOSTS *2]
Definition: db_admin.c:88
#define IO_MAX_PAGE_SIZE
DB_FETCH_MODE
Definition: dbtype_def.h:215
void db_set_session_id(const SESSION_ID session_id)
Definition: db_admin.c:2870
int db_value_clear(DB_VALUE *value)
Definition: db_macro.c:1588
int db_get_max_num_delayed_hosts_lookup(void)
Definition: db_admin.c:534
static int fetch_set_internal(DB_SET *set, DB_FETCH_MODE purpose, int quit_on_error)
Definition: db_admin.c:2302
int csession_end_session(SESSION_ID session_id)
int db_revoke(MOP user, MOP class_mop, AU_TYPE auth)
Definition: db_admin.c:1821
MOP sm_find_class(const char *name)
enum ha_server_state HA_SERVER_STATE
Definition: boot.h:126
int tran_2pc_recovery_prepared(int gtrids[], int size)
void sigfpe_handler(int sig)
Definition: db_admin.c:822
DB_VOLPURPOSE purpose
char * ws_copy_string(const char *str)
Definition: work_space.c:3457
int db_commit_is_needed(void)
Definition: db_admin.c:1154
int db_get_row_count(int *row_count)
Definition: db_admin.c:1046
const char * au_user_name(void)
const char * program_name
Definition: cas.c:147
#define CUB_MAXHOSTNAMELEN
Definition: porting.h:379
void db_set_host_status(char *hostname, int status)
Definition: db_admin.c:649
#define MAX_NUM_DB_HOSTS
void db_set_connect_order(int connect_order)
Definition: db_admin.c:522
int db_add_member(DB_OBJECT *user, DB_OBJECT *member)
Definition: db_admin.c:1694
void db_preload_classes(const char *name1,...)
Definition: db_admin.c:2476
int au_drop_user(MOP user)
int db_check_authorization(MOP op, DB_AUTH auth)
Definition: db_admin.c:1848
int db_list_length(DB_LIST *list)
Definition: db_old.c:69
#define CHECK_CONNECT_VOID()
Definition: db.h:70
int db_checkpoint(void)
Definition: db_admin.c:1473
SYSPRM_ERR sysprm_obtain_server_parameters(SYSPRM_ASSIGN_VALUE **prm_values_ptr)
int db_ping_server(int client_val, int *server_val)
Definition: db_admin.c:983
#define CHECK_CONNECT_MINUSONE()
Definition: db.h:100
int db_2pc_start_transaction(void)
Definition: db_admin.c:1327
int db_get_last_insert_id(DB_VALUE *value)
Definition: db_admin.c:1058
int db_error_init(const char *logfile)
Definition: db_admin.c:2164
SIGNAL_HANDLER_FUNCTION os_set_signal_handler(const int sig_no, SIGNAL_HANDLER_FUNCTION sig_handler)
Definition: porting.c:1333
#define DB_CONNECTION_STATUS_NOT_CONNECTED
Definition: db.h:46
#define GETHOSTNAME(p, l)
Definition: porting.h:381
void db_synchronize_cache(void)
Definition: db_admin.c:1586
int au_set_user_comment(MOP user, const char *comment)
int tran_set_global_tran_info(int gtrid, void *info, int size)
int db_commit_transaction(void)
Definition: db_admin.c:1091
#define CHECK_CONNECT_ERROR()
Definition: db.h:88
char * log_path
Definition: boot.h:106
void boot_clear_host_connected(void)
Definition: boot_cl.c:5717
int db_find_user_to_drop(const char *name, DB_OBJECT **user)
Definition: db_admin.c:1626