CUBRID Engine  latest
object_description.cpp
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  * object_description.cpp
21  */
22 
23 #include "object_description.hpp"
24 
25 #include "authenticate.h"
26 #include "class_object.h"
27 #include "db_value_printer.hpp"
28 #include "dbi.h"
29 #include "locator_cl.h"
30 #include "mem_block.hpp"
31 #include "object_print_util.hpp"
32 #include "schema_manager.h"
33 #include "string_buffer.hpp"
34 #include "transaction_cl.h"
35 #include "work_space.h"
36 #include "dbtype.h"
37 
39  : classname (0)
40  , oid (0)
41  , attributes (0)
42  , shared (0)
43 {
44 }
45 
47 {
48  if (op == NULL)
49  {
51  }
52 
53  int error;
54  SM_CLASS *class_;
55  SM_ATTRIBUTE *attribute_p;
56  char *obj;
57  int i, count;
58  char **strs;
59  int pin;
60  size_t buf_size;
61  DB_VALUE value;
62 
64  if (is_class)
65  {
68  }
69 
71  if (error != NO_ERROR)
72  {
73  return error;
74  }
75 
76  pin = ws_pin (op, 1);
77  error = au_fetch_class (ws_class_mop (op), &class_, AU_FETCH_READ, AU_SELECT);
78  if (error != NO_ERROR)
79  {
80  return error;
81  }
82  this->classname = object_print::copy_string ((char *) sm_ch_name ((MOBJ) class_));
83 
84  string_buffer sb;
85  db_value_printer printer (sb);
86 
87  db_make_object (&value, op);
88  printer.describe_data (&value);
89  db_value_clear (&value);
90  db_make_null (&value);
91 
92  this->oid = sb.release_ptr ();
93 
94  if (class_->ordered_attributes != NULL)
95  {
96  count = class_->att_count + class_->shared_count + 1;
97  buf_size = sizeof (char *) * count;
98 
99  strs = (char **) malloc (buf_size);
100  if (strs == NULL)
101  {
104  }
105 
106  i = 0;
107  for (attribute_p = class_->ordered_attributes; attribute_p != NULL;
108  attribute_p = attribute_p->order_link)
109  {
110  sb.clear ();// We're starting a new line here, so we don't want to append to the old buffer
111  sb ("%20s = ", attribute_p->header.name);
112  if (attribute_p->header.name_space == ID_SHARED_ATTRIBUTE)
113  {
114  printer.describe_value (&attribute_p->default_value.value);
115  }
116  else
117  {
118  db_get (op, attribute_p->header.name, &value);
119  printer.describe_value (&value);
120  }
121  strs[i] = sb.release_ptr ();
122  i++;
123  }
124 
125  strs[i] = NULL;
126  attributes = strs;//ToDo: refactor this->attributes as std::vector<char*>
127  }
128 
129  /* will we ever want to separate these lists ? */
130  (void) ws_pin (op, pin);
131 
132  return NO_ERROR;
133 }
134 
136 {
137  free (classname);
138  free (oid);
141 }
#define NO_ERROR
Definition: error_code.h:46
char * copy_string(const char *source)
char * release_ptr()
char * MOBJ
Definition: work_space.h:174
int db_make_object(DB_VALUE *value, DB_C_OBJECT *obj)
SM_DEFAULT_VALUE default_value
Definition: class_object.h:451
int init(struct db_object *op)
SM_NAME_SPACE name_space
Definition: class_object.h:386
void describe_data(const db_value *value)
void describe_value(const db_value *value)
static DB_OBJECT * is_class(OID *obj_oid, OID *class_oid)
Definition: compactdb.c:637
void er_set(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
const char * sm_ch_name(const MOBJ clobj)
int au_fetch_class(MOP op, SM_CLASS **class_ptr, AU_FETCHMODE fetchmode, DB_AUTH type)
int ws_pin(MOP mop, int pin)
Definition: work_space.c:2989
#define ER_OUT_OF_VIRTUAL_MEMORY
Definition: error_code.h:50
MOP ws_class_mop(MOP mop)
Definition: work_space.c:2907
#define NULL
Definition: freelistheap.h:34
#define TM_TRAN_READ_FETCH_VERSION()
void free_strarray(char **strs)
int count(int &result, const cub_regex_object &reg, const std::string &src, const int position, const INTL_CODESET codeset)
static void error(const char *msg)
Definition: gencat.c:331
#define AU_SELECT
Definition: authenticate.h:69
#define ARG_FILE_LINE
Definition: error_manager.h:44
SM_COMPONENT header
Definition: class_object.h:441
#define ER_OBJ_INVALID_ARGUMENTS
Definition: error_code.h:275
int db_get(DB_OBJECT *object, const char *attpath, DB_VALUE *value)
Definition: db_obj.c:233
int i
Definition: dynamic_load.c:954
int db_make_null(DB_VALUE *value)
const char * name
Definition: class_object.h:385
int au_fetch_instance(MOP op, MOBJ *obj_ptr, AU_FETCHMODE mode, LC_FETCH_VERSION_TYPE fetch_version_type, DB_AUTH type)
struct sm_attribute * order_link
Definition: class_object.h:461
int db_value_clear(DB_VALUE *value)
Definition: db_macro.c:1588
int locator_is_class(MOP mop, DB_FETCH_MODE hint_purpose)
Definition: locator_cl.c:239