CUBRID Engine  latest
db_query.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_query.h - Query interface header file(Client Side)
22  */
23 
24 #ifndef _DB_QUERY_H_
25 #define _DB_QUERY_H_
26 
27 #ident "$Id$"
28 
29 #if defined (SERVER_MODE)
30 #error Does not belong to server module
31 #endif /* defined (SERVER_MODE) */
32 
33 #include "config.h"
34 
35 #include "error_manager.h"
36 #include "class_object.h"
37 #include "cursor.h"
38 
39 #ifdef __cplusplus
40 extern "C"
41 {
42 #endif
43 
44 /* QUERY TYPE/FORMAT STRUCTURES */
45  typedef enum
46  {
47  OID_COLUMN, /* hidden OID column */
48  USER_COLUMN, /* user visible column */
49  SYSTEM_ADDED_COLUMN /* system added hidden column */
51 
53  {
55  DB_COL_TYPE col_type; /* Column type */
56  char *name; /* Column name */
57  char *attr_name; /* Attribute name */
58  char *spec_name; /* Spec name */
59  char *original_name; /* user specified column name */
60  DB_TYPE db_type; /* Column data type */
61  int size; /* Column data size */
62  SM_DOMAIN *domain; /* Column domain information */
63  SM_DOMAIN *src_domain; /* Column source domain information */
64  COL_VISIBLE_TYPE visible_type; /* Is the column user visible? */
65  };
66 
67 /* QUERY RESULT STRUCTURES */
68 
69  typedef struct db_select_result
70  {
71  QUERY_ID query_id; /* Query Identifier */
72  int stmt_id; /* Statement identifier */
73  int stmt_type; /* Statement type */
74  CURSOR_ID cursor_id; /* Cursor on the query result */
75  CACHE_TIME cache_time; /* query cache time */
76  bool holdable; /* true if this result is holdable */
77  } DB_SELECT_RESULT; /* Select query result structure */
78 
79  typedef struct db_call_result
80  {
81  CURSOR_POSITION crs_pos; /* Cursor position relative to value tuple */
82  DB_VALUE *val_ptr; /* single value */
83  } DB_CALL_RESULT; /* call_method result structure */
84 
85  typedef struct db_objfetch_result
86  {
87  CURSOR_POSITION crs_pos; /* Cursor position relative to value list tuple */
88  DB_VALUE **valptr_list; /* list of value pointers */
89  } DB_OBJFETCH_RESULT; /* object_fetch result structure */
90 
91  typedef struct db_get_result
92  {
93  CURSOR_POSITION crs_pos; /* Cursor position relative to value list tuple */
94  int tpl_idx;
95  int n_tuple;
97  } DB_GET_RESULT;
98 
99  typedef struct db_query_tplpos
100  {
101  CURSOR_POSITION crs_pos; /* Cursor position */
102  VPID vpid; /* Real page identifier containing tuple */
103  int tpl_no; /* Tuple number inside the page */
104  int tpl_off; /* Tuple offset inside the page */
105  } DB_QUERY_TPLPOS; /* Tuple position structure */
106 
107  typedef enum
109 
110  typedef enum
112 
114  {
115  DB_RESULT_TYPE type; /* result type */
116  DB_RESULT_STATUS status; /* result status */
117  int col_cnt; /* number of values */
118  bool oid_included; /* first oid column included? */
119  DB_QUERY_TYPE *query_type; /* query type list */
120  int type_cnt; /* query type list count */
121  int qtable_ind; /* index to the query table */
122  union
123  {
124  DB_SELECT_RESULT s; /* select query result */
125  DB_CALL_RESULT c; /* CALL result */
126  DB_OBJFETCH_RESULT o; /* OBJFETCH result */
127  DB_GET_RESULT g; /* GET result */
128  } res;
129  struct db_query_result *next; /* next str. ptr, used internally */
130  };
131 
133 
135  {
138  };
139 
141 
143  {
144  char *statement; /* statement literal */
145  DB_QUERY_TYPE *columns; /* columns */
146  CUBRID_STMT_TYPE stmt_type; /* statement type */
147  DB_VALUE_ARRAY host_variables; /* statement host variables */
149  int auto_param_count; /* number of auto parametrized values */
150  int recompile; /* statement should be recompiled */
152  char **into_list; /* names of the "into" variables */
153  int into_count; /* count of elements from the into array */
154  };
155 
156  extern SM_DOMAIN *db_query_format_src_domain (DB_QUERY_TYPE * query_type);
157 
158  extern int db_execute_with_values (const char *CSQL_query, DB_QUERY_RESULT ** result, DB_QUERY_ERROR * query_error,
159  int arg_count, DB_VALUE * vals);
160 
161  extern int db_query_seek_tuple (DB_QUERY_RESULT * result, int offset, int seek_mode);
162 
164 
165  extern int db_query_set_tplpos (DB_QUERY_RESULT * result, DB_QUERY_TPLPOS * tplpos);
166 
167  extern void db_query_free_tplpos (DB_QUERY_TPLPOS * tplpos);
168 
169  extern int db_query_get_tuple_object (DB_QUERY_RESULT * result, int index, DB_OBJECT ** object);
170 
171  extern int db_query_get_tuple_object_by_name (DB_QUERY_RESULT * result, char *column_name, DB_OBJECT ** object);
172 
173  extern int db_query_get_value_to_space (DB_QUERY_RESULT * result, int index, unsigned char *ptr, int maxlength,
174  bool * truncated, DB_TYPE user_type, bool * null_flag);
175 
176  extern int db_query_get_value_to_pointer (DB_QUERY_RESULT * result, int index, unsigned char **ptr, DB_TYPE user_type,
177  bool * null_flag);
178 
179 #if defined (ENABLE_UNUSED_FUNCTION)
180  extern DB_TYPE db_query_get_value_type (DB_QUERY_RESULT * result, int index);
181  extern int db_query_get_value_length (DB_QUERY_RESULT * result, int index);
182 #endif
183 #if defined (CUBRID_DEBUG)
184  extern void db_sqlx_debug_print_result (DB_QUERY_RESULT * result);
185 #endif
186  extern bool db_is_client_cache_reusable (DB_QUERY_RESULT * result);
187 
189 
190  extern DB_QUERY_TYPE *db_cp_query_type (DB_QUERY_TYPE * query_type, int copy_only_user);
191 
192  extern DB_QUERY_TYPE *db_alloc_query_format (int cnt);
193  extern void db_free_query_format (DB_QUERY_TYPE * q);
195 
196 #if defined (ENABLE_UNUSED_FUNCTION)
197  extern void db_free_colname_list (char **colname_list, int cnt);
198  extern void db_free_domain_list (SM_DOMAIN ** domain_list, int cnt);
199 #endif
200 
201  extern void db_free_query_result (DB_QUERY_RESULT * r);
202  extern DB_QUERY_RESULT *db_alloc_query_result (DB_RESULT_TYPE r_type, int col_cnt);
203  extern void db_init_query_result (DB_QUERY_RESULT * r, DB_RESULT_TYPE r_type);
204 #if defined (CUBRID_DEBUG)
205  extern void db_dump_query_result (DB_QUERY_RESULT * r);
206 #endif
207 #if defined (ENABLE_UNUSED_FUNCTION)
208  extern char **db_cp_colname_list (char **colname_list, int cnt);
209  extern SM_DOMAIN **db_cp_domain_list (SM_DOMAIN ** domain_list, int cnt);
210  extern DB_QUERY_TYPE *db_get_query_type (DB_TYPE * type_list, int *size_list, char **colname_list,
211  char **attrname_list, SM_DOMAIN ** domain_list, SM_DOMAIN ** src_domain_list,
212  int cnt, bool oid_included);
213  extern int db_query_execute_immediate (const char *CSQL_query, DB_QUERY_RESULT ** result,
214  DB_QUERY_ERROR * query_error);
215  extern DB_QUERY_RESULT *db_get_objfetch_query_result (DB_VALUE * val_list, int val_cnt, int *size_list,
216  char **colname_list, char **attrname_list);
217  extern int db_query_stmt_id (DB_QUERY_RESULT * result);
218 #endif
219 
220  extern int db_query_end (DB_QUERY_RESULT * result);
221  extern int db_query_end_internal (DB_QUERY_RESULT * result, bool notify_server);
222 
223  extern void db_clear_client_query_result (int notify_server, bool end_holdable);
224  extern void db_init_prepare_info (DB_PREPARE_INFO * info);
225  extern int db_pack_prepare_info (const DB_PREPARE_INFO * info, char **buffer);
226  extern int db_unpack_prepare_info (DB_PREPARE_INFO * info, char *buffer);
227 
228  extern void db_set_execution_plan (char *plan, int length);
229  extern char *db_get_execution_plan (void);
230  extern void db_free_execution_plan (void);
231 
232 #ifdef __cplusplus
233 }
234 #endif
235 
236 #endif /* _DB_QUERY_H_ */
void db_free_query_result(DB_QUERY_RESULT *r)
Definition: db_query.c:727
COL_VISIBLE_TYPE visible_type
Definition: db_query.h:64
void db_init_query_result(DB_QUERY_RESULT *r, DB_RESULT_TYPE r_type)
Definition: db_query.c:1011
CURSOR_POSITION crs_pos
Definition: db_query.h:93
SM_DOMAIN * src_domain
Definition: db_query.h:63
DB_CALL_RESULT c
Definition: db_query.h:125
DB_OBJFETCH_RESULT o
Definition: db_query.h:126
DB_GET_RESULT g
Definition: db_query.h:127
CURSOR_ID cursor_id
Definition: db_query.h:74
char ** into_list
Definition: db_query.h:152
int db_execute_with_values(const char *CSQL_query, DB_QUERY_RESULT **result, DB_QUERY_ERROR *query_error, int arg_count, DB_VALUE *vals)
Definition: db_query.c:1511
DB_TYPE
Definition: dbtype_def.h:670
int db_query_get_tuple_object_by_name(DB_QUERY_RESULT *result, char *column_name, DB_OBJECT **object)
DB_TYPE db_type
Definition: db_query.h:60
int db_query_get_value_to_pointer(DB_QUERY_RESULT *result, int index, unsigned char **ptr, DB_TYPE user_type, bool *null_flag)
char * original_name
Definition: db_query.h:59
DB_QUERY_RESULT * db_get_db_value_query_result(DB_VALUE *var)
Definition: db_query.c:1998
void db_query_free_tplpos(DB_QUERY_TPLPOS *tplpos)
Definition: db_query.c:2858
DB_QUERY_TYPE * db_cp_query_type(DB_QUERY_TYPE *query_type, int copy_only_user)
Definition: db_query.c:1329
CACHE_TIME cache_time
Definition: db_query.h:75
CURSOR_POSITION crs_pos
Definition: db_query.h:101
bool db_is_client_cache_reusable(DB_QUERY_RESULT *result)
Definition: db_query.c:3432
int db_pack_prepare_info(const DB_PREPARE_INFO *info, char **buffer)
Definition: db_query.c:433
DB_RESULT_TYPE
Definition: db_query.h:107
int db_query_seek_tuple(DB_QUERY_RESULT *result, int offset, int seek_mode)
Definition: db_query.c:2455
SM_DOMAIN * db_query_format_src_domain(DB_QUERY_TYPE *query_type)
Definition: db_query.c:1675
DB_RESULT_STATUS status
Definition: db_query.h:116
DB_QUERY_TYPE * query_type_list
Definition: db_query.h:136
DB_QUERY_TPLPOS * db_query_get_tplpos(DB_QUERY_RESULT *result)
Definition: db_query.c:2737
DB_SELECT_RESULT s
Definition: db_query.h:124
int db_query_end(DB_QUERY_RESULT *result)
Definition: db_query.c:3362
CURSOR_POSITION
Definition: cursor.h:44
DB_COL_TYPE
Definition: dbtype_def.h:269
DB_QUERY_TYPE * query_type
Definition: db_query.h:119
char * spec_name
Definition: db_query.h:58
TP_DOMAIN ** host_var_expected_domains
Definition: db_query.h:148
DB_VALUE ** valptr_list
Definition: db_query.h:88
char * db_get_execution_plan(void)
Definition: db_query.c:3621
char * name
Definition: db_query.h:56
void db_init_prepare_info(DB_PREPARE_INFO *info)
Definition: db_query.c:411
DB_VALUE_ARRAY host_variables
Definition: db_query.h:147
void db_clear_client_query_result(int notify_server, bool end_holdable)
Definition: db_query.c:1208
DB_QUERY_TYPE * db_alloc_query_format(int cnt)
Definition: db_query.c:807
SM_DOMAIN * domain
Definition: db_query.h:62
CURSOR_POSITION crs_pos
Definition: db_query.h:87
char * attr_name
Definition: db_query.h:57
bool oid_included
Definition: db_query.h:118
struct db_query_type * next
Definition: db_query.h:54
int db_query_get_cache_time(DB_QUERY_RESULT *result, CACHE_TIME *cache_time)
Definition: db_query.c:3451
void db_free_execution_plan(void)
Definition: db_query.c:3638
struct db_select_result DB_SELECT_RESULT
void db_free_query_format(DB_QUERY_TYPE *q)
Definition: db_query.c:154
DB_VALUE * tpl_list
Definition: db_query.h:96
QUERY_ID query_id
Definition: db_query.h:71
DB_COL_TYPE col_type
Definition: db_query.h:55
CUBRID_STMT_TYPE
Definition: cas_dbms_util.h:40
struct db_get_result DB_GET_RESULT
int db_query_set_tplpos(DB_QUERY_RESULT *result, DB_QUERY_TPLPOS *tplpos)
Definition: db_query.c:2800
struct db_objfetch_result DB_OBJFETCH_RESULT
struct db_call_result DB_CALL_RESULT
char * statement
Definition: db_query.h:144
int db_unpack_prepare_info(DB_PREPARE_INFO *info, char *buffer)
Definition: db_query.c:537
int auto_param_count
Definition: db_query.h:149
DB_RESULT_STATUS
Definition: db_query.h:110
DB_RESULT_TYPE type
Definition: db_query.h:115
int db_query_get_tuple_object(DB_QUERY_RESULT *result, int index, DB_OBJECT **object)
struct db_query_tplpos DB_QUERY_TPLPOS
DB_QUERY_TYPE * columns
Definition: db_query.h:145
void db_set_execution_plan(char *plan, int length)
Definition: db_query.c:3567
int db_query_get_value_to_space(DB_QUERY_RESULT *result, int index, unsigned char *ptr, int maxlength, bool *truncated, DB_TYPE user_type, bool *null_flag)
DB_VALUE * val_ptr
Definition: db_query.h:82
struct db_query_result * next
Definition: db_query.h:129
COL_VISIBLE_TYPE
Definition: db_query.h:45
DB_QUERY_RESULT * db_alloc_query_result(DB_RESULT_TYPE r_type, int col_cnt)
Definition: db_query.c:868
CUBRID_STMT_TYPE stmt_type
Definition: db_query.h:146
CURSOR_POSITION crs_pos
Definition: db_query.h:81
int db_query_end_internal(DB_QUERY_RESULT *result, bool notify_server)
Definition: db_query.c:3473