CUBRID Engine  latest
db_temp.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  * db_temp.c - API functions for schema definition templates.
21  */
22 
23 #ident "$Id$"
24 
25 #include "config.h"
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <stdarg.h>
30 #include <ctype.h>
31 #include <assert.h>
32 
33 #include "authenticate.h"
34 #include "system_parameter.h"
35 #include "storage_common.h"
36 #include "db.h"
37 #include "class_object.h"
38 #include "object_print.h"
39 #include "server_interface.h"
40 #include "boot_cl.h"
41 #include "locator_cl.h"
42 #include "schema_manager.h"
43 #include "schema_template.h"
44 #include "object_accessor.h"
45 #include "set_object.h"
46 #include "virtual_object.h"
47 #include "parser.h"
48 #include "execute_statement.h"
49 #include "execute_schema.h"
50 #include "network_interface_cl.h"
51 
52 #define ERROR_SET(error, code) \
53  do { \
54  error = code; \
55  er_set (ER_WARNING_SEVERITY, ARG_FILE_LINE, code, 0); \
56  } while (0)
57 
58 #define ATTR_RENAME_SAVEPOINT "aTTrNAMeSAVE"
59 
60 static DB_CTMPL *dbt_reserve_name (DB_CTMPL * def, const char *name);
61 
62 /*
63  * SCHEMA TEMPLATES
64  */
65 
66 /*
67  * dbt_create_class() - This function creates a class template for a new class.
68  * A class with the given name cannot already exist.
69  * return : class template
70  * name(in): new class name
71  *
72  * note : When the template is no longer needed, it should be applied using
73  * dbt_finish_class() or destroyed using dbt_abort_class().
74  */
75 DB_CTMPL *
76 dbt_create_class (const char *name)
77 {
78  DB_CTMPL *def = NULL;
79 
81  CHECK_1ARG_NULL (name);
83 
84  def = smt_def_class (name);
85 
86  if (def != NULL)
87  {
88  def = dbt_reserve_name (def, name);
89  }
90 
91  return (def);
92 }
93 
94 /*
95  * dbt_create_vclass() - This function creates a class template for a new
96  * virtual class. A class with the specified name cannot already exist.
97  * return : schema template
98  * name(in): the name of a virtual class
99  *
100  * note : The template can be applied using dbt_finish_class() or destroyed
101  * using dbt_abort_class().
102  */
103 DB_CTMPL *
104 dbt_create_vclass (const char *name)
105 {
106  DB_CTMPL *def = NULL;
107 
109  CHECK_1ARG_NULL (name);
111 
112  def = smt_def_typed_class (name, SM_VCLASS_CT);
113 
114  if (def != NULL)
115  {
116  def = dbt_reserve_name (def, name);
117  }
118 
119  return (def);
120 }
121 
122 /*
123  * dbt_edit_class() - This function creates a class template for an existing
124  * class. The template is initialized with the current definition of the
125  * class, and it is edited with the other class template functions.
126  * return : class template
127  * classobj(in): class object pointer
128  *
129  * note : When finished, the class template can be applied with
130  * dbt_finish_class() or destroyed with dbt_abort_class().
131  */
132 DB_CTMPL *
133 dbt_edit_class (MOP classobj)
134 {
135  DB_CTMPL *def = NULL;
136 
138  CHECK_1ARG_NULL (classobj);
140 
141  def = smt_edit_class_mop (classobj, AU_ALTER);
142 
143  return (def);
144 }
145 
146 /*
147  * dbt_copy_class() - This function creates a class template based on an
148  * existing class.
149  * return : class template
150  * new_name(in): name of the class to be created
151  * existing_name(in): name of the class to be duplicated
152  * class_(out): the current definition of the duplicated class is returned
153  * in order to be used for subsequent operations (such as
154  * duplicating indexes).
155  *
156  * Note : When finished, the class template can be applied with
157  * dbt_finish_class() or destroyed with dbt_abort_class().
158  */
159 DB_CTMPL *
160 dbt_copy_class (const char *new_name, const char *existing_name, SM_CLASS ** class_)
161 {
162  DB_CTMPL *def = NULL;
163 
165  CHECK_2ARGS_NULL (new_name, existing_name);
167 
168  def = smt_copy_class (new_name, existing_name, class_);
169 
170  if (def != NULL)
171  {
172  def = dbt_reserve_name (def, new_name);
173  }
174 
175  return (def);
176 }
177 
178 /*
179  * dbt_reserve_name () - Reserve new class or view name.
180  *
181  * return : Class template.
182  * def (in) : Class template.
183  * name (in) : Class name.
184  */
185 static DB_CTMPL *
186 dbt_reserve_name (DB_CTMPL * def, const char *name)
187 {
188  LC_FIND_CLASSNAME reserved;
189  OID class_oid = OID_INITIALIZER;
190 
191  assert (def != NULL);
192  assert (name != NULL);
193 
194  reserved = locator_reserve_class_name (def->name, &class_oid);
195  if (reserved != LC_CLASSNAME_RESERVED)
196  {
197  if (reserved == LC_CLASSNAME_EXIST)
198  {
200  }
201  else
202  {
203  ASSERT_ERROR ();
204  }
205  smt_quit (def);
206  return NULL;
207  }
208  return def;
209 }
210 
211 /*
212  * dbt_finish_class() - This function applies a class template. If the template
213  * is applied without error, a pointer to the class object is returned.
214  * If the template is for a new class, a new object pointer is returned.
215  * If the template is for an existing class, the same pointer that was
216  * passed to dbt_edit_class() is returned.
217  * return : class pointer
218  * def: class template
219  *
220  * note : If there are no errors, the template is freed and cannot be reused.
221  * If an error is detected, NULL is returned, the global error code is set,
222  * and the template is not freed. The template can either be corrected and
223  * reapplied, or destroyed.
224  */
225 DB_OBJECT *
227 {
228  MOP classmop = NULL;
229 
231  CHECK_1ARG_NULL (def);
233 
234  if (sm_finish_class (def, &classmop) != NO_ERROR)
235  {
236  classmop = NULL; /* probably not necessary but be safe */
237  }
238 
239  return (classmop);
240 }
241 
242 /*
243  * dbt_abort_class() - This function destroys a class template and frees all
244  * memory allocated for the template.
245  * return : none
246  * def(in): class template
247  */
248 void
250 {
251  if (def != NULL)
252  {
253  smt_quit (def);
254  }
255 }
256 
257 /*
258  * SCHEMA TEMPLATE OPERATIONS
259  * The descriptions of these functions is the same as that for the
260  * non-template versions.
261  */
262 
263 /*
264  * dbt_add_attribute() -
265  * return:
266  * def(in) :
267  * name(in) :
268  * domain(in) :
269  * default_value(in) :
270  */
271 int
272 dbt_add_attribute (DB_CTMPL * def, const char *name, const char *domain, DB_VALUE * default_value)
273 {
274  int error = NO_ERROR;
275 
277  CHECK_3ARGS_ERROR (def, name, domain);
279 
280  error = smt_add_attribute_w_dflt (def, name, domain, (DB_DOMAIN *) 0, default_value, ID_ATTRIBUTE, NULL, NULL, NULL);
281 
282  return (error);
283 }
284 
285 /*
286  * dbt_add_shared_attribute() -
287  * return:
288  * def(in) :
289  * name(in) :
290  * domain(in) :
291  * default_value(in) :
292  */
293 int
294 dbt_add_shared_attribute (DB_CTMPL * def, const char *name, const char *domain, DB_VALUE * default_value)
295 {
296  int error = NO_ERROR;
297 
299  CHECK_3ARGS_ERROR (def, name, domain);
301 
302  error =
303  smt_add_attribute_w_dflt (def, name, domain, (DB_DOMAIN *) 0, default_value, ID_SHARED_ATTRIBUTE, NULL, NULL, NULL);
304 
305  return (error);
306 }
307 
308 /*
309  * dbt_add_class_attribute() -
310  * return:
311  * def(in) :
312  * name(in) :
313  * domain(in) :
314  * default_value(in) :
315  */
316 int
317 dbt_add_class_attribute (DB_CTMPL * def, const char *name, const char *domain, DB_VALUE * default_value)
318 {
319  int error = NO_ERROR;
320 
322  CHECK_3ARGS_ERROR (def, name, domain);
324 
325  error =
326  smt_add_attribute_w_dflt (def, name, domain, (DB_DOMAIN *) 0, default_value, ID_CLASS_ATTRIBUTE, NULL, NULL, NULL);
327 
328  return (error);
329 }
330 
331 
332 /*
333  * dbt_constrain_non_null() -
334  * return:
335  * def(in) :
336  * name(in) :
337  * class_attribute(in) :
338  * on_or_off(in) :
339  *
340  * note : Please consider using the newer functions dbt_add_constraint()
341  * and dbt_drop_constraint().
342  */
343 int
344 dbt_constrain_non_null (DB_CTMPL * def, const char *name, int class_attribute, int on_or_off)
345 {
346  const char *names[2];
347  int error = NO_ERROR;
348 
350  CHECK_2ARGS_ERROR (def, name);
352 
353  names[0] = name;
354  names[1] = NULL;
355  if (on_or_off)
356  {
357  error = dbt_add_constraint (def, DB_CONSTRAINT_NOT_NULL, NULL, names, class_attribute, NULL);
358  if (error == NO_ERROR)
359  {
360  error = do_check_fk_constraints (def, NULL);
361  }
362  }
363  else
364  {
365  error = dbt_drop_constraint (def, DB_CONSTRAINT_NOT_NULL, NULL, names, class_attribute);
366  }
367 
368  return (error);
369 }
370 
371 /*
372  * dbt_constrain_unique() -
373  * return:
374  * def(in) :
375  * attname(in) :
376  * on_or_off(in) :
377  *
378  * note : Please consider using the newer functions dbt_add_constraint()
379  * and dbt_drop_constraint().
380  */
381 int
382 dbt_constrain_unique (DB_CTMPL * def, const char *attname, int on_or_off)
383 {
384  int error = NO_ERROR;
385  const char *attnames[2];
386 
388  CHECK_2ARGS_ERROR (def, attnames);
390 
391  attnames[0] = attname;
392  attnames[1] = NULL;
393  if (on_or_off)
394  {
395  error = dbt_add_constraint (def, DB_CONSTRAINT_UNIQUE, NULL, attnames, 0, NULL);
396  }
397  else
398  {
399  error = dbt_drop_constraint (def, DB_CONSTRAINT_UNIQUE, NULL, attnames, 0);
400  }
401 
402  return (error);
403 }
404 
405 /*
406  * dbt_add_constraint() - This function adds a constraint to one or more
407  * attributes if one does not already exist. This function is similar
408  * to the db_add_constraint() function, except that it operates on a
409  * schema template. Since INDEX'es are not manipulated via templates,
410  * this function should only be called for DB_CONSTRAINT_UNIQUE,
411  * DB_CONSTRAINT_NOT_NULL, and DB_CONSTRAINT_PRIMARY_KEY constraint types.
412  * return : error code
413  * def(in): class template
414  * constraint_type(in): constraint type.
415  * constraint_name(in): optional name for constraint.
416  * attnames(in): NULL terminated array of attribute names.
417  * class_attributes(in): non-zero if the attributes are class attributes and
418  * zero otherwise. Unique constraints cannot be applied to
419  * class attributes.
420  * comment(in): constraint comment
421  */
422 int
423 dbt_add_constraint (DB_CTMPL * def, DB_CONSTRAINT_TYPE constraint_type, const char *constraint_name,
424  const char **attnames, int class_attributes, const char *comment)
425 {
426  int error = NO_ERROR;
427  char *name = NULL;
428 
430  CHECK_2ARGS_ERROR (def, attnames);
432 
433  if (!DB_IS_CONSTRAINT_UNIQUE_FAMILY (constraint_type) && constraint_type != DB_CONSTRAINT_NOT_NULL)
434  {
436  }
437 
438  if (error == NO_ERROR)
439  {
440  name = sm_produce_constraint_name_tmpl (def, constraint_type, attnames, NULL, constraint_name);
441  if (name == NULL)
442  {
443  assert (er_errid () != NO_ERROR);
444  error = er_errid ();
445  }
446  else
447  {
448  error = smt_add_constraint (def, constraint_type, name, attnames, NULL, NULL, class_attributes, NULL, NULL,
449  NULL, comment, SM_NORMAL_INDEX);
450  free_and_init (name);
451  }
452  }
453 
454  return (error);
455 }
456 
457 /*
458  * dbt_drop_constraint() - This is a version of db_drop_constraint() which is
459  * designed to operate on templates. Since INDEX'es are not manipulated via
460  * templates, this function should only be called for DB_CONSTRAINT_UNIQUE,
461  * DB_CONSTRAINT_NOT_NULL, and DB_CONSTRAINT_PRIMARY_KEY constraint types.
462  * return : error code
463  * def(in): Class template
464  * constraint_type(in): Constraint type.
465  * constraint_name(in): Constraint name. NOT NULL constraints are not named
466  * so this parameter should be NULL in that case.
467  * attnames(in): NULL terminated array of attribute names.
468  * class_attributes(in): non-zero if the attributes are class attributes and
469  * zero otherwise. Unique constraints cannot be applied
470  * to class attributes.
471  */
472 int
473 dbt_drop_constraint (DB_CTMPL * def, DB_CONSTRAINT_TYPE constraint_type, const char *constraint_name,
474  const char **attnames, int class_attributes)
475 {
476  int error = NO_ERROR;
477  char *name = NULL;
479 
481  CHECK_1ARG_ERROR (def);
483 
484  if (!DB_IS_CONSTRAINT_FAMILY (constraint_type))
485  {
487  }
488 
489  attflag = SM_MAP_CONSTRAINT_TO_ATTFLAG (constraint_type);
490 
491  if (error == NO_ERROR)
492  {
493  name = sm_produce_constraint_name_tmpl (def, constraint_type, attnames, NULL, constraint_name);
494 
495  if (name == NULL)
496  {
497  assert (er_errid () != NO_ERROR);
498  error = er_errid ();
499  }
500  else
501  {
502  /* TODO We might want to check that the dropped constraint really had the type indicated by the
503  * constraint_type parameter. */
504  error = smt_drop_constraint (def, attnames, name, class_attributes, attflag);
505  free_and_init (name);
506  }
507  }
508 
509  return (error);
510 }
511 
512 /*
513  * dbt_add_foreign_key() -
514  * return:
515  * def(in) :
516  * constraint_name(in) :
517  * attnames(in) :
518  * ref_class(in) :
519  * ref_attrs(in) :
520  * del_action(in) :
521  * upd_action(in) :
522  */
523 int
524 dbt_add_foreign_key (DB_CTMPL * def, const char *constraint_name, const char **attnames, const char *ref_class,
525  const char **ref_attrs, int del_action, int upd_action, const char *comment)
526 {
527  int error = NO_ERROR;
528  char *name;
529  SM_CLASS_CONSTRAINT *temp_cons = NULL;
530  SM_FOREIGN_KEY_INFO fk_info;
531 
532  name = sm_produce_constraint_name_tmpl (def, DB_CONSTRAINT_FOREIGN_KEY, attnames, NULL, constraint_name);
533 
534  fk_info.ref_class = ref_class;
535  fk_info.ref_attrs = ref_attrs;
536  fk_info.delete_action = (SM_FOREIGN_KEY_ACTION) del_action;
537  fk_info.update_action = (SM_FOREIGN_KEY_ACTION) upd_action;
538  fk_info.is_dropped = false;
539 
540  if (name == NULL)
541  {
542  assert (er_errid () != NO_ERROR);
543  error = er_errid ();
544  }
545  else
546  {
547  error = smt_add_constraint (def, DB_CONSTRAINT_FOREIGN_KEY, name, attnames, NULL, NULL, 0, &fk_info, NULL, NULL,
548  comment, SM_NORMAL_INDEX);
549  free_and_init (name);
550  }
551 
552  if (def->op == NULL && temp_cons != NULL)
553  {
555  }
556 
557  return error;
558 }
559 
560 /*
561  * dbt_add_set_attribute_domain() -
562  * return:
563  * def(in) :
564  * name(in) :
565  * class_attribute(in) :
566  * domain(in) :
567  */
568 int
569 dbt_add_set_attribute_domain (DB_CTMPL * def, const char *name, int class_attribute, const char *domain)
570 {
571  int error = NO_ERROR;
572 
574  CHECK_2ARGS_ERROR (def, name);
576 
577  error = smt_add_set_attribute_domain (def, name, class_attribute, domain, (DB_DOMAIN *) 0);
578 
579  return (error);
580 }
581 
582 /*
583  * dbt_change_domain() -
584  * return:
585  * def(in) :
586  * name(in) :
587  * class_attribute(in) :
588  * domain(in) :
589  */
590 int
591 dbt_change_domain (DB_CTMPL * def, const char *name, int class_attribute, const char *domain)
592 {
594  CHECK_2ARGS_ERROR (def, name);
596 
597  /* need a function for this ! */
599  return ER_DB_NO_DOMAIN_CHANGE;
600 }
601 
602 /*
603  * dbt_change_default() -
604  * return:
605  * def(in) :
606  * name(in) :
607  * class_attribute(in) :
608  * value(in) :
609  */
610 int
611 dbt_change_default (DB_CTMPL * def, const char *name, int class_attribute, DB_VALUE * value)
612 {
613  int error = NO_ERROR;
614 
616  CHECK_2ARGS_ERROR (def, name);
618 
619  error = smt_set_attribute_default (def, name, class_attribute, value, NULL);
620 
621  return (error);
622 }
623 
624 /*
625  * dbt_drop_set_attribute_domain() -
626  * return:
627  * def(in) :
628  * name(in) :
629  * class_attribute(in) :
630  * domain(in) :
631  */
632 int
633 dbt_drop_set_attribute_domain (DB_CTMPL * def, const char *name, int class_attribute, const char *domain)
634 {
635  int error = NO_ERROR;
636 
638  CHECK_2ARGS_ERROR (def, name);
640 
641  error = smt_delete_set_attribute_domain (def, name, class_attribute, domain, (DB_DOMAIN *) 0);
642 
643  return (error);
644 }
645 
646 /*
647  * dbt_drop_attribute() -
648  * return:
649  * def(in) :
650  * name(in) :
651  */
652 int
653 dbt_drop_attribute (DB_CTMPL * def, const char *name)
654 {
655  int error = NO_ERROR;
656  int sr_error = NO_ERROR;
657  int au_save;
658  SM_ATTRIBUTE *att;
659  MOP auto_increment_obj = NULL;
660 
662  CHECK_2ARGS_ERROR (def, name);
664 
665  sr_error = smt_find_attribute (def, name, false, &att);
666  if ((sr_error == NO_ERROR) && (att != NULL))
667  {
668  auto_increment_obj = att->auto_increment;
669  }
670 
671  error = smt_delete_any (def, name, ID_ATTRIBUTE);
672  if (error == ER_SM_ATTRIBUTE_NOT_FOUND)
673  {
674  error = smt_delete_any (def, name, ID_SHARED_ATTRIBUTE);
675  }
676 
677  /* remove related auto_increment serial obj if exist */
678  if ((error == NO_ERROR) && (auto_increment_obj != NULL))
679  {
680  OID *oidp, serial_obj_id;
681  /*
682  * check if user is creator or DBA
683  */
684  error = au_check_serial_authorization (auto_increment_obj);
685  if (error != NO_ERROR)
686  {
687  goto exit_on_error;
688  }
689 
690  oidp = ws_identifier (auto_increment_obj);
691  COPY_OID (&serial_obj_id, oidp);
692 
693  AU_DISABLE (au_save);
694 
695  error = obj_delete (auto_increment_obj);
696 
697  AU_ENABLE (au_save);
698  if (error == NO_ERROR)
699  {
700  (void) serial_decache (&serial_obj_id);
701  }
702  }
703 exit_on_error:
704  return (error);
705 }
706 
707 /*
708  * dbt_drop_shared_attribute() -
709  * return:
710  * def(in) :
711  * name(in) :
712  */
713 int
714 dbt_drop_shared_attribute (DB_CTMPL * def, const char *name)
715 {
716  int error = NO_ERROR;
717 
719  CHECK_2ARGS_ERROR (def, name);
721 
722  error = smt_delete_any (def, name, ID_SHARED_ATTRIBUTE);
723 
724  return (error);
725 }
726 
727 /*
728  * dbt_drop_class_attribute() -
729  * return:
730  * def(in) :
731  * name(in) :
732  */
733 int
734 dbt_drop_class_attribute (DB_CTMPL * def, const char *name)
735 {
736  int error = NO_ERROR;
737 
739  CHECK_2ARGS_ERROR (def, name);
741 
742  error = smt_delete_any (def, name, ID_CLASS_ATTRIBUTE);
743 
744  return (error);
745 }
746 
747 
748 /*
749  * dbt_add_method() -
750  * return:
751  * def(in) :
752  * name(in) :
753  * implementation(in) :
754  */
755 int
756 dbt_add_method (DB_CTMPL * def, const char *name, const char *implementation)
757 {
758  int error = NO_ERROR;
759 
761  CHECK_2ARGS_ERROR (def, name);
763 
764  error = smt_add_method_any (def, name, implementation, ID_METHOD);
765 
766  return (error);
767 }
768 
769 /*
770  * dbt_add_class_method() -
771  * return:
772  * def(in) :
773  * name(in) :
774  * implementation(in) :
775  */
776 int
777 dbt_add_class_method (DB_CTMPL * def, const char *name, const char *implementation)
778 {
779  int error = NO_ERROR;
780 
782  CHECK_2ARGS_ERROR (def, name);
784 
785  error = smt_add_method_any (def, name, implementation, ID_CLASS_METHOD);
786 
787  return (error);
788 }
789 
790 /*
791  * dbt_add_argument() -
792  * return:
793  * def(in) :
794  * name(in) :
795  * class_method(in) :
796  * index(in) :
797  * domain(in) :
798  */
799 int
800 dbt_add_argument (DB_CTMPL * def, const char *name, int class_method, int index, const char *domain)
801 {
802  int error = NO_ERROR;
803 
805  CHECK_2ARGS_ERROR (def, name);
807 
808  error = smt_assign_argument_domain (def, name, class_method, NULL, index, domain, (DB_DOMAIN *) 0);
809 
810  return (error);
811 }
812 
813 /*
814  * dbt_add_set_argument_domain() -
815  * return:
816  * def(in) :
817  * name(in) :
818  * class_method(in) :
819  * index(in) :
820  * domain(in) :
821  */
822 int
823 dbt_add_set_argument_domain (DB_CTMPL * def, const char *name, int class_method, int index, const char *domain)
824 {
825  int error = NO_ERROR;
826 
828  CHECK_2ARGS_ERROR (def, name);
830 
831  error = smt_add_set_argument_domain (def, name, class_method, NULL, index, domain, (DB_DOMAIN *) 0);
832 
833  return (error);
834 }
835 
836 /*
837  * dbt_change_method_implementation() -
838  * return:
839  * def(in) :
840  * name(in) :
841  * class_method(in) :
842  * newname(in) :
843  */
844 int
845 dbt_change_method_implementation (DB_CTMPL * def, const char *name, int class_method, const char *newname)
846 {
847  int error = NO_ERROR;
848 
850  CHECK_3ARGS_ERROR (def, name, newname);
852 
853  error = smt_change_method_implementation (def, name, class_method, newname);
854 
855  return (error);
856 }
857 
858 /*
859  * dbt_drop_method() -
860  * return:
861  * def(in) :
862  * name(in) :
863  */
864 int
865 dbt_drop_method (DB_CTMPL * def, const char *name)
866 {
867  int error = NO_ERROR;
868 
870  CHECK_2ARGS_ERROR (def, name);
872 
873  error = smt_delete_any (def, name, ID_METHOD);
874 
875  return (error);
876 }
877 
878 /*
879  * dbt_drop_class_method() -
880  * return:
881  * def(in) :
882  * name(in) :
883  */
884 int
885 dbt_drop_class_method (DB_CTMPL * def, const char *name)
886 {
887  int error = NO_ERROR;
888 
890  CHECK_2ARGS_ERROR (def, name);
892 
893  error = smt_delete_any (def, name, ID_CLASS_METHOD);
894 
895  return (error);
896 }
897 
898 /*
899  * dbt_add_super() -
900  * return:
901  * def(in) :
902  * super(in) :
903  */
904 int
905 dbt_add_super (DB_CTMPL * def, MOP super)
906 {
907  int error = NO_ERROR;
908 
910  CHECK_2ARGS_ERROR (def, super);
912 
913  error = smt_add_super (def, super);
914 
915  return (error);
916 }
917 
918 /*
919  * dbt_drop_super() -
920  * return:
921  * def(in) :
922  * super(in) :
923  */
924 int
926 {
927  int error = NO_ERROR;
928 
930  CHECK_2ARGS_ERROR (def, super);
932 
933  error = smt_delete_super (def, super);
934 
935  return (error);
936 }
937 
938 /*
939  * dbt_drop_super_connect() -
940  * return:
941  * def(in) :
942  * super(in) :
943  */
944 int
946 {
947  int error = NO_ERROR;
948 
950  CHECK_2ARGS_ERROR (def, super);
952 
953  error = smt_delete_super_connect (def, super);
954 
955  return (error);
956 }
957 
958 /*
959  * dbt_rename() -
960  * return:
961  * def(in) :
962  * name(in) :
963  * class_namespace(in) :
964  * newname(in) :
965  */
966 int
967 dbt_rename (DB_CTMPL * def, const char *name, int class_namespace, const char *newname)
968 {
969  int error = NO_ERROR;
970  SM_ATTRIBUTE *att;
971  MOP auto_increment_obj = NULL;
972 
974  CHECK_3ARGS_ERROR (def, name, newname);
976 
977  if (!class_namespace)
978  {
980  if (att != NULL)
981  auto_increment_obj = att->auto_increment;
982  }
983 
984  if (auto_increment_obj != NULL)
985  {
987  }
988 
989  if (error == NO_ERROR)
990  {
991  error = smt_rename_any (def, name, class_namespace, newname);
992 
993  /* rename related auto_increment serial obj if exist */
994  if ((error == NO_ERROR) && (auto_increment_obj != NULL))
995  {
996  error = do_update_auto_increment_serial_on_rename (att->auto_increment, def->name, newname);
997 
998  if (error != NO_ERROR)
999  {
1001  }
1002  }
1003  }
1004 
1005  return (error);
1006 }
1007 
1008 /*
1009  * dbt_add_method_file() -
1010  * return:
1011  * def(in) :
1012  * name(in) :
1013  */
1014 int
1015 dbt_add_method_file (DB_CTMPL * def, const char *name)
1016 {
1017  int error = NO_ERROR;
1018 
1020  CHECK_2ARGS_ERROR (def, name);
1022 
1023  error = smt_add_method_file (def, name);
1024 
1025  return (error);
1026 }
1027 
1028 /*
1029  * dbt_drop_method_file() -
1030  * return:
1031  * def(in) :
1032  * name(in) :
1033  */
1034 int
1035 dbt_drop_method_file (DB_CTMPL * def, const char *name)
1036 {
1037  int error = NO_ERROR;
1038 
1040  CHECK_2ARGS_ERROR (def, name);
1042 
1043  error = smt_drop_method_file (def, name);
1044 
1045  return (error);
1046 }
1047 
1048 /*
1049  * dbt_drop_method_files() -
1050  * return:
1051  * def(in) :
1052  */
1053 int
1055 {
1056  int error = NO_ERROR;
1057 
1059  CHECK_1ARG_ERROR (def);
1061 
1062  error = smt_reset_method_files (def);
1063 
1064  return (error);
1065 }
1066 
1067 /*
1068  * dbt_rename_method_file() -
1069  * return:
1070  * def(in) :
1071  * old_name(in) :
1072  * new_name(in) :
1073  */
1074 int
1075 dbt_rename_method_file (DB_CTMPL * def, const char *old_name, const char *new_name)
1076 {
1077  int error = NO_ERROR;
1078 
1080  CHECK_3ARGS_ERROR (def, old_name, new_name);
1082 
1083  error = smt_rename_method_file (def, old_name, new_name);
1084 
1085  return (error);
1086 }
1087 
1088 /*
1089  * dbt_set_loader_commands() -
1090  * return:
1091  * def(in) :
1092  * commands(in) :
1093  */
1094 int
1095 dbt_set_loader_commands (DB_CTMPL * def, const char *commands)
1096 {
1097  int error = NO_ERROR;
1098 
1100  CHECK_2ARGS_ERROR (def, commands);
1102 
1103  error = smt_set_loader_commands (def, commands);
1104 
1105  return (error);
1106 }
1107 
1108 /*
1109  * dbt_add_resolution() -
1110  * return:
1111  * def(in) :
1112  * super(in) :
1113  * name(in) :
1114  * alias(in) :
1115  */
1116 int
1117 dbt_add_resolution (DB_CTMPL * def, MOP super, const char *name, const char *alias)
1118 {
1119  int error = NO_ERROR;
1120 
1122  CHECK_3ARGS_ERROR (def, super, name);
1124 
1125  error = smt_add_resolution (def, super, name, alias);
1126 
1127  return (error);
1128 }
1129 
1130 /*
1131  * dbt_add_class_resolution() -
1132  * return:
1133  * def(in) :
1134  * super(in) :
1135  * name(in) :
1136  * alias(in) :
1137  */
1138 int
1139 dbt_add_class_resolution (DB_CTMPL * def, MOP super, const char *name, const char *alias)
1140 {
1141  int error = NO_ERROR;
1142 
1144  CHECK_3ARGS_ERROR (def, super, name);
1146 
1147  error = smt_add_class_resolution (def, super, name, alias);
1148 
1149  return (error);
1150 }
1151 
1152 /*
1153  * dbt_drop_resolution() -
1154  * return:
1155  * def(in) :
1156  * super(in) :
1157  * name(in) :
1158  */
1159 int
1160 dbt_drop_resolution (DB_CTMPL * def, MOP super, const char *name)
1161 {
1162  int error = NO_ERROR;
1163 
1165  CHECK_3ARGS_ERROR (def, super, name);
1167 
1168  error = smt_delete_resolution (def, super, name);
1169 
1170  return (error);
1171 }
1172 
1173 /*
1174  * dbt_drop_class_resolution() -
1175  * return:
1176  * def(in) :
1177  * super(in) :
1178  * name(in) :
1179  */
1180 int
1181 dbt_drop_class_resolution (DB_CTMPL * def, MOP super, const char *name)
1182 {
1183  int error = NO_ERROR;
1184 
1186  CHECK_3ARGS_ERROR (def, super, name);
1188 
1189  error = smt_delete_class_resolution (def, super, name);
1190 
1191  return (error);
1192 }
1193 
1194 /*
1195  * dbt_add_query_spec() -
1196  * return:
1197  * def(in) :
1198  * query(in) :
1199  */
1200 int
1201 dbt_add_query_spec (DB_CTMPL * def, const char *query)
1202 {
1203  int error = NO_ERROR;
1204 
1206  CHECK_2ARGS_ERROR (def, query);
1208 
1209  error = smt_add_query_spec (def, query);
1210 
1211  return (error);
1212 }
1213 
1214 /*
1215  * dbt_drop_query_spec() -
1216  * return:
1217  * def(in) :
1218  * query_no(in) :
1219  */
1220 int
1221 dbt_drop_query_spec (DB_CTMPL * def, const int query_no)
1222 {
1223  int error = NO_ERROR;
1224 
1226  CHECK_1ARG_ERROR (def);
1228 
1229  error = smt_drop_query_spec (def, query_no);
1230 
1231  return (error);
1232 }
1233 
1234 /*
1235  * dbt_reset_query_spec() - delete all query specs from template
1236  * return:
1237  * def(in) :
1238  */
1239 int
1241 {
1242  int error = NO_ERROR;
1243 
1245  CHECK_1ARG_ERROR (def);
1247 
1248  error = smt_reset_query_spec (def);
1249 
1250  return (error);
1251 }
1252 
1253 /*
1254  * dbt_change_query_spec() -
1255  * return:
1256  * def(in) :
1257  * new_query(in) :
1258  * query_no(in) :
1259  */
1260 int
1261 dbt_change_query_spec (DB_CTMPL * def, const char *new_query, const int query_no)
1262 {
1263  int error = NO_ERROR;
1264 
1266  CHECK_2ARGS_ERROR (def, new_query);
1268 
1269  error = smt_change_query_spec (def, new_query, query_no);
1270 
1271  return (error);
1272 }
1273 
1274 /*
1275  * dbt_set_object_id() -
1276  * return:
1277  * def(in) :
1278  * id_list(in) :
1279  */
1280 int
1282 {
1283  return NO_ERROR;
1284 }
char * sm_produce_constraint_name_tmpl(SM_TEMPLATE *tmpl, DB_CONSTRAINT_TYPE constraint_type, const char **att_names, const int *asc_desc, const char *given_name)
int dbt_constrain_non_null(DB_CTMPL *def, const char *name, int class_attribute, int on_or_off)
Definition: db_temp.c:344
int au_check_serial_authorization(MOP serial_object)
#define OID_INITIALIZER
Definition: oid.h:36
#define ER_SM_ATTRIBUTE_NOT_FOUND
Definition: error_code.h:311
int tran_system_savepoint(const char *savept_name)
static DB_CTMPL * dbt_reserve_name(DB_CTMPL *def, const char *name)
Definition: db_temp.c:186
#define CHECK_MODIFICATION_ERROR()
Definition: db.h:121
#define NO_ERROR
Definition: error_code.h:46
#define AU_DISABLE(save)
Definition: authenticate.h:106
int smt_set_loader_commands(SM_TEMPLATE *template_, const char *commands)
int smt_add_super(SM_TEMPLATE *template_, MOP super_class)
int dbt_add_foreign_key(DB_CTMPL *def, const char *constraint_name, const char **attnames, const char *ref_class, const char **ref_attrs, int del_action, int upd_action, const char *comment)
Definition: db_temp.c:524
#define DB_IS_CONSTRAINT_UNIQUE_FAMILY(c)
Definition: dbtype_def.h:170
int dbt_reset_query_spec(DB_CTMPL *def)
Definition: db_temp.c:1240
int dbt_drop_class_method(DB_CTMPL *def, const char *name)
Definition: db_temp.c:885
#define SM_MAP_CONSTRAINT_TO_ATTFLAG(c)
Definition: class_object.h:93
int dbt_drop_attribute(DB_CTMPL *def, const char *name)
Definition: db_temp.c:653
#define ASSERT_ERROR()
int smt_delete_any(SM_TEMPLATE *template_, const char *name, SM_NAME_SPACE name_space)
int smt_quit(SM_TEMPLATE *template_)
int smt_rename_method_file(SM_TEMPLATE *template_, const char *old_name, const char *new_name)
#define CHECK_2ARGS_ERROR(obj1, obj2)
Definition: db.h:195
int dbt_drop_constraint(DB_CTMPL *def, DB_CONSTRAINT_TYPE constraint_type, const char *constraint_name, const char **attnames, int class_attributes)
Definition: db_temp.c:473
int obj_delete(MOP op)
int smt_drop_method_file(SM_TEMPLATE *template_, const char *name)
int dbt_drop_resolution(DB_CTMPL *def, MOP super, const char *name)
Definition: db_temp.c:1160
int dbt_change_default(DB_CTMPL *def, const char *name, int class_attribute, DB_VALUE *value)
Definition: db_temp.c:611
struct tp_domain * domain
Definition: set_object.h:85
DB_CTMPL * dbt_copy_class(const char *new_name, const char *existing_name, SM_CLASS **class_)
Definition: db_temp.c:160
SM_FOREIGN_KEY_ACTION
#define CHECK_2ARGS_NULL(obj1, obj2)
Definition: db.h:174
int dbt_drop_class_resolution(DB_CTMPL *def, MOP super, const char *name)
Definition: db_temp.c:1181
DB_OBJECT * dbt_finish_class(DB_CTMPL *def)
Definition: db_temp.c:226
int smt_delete_set_attribute_domain(SM_TEMPLATE *template_, const char *name, int class_attribute, const char *domain_string, DB_DOMAIN *domain)
OID * ws_identifier(MOP mop)
Definition: work_space.c:2805
int do_update_auto_increment_serial_on_rename(MOP serial_obj, const char *class_name, const char *att_name)
#define ER_DB_NO_DOMAIN_CHANGE
Definition: error_code.h:894
int smt_add_constraint(SM_TEMPLATE *template_, DB_CONSTRAINT_TYPE constraint_type, const char *constraint_name, const char **att_names, const int *asc_desc, const int *attrs_prefix_length, int class_attribute, SM_FOREIGN_KEY_INFO *fk_info, SM_PREDICATE_INFO *filter_index, SM_FUNCTION_INFO *function_index, const char *comment, SM_INDEX_STATUS index_status)
int dbt_add_class_attribute(DB_CTMPL *def, const char *name, const char *domain, DB_VALUE *default_value)
Definition: db_temp.c:317
int er_errid(void)
int smt_add_set_argument_domain(SM_TEMPLATE *template_, const char *name, int class_method, const char *implementation, int index, const char *domain_string, DB_DOMAIN *domain)
int smt_rename_any(SM_TEMPLATE *template_, const char *name, const bool class_namespace, const char *new_name)
int dbt_add_set_attribute_domain(DB_CTMPL *def, const char *name, int class_attribute, const char *domain)
Definition: db_temp.c:569
int dbt_add_shared_attribute(DB_CTMPL *def, const char *name, const char *domain, DB_VALUE *default_value)
Definition: db_temp.c:294
#define AU_ALTER
Definition: authenticate.h:73
#define COPY_OID(dest_oid_ptr, src_oid_ptr)
Definition: oid.h:63
SM_FOREIGN_KEY_ACTION update_action
Definition: class_object.h:482
int smt_reset_query_spec(SM_TEMPLATE *template_)
int smt_add_method_any(SM_TEMPLATE *template_, const char *name, const char *function, SM_NAME_SPACE name_space)
int dbt_add_super(DB_CTMPL *def, MOP super)
Definition: db_temp.c:905
int smt_reset_method_files(SM_TEMPLATE *template_)
int smt_delete_super_connect(SM_TEMPLATE *template_, MOP super_class)
int dbt_add_class_resolution(DB_CTMPL *def, MOP super, const char *name, const char *alias)
Definition: db_temp.c:1139
SM_ATTRIBUTE_FLAG
void er_set(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
int smt_delete_resolution(SM_TEMPLATE *template_, MOP super_class, const char *name)
int tran_abort_upto_system_savepoint(const char *savepoint_name)
#define assert(x)
int dbt_drop_method(DB_CTMPL *def, const char *name)
Definition: db_temp.c:865
int smt_drop_query_spec(SM_TEMPLATE *def, const int index)
DB_CONSTRAINT_TYPE
Definition: dbtype_def.h:452
#define CHECK_MODIFICATION_NULL()
Definition: db.h:124
#define ATTR_RENAME_SAVEPOINT
Definition: db_temp.c:58
int smt_assign_argument_domain(SM_TEMPLATE *template_, const char *name, int class_method, const char *implementation, int index, const char *domain_string, DB_DOMAIN *domain)
int smt_add_attribute_w_dflt(DB_CTMPL *def, const char *name, const char *domain_string, DB_DOMAIN *domain, DB_VALUE *default_value, const SM_NAME_SPACE name_space, DB_DEFAULT_EXPR *default_expr, DB_DEFAULT_EXPR_TYPE *on_update, const char *comment)
#define CHECK_1ARG_ERROR(obj)
Definition: db.h:186
int dbt_rename_method_file(DB_CTMPL *def, const char *old_name, const char *new_name)
Definition: db_temp.c:1075
SM_TEMPLATE * smt_copy_class(const char *new_name, const char *existing_name, SM_CLASS **class_)
#define CHECK_1ARG_NULL(obj)
Definition: db.h:171
DB_CTMPL * dbt_create_vclass(const char *name)
Definition: db_temp.c:104
int dbt_drop_super(DB_CTMPL *def, MOP super)
Definition: db_temp.c:925
int dbt_add_resolution(DB_CTMPL *def, MOP super, const char *name, const char *alias)
Definition: db_temp.c:1117
int dbt_drop_super_connect(DB_CTMPL *def, MOP super)
Definition: db_temp.c:945
int smt_change_query_spec(SM_TEMPLATE *def, const char *query, const int index)
#define CHECK_3ARGS_ERROR(obj1, obj2, obj3)
Definition: db.h:198
int do_check_fk_constraints(DB_CTMPL *ctemplate, PT_NODE *constraints)
#define NULL
Definition: freelistheap.h:34
int dbt_add_attribute(DB_CTMPL *def, const char *name, const char *domain, DB_VALUE *default_value)
Definition: db_temp.c:272
LC_FIND_CLASSNAME
DB_CTMPL * dbt_create_class(const char *name)
Definition: db_temp.c:76
int dbt_add_argument(DB_CTMPL *def, const char *name, int class_method, int index, const char *domain)
Definition: db_temp.c:800
SM_TEMPLATE * smt_edit_class_mop(MOP op, DB_AUTH db_auth_type)
int smt_add_set_attribute_domain(SM_TEMPLATE *template_, const char *name, int class_attribute, const char *domain_string, DB_DOMAIN *domain)
int dbt_constrain_unique(DB_CTMPL *def, const char *attname, int on_or_off)
Definition: db_temp.c:382
int smt_add_class_resolution(SM_TEMPLATE *template_, MOP super_class, const char *name, const char *alias)
int dbt_set_object_id(DB_CTMPL *def, DB_NAMELIST *id_list)
Definition: db_temp.c:1281
DB_CTMPL * dbt_edit_class(MOP classobj)
Definition: db_temp.c:133
int dbt_add_method(DB_CTMPL *def, const char *name, const char *implementation)
Definition: db_temp.c:756
int dbt_add_query_spec(DB_CTMPL *def, const char *query)
Definition: db_temp.c:1201
#define ERROR_SET(error, code)
Definition: db_temp.c:52
void classobj_free_class_constraints(SM_CLASS_CONSTRAINT *constraints)
static void error(const char *msg)
Definition: gencat.c:331
int dbt_drop_set_attribute_domain(DB_CTMPL *def, const char *name, int class_attribute, const char *domain)
Definition: db_temp.c:633
int dbt_drop_method_files(DB_CTMPL *def)
Definition: db_temp.c:1054
int dbt_add_class_method(DB_CTMPL *def, const char *name, const char *implementation)
Definition: db_temp.c:777
int smt_delete_class_resolution(SM_TEMPLATE *template_, MOP super_class, const char *name)
const char * ref_class
Definition: class_object.h:475
#define CHECK_CONNECT_NULL()
Definition: db.h:91
#define ER_LC_CLASSNAME_EXIST
Definition: error_code.h:122
#define ARG_FILE_LINE
Definition: error_manager.h:44
int dbt_add_constraint(DB_CTMPL *def, DB_CONSTRAINT_TYPE constraint_type, const char *constraint_name, const char **attnames, int class_attributes, const char *comment)
Definition: db_temp.c:423
#define AU_ENABLE(save)
Definition: authenticate.h:113
const char * name
Definition: class_object.h:787
SM_FOREIGN_KEY_ACTION delete_action
Definition: class_object.h:481
#define DB_IS_CONSTRAINT_FAMILY(c)
Definition: dbtype_def.h:181
#define free_and_init(ptr)
Definition: memory_alloc.h:147
int smt_change_method_implementation(SM_TEMPLATE *template_, const char *name, int class_method, const char *function)
LC_FIND_CLASSNAME locator_reserve_class_name(const char *class_name, OID *class_oid)
Definition: locator_cl.c:179
int dbt_drop_shared_attribute(DB_CTMPL *def, const char *name)
Definition: db_temp.c:714
int smt_drop_constraint(SM_TEMPLATE *template_, const char **att_names, const char *constraint_name, int class_attribute, SM_ATTRIBUTE_FLAG constraint)
int dbt_drop_query_spec(DB_CTMPL *def, const int query_no)
Definition: db_temp.c:1221
int dbt_change_query_spec(DB_CTMPL *def, const char *new_query, const int query_no)
Definition: db_temp.c:1261
SM_TEMPLATE * smt_def_class(const char *name)
int smt_add_query_spec(SM_TEMPLATE *template_, const char *specification)
int serial_decache(OID *oid)
const char ** ref_attrs
Definition: class_object.h:476
int dbt_rename(DB_CTMPL *def, const char *name, int class_namespace, const char *newname)
Definition: db_temp.c:967
int smt_add_method_file(SM_TEMPLATE *template_, const char *filename)
SM_TEMPLATE * smt_def_typed_class(const char *name, SM_CLASS_TYPE ct)
#define ER_SM_INVALID_CONSTRAINT
Definition: error_code.h:871
int dbt_add_set_argument_domain(DB_CTMPL *def, const char *name, int class_method, int index, const char *domain)
Definition: db_temp.c:823
void dbt_abort_class(DB_CTMPL *def)
Definition: db_temp.c:249
int smt_find_attribute(SM_TEMPLATE *template_, const char *name, int class_attribute, SM_ATTRIBUTE **attp)
int dbt_add_method_file(DB_CTMPL *def, const char *name)
Definition: db_temp.c:1015
int smt_set_attribute_default(SM_TEMPLATE *template_, const char *name, int class_attribute, DB_VALUE *proposed_value, DB_DEFAULT_EXPR *default_expr)
int sm_finish_class(SM_TEMPLATE *template_, MOP *classmop)
int dbt_change_method_implementation(DB_CTMPL *def, const char *name, int class_method, const char *newname)
Definition: db_temp.c:845
int dbt_set_loader_commands(DB_CTMPL *def, const char *commands)
Definition: db_temp.c:1095
#define SM_FIND_NAME_IN_COMPONENT_LIST(complist, name)
Definition: class_object.h:146
DB_VALUE * default_value
Definition: esql_cli.c:348
int dbt_change_domain(DB_CTMPL *def, const char *name, int class_attribute, const char *domain)
Definition: db_temp.c:591
int dbt_drop_method_file(DB_CTMPL *def, const char *name)
Definition: db_temp.c:1035
int dbt_drop_class_attribute(DB_CTMPL *def, const char *name)
Definition: db_temp.c:734
SM_ATTRIBUTE * attributes
Definition: class_object.h:790
int smt_delete_super(SM_TEMPLATE *template_, MOP super_class)
#define CHECK_CONNECT_ERROR()
Definition: db.h:88
int smt_add_resolution(SM_TEMPLATE *template_, MOP super_class, const char *name, const char *alias)