CUBRID Engine  latest
api_common.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  * api_common.h -
21  */
22 
23 #ifndef _API_COMMON_H_
24 #define _API_COMMON_H_
25 
26 #include "api_handle.h"
27 
28 /*
29  * This file defines abstract structures that are used in CUBRID C API
30  * implementation. Each API sub-system (e.g. CCI or client C API) hides
31  * their implementation detailes behind these structures.
32  */
33 
34 
41 
42 typedef struct VALUE_AREA VALUE_AREA;
43 typedef struct API_VALUE API_VALUE;
46 
49 
52 
54 
55 /*
56  * type of CUBRID API handle
57  */
59 {
67 };
69 
70 /*
71  * connection handle status
72  */
74 {
78 };
80 
81 /*
82  * statement handle status
83  */
85 {
91 };
93 
94 #define COMMON_API_STRUCTURE_HEADER \
95  BH_BIND bind; \
96  CI_HANDLE_TYPE handle_type
97 
98 /*
99  * COMMON_API_STRUCTURE is base of the implementation structure of
100  * CUBRID API handle.
101  */
103 {
105 };
106 
107 #define COMMON_RESULTSET_META_HEADER \
108  COMMON_API_STRUCTURE_HEADER; \
109  API_RESULTSET_META_IFS *ifs
110 
111 /*
112  * API_RESULTSET_META structure is COMMON_API_STRUCTURE that provides
113  * API_RESULTSET_META_IFS in addition.
114  */
116 {
118 };
119 
120 /*
121  * API_RESULTSET_META_IFS structure is abstract data structure that
122  * provides resultset meta data information.
123  */
125 {
126  int (*get_count) (API_RESULTSET_META * rm, int *count);
127  int (*get_info) (API_RESULTSET_META * rm, int index, CI_RMETA_INFO_TYPE type, void *arg, size_t size);
128 };
129 
130 #define COMMON_RESULTSET_HEADER \
131  COMMON_API_STRUCTURE_HEADER; \
132  API_RESULTSET_IFS *ifs
133 
134 /*
135  * API_RESULTSET structure is COMMON_API_STRUCTURE that provides
136  * API_RESULTSET_IFS in addition
137  */
139 {
141 };
142 
143 /*
144  * API_RESULTSET_IFS structure is abstract data structure that provides
145  * resultset related informations. Each function matches actual CUBRID
146  * C API
147  */
149 {
150  int (*get_resultset_metadata) (API_RESULTSET * res, API_RESULTSET_META ** rimpl);
151  int (*fetch) (API_RESULTSET * res, int offset, CI_FETCH_POSITION pos);
152  int (*tell) (API_RESULTSET * res, int *offset);
153  int (*clear_updates) (API_RESULTSET * res);
154  int (*delete_row) (API_RESULTSET * res);
155  int (*get_value) (API_RESULTSET * res, int index, CI_TYPE type, void *addr, size_t len, size_t * outlen,
156  bool * is_null);
157  int (*get_value_by_name) (API_RESULTSET * res, const char *name, CI_TYPE type, void *addr, size_t len,
158  size_t * outlen, bool * isnull);
159  int (*update_value) (API_RESULTSET * res, int index, CI_TYPE type, void *addr, size_t len);
160  int (*apply_update) (API_RESULTSET * res);
161  void (*destroy) (API_RESULTSET * res);
162 };
163 
164 /*
165  * API_OBJECT_RESULTSET_POOL is abstract structure that provides
166  * object related functions.
167  */
169 {
170  int (*get_object_resultset) (API_OBJECT_RESULTSET_POOL * pool, CI_OID * oid, API_RESULTSET ** rres);
171  int (*oid_delete) (API_OBJECT_RESULTSET_POOL * pool, CI_OID * oid);
172  int (*oid_get_classname) (API_OBJECT_RESULTSET_POOL * pool, CI_OID * oid, char *name, size_t size);
173  void (*destroy) (API_OBJECT_RESULTSET_POOL * pool);
174  int (*glo_create) (API_OBJECT_RESULTSET_POOL * pool, CI_CONNECTION conn, const char *file_path,
175  const char *init_file_path, CI_OID * glo);
176  int (*glo_get_path_name) (API_OBJECT_RESULTSET_POOL * pool, CI_OID * glo, char *buf, size_t bufsz, bool full_path);
177  int (*glo_do_compaction) (API_OBJECT_RESULTSET_POOL * pool, CI_OID * glo);
178  int (*glo_insert) (API_OBJECT_RESULTSET_POOL * pool, CI_OID * glo, const char *buf, size_t bufsz);
179  int (*glo_delete) (API_OBJECT_RESULTSET_POOL * pool, CI_OID * glo, size_t sz, size_t * ndeleted);
180  int (*glo_read) (API_OBJECT_RESULTSET_POOL * pool, CI_OID * glo, char *buf, size_t bufsz, size_t * nread);
181  int (*glo_write) (API_OBJECT_RESULTSET_POOL * pool, CI_OID * glo, const char *buf, size_t sz);
182  int (*glo_truncate) (API_OBJECT_RESULTSET_POOL * pool, CI_OID * glo, size_t * ndeleted);
183  int (*glo_seek) (API_OBJECT_RESULTSET_POOL * pool, CI_OID * glo, long offset, int whence);
184  int (*glo_tell) (API_OBJECT_RESULTSET_POOL * pool, CI_OID * glo, long *offset);
185  int (*glo_like_search) (API_OBJECT_RESULTSET_POOL * pool, CI_OID * glo, const char *str, size_t strsz, bool * found);
186  int (*glo_reg_search) (API_OBJECT_RESULTSET_POOL * pool, CI_OID * glo, const char *str, size_t strsz, bool * found);
187  int (*glo_bin_search) (API_OBJECT_RESULTSET_POOL * pool, CI_OID * glo, const char *str, size_t strsz, bool * found);
188  int (*glo_copy) (API_OBJECT_RESULTSET_POOL * pool, CI_OID * to, CI_OID * from);
189 };
190 
191 /*
192  * CHECK_PURPOSE is an enumeration definition which defines check purpose
193  * of VALUE_INDEXER_IFS::check() function (see below)
194  */
195 typedef enum check_purpose_s
196 {
201 } CHECK_PURPOSE;
202 
203 /*
204  * VALUE_INDEXER is somthing that provides VALUE_INDEXER_IFS
205  */
207 {
209 };
210 
211 /*
212  * VALUE_INDEXER_IFS is abstract data structure that defines interface for
213  * manipulating tuples of (VALUE_AREA, API_VALUE) pair indexed by unique
214  * integer position.
215  */
217 {
218  int (*check) (VALUE_INDEXER * indexer, int index, CHECK_PURPOSE pup);
219  int (*length) (VALUE_INDEXER * indexer, int *len);
220  int (*get) (VALUE_INDEXER * indexer, int index, VALUE_AREA ** rva, API_VALUE ** rv);
221  int (*set) (VALUE_INDEXER * indexer, int index, VALUE_AREA * va, API_VALUE * val);
222  int (*map) (VALUE_INDEXER * indexer, int (*mapf) (void *, int, VALUE_AREA *, API_VALUE *), void *arg);
223  int (*insert) (VALUE_INDEXER * indexer, int index, VALUE_AREA * va, API_VALUE * dval);
224  int (*delete) (VALUE_INDEXER * indexer, int index, VALUE_AREA ** rva, API_VALUE ** rval);
225  void (*destroy) (VALUE_INDEXER * indexer, void (*df) (VALUE_AREA * va, API_VALUE * db));
226 };
227 
228 /*
229  * VALUE_BIND_TABLE is something that provides VALUE_BIND_TABLE_IFS
230  */
232 {
234 };
235 
236 /*
237  * VALUE_BIND_TABLE_IFS is abstract data structure that provides value
238  * containing and binding to actual implementation of target API sub-system.
239  */
241 {
242  int (*get_value) (VALUE_BIND_TABLE * tbl, int index, CI_TYPE type, void *addr, size_t len, size_t * outlen,
243  bool * isnull);
244  int (*set_value) (VALUE_BIND_TABLE * tbl, int index, CI_TYPE type, void *addr, size_t len);
245  int (*get_value_by_name) (VALUE_BIND_TABLE * tbl, const char *name, CI_TYPE type, void *addr, size_t len,
246  size_t * outlen, bool * isnull);
247  int (*set_value_by_name) (VALUE_BIND_TABLE * tbl, const char *name, CI_TYPE type, void *addr, size_t len);
248  int (*apply_updates) (VALUE_BIND_TABLE * tbl);
249  int (*reset) (VALUE_BIND_TABLE * tbl);
250  void (*destroy) (VALUE_BIND_TABLE * tbl);
251 };
252 
253 /*
254  * API_COLLECTION is value-copy of API sub-system collection implementation.
255  */
257 {
258  BIND_HANDLE conn; /* connection handle */
259  API_COLLECTION_IFS *ifs; /* collection interface */
260 };
261 
262 /*
263  * API_COLLECTION_IFS is abstract structure that provides collection related
264  * CUBRID C API function.
265  */
267 {
268  int (*length) (API_COLLECTION * col, int *len);
269  int (*insert) (API_COLLECTION * col, long pos, CI_TYPE type, void *ptr, size_t size);
270  int (*update) (API_COLLECTION * col, long pos, CI_TYPE type, void *ptr, size_t size);
271  int (*delete) (API_COLLECTION * col, long pos);
272  int (*get_elem_domain_info) (API_COLLECTION * col, long pos, CI_TYPE * type, int *precision, int *scale);
273  int (*get_elem) (API_COLLECTION * col, long pos, CI_TYPE type, void *addr, size_t len, size_t * outlen,
274  bool * isnull);
275  void (*destroy) (API_COLLECTION * col);
276 };
277 
278 /* api_value_indexer.c */
279 extern int array_indexer_create (int nvalue, VALUE_INDEXER ** rvi);
280 extern int list_indexer_create (VALUE_INDEXER ** rvi);
281 
282 /*
283  * API sub-system CUBRID C API implemetation table
284  */
286 {
287  int (*create_connection) (CI_CONNECTION * conn);
288  int (*err_set) (int err_code);
289  int (*conn_connect) (COMMON_API_STRUCTURE * conn, const char *host, unsigned short port, const char *databasename,
290  const char *user_name, const char *password);
291  int (*conn_close) (COMMON_API_STRUCTURE * conn);
292  int (*conn_create_statement) (COMMON_API_STRUCTURE * conn, CI_STATEMENT * stmt);
293  int (*conn_set_option) (COMMON_API_STRUCTURE * conn, CI_CONNECTION_OPTION option, void *arg, size_t size);
294  int (*conn_get_option) (COMMON_API_STRUCTURE * conn, CI_CONNECTION_OPTION option, void *arg, size_t size);
295  int (*conn_commit) (COMMON_API_STRUCTURE * conn);
296  int (*conn_rollback) (COMMON_API_STRUCTURE * conn);
297  int (*conn_get_error) (COMMON_API_STRUCTURE * conn, int *err, char *msg, size_t size);
298  int (*stmt_add_batch_query) (COMMON_API_STRUCTURE * stmt, const char *sql, size_t len);
299  int (*stmt_add_batch) (COMMON_API_STRUCTURE * stmt);
300  int (*stmt_clear_batch) (COMMON_API_STRUCTURE * stmt);
301  int (*stmt_execute_immediate) (COMMON_API_STRUCTURE * stmt, char *sql, size_t len, CI_RESULTSET * rs, int *r);
302  int (*stmt_execute) (COMMON_API_STRUCTURE * stmt, CI_RESULTSET * rs, int *r);
303  int (*stmt_execute_batch) (COMMON_API_STRUCTURE * stmt, CI_BATCH_RESULT * br);
304  int (*stmt_get_option) (COMMON_API_STRUCTURE * stmt, CI_STATEMENT_OPTION option, void *arg, size_t size);
305  int (*stmt_set_option) (COMMON_API_STRUCTURE * stmt, CI_STATEMENT_OPTION option, void *arg, size_t size);
306  int (*stmt_prepare) (COMMON_API_STRUCTURE * stmt, const char *sql, size_t len);
307  int (*stmt_register_out_parameter) (COMMON_API_STRUCTURE * stmt, int index);
308  int (*stmt_get_resultset_metadata) (COMMON_API_STRUCTURE * stmt, CI_RESULTSET_METADATA * r);
309  int (*stmt_get_parameter_metadata) (COMMON_API_STRUCTURE * stmt, CI_PARAMETER_METADATA * r);
310  int (*stmt_get_parameter) (COMMON_API_STRUCTURE * stmt, int index, CI_TYPE type, void *addr, size_t len,
311  size_t * outlen, bool * isnull);
312  int (*stmt_set_parameter) (COMMON_API_STRUCTURE * stmt, int index, CI_TYPE type, void *val, size_t size);
313  int (*stmt_get_resultset) (COMMON_API_STRUCTURE * stmt, CI_RESULTSET * res);
314  int (*stmt_affected_rows) (COMMON_API_STRUCTURE * stmt, int *out);
315  int (*stmt_get_query_type) (COMMON_API_STRUCTURE * stmt, CUBRID_STMT_TYPE * type);
316  int (*stmt_get_start_line) (COMMON_API_STRUCTURE * stmt, int *line);
317  int (*stmt_next_result) (COMMON_API_STRUCTURE * stmt, bool * exist_result);
318  int (*stmt_get_first_error) (COMMON_API_STRUCTURE * stmt, int *line, int *col, int *errcode, char *err_msg,
319  size_t size);
320  int (*stmt_get_next_error) (COMMON_API_STRUCTURE * stmt, int *line, int *col, int *errcode, char *err_msg,
321  size_t size);
322  int (*batch_res_query_count) (COMMON_API_STRUCTURE * pst, int *count);
323  int (*batch_res_get_result) (COMMON_API_STRUCTURE * pst, int index, int *ret, int *nr);
324  int (*batch_res_get_error) (COMMON_API_STRUCTURE * pst, int index, int *err_code, char *err_msg, size_t size);
325  int (*pmeta_get_count) (COMMON_API_STRUCTURE * pst, int *count);
326  int (*pmeta_get_info) (COMMON_API_STRUCTURE * pst, int index, CI_PMETA_INFO_TYPE type, void *arg, size_t size);
328  int (*collection_new) (CI_CONNECTION conn, CI_COLLECTION * coll);
329 };
330 
331 /* external function table */
333 
334 #endif /* _API_COMMON_H_ */
enum ci_conn_status CI_CONN_STATUS
Definition: api_common.h:79
int array_indexer_create(int nvalue, VALUE_INDEXER **rvi)
enum check_purpose_s CHECK_PURPOSE
API_COLLECTION_IFS * ifs
Definition: api_common.h:259
struct VALUE_AREA VALUE_AREA
Definition: api_common.h:42
BIND_HANDLE conn
Definition: api_common.h:258
check_purpose_s
Definition: api_common.h:195
handle_type
Definition: api_common.h:58
CUBRID_API_FUNCTION_TABLE Cubrid_api_function_table
Definition: cci_stub.c:5491
static int rv
Definition: area_alloc.c:52
struct API_VALUE API_VALUE
Definition: api_common.h:43
#define err(fd,...)
Definition: porting.h:431
int count(int &result, const cub_regex_object &reg, const std::string &src, const int position, const INTL_CODESET codeset)
enum ci_stmt_status CI_STMT_STATUS
Definition: api_common.h:92
enum handle_type CI_HANDLE_TYPE
Definition: api_common.h:68
VALUE_BIND_TABLE_IFS * ifs
Definition: api_common.h:233
CUBRID_STMT_TYPE
Definition: cas_dbms_util.h:40
int list_indexer_create(VALUE_INDEXER **rvi)
static int get_connection_opool(COMMON_API_STRUCTURE *pst, API_OBJECT_RESULTSET_POOL **opool)
Definition: db_stub.c:3041
ci_conn_status
Definition: api_common.h:73
UINT64 BIND_HANDLE
Definition: api_handle.h:28
VALUE_INDEXER_IFS * ifs
Definition: api_common.h:208
static char * host
ci_stmt_status
Definition: api_common.h:84