3 * Description: See "statement.c"
5 * Comments: See "notice.txt" for copyright and license information.
9 #ifndef __STATEMENT_H__
10 #define __STATEMENT_H__
33 STMT_ALLOCATED, /* The statement handle is allocated, but
35 STMT_READY, /* the statement is waiting to be executed */
36 STMT_PREMATURE, /* ODBC states that it is legal to call
37 * e.g. SQLDescribeCol before a call to
38 * SQLExecute, but after SQLPrepare. To
39 * get all the necessary information in
40 * such a case, we simply execute the
41 * query _before_ the actual call to
42 * SQLExecute, so that statement is
43 * considered to be "premature". */
44 STMT_FINISHED, /* statement execution has finished */
45 STMT_EXECUTING /* statement execution is still going on */
48 #define STMT_ROW_VERSION_CHANGED (-4)
49 #define STMT_POS_BEFORE_RECORDSET (-3)
50 #define STMT_TRUNCATED (-2)
51 #define STMT_INFO_ONLY (-1) /* not an error message,
55 #define STMT_OK 0 /* will be interpreted
56 * as "no error pending" */
57 #define STMT_EXEC_ERROR 1
58 #define STMT_STATUS_ERROR 2
59 #define STMT_SEQUENCE_ERROR 3
60 #define STMT_NO_MEMORY_ERROR 4
61 #define STMT_COLNUM_ERROR 5
62 #define STMT_NO_STMTSTRING 6
63 #define STMT_ERROR_TAKEN_FROM_BACKEND 7
64 #define STMT_INTERNAL_ERROR 8
65 #define STMT_STILL_EXECUTING 9
66 #define STMT_NOT_IMPLEMENTED_ERROR 10
67 #define STMT_BAD_PARAMETER_NUMBER_ERROR 11
68 #define STMT_OPTION_OUT_OF_RANGE_ERROR 12
69 #define STMT_INVALID_COLUMN_NUMBER_ERROR 13
70 #define STMT_RESTRICTED_DATA_TYPE_ERROR 14
71 #define STMT_INVALID_CURSOR_STATE_ERROR 15
72 #define STMT_OPTION_VALUE_CHANGED 16
73 #define STMT_CREATE_TABLE_ERROR 17
74 #define STMT_NO_CURSOR_NAME 18
75 #define STMT_INVALID_CURSOR_NAME 19
76 #define STMT_INVALID_ARGUMENT_NO 20
77 #define STMT_ROW_OUT_OF_RANGE 21
78 #define STMT_OPERATION_CANCELLED 22
79 #define STMT_INVALID_CURSOR_POSITION 23
80 #define STMT_VALUE_OUT_OF_RANGE 24
81 #define STMT_OPERATION_INVALID 25
82 #define STMT_PROGRAM_TYPE_OUT_OF_RANGE 26
83 #define STMT_BAD_ERROR 27
84 #define STMT_INVALID_OPTION_IDENTIFIER 28
89 STMT_TYPE_UNKNOWN = -2,
103 #define STMT_UPDATE(stmt) (stmt->statement_type > STMT_TYPE_SELECT)
111 STMT_PARSE_INCOMPLETE,
125 COL_INFO *col_info; /* cached SQLColumns info for this table */
126 char name[MAX_TABLE_LEN + 1];
127 char alias[MAX_TABLE_LEN + 1];
132 TABLE_INFO *ti; /* resolve to explicit table names */
144 char dot[MAX_TABLE_LEN + 1];
145 char name[MAX_COLUMN_LEN + 1];
146 char alias[MAX_COLUMN_LEN + 1];
150 /******** Statement Handle ***********/
151 struct StatementClass_
153 ConnectionClass *hdbc; /* pointer to ConnectionClass this
154 * statement belongs to */
155 QResultClass *result; /* result of the current statement */
157 StatementOptions options;
163 /* information on bindings */
164 BindInfoClass *bindings; /* array to store the binding information */
165 BindInfoClass bookmark;
166 int bindings_allocated;
168 /* information on statement parameters */
169 int parameters_allocated;
170 ParameterInfoClass *parameters;
172 Int4 currTuple; /* current absolute row number (GetData,
173 * SetPos, SQLFetch) */
174 int save_rowset_size; /* saved rowset size in case of
175 * change/FETCH_NEXT */
176 int rowset_start; /* start of rowset (an absolute row
178 int bind_row; /* current offset for Multiple row/column
180 int last_fetch_count; /* number of rows retrieved in
181 * last fetch/extended fetch */
182 int current_col; /* current column for GetData -- used to
183 * handle multiple calls */
184 int lobj_fd; /* fd of the current large object */
186 char *statement; /* if non--null pointer to the SQL
187 * statement that has been executed */
196 int statement_type; /* According to the defines above */
197 int data_at_exec; /* Number of params needing SQLPutData */
198 int current_exec_param; /* The current parameter for
201 char put_data; /* Has SQLPutData been called yet? */
203 char errormsg_created; /* has an informative error msg
205 char manual_result; /* Is the statement result manually built? */
206 char prepare; /* is this statement a prepared statement
209 char internal; /* Is this statement being called
212 char cursor_name[MAX_CURSOR_LEN + 1];
214 char *stmt_with_params; /* statement after
219 char pre_executing; /* This statement is prematurely executing */
220 char inaccurate_result; /* Current status is PREMATURE but
221 * result is inaccurate */
222 char errormsg_malloced; /* Current error message is malloed (not in a static variable) ? */
226 #define SC_get_conn(a) (a->hdbc)
227 #define SC_get_Result(a) (a->result);
229 /* options for SC_free_params() */
230 #define STMT_FREE_PARAMS_ALL 0
231 #define STMT_FREE_PARAMS_DATA_AT_EXEC_ONLY 1
234 #define SC_set_pre_executable(a) (a->miscinfo |= 1L)
235 #define SC_no_pre_executable(a) (a->miscinfo &= ~1L)
236 #define SC_is_pre_executable(a) ((a->miscinfo & 1L) != 0)
237 #define SC_set_fetchcursor(a) (a->miscinfo |= 2L)
238 #define SC_no_fetchcursor(a) (a->miscinfo &= ~2L)
239 #define SC_is_fetchcursor(a) ((a->miscinfo & 2L) != 0)
241 /* Statement prototypes */
242 StatementClass *SC_Constructor(void);
243 void InitializeStatementOptions(StatementOptions *opt);
244 char SC_Destructor(StatementClass *self);
245 int statement_type(char *statement);
246 char parse_statement(StatementClass *stmt);
247 void SC_pre_execute(StatementClass *self);
248 char SC_unbind_cols(StatementClass *self);
249 char SC_recycle_statement(StatementClass *self);
251 void SC_clear_error(StatementClass *self);
252 char SC_get_error(StatementClass *self, int *number, char **message);
253 char *SC_create_errormsg(StatementClass *self);
254 RETCODE SC_execute(StatementClass *self);
255 RETCODE SC_fetch(StatementClass *self);
256 void SC_free_params(StatementClass *self, char option);
257 void SC_log_error(char *func, char *desc, StatementClass *self);
258 unsigned long SC_get_bookmark(StatementClass *self);