CUBRID Engine  latest
db_class.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_class.c - API functions for schema definition.
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_schema.h"
49 
50 /* Error signaling macros */
51 static int drop_internal (MOP class_, const char *name, SM_NAME_SPACE name_space);
52 
53 static int add_method_internal (MOP class_, const char *name, const char *implementation, SM_NAME_SPACE name_space);
54 
55 static int add_arg_domain (DB_OBJECT * class_, const char *name, int class_method, int index, int initial_domain,
56  const char *domain);
57 /*
58  * CLASS DEFINITION
59  */
60 
61 /*
62  * db_create_class() - This function creates a new class.
63  * Returns NULL on error with error status left in global error.
64  * The most common reason for returning NULL was that a class with
65  * the given name could not be found.
66  * return : new class object pointer.
67  * name(in): the name of a class
68  */
69 DB_OBJECT *
70 db_create_class (const char *name)
71 {
72  SM_TEMPLATE *def;
73  MOP class_;
74  OID class_oid = OID_INITIALIZER;
75 
77  CHECK_1ARG_NULL (name);
79 
80  class_ = NULL;
81  def = smt_def_class (name);
82  if (def != NULL)
83  {
84  /* Reserve class name. We don't expect failures. */
85  if (locator_reserve_class_name (def->name, &class_oid) != LC_CLASSNAME_RESERVED)
86  {
87  assert_release (false);
88  smt_quit (def);
89  return NULL;
90  }
91 
92  if (sm_update_class (def, &class_) != NO_ERROR)
93  {
94  smt_quit (def);
95  }
96  }
97  return (class_);
98 }
99 
100 /*
101  * db_drop_class() - This function is used to completely remove a class and
102  * all of its instances from the database. Obviously this should be used
103  * with care. Returns non-zero error status if the operation could not be
104  * performed. The most common reason for error is that the current user was
105  * not authorized to delete the specified class.
106  * return : error code
107  * class(in): class object
108  */
109 int
111 {
112  return db_drop_class_ex (class_, false);
113 }
114 
115 /*
116  * db_drop_class_ex() - Implement to remove class.
117  * return : error code
118  * class(in): class object
119  * is_cascade_constraints(in): whether drop ralative FK constrants
120  */
121 int
122 db_drop_class_ex (MOP class_, bool is_cascade_constraints)
123 {
124  int retval;
125 
127  CHECK_1ARG_ERROR (class_);
129 
131 
132  if (!retval)
133  {
134  retval = sm_delete_class_mop (class_, is_cascade_constraints);
135  }
136 
137  return (retval);
138 }
139 
140 /*
141  * db_rename_class() - This function changes the name of a class in the
142  * database. Returns non-zero error if the operation could not be
143  * performed. The most common reason for rename failure is that another
144  * class with the desired name existed. The current user may also not
145  * have ALTER class authorization.
146  * return : error code
147  * classop(in/out): class object
148  * new_name(in) : the new name
149  */
150 int
151 db_rename_class (MOP classop, const char *new_name)
152 {
153  int retval;
154 
156  CHECK_2ARGS_ERROR (classop, new_name);
158 
160  if (!retval)
161  {
162  retval = sm_rename_class (classop, new_name);
163  }
164 
165  return (retval);
166 }
167 
168 /*
169  * ATTRIBUTES
170  */
171 
172 /*
173  * db_add_attribute_internal() - This is a generic work function for adding
174  * attributes of the various types. It saves redundant error checking code
175  * in each of the type specific attribute routines.
176  * return : error code
177  * class(in/out) : class object
178  * name(in) : attribute name
179  * domain(in) : domain string
180  * default_value(in): default_value
181  * namespace(in) : namespace identifier
182  */
183 int
184 db_add_attribute_internal (MOP class_, const char *name, const char *domain, DB_VALUE * default_value,
185  SM_NAME_SPACE name_space)
186 {
187  int error = NO_ERROR;
188  SM_TEMPLATE *def;
189  MOP newmop;
190 
193  CHECK_3ARGS_RETURN_EXPR (class_, name, domain, ER_OBJ_INVALID_ARGUMENTS);
194 
195  def = smt_edit_class_mop (class_, AU_ALTER);
196  if (def == NULL)
197  {
198  assert (er_errid () != NO_ERROR);
199  error = er_errid ();
200  }
201  else
202  {
203  error = smt_add_attribute_any (def, name, domain, (DB_DOMAIN *) 0, name_space, false, NULL, NULL);
204  if (error)
205  {
206  smt_quit (def);
207  }
208  else
209  {
210  if (default_value != NULL)
211  {
212  if (name_space == ID_CLASS || name_space == ID_CLASS_ATTRIBUTE)
213  {
214  error = smt_set_attribute_default (def, name, 1, default_value, NULL);
215  }
216  else
217  {
218  error = smt_set_attribute_default (def, name, 0, default_value, NULL);
219  }
220  }
221  if (error)
222  {
223  smt_quit (def);
224  }
225  else
226  {
227  error = sm_update_class_auto (def, &newmop);
228  if (error)
229  {
230  smt_quit (def);
231  }
232  }
233  }
234  }
235  return (error);
236 }
237 
238 /*
239  * db_add_attribute() - This function adds a normal attribute to a class
240  * definition.
241  * return : error code
242  * obj(in/out): class or instance (usually a class)
243  * name(in) : attribute name
244  * domain(in) : domain specifier
245  * default_value(in): optional default value
246  */
247 int
248 db_add_attribute (MOP obj, const char *name, const char *domain, DB_VALUE * default_value)
249 {
250  int retval = 0;
251 
252  retval = db_add_attribute_internal (obj, name, domain, default_value, ID_ATTRIBUTE);
253 
254  return (retval);
255 }
256 
257 /*
258  * db_add_shared_attribute() - This function adds a shared attribute to a class
259  * definition.
260  * return : error code
261  * obj(in) : class or instance (usually a class)
262  * name(in) : attribute name
263  * domain(in) : domain specifier
264  * default_value(in): optional default value
265  *
266  */
267 int
268 db_add_shared_attribute (MOP obj, const char *name, const char *domain, DB_VALUE * default_value)
269 {
270  int retval;
271 
272  retval = (db_add_attribute_internal (obj, name, domain, default_value, ID_SHARED_ATTRIBUTE));
273 
274  return (retval);
275 }
276 
277 /*
278  * db_add_class_attribute() - This function adds a class attribute to a class
279  * definition.
280  * return : error code
281  * obj(in): class or instance (usually a class)
282  * name(in): attribute name
283  * domain(in): domain specifier
284  * default_value(in): optional default value
285  *
286  */
287 int
288 db_add_class_attribute (MOP obj, const char *name, const char *domain, DB_VALUE * default_value)
289 {
290  int retval;
291 
292  retval = (db_add_attribute_internal (obj, name, domain, default_value, ID_CLASS_ATTRIBUTE));
293 
294  return (retval);
295 }
296 
297 /*
298  * drop_attribute_internal() - This is internal work function for removing
299  * definitions from a class. Can be used to remove any type of attribute
300  * or method. The db_ function layer currently forces the callers to
301  * recognize the difference between normal/shared/class attributes and
302  * normal/class methods when calling the drop routines. The interpreter
303  * doesn't have this restriction since the smt_ layer offers an interface
304  * similar to this one. Consider offering the same thing at the db_ layer.
305  * return : error code
306  * class(in) : class or instance
307  * name(in) : attribute or method name
308  * namespace(in): namespace identifier
309  */
310 static int
311 drop_internal (MOP class_, const char *name, SM_NAME_SPACE name_space)
312 {
313  int error = NO_ERROR;
314  SM_TEMPLATE *def;
315  MOP newmop;
316 
320 
321  def = smt_edit_class_mop (class_, AU_ALTER);
322  if (def == NULL)
323  {
324  assert (er_errid () != NO_ERROR);
325  error = er_errid ();
326  }
327  else
328  {
329  error = smt_delete_any (def, name, name_space);
330  if (error)
331  {
332  smt_quit (def);
333  }
334  else
335  {
336  error = sm_update_class_auto (def, &newmop);
337  if (error)
338  {
339  smt_quit (def);
340  }
341  }
342  }
343 
344  return (error);
345 }
346 
347 /*
348  * db_drop_attribute() - see the function db_drop_attribute_internal()
349  * return : error code
350  * class(in): class or instance
351  * name(in) : attribute name
352  */
353 int
354 db_drop_attribute (MOP class_, const char *name)
355 {
356  int error = NO_ERROR;
357 
360  CHECK_2ARGS_ERROR (class_, name);
361 
362  error = do_check_partitioned_class (class_, CHECK_PARTITION_SUBS, (char *) name);
363  if (!error)
364  {
365  error = db_drop_attribute_internal (class_, name);
366  }
367 
368  return error;
369 }
370 
371 /*
372  * db_drop_attribute_internal() - This function removes both instance & shared
373  * attributes from a class. The attribute is consequently dropped from any
374  * subclasses, as well.
375  * return : error code
376  * class(in): class or instance
377  * name(in) : attribute name
378  */
379 int
380 db_drop_attribute_internal (MOP class_, const char *name)
381 {
382  int error = NO_ERROR;
383 
384  /* kludge, since instance & shared attributes are really supposed to be in the same logical namespace, we should
385  * allow shared attributes to be deleted here as well. Unfortunately, the template function smt_delete_any() doesn't
386  * support this. Instead, we try the operation and if it gets an error, we try again. */
387  error = drop_internal (class_, name, ID_ATTRIBUTE);
388  if (error == ER_SM_ATTRIBUTE_NOT_FOUND)
389  error = drop_internal (class_, name, ID_SHARED_ATTRIBUTE);
390 
391  return (error);
392 }
393 
394 /*
395  * db_drop_shared_attribute - This function Removes the definitino of a
396  * shared attribute.
397  * return: error code
398  * class(in): class or instance
399  * name(in) : attribute name
400  *
401  * note : Not necessary now that db_drop_attribute handles this.
402  */
403 int
404 db_drop_shared_attribute (MOP class_, const char *name)
405 {
406  int retval;
407 
408  retval = drop_internal (class_, name, ID_SHARED_ATTRIBUTE);
409 
410  return (retval);
411 }
412 
413 /*
414  * db_drop_class_attribute() - This function removes a class attribute
415  * from a class.
416  * return : error code
417  * class(in): class or instance
418  * name(in) : attribute name
419  */
420 int
421 db_drop_class_attribute (MOP class_, const char *name)
422 {
423  int retval;
424 
425  retval = drop_internal (class_, name, ID_CLASS_ATTRIBUTE);
426 
427  return (retval);
428 }
429 
430 /*
431  * db_add_set_attribute_domain() - This function adds domain information to an
432  * attribute whose basic domain is one of the set types: set, multiset, or
433  * sequence. If the named attribute has one of these set domains, this
434  * function further specifies the allowed domains for the elements of the
435  * set.
436  * return : error code
437  * class(in): class or instance pointer
438  * name(in) : attribute name
439  * class_attribute(in) : 0 if this is not a class attribute
440  * non-zero if this is a class attribute
441  * domain(in): domain name
442  */
443 int
444 db_add_set_attribute_domain (MOP class_, const char *name, int class_attribute, const char *domain)
445 {
446  int error = NO_ERROR;
447  SM_TEMPLATE *def;
448  MOP newmop;
449 
452  CHECK_3ARGS_RETURN_EXPR (class_, name, domain, ER_OBJ_INVALID_ARGUMENTS);
453 
454  def = smt_edit_class_mop (class_, AU_ALTER);
455  if (def == NULL)
456  {
457  assert (er_errid () != NO_ERROR);
458  error = er_errid ();
459  }
460  else
461  {
462  /* should make sure this is a set attribute */
463  error = smt_add_set_attribute_domain (def, name, class_attribute, domain, (DB_DOMAIN *) 0);
464  if (error)
465  {
466  smt_quit (def);
467  }
468  else
469  {
470  error = sm_update_class (def, &newmop);
471  if (error)
472  {
473  smt_quit (def);
474  }
475  }
476  }
477  return (error);
478 }
479 
480 /*
481  * db_add_set_attribute_domain() - see the function db_add_set_attribute_domain
482  * return : error code
483  * class(in): class or instance pointer
484  * name(in) : attribute name
485  * domain(in): domain name
486  *
487  * note : This function is provided for backwards compatibility.
488  */
489 int
490 db_add_element_domain (MOP class_, const char *name, const char *domain)
491 {
492  int retval;
493 
494  retval = db_add_set_attribute_domain (class_, name, 0, domain);
495 
496  return (retval);
497 }
498 
499 /*
500  * db_drop_set_attribute_domain() - This function used to remove domain
501  * specifications for attributes whose original domain was "set",
502  * "multi_set", or "sequence". The set valued attributes can be given
503  * further domain information using db_add_element_domain which defines
504  * the allowed types for elements of the set. Use db_drop_element_domain
505  * to remove entries from the set domain list.
506  * returns/side-effects: error code
507  * class(in) : class or instance
508  * name(in) : attribute name
509  * domain(in): domain name
510  *
511  */
512 int
513 db_drop_set_attribute_domain (MOP class_, const char *name, int class_attribute, const char *domain)
514 {
515  int error = NO_ERROR;
516  SM_TEMPLATE *def;
517  MOP newmop;
518 
521  CHECK_3ARGS_RETURN_EXPR (class_, name, domain, ER_OBJ_INVALID_ARGUMENTS);
522 
523  def = smt_edit_class_mop (class_, AU_ALTER);
524  if (def == NULL)
525  {
526  assert (er_errid () != NO_ERROR);
527  error = er_errid ();
528  }
529  else
530  {
531  error = smt_delete_set_attribute_domain (def, name, class_attribute, domain, (DB_DOMAIN *) 0);
532  if (error)
533  {
534  smt_quit (def);
535  }
536  else
537  {
538  error = sm_update_class (def, &newmop);
539  if (error)
540  {
541  smt_quit (def);
542  }
543  }
544  }
545 
546  return (error);
547 }
548 
549 /*
550  * db_drop_element_domain() - See the function db_drop_set_attribute_domain
551  * returns/side-effects: error code
552  * class(in) : class or instance
553  * name(in) : attribute name
554  * domain(in): domain name
555  *
556  * note : This function is provided for backwards compatibility.
557  */
558 int
559 db_drop_element_domain (MOP class_, const char *name, const char *domain)
560 {
561  int retval;
562 
563  retval = db_drop_set_attribute_domain (class_, name, 0, domain);
564 
565  return (retval);
566 }
567 
568 /*
569  * db_change_default() - This function changes the default value definition of
570  * an attribute. Default values are normally established when the attribute
571  * is first defined using the db_add_attribute() function. This function
572  * can be used to change the default value after the attribute has been
573  * defined.
574  * return : error code
575  * class(in): class or instance pointer
576  * name(in) : attribute name
577  * value(in): value container with value
578  *
579  * note: Do not use this function to change the values of class attributes.
580  * Instead, the db_put() function is used with the class object as the
581  * first argument.
582  */
583 int
584 db_change_default (MOP class_, const char *name, DB_VALUE * value)
585 {
586  int error = NO_ERROR;
587  SM_TEMPLATE *def;
588  MOP newmop;
589 
592  CHECK_3ARGS_RETURN_EXPR (class_, name, value, ER_OBJ_INVALID_ARGUMENTS);
593 
594  def = smt_edit_class_mop (class_, AU_ALTER);
595  if (def == NULL)
596  {
597  assert (er_errid () != NO_ERROR);
598  error = er_errid ();
599  }
600  else
601  {
602  error = smt_set_attribute_default (def, name, false, value, NULL);
603  if (error)
604  {
605  smt_quit (def);
606  }
607  else
608  {
609  error = sm_update_class (def, &newmop);
610  if (error)
611  {
612  smt_quit (def);
613  }
614  }
615  }
616  return (error);
617 }
618 
619 /*
620  * db_rename() - See the db_rename_internal function.
621  * return : error code
622  * class(in) : class to alter
623  * name(in) : component name
624  * class_namespace(in): class namespace flag
625  * newname(in) : new component name
626  */
627 int
628 db_rename (MOP class_, const char *name, int class_namespace, const char *newname)
629 {
630  int error = NO_ERROR;
631 
634 
635  error = do_check_partitioned_class (class_, CHECK_PARTITION_SUBS, (char *) name);
636  if (!error)
637  {
638  error = db_rename_internal (class_, name, class_namespace, newname);
639  }
640 
641  return error;
642 }
643 
644 /*
645  * db_rename_internal() - This will rename any of the various class components:
646  * attributes, class attributes, methods, class methods.
647  * return : error code
648  * class(in) : class to alter
649  * name(in) : component name
650  * class_namespace(in): class namespace flag
651  * newname(in) : new component name
652  */
653 int
654 db_rename_internal (MOP class_, const char *name, int class_namespace, const char *newname)
655 {
656  int error = NO_ERROR;
657  SM_TEMPLATE *def;
658  MOP newmop;
659 
662 
663  def = smt_edit_class_mop (class_, AU_ALTER);
664  if (def == NULL)
665  {
666  assert (er_errid () != NO_ERROR);
667  error = er_errid ();
668  }
669  else
670  {
671  error = smt_rename_any (def, name, class_namespace, newname);
672  if (error)
673  {
674  smt_quit (def);
675  }
676  else
677  {
678  error = sm_update_class_auto (def, &newmop);
679  if (error)
680  {
681  smt_quit (def);
682  }
683  }
684  }
685 
686  return (error);
687 }
688 
689 /*
690  * db_rename_attribute() - This function renames an attribute and propagates
691  * the changes to the affected sub classes.
692  * return: error code
693  * class(in) : class or instance
694  * name(in) : current attribute name
695  * class_attribute(in): class attribute flag
696  * newname(in) : new attribute name
697  *
698  * note : This function is obsoleted, use db_rename function
699  */
700 int
701 db_rename_attribute (MOP class_, const char *name, int class_attribute, const char *newname)
702 {
703  int error = NO_ERROR;
704 
705  error = do_check_partitioned_class (class_, CHECK_PARTITION_SUBS, (char *) name);
706  if (!error)
707  {
708  error = db_rename_internal (class_, name, class_attribute, newname);
709  }
710 
711  return error;
712 }
713 
714 /*
715  * db_rename_method() - This function renames an method and propagates the
716  * changes to the affected sub classes.
717  * return: error code
718  * class(in) : class or instance
719  * name(in) : current method name
720  * class_method(in): class method flag
721  * newname(in) : new method name
722  *
723  * note : This function is obsoleted, use db_rename function
724  */
725 int
726 db_rename_method (MOP class_, const char *name, int class_method, const char *newname)
727 {
728  int retval;
729 
730  retval = db_rename_internal (class_, name, class_method, newname);
731 
732  return (retval);
733 }
734 
735 /*
736  * METHODS
737  */
738 
739 /*
740  * add_method_internal() - This is internal work function to add a method
741  * definition.
742  * return : error code
743  * class(in) : class or instance
744  * name(in): method name
745  * implementation(in): implementation function name
746  * namespace(in): attribute or class namespace identifier
747  */
748 static int
749 add_method_internal (MOP class_, const char *name, const char *implementation, SM_NAME_SPACE name_space)
750 {
751  int error = NO_ERROR;
752  SM_TEMPLATE *def;
753  MOP newmop;
754 
758 
759  def = smt_edit_class_mop (class_, AU_ALTER);
760  if (def == NULL)
761  {
762  assert (er_errid () != NO_ERROR);
763  error = er_errid ();
764  }
765  else
766  {
767  error = smt_add_method_any (def, name, implementation, name_space);
768  if (error)
769  {
770  smt_quit (def);
771  }
772  else
773  {
774  error = sm_update_class_auto (def, &newmop);
775  if (error)
776  {
777  smt_quit (def);
778  }
779  }
780  }
781  return (error);
782 }
783 
784 /*
785  * db_add_method() - This function Defines a normal (instance) method.
786  * return : error code
787  * class(in) : class or instance
788  * name(in): method name
789  * implementation(in): implementation function name
790  *
791  * note : The implementation name argument can accept a value of NULL.
792  * This means the system uses a default name that is formed by
793  * combining the class name with the method name
794  * (for example, classname_methodname).
795  */
796 int
797 db_add_method (MOP class_, const char *name, const char *implementation)
798 {
799  int retval;
800 
801  retval = add_method_internal (class_, name, implementation, ID_METHOD);
802 
803  return (retval);
804 }
805 
806 /*
807  * db_add_class_method() - This function define a class method.
808  * return : error code
809  * class(in): class or instance
810  * name(in) : method name
811  * implementation(in) : function name
812  *
813  * note : The implementation name argument can accept a value that is NULL.
814  * This means the system uses a default name that is formed by combining
815  * the class name with the method name
816  * (for example, classname_methodname).
817  */
818 int
819 db_add_class_method (MOP class_, const char *name, const char *implementation)
820 {
821  int retval;
822 
823  retval = add_method_internal (class_, name, implementation, ID_CLASS_METHOD);
824 
825  return (retval);
826 }
827 
828 /*
829  * db_drop_method() - This function removes a method from a class.
830  * return : error code
831  * class(in): class or instance
832  * name(in) : method name
833  */
834 int
835 db_drop_method (MOP class_, const char *name)
836 {
837  int retval;
838 
839  retval = drop_internal (class_, name, ID_METHOD);
840 
841  return (retval);
842 }
843 
844 /*
845  * db_drop_class_method() - This function removes a class method from a class.
846  * return : error code
847  * class(in): class or instance
848  * name(in) : class method name
849  *
850  */
851 int
852 db_drop_class_method (MOP class_, const char *name)
853 {
854  int retval;
855 
856  retval = drop_internal (class_, name, ID_CLASS_METHOD);
857 
858  return (retval);
859 }
860 
861 /*
862  * db_change_method_implementation() - This function changes the name of C
863  * function that is called when the method is invoked.
864  * returns/side-effects: error code
865  * class(in) : class or instance
866  * name(in) : method name
867  * class_method(in): class method flag
868  * newname(in) : new interface function name
869  */
870 int
871 db_change_method_implementation (MOP class_, const char *name, int class_method, const char *newname)
872 {
873  int error = NO_ERROR;
874  SM_TEMPLATE *def;
875  MOP newmop;
876 
879  CHECK_3ARGS_RETURN_EXPR (class_, name, newname, ER_OBJ_INVALID_ARGUMENTS);
880 
881  def = smt_edit_class_mop (class_, AU_ALTER);
882  if (def == NULL)
883  {
884  assert (er_errid () != NO_ERROR);
885  error = er_errid ();
886  }
887  else
888  {
889  error = smt_change_method_implementation (def, name, class_method, newname);
890  if (error)
891  {
892  smt_quit (def);
893  }
894  else
895  {
896  error = sm_update_class (def, &newmop);
897  if (error)
898  {
899  smt_quit (def);
900  }
901  }
902  }
903  return (error);
904 }
905 
906 /*
907  * add_arg_domain() - This function describes the domain of a method argument
908  * used for run time consistency checking by the interpreter. If the index
909  * argument is 0, the domain is used as the domain of the return value of
910  * the method. Otherwise, the index references the arguments of the method
911  * from 1 to n.
912  * return : error code
913  * class(in): class object
914  * name(in): method name
915  * class_method(in): class method flag
916  * index(in): argument index (zero is return value)
917  * initial_domain(in): initialize flag.
918  * domain(in): domain descriptor string
919  *
920  * note : Argument indexes can be specified that do not necessarily increase
921  * by 1, i.e., arg1, arg2, arg5 leaves arg3 and arg4 unspecified and
922  * logically void.
923  * If the supplied index is greater than any of the indexes that were
924  * previously supplied for the arguments, the argument list of the
925  * method is extended.
926  */
927 static int
928 add_arg_domain (DB_OBJECT * class_, const char *name, int class_method, int index, int initial_domain,
929  const char *domain)
930 {
931  int error = NO_ERROR;
932  SM_TEMPLATE *def;
933  MOP newmop;
934 
938 
939  def = smt_edit_class_mop (class_, AU_ALTER);
940  if (def == NULL)
941  {
942  assert (er_errid () != NO_ERROR);
943  error = er_errid ();
944  }
945  else
946  {
947  if (domain == NULL)
948  {
949  error = smt_assign_argument_domain (def, name, class_method, NULL, index, NULL, (DB_DOMAIN *) 0);
950  }
951  else
952  {
953  if (initial_domain)
954  {
955  error = smt_assign_argument_domain (def, name, class_method, NULL, index, domain, (DB_DOMAIN *) 0);
956  }
957  else
958  {
959  error = smt_add_set_argument_domain (def, name, class_method, NULL, index, domain, (DB_DOMAIN *) 0);
960  }
961  }
962  if (error)
963  {
964  smt_quit (def);
965  }
966  else
967  {
968  error = sm_update_class (def, &newmop);
969  if (error)
970  {
971  smt_quit (def);
972  }
973  }
974  }
975  return (error);
976 }
977 
978 /*
979  * db_add_argument() - see the add_arg_domain function.
980  * return : error code
981  * class(in): class object
982  * name(in): method name
983  * class_method(in): class method flag
984  * index(in): argument index (zero is return value)
985  * domain(in): domain descriptor string
986  */
987 int
988 db_add_argument (DB_OBJECT * class_, const char *name, int class_method, int index, const char *domain)
989 {
990  int retval;
991 
992  retval = (add_arg_domain (class_, name, class_method, index, 1, domain));
993 
994  return (retval);
995 }
996 
997 /*
998  * db_set_method_arg_domain() -
999  * return :
1000  * class(in) :
1001  * name(in) :
1002  * index(in) :
1003  * domain(in) :
1004  */
1005 int
1006 db_set_method_arg_domain (DB_OBJECT * class_, const char *name, int index, const char *domain)
1007 {
1008  int retval;
1009 
1010  retval = (add_arg_domain (class_, name, 0, index, 1, domain));
1011 
1012  return (retval);
1013 }
1014 
1015 /*
1016  * db_set_class_method_arg_domain() -
1017  * return :
1018  * class(in) :
1019  * name(in) :
1020  * index(in) :
1021  * domain(in) :
1022  */
1023 int
1024 db_set_class_method_arg_domain (DB_OBJECT * class_, const char *name, int index, const char *domain)
1025 {
1026  int retval;
1027 
1028  retval = (add_arg_domain (class_, name, 1, index, 1, domain));
1029 
1030  return (retval);
1031 }
1032 
1033 /*
1034  * db_add_set_argument_domain() - This function is used to add additional
1035  * domain information to a method argument whose fundamental domain is
1036  * set, multiset, or sequence.
1037  * return : error code
1038  * class(in) : class object
1039  * name(in) : method name
1040  * class_method(in): class method flag
1041  * index(in) : argument index
1042  * domain(in) : domain descriptor
1043  *
1044  * note : Use the db_add_argument() function first to specify the set type,
1045  * then make repeated calls to the db_add_set_argument_domain()function
1046  * to further specify the domains of the set elements.
1047  */
1048 int
1049 db_add_set_argument_domain (DB_OBJECT * class_, const char *name, int class_method, int index, const char *domain)
1050 {
1051  int retval;
1052 
1053  retval = (add_arg_domain (class_, name, class_method, index, 0, domain));
1054 
1055  return (retval);
1056 }
1057 
1058 /*
1059  * METHOD FILES & LOADER COMMNADS
1060  */
1061 
1062 /*
1063  * db_set_loader_commands() - This function sets the dynamic linking loader
1064  * command string for a class. This is usually a list of library names that
1065  * are to be included when linking the methods for a particular class.
1066  * return : error code
1067  * class(in): class or instance
1068  * commands(in): link command string
1069  *
1070  * note : The format of this string must be suitable for insertion in the
1071  * command line of the UNIX ld command (link editor), such as
1072  * "-L /usr/local/lib -l utilities"
1073  */
1074 int
1075 db_set_loader_commands (MOP class_, const char *commands)
1076 {
1077  int error = NO_ERROR;
1078  SM_TEMPLATE *def;
1079 
1081  CHECK_1ARG_ERROR (class_);
1082 
1083  def = smt_edit_class_mop (class_, AU_ALTER);
1084  if (def == NULL)
1085  {
1086  assert (er_errid () != NO_ERROR);
1087  error = er_errid ();
1088  }
1089  else
1090  {
1091  error = smt_set_loader_commands (def, commands);
1092  if (error)
1093  {
1094  smt_quit (def);
1095  }
1096  else
1097  {
1098  error = sm_update_class (def, NULL);
1099  if (error)
1100  {
1101  smt_quit (def);
1102  }
1103  }
1104  }
1105 
1106  return (error);
1107 }
1108 
1109 /*
1110  * db_add_method_file() - This function adds a method file to the list of
1111  * method files for a class.
1112  * return : error code
1113  * class(in): class or instance
1114  * name(in) : file pathname
1115  *
1116  * note : The file does not have to exist at the time it is added, but it must
1117  * exist before dynamic linking can occur. Linking normally occurs the
1118  * first time a method is called on an instance of the class. There is
1119  * no implicit ordering of method files that are added by this function.
1120  * If you attempt to add a method file twice, the second addition is
1121  * ignored. The name of a method file may contain an environment
1122  * variable reference. This environment variable is expanded during
1123  * dynamic linking, but it is not expanded at the time the file is
1124  * defined.
1125  */
1126 int
1127 db_add_method_file (MOP class_, const char *name)
1128 {
1129  int error = NO_ERROR;
1130  SM_TEMPLATE *def;
1131  MOP newmop;
1132 
1136 
1137  def = smt_edit_class_mop (class_, AU_ALTER);
1138  if (def == NULL)
1139  {
1140  assert (er_errid () != NO_ERROR);
1141  error = er_errid ();
1142  }
1143  else
1144  {
1145  error = smt_add_method_file (def, name);
1146  if (error)
1147  {
1148  smt_quit (def);
1149  }
1150  else
1151  {
1152  error = sm_update_class (def, &newmop);
1153  if (error)
1154  {
1155  smt_quit (def);
1156  }
1157  }
1158  }
1159  return (error);
1160 }
1161 
1162 /*
1163  * db_drop_method_file() - This function removes a method file from a class.
1164  * returns : error code
1165  * class(in): class or instance
1166  * name(in): file pathname
1167  *
1168  * note : The effects of this function is not seen during the current session.
1169  * The next time a database session is started and dynamic linking occurs
1170  * for this class, the file is not included.
1171  *
1172  */
1173 int
1174 db_drop_method_file (MOP class_, const char *name)
1175 {
1176  int error = NO_ERROR;
1177  SM_TEMPLATE *def;
1178  MOP newmop;
1179 
1183 
1184  def = smt_edit_class_mop (class_, AU_ALTER);
1185  if (def == NULL)
1186  {
1187  assert (er_errid () != NO_ERROR);
1188  error = er_errid ();
1189  }
1190  else
1191  {
1192  error = smt_drop_method_file (def, name);
1193  if (error)
1194  {
1195  smt_quit (def);
1196  }
1197  else
1198  {
1199  error = sm_update_class (def, &newmop);
1200  if (error)
1201  {
1202  smt_quit (def);
1203  }
1204  }
1205  }
1206  return (error);
1207 }
1208 
1209 /*
1210  * db_drop_method_files() - This function removes all of the currently defined
1211  * method files for a class. This can be used in cases where you want to
1212  * completely respecify the file list without making multiple calls to
1213  * db_drop_method_file().
1214  * return : error code.
1215  * class(in): class or instance.
1216  */
1217 int
1219 {
1220  int error = NO_ERROR;
1221  SM_TEMPLATE *def;
1222  MOP newmop;
1223 
1227 
1228  def = smt_edit_class_mop (class_, AU_ALTER);
1229  if (def == NULL)
1230  {
1231  assert (er_errid () != NO_ERROR);
1232  error = er_errid ();
1233  }
1234  else
1235  {
1236  error = smt_reset_method_files (def);
1237  if (error)
1238  {
1239  smt_quit (def);
1240  }
1241  else
1242  {
1243  error = sm_update_class (def, &newmop);
1244  if (error)
1245  {
1246  smt_quit (def);
1247  }
1248  }
1249  }
1250 
1251  return (error);
1252 }
1253 
1254 /*
1255  * CLASS HIERARCHY
1256  */
1257 
1258 /*
1259  * db_add_super() - This function adds a super class to a class if it did not
1260  * already exist. If the class is partitioned, function returns
1261  * ER_NOT_ALLOWED_ACCESS_TO_PARTITION
1262  * return : error code
1263  * class(in): class or instance
1264  * super(in): super class
1265  */
1266 int
1267 db_add_super (MOP class_, MOP super)
1268 {
1269  int error = NO_ERROR;
1270 
1273 
1275  if (!error)
1276  {
1278  if (!error)
1279  {
1280  error = db_add_super_internal (class_, super);
1281  }
1282  }
1283 
1284  return error;
1285 }
1286 
1287 /*
1288  * db_add_super_internal() - This function adds a super class to a class if it
1289  * did not already exist.
1290  * return : error code
1291  * class(in): class or instance
1292  * super(in): super class
1293  */
1294 int
1296 {
1297  int error = NO_ERROR;
1298  SM_TEMPLATE *def;
1299  MOP newmop;
1300 
1304 
1305  def = smt_edit_class_mop (class_, AU_ALTER);
1306  if (def == NULL)
1307  {
1308  assert (er_errid () != NO_ERROR);
1309  error = er_errid ();
1310  }
1311  else
1312  {
1313  error = smt_add_super (def, super);
1314  if (error)
1315  {
1316  smt_quit (def);
1317  }
1318  else
1319  {
1320  error = sm_update_class_auto (def, &newmop);
1321  if (error)
1322  {
1323  smt_quit (def);
1324  }
1325  }
1326  }
1327 
1328  return (error);
1329 }
1330 
1331 /*
1332  * db_drop_super() - This function removes a superclass link from a class.
1333  * The attributes and methods that were inherited from the superclass are
1334  * removed, and the changes are propagated to the subclasses. If the class
1335  * is partitioned, function returns ER_NOT_ALLOWED_ACCESS_TO_PARTITION.
1336  * return : error code
1337  * class(in): class or instance pointer
1338  * super(in): class pointer
1339  *
1340  * note : Any resulting conflicts are resolved automatically by the system.
1341  * If the system's resolution is unsatisfactory, it can be redefined
1342  * with the db_add_resolution() function or the db_add_class_resolution()
1343  * function, as appropriate.
1344  */
1345 int
1346 db_drop_super (MOP class_, MOP super)
1347 {
1348  int error = NO_ERROR;
1349  SM_TEMPLATE *def;
1350  MOP newmop;
1351 
1355 
1357  if (!error)
1358  {
1359  def = smt_edit_class_mop (class_, AU_ALTER);
1360  if (def == NULL)
1361  {
1362  assert (er_errid () != NO_ERROR);
1363  error = er_errid ();
1364  }
1365  else
1366  {
1367  error = smt_delete_super (def, super);
1368  if (error)
1369  {
1370  smt_quit (def);
1371  }
1372  else
1373  {
1374  error = sm_update_class_auto (def, &newmop);
1375  if (error)
1376  {
1377  smt_quit (def);
1378  }
1379  }
1380  }
1381  }
1382 
1383  return (error);
1384 }
1385 
1386 /*
1387  * db_drop_super_connect() - This function removes a superclass link from a
1388  * class.
1389  * return : error code
1390  * class(in): class or instance pointer
1391  * super(in): class pointer
1392  *
1393  * note : It behaves somewhat differently from the db_drop_super () function.
1394  * When you use the function db_drop_super_connect(), the superclasses of
1395  * the superclass that is dropped(the super argument) are reconnected as
1396  * superclasses of the class argument.
1397  */
1398 int
1400 {
1401  int error = NO_ERROR;
1402  SM_TEMPLATE *def;
1403  MOP newmop;
1404 
1408 
1410  if (!error)
1411  {
1412  def = smt_edit_class_mop (class_, AU_ALTER);
1413  if (def == NULL)
1414  {
1415  assert (er_errid () != NO_ERROR);
1416  error = er_errid ();
1417  }
1418  else
1419  {
1420  error = smt_delete_super_connect (def, super);
1421  if (error)
1422  {
1423  smt_quit (def);
1424  }
1425  else
1426  {
1427  error = sm_update_class_auto (def, &newmop);
1428  if (error)
1429  {
1430  smt_quit (def);
1431  }
1432  }
1433  }
1434  }
1435  return (error);
1436 }
1437 
1438 /*
1439  * INTEGRITY CONSTRAINTS
1440  */
1441 
1442 /*
1443  * db_constrain_non_null() - This function sets the state of an attribute's
1444  * NON_NULL constraint.
1445  * return : error code
1446  * class(in): class or instance object
1447  * name(in) : attribute name
1448  * class_attribute(in): flag indicating class attribute status
1449  * (0 if this is not a class attribute,
1450  * non-zero if this is a class attribute)
1451  * on_or_off(in): non-zero if constraint is to be enabled
1452  *
1453  */
1454 int
1455 db_constrain_non_null (MOP class_, const char *name, int class_attribute, int on_or_off)
1456 {
1457  const char *att_names[2];
1458  int retval;
1459 
1460  att_names[0] = name;
1461  att_names[1] = NULL;
1462  if (on_or_off)
1463  {
1464  bool has_nulls = false;
1465  retval = do_check_rows_for_null (class_, name, &has_nulls);
1466  if (retval != NO_ERROR)
1467  {
1468  return retval;
1469  }
1470 
1471  if (has_nulls)
1472  {
1473  retval = ER_SM_ATTR_NOT_NULL;
1474  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, retval, 1, name);
1475  return retval;
1476  }
1477 
1478  retval = db_add_constraint (class_, DB_CONSTRAINT_NOT_NULL, NULL, att_names, class_attribute);
1479  }
1480  else
1481  {
1482  retval = db_drop_constraint (class_, DB_CONSTRAINT_NOT_NULL, NULL, att_names, class_attribute);
1483  }
1484 
1485  return (retval);
1486 }
1487 
1488 /*
1489  * db_constrain_unique() - This function sets the state of an attribute's
1490  * UNIQUE constraint.
1491  * return : error code
1492  * class(in): class or instance object
1493  * name(in): attribute name
1494  * on_or_off(in): true if constraint is to be enabled
1495  */
1496 int
1497 db_constrain_unique (MOP class_, const char *name, int on_or_off)
1498 {
1499  const char *att_names[2];
1500  int retval;
1501 
1502  att_names[0] = name;
1503  att_names[1] = NULL;
1504  if (on_or_off)
1505  {
1506  retval = db_add_constraint (class_, DB_CONSTRAINT_UNIQUE, NULL, att_names, false);
1507  }
1508  else
1509  {
1510  retval = db_drop_constraint (class_, DB_CONSTRAINT_UNIQUE, NULL, att_names, false);
1511  }
1512 
1513  return (retval);
1514 }
1515 
1516 /*
1517  * CONFLICT RESOLUTIONS
1518  */
1519 
1520 /*
1521  * db_add_resolution() - This defines a conflict resolution specification for
1522  * a class. Conflict resolutions must be specified BEFORE an operation which
1523  * would generate a conflict. Normally, the alias name is not given in which
1524  * case this function simply selects the class from which the
1525  * attribute/method will be inherited. If the alias name is given, both of
1526  * the conflicting entities are inherited, one with a new name.
1527  * return : error code
1528  * class(in): class or instance pointer
1529  * super(in): class pointer
1530  * name(in) : attribute or method name
1531  * alias(in): optional alias name
1532  */
1533 int
1534 db_add_resolution (MOP class_, MOP super, const char *name, const char *alias)
1535 {
1536  int error = NO_ERROR;
1537  SM_TEMPLATE *def;
1538  MOP newmop;
1539 
1542 
1543  def = smt_edit_class_mop (class_, AU_ALTER);
1544  if (def == NULL)
1545  {
1546  assert (er_errid () != NO_ERROR);
1547  error = er_errid ();
1548  }
1549  else
1550  {
1551  error = smt_add_resolution (def, super, name, alias);
1552  if (error)
1553  {
1554  smt_quit (def);
1555  }
1556  else
1557  {
1558  error = sm_update_class_auto (def, &newmop);
1559  if (error)
1560  {
1561  smt_quit (def);
1562  }
1563  }
1564  }
1565 
1566  return (error);
1567 }
1568 
1569 /*
1570  * db_add_class_resolution() - This function adds a resolution specifier for
1571  * the class attributes or class methods of a class. It functions exactly
1572  * like the db_add_resolution() function, except that the namespace for
1573  * the resolution is the class namespace instead of the instance namespace.
1574  * return : error code
1575  * class(in): class or instance pointer
1576  * super(in): super class pointer
1577  * name(in) : attribute or method name
1578  * alias(in): optional alias name
1579  */
1580 int
1581 db_add_class_resolution (MOP class_, MOP super, const char *name, const char *alias)
1582 {
1583  int error = NO_ERROR;
1584  SM_TEMPLATE *def;
1585  MOP newmop;
1586 
1589 
1590  def = smt_edit_class_mop (class_, AU_ALTER);
1591  if (def == NULL)
1592  {
1593  assert (er_errid () != NO_ERROR);
1594  error = er_errid ();
1595  }
1596  else
1597  {
1598  error = smt_add_class_resolution (def, super, name, alias);
1599  if (error)
1600  {
1601  smt_quit (def);
1602  }
1603  else
1604  {
1605  error = sm_update_class_auto (def, &newmop);
1606  if (error)
1607  {
1608  smt_quit (def);
1609  }
1610  }
1611  }
1612 
1613  return (error);
1614 }
1615 
1616 /*
1617  * db_drop_resolution() - This function removes a previously specified
1618  * resolution.
1619  * return : error code
1620  * class(in): class pointer
1621  * super(in): class pointer
1622  * name(in): attribute/method name
1623  */
1624 int
1625 db_drop_resolution (MOP class_, MOP super, const char *name)
1626 {
1627  int error = NO_ERROR;
1628  SM_TEMPLATE *def;
1629  MOP newmop;
1630 
1633 
1634  def = smt_edit_class_mop (class_, AU_ALTER);
1635  if (def == NULL)
1636  {
1637  assert (er_errid () != NO_ERROR);
1638  error = er_errid ();
1639  }
1640  else
1641  {
1642  error = smt_delete_resolution (def, super, name);
1643  if (error)
1644  {
1645  smt_quit (def);
1646  }
1647  else
1648  {
1649  error = sm_update_class_auto (def, &newmop);
1650  if (error)
1651  {
1652  smt_quit (def);
1653  }
1654  }
1655  }
1656 
1657  return (error);
1658 }
1659 
1660 /*
1661  * db_drop_class_resolution() - This function removes a class-level resolution.
1662  * returns : error code
1663  * class(in): class pointer
1664  * super(in): class pointer
1665  * name(in): attribute/method name
1666  */
1667 int
1668 db_drop_class_resolution (MOP class_, MOP super, const char *name)
1669 {
1670  int error = NO_ERROR;
1671  SM_TEMPLATE *def;
1672  MOP newmop;
1673 
1676 
1677  def = smt_edit_class_mop (class_, AU_ALTER);
1678  if (def == NULL)
1679  {
1680  assert (er_errid () != NO_ERROR);
1681  error = er_errid ();
1682  }
1683  else
1684  {
1685  error = smt_delete_class_resolution (def, super, name);
1686  if (error)
1687  {
1688  smt_quit (def);
1689  }
1690  else
1691  {
1692  error = sm_update_class_auto (def, &newmop);
1693  if (error)
1694  {
1695  smt_quit (def);
1696  }
1697  }
1698  }
1699 
1700  return (error);
1701 }
1702 
1703 
1704 /*
1705  * INDEX CONTROL
1706  */
1707 
1708 /*
1709  * db_add_index() - This will add an index to an attribute if one doesn't
1710  * already exist.
1711  * return : error code
1712  * classmop(in): class (or instance) pointer
1713  * attname(in) : attribute name
1714  *
1715  * note : This may be an expensive operation if there are a lot of previously
1716  * created instances in the database since the index attributes for all of
1717  * those instances must be added to the b-tree after it is created.
1718  */
1719 int
1720 db_add_index (MOP classmop, const char *attname)
1721 {
1722  const char *att_names[2];
1723  int retval;
1724 
1726  CHECK_2ARGS_ERROR (classmop, attname);
1728 
1729  att_names[0] = attname;
1730  att_names[1] = NULL;
1731  retval = db_add_constraint (classmop, DB_CONSTRAINT_INDEX, NULL, att_names, false);
1732 
1733  return (retval);
1734 }
1735 
1736 /*
1737  * db_drop_index() - This function drops an index for an attribute if one was
1738  * defined. Multi-attribute indexes can be dropped with the
1739  * db_drop_constraint() function.
1740  * return : error code
1741  * classmop(in): class (or instance) pointer
1742  * attname(in) : attribute name
1743  */
1744 int
1745 db_drop_index (MOP classmop, const char *attname)
1746 {
1747  const char *att_names[2];
1748  int retval;
1749 
1751  CHECK_2ARGS_ERROR (classmop, attname);
1753 
1754  att_names[0] = attname;
1755  att_names[1] = NULL;
1756  retval = db_drop_constraint (classmop, DB_CONSTRAINT_INDEX, NULL, att_names, false);
1757 
1758  return (retval);
1759 }
1760 
1761 /*
1762  * db_add_constraint() - This function is used to add constraints to a class.
1763  * The types of constraints are defined by DB_CONSTRAINT_TYPE and currently
1764  * include UNIQUE, REVERSE_UNIQUE, NOT NULL, INDEX, REVERSE_INDEX,
1765  * PRIMARY_KEY.
1766  * return : error code
1767  * classmop(in): class (or instance) pointer
1768  * constraint_type(in): type of constraint to add(refer to DB_CONSTRAINT_TYPE).
1769  * constraint_name(in): constraint name.
1770  * att_names(in): Names of attributes to be constrained
1771  * class_attributes(in): flag indicating class attribute status
1772  * (0 if this is not a class attribute,
1773  * non-zero if this is a class attribute)
1774  *
1775  */
1776 int
1777 db_add_constraint (MOP classmop, DB_CONSTRAINT_TYPE constraint_type, const char *constraint_name,
1778  const char **att_names, int class_attributes)
1779 {
1780  int retval;
1781  char *name = NULL;
1782 
1784  CHECK_2ARGS_ERROR (classmop, att_names);
1786 
1787  name = sm_produce_constraint_name_mop (classmop, constraint_type, att_names, NULL, constraint_name);
1788  if (name == NULL)
1789  {
1790  assert (er_errid () != NO_ERROR);
1791  retval = er_errid ();
1792  }
1793  else
1794  {
1795  retval =
1796  sm_add_constraint (classmop, constraint_type, name, att_names, NULL, NULL, class_attributes, NULL, NULL, NULL,
1797  SM_NORMAL_INDEX);
1798  free_and_init (name);
1799  }
1800 
1801  return (retval);
1802 }
1803 
1804 /*
1805  * db_drop_constraint() - This function is used remove constraint from a class.
1806  * Please refer to the header information for db_add_constraint() for basic
1807  * information on classes and constraints.
1808  * return : error code
1809  * classmop: class (or instance) pointer
1810  * constraint_type: type of constraint to drop
1811  * constraint_name: constraint name
1812  * att_names: names of attributes to be constrained
1813  * class_attributes: flag indicating class attribute status
1814  * (0 if this is not a class attribute,
1815  * non-zero if this is a class attribute)
1816  *
1817  * note :
1818  * If the name is known, the constraint can be dropped by name, in which
1819  * case the <att_names> parameter should be NULL.
1820  * If the name is not known, the constraint can be specified by the
1821  * combination of class pointer and attribute names.
1822  * The order of the attribute names must match the order given when the
1823  * constraint was added. In this case, the <constraint_name> should be NULL.
1824  */
1825 int
1826 db_drop_constraint (MOP classmop, DB_CONSTRAINT_TYPE constraint_type, const char *constraint_name,
1827  const char **att_names, int class_attributes)
1828 {
1829  int retval;
1830  char *name = NULL;
1831 
1833  CHECK_1ARG_ERROR (classmop);
1835 
1836  name = sm_produce_constraint_name_mop (classmop, constraint_type, att_names, NULL, constraint_name);
1837 
1838  if (name == NULL)
1839  {
1840  assert (er_errid () != NO_ERROR);
1841  retval = er_errid ();
1842  }
1843  else
1844  {
1845  retval = sm_drop_constraint (classmop, constraint_type, name, att_names, class_attributes ? true : false, false);
1846  free_and_init (name);
1847  }
1848 
1849  return (retval);
1850 }
1851 
1852 /*
1853  * db_truncate_class() - This function is used to truncate a class.
1854  * Returns non-zero error status if the operation could not be performed.
1855  * return : error code
1856  * class(in): class object
1857  */
1858 int
1860 {
1861  int error_code = NO_ERROR;
1862 
1864  CHECK_1ARG_ERROR (class_);
1866 
1867  error_code = sm_truncate_class (class_);
1868  return error_code;
1869 }
#define OID_INITIALIZER
Definition: oid.h:36
#define ER_SM_ATTRIBUTE_NOT_FOUND
Definition: error_code.h:311
#define CHECK_MODIFICATION_ERROR()
Definition: db.h:121
#define NO_ERROR
Definition: error_code.h:46
int smt_set_loader_commands(SM_TEMPLATE *template_, const char *commands)
int smt_add_super(SM_TEMPLATE *template_, MOP super_class)
int db_drop_class_method(MOP class_, const char *name)
Definition: db_class.c:852
int sm_add_constraint(MOP classop, DB_CONSTRAINT_TYPE constraint_type, const char *constraint_name, const char **att_names, const int *asc_desc, const int *attrs_prefix_length, int class_attributes, SM_PREDICATE_INFO *filter_index, SM_FUNCTION_INFO *function_index, const char *comment, SM_INDEX_STATUS index_status)
int db_rename_internal(MOP class_, const char *name, int class_namespace, const char *newname)
Definition: db_class.c:654
int db_add_super(MOP class_, MOP super)
Definition: db_class.c:1267
#define ER_SM_ATTR_NOT_NULL
Definition: error_code.h:1327
int smt_delete_any(SM_TEMPLATE *template_, const char *name, SM_NAME_SPACE name_space)
int smt_quit(SM_TEMPLATE *template_)
#define CHECK_2ARGS_ERROR(obj1, obj2)
Definition: db.h:195
int sm_truncate_class(MOP class_mop)
int smt_drop_method_file(SM_TEMPLATE *template_, const char *name)
#define CHECK_3ARGS_RETURN_EXPR(obj1, obj2, obj3, expr)
Definition: db.h:163
int db_add_set_attribute_domain(MOP class_, const char *name, int class_attribute, const char *domain)
Definition: db_class.c:444
int db_add_method(MOP class_, const char *name, const char *implementation)
Definition: db_class.c:797
int db_add_super_internal(MOP class_, MOP super)
Definition: db_class.c:1295
int do_check_partitioned_class(DB_OBJECT *classop, int check_map, char *keyattr)
#define assert_release(e)
Definition: error_manager.h:96
int db_drop_super(MOP class_, MOP super)
Definition: db_class.c:1346
int db_truncate_class(DB_OBJECT *class_)
Definition: db_class.c:1859
SM_NAME_SPACE
int smt_delete_set_attribute_domain(SM_TEMPLATE *template_, const char *name, int class_attribute, const char *domain_string, DB_DOMAIN *domain)
int smt_add_attribute_any(SM_TEMPLATE *template_, const char *name, const char *domain_string, DB_DOMAIN *domain, const SM_NAME_SPACE name_space, const bool add_first, const char *add_after_attribute, const char *comment)
int db_constrain_unique(MOP class_, const char *name, int on_or_off)
Definition: db_class.c:1497
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 db_rename(MOP class_, const char *name, int class_namespace, const char *newname)
Definition: db_class.c:628
DB_OBJECT * db_create_class(const char *name)
Definition: db_class.c:70
char * sm_produce_constraint_name_mop(MOP classop, DB_CONSTRAINT_TYPE constraint_type, const char **att_names, const int *asc_desc, const char *given_name)
#define AU_ALTER
Definition: authenticate.h:73
int smt_add_method_any(SM_TEMPLATE *template_, const char *name, const char *function, SM_NAME_SPACE name_space)
int smt_reset_method_files(SM_TEMPLATE *template_)
int smt_delete_super_connect(SM_TEMPLATE *template_, MOP super_class)
int db_drop_method_file(MOP class_, const char *name)
Definition: db_class.c:1174
int db_drop_element_domain(MOP class_, const char *name, const char *domain)
Definition: db_class.c:559
int db_set_loader_commands(MOP class_, const char *commands)
Definition: db_class.c:1075
int db_add_set_argument_domain(DB_OBJECT *class_, const char *name, int class_method, int index, const char *domain)
Definition: db_class.c:1049
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 db_drop_method_files(MOP class_)
Definition: db_class.c:1218
#define assert(x)
int db_drop_index(MOP classmop, const char *attname)
Definition: db_class.c:1745
DB_CONSTRAINT_TYPE
Definition: dbtype_def.h:452
int db_rename_method(MOP class_, const char *name, int class_method, const char *newname)
Definition: db_class.c:726
int db_add_attribute(MOP obj, const char *name, const char *domain, DB_VALUE *default_value)
Definition: db_class.c:248
int db_drop_set_attribute_domain(MOP class_, const char *name, int class_attribute, const char *domain)
Definition: db_class.c:513
int db_constrain_non_null(MOP class_, const char *name, int class_attribute, int on_or_off)
Definition: db_class.c:1455
int db_drop_attribute(MOP class_, const char *name)
Definition: db_class.c:354
#define CHECK_MODIFICATION_NULL()
Definition: db.h:124
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 sm_update_class_auto(SM_TEMPLATE *template_, MOP *classmop)
#define CHECK_1ARG_ERROR(obj)
Definition: db.h:186
static int add_arg_domain(DB_OBJECT *class_, const char *name, int class_method, int index, int initial_domain, const char *domain)
Definition: db_class.c:928
int db_change_method_implementation(MOP class_, const char *name, int class_method, const char *newname)
Definition: db_class.c:871
#define CHECK_2ARGS_RETURN_EXPR(obj1, obj2, expr)
Definition: db.h:155
#define CHECK_1ARG_NULL(obj)
Definition: db.h:171
int db_drop_resolution(MOP class_, MOP super, const char *name)
Definition: db_class.c:1625
int db_drop_shared_attribute(MOP class_, const char *name)
Definition: db_class.c:404
#define NULL
Definition: freelistheap.h:34
int db_add_attribute_internal(MOP class_, const char *name, const char *domain, DB_VALUE *default_value, SM_NAME_SPACE name_space)
Definition: db_class.c:184
int db_add_class_resolution(MOP class_, MOP super, const char *name, const char *alias)
Definition: db_class.c:1581
int db_drop_super_connect(MOP class_, MOP super)
Definition: db_class.c:1399
int db_add_index(MOP classmop, const char *attname)
Definition: db_class.c:1720
int db_add_class_attribute(MOP obj, const char *name, const char *domain, DB_VALUE *default_value)
Definition: db_class.c:288
int db_drop_class_attribute(MOP class_, const char *name)
Definition: db_class.c:421
int db_rename_class(MOP classop, const char *new_name)
Definition: db_class.c:151
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 db_add_argument(DB_OBJECT *class_, const char *name, int class_method, int index, const char *domain)
Definition: db_class.c:988
int smt_add_class_resolution(SM_TEMPLATE *template_, MOP super_class, const char *name, const char *alias)
static int add_method_internal(MOP class_, const char *name, const char *implementation, SM_NAME_SPACE name_space)
Definition: db_class.c:749
int db_change_default(MOP class_, const char *name, DB_VALUE *value)
Definition: db_class.c:584
#define CHECK_1ARG_RETURN_EXPR(obj, expr)
Definition: db.h:147
int db_set_method_arg_domain(DB_OBJECT *class_, const char *name, int index, const char *domain)
Definition: db_class.c:1006
int db_set_class_method_arg_domain(DB_OBJECT *class_, const char *name, int index, const char *domain)
Definition: db_class.c:1024
int db_add_resolution(MOP class_, MOP super, const char *name, const char *alias)
Definition: db_class.c:1534
static void error(const char *msg)
Definition: gencat.c:331
int db_drop_class_resolution(MOP class_, MOP super, const char *name)
Definition: db_class.c:1668
int smt_delete_class_resolution(SM_TEMPLATE *template_, MOP super_class, const char *name)
int db_drop_class(MOP class_)
Definition: db_class.c:110
#define CHECK_PARTITION_SUBS
#define CHECK_CONNECT_NULL()
Definition: db.h:91
#define ARG_FILE_LINE
Definition: error_manager.h:44
int db_add_shared_attribute(MOP obj, const char *name, const char *domain, DB_VALUE *default_value)
Definition: db_class.c:268
int db_rename_attribute(MOP class_, const char *name, int class_attribute, const char *newname)
Definition: db_class.c:701
int db_drop_method(MOP class_, const char *name)
Definition: db_class.c:835
const char * name
Definition: class_object.h:787
#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)
int db_drop_constraint(MOP classmop, DB_CONSTRAINT_TYPE constraint_type, const char *constraint_name, const char **att_names, int class_attributes)
Definition: db_class.c:1826
LC_FIND_CLASSNAME locator_reserve_class_name(const char *class_name, OID *class_oid)
Definition: locator_cl.c:179
#define ER_OBJ_INVALID_ARGUMENTS
Definition: error_code.h:275
SM_TEMPLATE * smt_def_class(const char *name)
int sm_drop_constraint(MOP classop, DB_CONSTRAINT_TYPE constraint_type, const char *constraint_name, const char **att_names, bool class_attributes, bool mysql_index_name)
int db_add_class_method(MOP class_, const char *name, const char *implementation)
Definition: db_class.c:819
int db_add_method_file(MOP class_, const char *name)
Definition: db_class.c:1127
int smt_add_method_file(SM_TEMPLATE *template_, const char *filename)
int db_add_element_domain(MOP class_, const char *name, const char *domain)
Definition: db_class.c:490
int smt_set_attribute_default(SM_TEMPLATE *template_, const char *name, int class_attribute, DB_VALUE *proposed_value, DB_DEFAULT_EXPR *default_expr)
int do_check_rows_for_null(MOP class_mop, const char *att_name, bool *has_nulls)
int db_drop_attribute_internal(MOP class_, const char *name)
Definition: db_class.c:380
DB_VALUE * default_value
Definition: esql_cli.c:348
static int drop_internal(MOP class_, const char *name, SM_NAME_SPACE name_space)
Definition: db_class.c:311
int db_drop_class_ex(MOP class_, bool is_cascade_constraints)
Definition: db_class.c:122
int db_add_constraint(MOP classmop, DB_CONSTRAINT_TYPE constraint_type, const char *constraint_name, const char **att_names, int class_attributes)
Definition: db_class.c:1777
int sm_rename_class(MOP op, const char *new_name)
int smt_delete_super(SM_TEMPLATE *template_, MOP super_class)
#define CHECK_CONNECT_ERROR()
Definition: db.h:88
int sm_delete_class_mop(MOP op, bool is_cascade_constraints)
int sm_update_class(SM_TEMPLATE *template_, MOP *classmop)
int smt_add_resolution(SM_TEMPLATE *template_, MOP super_class, const char *name, const char *alias)