CUBRID Engine  latest
db.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 
20 /*
21  * db.h - Stubs for the SQL interface layer.
22  */
23 
24 #ifndef _DB_H_
25 #define _DB_H_
26 
27 #ident "$Id$"
28 
29 #include "config.h"
30 
31 #include <stdio.h>
32 #include "error_manager.h"
33 #include "intl_support.h"
34 #include "db_date.h"
35 #include "object_domain.h"
36 #if !defined(SERVER_MODE)
37 #include "trigger_manager.h"
38 #include "dbi.h"
39 #include "parser.h"
40 #endif
41 #include "log_comm.h"
42 #include "dbtype_def.h"
43 #include "db_admin.h"
44 
45 /* GLOBAL STATE */
46 #define DB_CONNECTION_STATUS_NOT_CONNECTED 0
47 #define DB_CONNECTION_STATUS_CONNECTED 1
48 #define DB_CONNECTION_STATUS_RESET -1
49 extern int db_Connect_status;
50 
52 
53 extern int db_Row_count;
54 
55 #if !defined(_DB_DISABLE_MODIFICATIONS_)
56 #define _DB_DISABLE_MODIFICATIONS_
57 extern int db_Disable_modifications;
58 #endif /* _DB_DISABLE_MODIFICATIONS_ */
59 
60 #if !defined(SERVER_MODE)
61 extern char db_Database_name[];
62 extern char db_Program_name[];
63 #endif /* !SERVER_MODE */
64 
65 /* MACROS FOR ERROR CHECKING */
66 /* These should be used at the start of every db_ function so we can check
67  various validations before executing. */
68 
69 /* CHECK CONNECT */
70 #define CHECK_CONNECT_VOID() \
71  do { \
72  if (db_Connect_status != DB_CONNECTION_STATUS_CONNECTED) \
73  { \
74  er_set(ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OBJ_NO_CONNECT, 0); \
75  return; \
76  } \
77  } while (0)
78 
79 #define CHECK_CONNECT_AND_RETURN_EXPR(return_expr_) \
80  do { \
81  if (db_Connect_status != DB_CONNECTION_STATUS_CONNECTED) \
82  { \
83  er_set(ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OBJ_NO_CONNECT, 0); \
84  return (return_expr_); \
85  } \
86  } while (0)
87 
88 #define CHECK_CONNECT_ERROR() \
89  CHECK_CONNECT_AND_RETURN_EXPR((DB_TYPE) ER_OBJ_NO_CONNECT)
90 
91 #define CHECK_CONNECT_NULL() \
92  CHECK_CONNECT_AND_RETURN_EXPR(NULL)
93 
94 #define CHECK_CONNECT_ZERO() \
95  CHECK_CONNECT_AND_RETURN_EXPR(0)
96 
97 #define CHECK_CONNECT_ZERO_TYPE(TYPE) \
98  CHECK_CONNECT_AND_RETURN_EXPR((TYPE)0)
99 
100 #define CHECK_CONNECT_MINUSONE() \
101  CHECK_CONNECT_AND_RETURN_EXPR(-1)
102 
103 #define CHECK_CONNECT_FALSE() \
104  CHECK_CONNECT_AND_RETURN_EXPR(false)
105 
106 /* CHECK MODIFICATION */
107 #define CHECK_MODIFICATION_VOID() \
108  do { \
109  if (db_Disable_modifications) { \
110  er_set(ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_DB_NO_MODIFICATIONS, 0); \
111  return; \
112  } \
113  } while (0)
114 
115 #define CHECK_MODIFICATION_AND_RETURN_EXPR(return_expr_) \
116  if (db_Disable_modifications) { \
117  er_set(ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_DB_NO_MODIFICATIONS, 0); \
118  return (return_expr_); \
119  }
120 
121 #define CHECK_MODIFICATION_ERROR() \
122  CHECK_MODIFICATION_AND_RETURN_EXPR(ER_DB_NO_MODIFICATIONS)
123 
124 #define CHECK_MODIFICATION_NULL() \
125  CHECK_MODIFICATION_AND_RETURN_EXPR(NULL)
126 
127 #define CHECK_MODIFICATION_MINUSONE() \
128  CHECK_MODIFICATION_AND_RETURN_EXPR(-1)
129 
130 #ifndef CHECK_MODIFICATION_NO_RETURN
131 #if defined (SA_MODE)
132 #define CHECK_MODIFICATION_NO_RETURN(error) \
133  error = NO_ERROR;
134 #else /* SA_MODE */
135 #define CHECK_MODIFICATION_NO_RETURN(error) \
136  if (db_Disable_modifications) { \
137  er_set(ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_DB_NO_MODIFICATIONS, 0); \
138  er_log_debug (ARG_FILE_LINE, "db_Disable_modification = %d\n", \
139  db_Disable_modifications); \
140  error = ER_DB_NO_MODIFICATIONS; \
141  } else { \
142  error = NO_ERROR; \
143  }
144 #endif /* !SA_MODE */
145 #endif /* CHECK_MODIFICATION_NO_RETURN */
146 
147 #define CHECK_1ARG_RETURN_EXPR(obj, expr) \
148  do { \
149  if((obj) == NULL) { \
150  er_set(ER_WARNING_SEVERITY, ARG_FILE_LINE, ER_OBJ_INVALID_ARGUMENTS, 0); \
151  return (expr); \
152  } \
153  } while (0)
154 
155 #define CHECK_2ARGS_RETURN_EXPR(obj1, obj2, expr) \
156  do { \
157  if((obj1) == NULL || (obj2) == NULL) { \
158  er_set(ER_WARNING_SEVERITY, ARG_FILE_LINE, ER_OBJ_INVALID_ARGUMENTS, 0); \
159  return (expr); \
160  } \
161  } while (0)
162 
163 #define CHECK_3ARGS_RETURN_EXPR(obj1, obj2, obj3, expr) \
164  do { \
165  if((obj1) == NULL || (obj2) == NULL || (obj3) == NULL) { \
166  er_set(ER_WARNING_SEVERITY, ARG_FILE_LINE, ER_OBJ_INVALID_ARGUMENTS, 0); \
167  return (expr); \
168  } \
169  } while (0)
170 
171 #define CHECK_1ARG_NULL(obj) \
172  CHECK_1ARG_RETURN_EXPR(obj, NULL)
173 
174 #define CHECK_2ARGS_NULL(obj1, obj2) \
175  CHECK_2ARGS_RETURN_EXPR(obj1,obj2,NULL)
176 
177 #define CHECK_3ARGS_NULL(obj1, obj2, obj3) \
178  CHECK_3ARGS_RETURN_EXPR(obj1,obj2,obj3,NULL)
179 
180 #define CHECK_1ARG_FALSE(obj) \
181  CHECK_1ARG_RETURN_EXPR(obj,false)
182 
183 #define CHECK_1ARG_TRUE(obj) \
184  CHECK_1ARG_RETURN_EXPR(obj, true)
185 
186 #define CHECK_1ARG_ERROR(obj) \
187  CHECK_1ARG_RETURN_EXPR(obj,ER_OBJ_INVALID_ARGUMENTS)
188 
189 #define CHECK_1ARG_ERROR_WITH_TYPE(obj, TYPE) \
190  CHECK_1ARG_RETURN_EXPR(obj,(TYPE)ER_OBJ_INVALID_ARGUMENTS)
191 
192 #define CHECK_1ARG_MINUSONE(obj) \
193  CHECK_1ARG_RETURN_EXPR(obj,-1)
194 
195 #define CHECK_2ARGS_ERROR(obj1, obj2) \
196  CHECK_2ARGS_RETURN_EXPR(obj1, obj2, ER_OBJ_INVALID_ARGUMENTS)
197 
198 #define CHECK_3ARGS_ERROR(obj1, obj2, obj3) \
199  CHECK_3ARGS_RETURN_EXPR(obj1, obj2, obj3, ER_OBJ_INVALID_ARGUMENTS)
200 
201 #define CHECK_1ARG_ZERO(obj) \
202  CHECK_1ARG_RETURN_EXPR(obj, 0)
203 
204 #define CHECK_1ARG_ZERO_WITH_TYPE(obj1, RETURN_TYPE) \
205  CHECK_1ARG_RETURN_EXPR(obj1, (RETURN_TYPE) 0)
206 
207 #define CHECK_2ARGS_ZERO(obj1, obj2) \
208  CHECK_2ARGS_RETURN_EXPR(obj1,obj2, 0)
209 
210 #define CHECK_1ARG_UNKNOWN(obj1) \
211  CHECK_1ARG_RETURN_EXPR(obj1, DB_TYPE_UNKNOWN)
212 
213 extern int db_init (const char *program, int print_version, const char *dbname, const char *db_path,
214  const char *vol_path, const char *log_path, const char *lob_path,
215  const char *host_name, const bool overwrite, const char *comments, const char *addmore_vols_file,
216  int npages, int desired_pagesize, int log_npages, int desired_log_page_size,
217  const char *lang_charset);
218 
219 extern int db_parse_one_statement (DB_SESSION * session);
220 #ifdef __cplusplus
221 extern "C"
222 {
223 #endif
224  extern int parse_one_statement (int state);
225 #ifdef __cplusplus
226 }
227 #endif
228 extern int db_get_parser_line_col (DB_SESSION * session, int *line, int *col);
229 extern int db_get_line_of_statement (DB_SESSION * session, int stmt_id);
230 extern int db_get_line_col_of_1st_error (DB_SESSION * session, DB_QUERY_ERROR * linecol);
231 extern DB_VALUE *db_get_hostvars (DB_SESSION * session);
232 extern char **db_get_lock_classes (DB_SESSION * session);
233 extern void db_drop_all_statements (DB_SESSION * session);
234 #if !defined (SERVER_MODE)
235 extern PARSER_CONTEXT *db_get_parser (DB_SESSION * session);
236 #endif /* !defined (SERVER_MODE) */
237 extern DB_NODE *db_get_statement (DB_SESSION * session, int id);
239 extern int db_abort_to_savepoint_internal (const char *savepoint_name);
240 
241 extern int db_error_code_test (void);
242 
243 extern const char *db_error_string_test (int level);
244 
245 #if defined (ENABLE_UNUSED_FUNCTION)
246 extern void *db_value_eh_key (DB_VALUE * value);
247 extern int db_value_put_db_data (DB_VALUE * value, const DB_DATA * data);
248 #endif
249 extern DB_DATA *db_value_get_db_data (DB_VALUE * value);
250 
251 extern DB_OBJECT *db_create_internal (DB_OBJECT * obj);
252 extern DB_OBJECT *db_create_by_name_internal (const char *name);
253 extern int db_put_internal (DB_OBJECT * obj, const char *name, DB_VALUE * value);
254 extern DB_OTMPL *dbt_create_object_internal (DB_OBJECT * classobj);
255 extern int dbt_put_internal (DB_OTMPL * def, const char *name, DB_VALUE * value);
256 extern int db_dput_internal (DB_OBJECT * obj, DB_ATTDESC * attribute, DB_VALUE * value);
257 extern int dbt_dput_internal (DB_OTMPL * def, DB_ATTDESC * attribute, DB_VALUE * value);
258 extern DB_DOMAIN *db_attdesc_domain (DB_ATTDESC * desc);
259 
260 extern int db_add_super_internal (DB_OBJECT * classobj, DB_OBJECT * super);
261 extern int db_add_attribute_internal (MOP class_, const char *name, const char *domain, DB_VALUE * default_value,
262  SM_NAME_SPACE name_space);
263 extern int db_rename_internal (DB_OBJECT * classobj, const char *name, int class_namespace, const char *newname);
264 extern int db_drop_attribute_internal (DB_OBJECT * classobj, const char *name);
265 extern DB_SESSION *db_open_buffer_local (const char *buffer);
266 extern int db_compile_statement_local (DB_SESSION * session);
267 extern int db_execute_statement_local (DB_SESSION * session, int stmt, DB_QUERY_RESULT ** result);
268 extern int db_open_buffer_and_compile_first_statement (const char *CSQL_query, DB_QUERY_ERROR * query_error,
269  int include_oid, DB_SESSION ** session, int *stmt_no);
270 extern int db_compile_and_execute_local (const char *CSQL_query, void *result, DB_QUERY_ERROR * query_error);
271 extern int db_compile_and_execute_queries_internal (const char *CSQL_query, void *result, DB_QUERY_ERROR * query_error,
272  int include_oid, int execute, bool is_new_statement);
273 extern int db_set_system_generated_statement (DB_SESSION * session);
274 extern void db_close_session_local (DB_SESSION * session);
275 extern int db_savepoint_transaction_internal (const char *savepoint_name);
276 extern int db_drop_set_attribute_domain (MOP class_, const char *name, int class_attribute, const char *domain);
277 extern BTID *db_constraint_index (DB_CONSTRAINT * constraint, BTID * index);
278 
279 extern int db_col_optimize (DB_COLLECTION * col);
280 
281 extern int db_get_connect_status (void);
282 extern void db_set_connect_status (int status);
283 
284 #endif /* _DB_H_ */
int db_execute_statement_local(DB_SESSION *session, int stmt, DB_QUERY_RESULT **result)
Definition: db_vdb.c:2939
int db_col_optimize(DB_COLLECTION *col)
Definition: db_set.c:1478
int db_rename_internal(DB_OBJECT *classobj, const char *name, int class_namespace, const char *newname)
int db_savepoint_transaction_internal(const char *savepoint_name)
Definition: db_admin.c:1166
int db_Connect_status
Definition: db_macro.c:88
DB_SESSION * db_open_buffer_local(const char *buffer)
Definition: db_vdb.c:205
void db_drop_all_statements(DB_SESSION *session)
Definition: db_vdb.c:3218
int db_drop_set_attribute_domain(MOP class_, const char *name, int class_attribute, const char *domain)
Definition: db_class.c:513
int db_get_parser_line_col(DB_SESSION *session, int *line, int *col)
Definition: db_vdb.c:355
int db_dput_internal(DB_OBJECT *obj, DB_ATTDESC *attribute, DB_VALUE *value)
Definition: db_obj.c:933
SM_NAME_SPACE
PARSER_CONTEXT * db_get_parser(DB_SESSION *session)
Definition: db_vdb.c:3714
int db_error_code_test(void)
Definition: db_admin.c:2123
DB_DATA * db_value_get_db_data(DB_VALUE *value)
Definition: db_macro.c:1211
char db_Database_name[]
Definition: db_admin.c:100
DB_OBJECT * db_create_by_name_internal(const char *name)
Definition: db_obj.c:145
int db_Row_count
Definition: db_macro.c:81
int db_open_buffer_and_compile_first_statement(const char *CSQL_query, DB_QUERY_ERROR *query_error, int include_oid, DB_SESSION **session, int *stmt_no)
Definition: db_vdb.c:3007
char db_Program_name[]
Definition: db_admin.c:101
int parse_one_statement(int state)
int dbt_put_internal(DB_OTMPL *def, const char *name, DB_VALUE *value)
Definition: db_obj.c:670
DB_NODE * db_get_statement(DB_SESSION *session, int id)
Definition: db_vdb.c:3729
INTL_CODESET lang_charset(void)
DB_OBJECT * db_create_internal(DB_OBJECT *obj)
Definition: db_obj.c:93
int db_parse_one_statement(DB_SESSION *session)
Definition: db_vdb.c:298
Definition: db_set.h:35
int db_init(const char *program, int print_version, const char *dbname, const char *db_path, const char *vol_path, const char *log_path, const char *lob_path, const char *host_name, const bool overwrite, const char *comments, const char *addmore_vols_file, int npages, int desired_pagesize, int log_npages, int desired_log_page_size, const char *lang_charset)
Definition: db_admin.c:164
int db_set_system_generated_statement(DB_SESSION *session)
Definition: db_vdb.c:3173
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
DB_SESSION * db_make_session_for_one_statement_execution(FILE *file)
Definition: db_vdb.c:276
int db_Disable_modifications
Definition: db_macro.c:90
void db_close_session_local(DB_SESSION *session)
Definition: db_vdb.c:3244
static char * dbname
BTID * db_constraint_index(DB_CONSTRAINT *constraint, BTID *index)
Definition: db_info.c:2107
int db_put_internal(DB_OBJECT *obj, const char *name, DB_VALUE *value)
Definition: db_obj.c:347
char ** db_get_lock_classes(DB_SESSION *session)
Definition: db_vdb.c:1573
const char * db_error_string_test(int level)
Definition: db_admin.c:2089
DB_DOMAIN * db_attdesc_domain(DB_ATTDESC *desc)
Definition: db_obj.c:790
DB_OTMPL * dbt_create_object_internal(DB_OBJECT *classobj)
SESSION_ID db_Session_id
Definition: db_macro.c:79
int db_abort_to_savepoint_internal(const char *savepoint_name)
Definition: db_admin.c:1210
unsigned int SESSION_ID
Definition: dbtype_def.h:480
int dbt_dput_internal(DB_OTMPL *def, DB_ATTDESC *attribute, DB_VALUE *value)
Definition: db_obj.c:977
int db_add_super_internal(DB_OBJECT *classobj, DB_OBJECT *super)
void db_set_connect_status(int status)
Definition: db_macro.c:4936
int db_compile_and_execute_queries_internal(const char *CSQL_query, void *result, DB_QUERY_ERROR *query_error, int include_oid, int execute, bool is_new_statement)
Definition: db_vdb.c:3096
DB_VALUE * db_get_hostvars(DB_SESSION *session)
Definition: db_vdb.c:1562
DB_VALUE * default_value
Definition: esql_cli.c:348
int db_compile_statement_local(DB_SESSION *session)
Definition: db_vdb.c:510
int db_compile_and_execute_local(const char *CSQL_query, void *result, DB_QUERY_ERROR *query_error)
Definition: db_vdb.c:3068
int db_drop_attribute_internal(DB_OBJECT *classobj, const char *name)
int db_get_line_col_of_1st_error(DB_SESSION *session, DB_QUERY_ERROR *linecol)
Definition: db_vdb.c:1095
int db_get_line_of_statement(DB_SESSION *session, int stmt_id)
Definition: db_vdb.c:4236
int db_get_connect_status(void)
Definition: db_macro.c:4930