-
Notifications
You must be signed in to change notification settings - Fork 4
/
php_pdo_nuodb_c_cpp_common.h
273 lines (226 loc) · 11.1 KB
/
php_pdo_nuodb_c_cpp_common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/****************************************************************************
* Copyright (c) 2012 - 2013, NuoDB, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of NuoDB, Inc. nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NUODB, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
****************************************************************************/
#ifndef PHP_PDO_NUODB_C_CPP_COMMON_H
#define PHP_PDO_NUODB_C_CPP_COMMON_H
/*
** This is a common file that will be compiled by both C and C++.
** The definitions here are use by both the "C/PHP/Zend" parts of this
** driver as well as the "C++/NuoDB" parts of this driver.
**
*/
#define SHORT_MAX (1 << (8*sizeof(short)-1))
#define PDO_NUODB_SQLTYPE_BOOLEAN 1
#define PDO_NUODB_SQLTYPE_INTEGER 2
#define PDO_NUODB_SQLTYPE_BIGINT 3
#define PDO_NUODB_SQLTYPE_DOUBLE 4
#define PDO_NUODB_SQLTYPE_STRING 5
#define PDO_NUODB_SQLTYPE_DATE 6
#define PDO_NUODB_SQLTYPE_TIME 7
#define PDO_NUODB_SQLTYPE_TIMESTAMP 8
#define PDO_NUODB_SQLTYPE_ARRAY 9 // Not Yet Supported by this driver.
#define PDO_NUODB_SQLTYPE_BLOB 10
#define PDO_NUODB_SQLTYPE_CLOB 11
#ifdef __cplusplus
extern "C" {
#endif
struct pdo_nuodb_timer_t {
int startTimeInMicroSec;
int endTimeInMicroSec;
int stopped;
#ifdef WIN32
LARGE_INTEGER frequency; // ticks per second
LARGE_INTEGER startCount;
LARGE_INTEGER endCount;
#else
struct timeval startCount;
struct timeval endCount;
#endif
};
void pdo_nuodb_timer_init(struct pdo_nuodb_timer_t *timer);
void pdo_nuodb_timer_start(struct pdo_nuodb_timer_t *timer);
void pdo_nuodb_timer_end(struct pdo_nuodb_timer_t *timer);
int pdo_nuodb_get_elapsed_time_in_microseconds(struct pdo_nuodb_timer_t *timer);
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
extern "C" {
#endif
void pdo_nuodb_log(int lineno, const char *file, const char *log_level, const char *log_msg);
void pdo_nuodb_log_va(int lineno, const char *file, const char *log_level, char *format, ...);
int pdo_nuodb_func_enter(int lineno, const char *file, const char *func_name, int func_name_len);
void pdo_nuodb_func_leave(int lineno, const char *file);
#ifdef __cplusplus
}
#endif
#if PHP_DEBUG && !defined(PHP_WIN32)
#define PDO_DBG_ENABLED 1
#define PDO_DBG_INF(msg) do { if (dbg_skip_trace == FALSE) pdo_nuodb_log(__LINE__, __FILE__, "info", (msg)); } while (0)
#define PDO_DBG_ERR(msg) do { if (dbg_skip_trace == FALSE) pdo_nuodb_log(__LINE__, __FILE__, "error", (msg)); } while (0)
#define PDO_DBG_INF_FMT(...) do { if (dbg_skip_trace == FALSE) pdo_nuodb_log_va(__LINE__, __FILE__, "info", __VA_ARGS__); } while (0)
#define PDO_DBG_ERR_FMT(...) do { if (dbg_skip_trace == FALSE) pdo_nuodb_log_va(__LINE__, __FILE__, "error", __VA_ARGS__); } while (0)
#define PDO_DBG_ENTER(func_name) int dbg_skip_trace = TRUE; dbg_skip_trace = !pdo_nuodb_func_enter(__LINE__, __FILE__, func_name, strlen(func_name));
#define PDO_DBG_RETURN(value) do { pdo_nuodb_func_leave(__LINE__, __FILE__); return (value); } while (0)
#define PDO_DBG_VOID_RETURN do { pdo_nuodb_func_leave(__LINE__, __FILE__); return; } while (0)
#else
#define PDO_DBG_ENABLED 0
static inline void PDO_DBG_INF(char *msg) {}
static inline void PDO_DBG_ERR(char *msg) {}
static inline void PDO_DBG_INF_FMT(char *format, ...) {}
static inline void PDO_DBG_ERR_FMT(char *format, ...) {}
static inline void PDO_DBG_ENTER(const char *func_name) {}
#define PDO_DBG_RETURN(value) return (value)
#define PDO_DBG_VOID_RETURN return;
#endif
typedef struct {
char *file;
int line;
int errcode;
char *errmsg;
} pdo_nuodb_error_info;
typedef struct SqlOption_t
{
char const * option;
void * extra;
} SqlOption;
typedef struct SqlOptionArray_t
{
size_t count;
SqlOption const * array;
} SqlOptionArray;
typedef struct
{
short sqltype; // datatype
short scale; // scale factor
short col_name_length; // length of column name
char col_name[32];
short len; // length of data buffer
char *data; // address of data buffer
} nuo_param; // XSQLVAR
typedef struct
{
short num_params; // number of actual params (sqld)
short num_alloc; // number of allocated params (sqln)
nuo_param params[1]; // address of first param
} nuo_params; //XSQLDA
#define NUO_PARAMS_LENGTH(n) (sizeof(nuo_params) + (n-1) * sizeof(nuo_param))
#ifdef __cplusplus
extern "C" {
#endif
// Workaround DB-4112
const char *nuodb_get_sqlstate(int sqlcode);
void nuodb_throw_zend_exception(const char *sql_state, int code, const char *format, ...);
//void _nuodb_error_new(pdo_dbh_t * dbh, pdo_stmt_t * stmt, char const * file, long line, const char *sql_state, int nuodb_error_code, const char *format, ...);
int _pdo_nuodb_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line/* TSRMLS_DC*/);
int _record_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line, const char *sql_state, int error_code, const char *error_message);
int _record_error_formatted(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line, const char *sql_state, int error_code, const char *format, ...);
typedef struct
{
/* the connection handle */
void *db; // opaque for PdoNuoDbHandle * db;
/* PHP PDO parent pdo_dbh_t handle */
pdo_dbh_t *pdo_dbh;
/* NuoDB error information */
pdo_nuodb_error_info einfo;
/* the last error that didn't come from the API */
//char const * last_app_error; // TODO: this needs to go away in favor of 'einfo'
char in_nuodb_implicit_txn; /* may not be the same as pdo_dbh->in_txn */
char in_nuodb_explicit_txn; /* may not be the same as pdo_dbh->in_txn */
/* prepend table names on column names in fetch */
unsigned fetch_table_names:1;
} pdo_nuodb_db_handle;
int pdo_nuodb_db_handle_errno(pdo_nuodb_db_handle *H);
const char *pdo_nuodb_db_handle_errmsg(pdo_nuodb_db_handle *H);
pdo_error_type * pdo_nuodb_db_handle_sqlstate(pdo_nuodb_db_handle *H);
int pdo_nuodb_db_handle_commit(pdo_nuodb_db_handle *H);
int pdo_nuodb_db_handle_rollback(pdo_nuodb_db_handle *H);
int pdo_nuodb_db_handle_close_connection(pdo_nuodb_db_handle *H);
int pdo_nuodb_db_handle_delete(pdo_nuodb_db_handle *H);
int pdo_nuodb_db_handle_set_auto_commit(pdo_nuodb_db_handle *H, unsigned int auto_commit);
void *pdo_nuodb_db_handle_create_statement(pdo_nuodb_db_handle * H, pdo_stmt_t * stmt, const char *sql) ;
long pdo_nuodb_db_handle_doer(pdo_nuodb_db_handle * H, void *dbh_opaque, const char *sql, unsigned in_txn, unsigned auto_commit, void (*pt2pdo_dbh_t_set_in_txn)(void *dbh_opaque, unsigned in_txn));
int pdo_nuodb_db_handle_factory(pdo_nuodb_db_handle * H, SqlOptionArray *optionsArray, char **errMessage);
int pdo_nuodb_db_handle_last_id(pdo_nuodb_db_handle *H, const char *name);
const char *pdo_nuodb_db_handle_get_nuodb_product_name(pdo_nuodb_db_handle *H);
const char *pdo_nuodb_db_handle_get_nuodb_product_version(pdo_nuodb_db_handle *H);
typedef struct
{
/* the link that owns this statement */
void *H; // opaque for pdo_nuodb_db_handle *H;
/* the statement handle */
void *stmt; // opaque for PdoNuoDbStatement *stmt;
/* NuoDB error information */
pdo_nuodb_error_info einfo;
/* copy of the sql statement */
char *sql;
/* the name of the cursor (if it has one) */
char name[32];
/* implicit txn - true when autocommit is disabled and
* NuoDB will create a implicit txn because the app didn't
* start one by calling nuodb_handle_begin. */
char implicit_txn;
/* for an implicit_txn, do we want to commit on close? */
char commit_on_close;
/* whether EOF was reached for this statement */
unsigned exhausted:1;
/* successful execute opens a cursor */
unsigned cursor_open:1;
unsigned _reserved:22;
//int error_code; // TODO: this needs to go away in favor of 'einfo'
//char *error_msg; // pointer to error_msg. NULL if no error. // TODO: this needs to go away in favor of 'einfo'
unsigned qty_input_params;
/* the input params */
nuo_params * in_params;
/* the output params */
nuo_params * out_params;
} pdo_nuodb_stmt;
int pdo_nuodb_stmt_errno(pdo_nuodb_stmt *S);
const char *pdo_nuodb_stmt_errmsg(pdo_nuodb_stmt *S);
pdo_error_type *pdo_nuodb_stmt_sqlstate(pdo_nuodb_stmt *S);
int pdo_nuodb_stmt_delete(pdo_nuodb_stmt *S);
int pdo_nuodb_stmt_execute(pdo_nuodb_stmt *S, int *column_count, long *row_count);
int pdo_nuodb_stmt_fetch(pdo_nuodb_stmt *S, long *row_count);
char const *pdo_nuodb_stmt_get_column_name(pdo_nuodb_stmt * S, int colno);
int pdo_nuodb_stmt_get_sql_type(pdo_nuodb_stmt * S, int colno);
int pdo_nuodb_stmt_set_integer(pdo_nuodb_stmt *S, int paramno, long int_val);
int pdo_nuodb_stmt_set_boolean(pdo_nuodb_stmt *S, int paramno, char bool_val);
int pdo_nuodb_stmt_set_string(pdo_nuodb_stmt *S, int paramno, char *str_val);
int pdo_nuodb_stmt_set_bytes(pdo_nuodb_stmt *S, int paramno, const void *val, int length);
void pdo_nuodb_stmt_get_integer(pdo_nuodb_stmt *S, int colno, int **int_val);
void pdo_nuodb_stmt_get_boolean(pdo_nuodb_stmt *S, int colno, char **bool_val);
void pdo_nuodb_stmt_get_long(pdo_nuodb_stmt *S, int colno, int64_t **long_val);
const char *pdo_nuodb_stmt_get_string(pdo_nuodb_stmt *S, int colno);
void pdo_nuodb_stmt_get_date(pdo_nuodb_stmt *S, int colno, int64_t **date_val);
void pdo_nuodb_stmt_get_time(pdo_nuodb_stmt *S, int colno, int64_t **time_val);
const char * pdo_nuodb_stmt_get_timestamp(pdo_nuodb_stmt *S, int colno);
void pdo_nuodb_stmt_get_blob(pdo_nuodb_stmt *S, int colno, char ** ptr, unsigned long * len, void * (*erealloc)(void *ptr, size_t size, int allow_failure ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC));
void pdo_nuodb_stmt_get_clob(pdo_nuodb_stmt *S, int colno, char ** ptr, unsigned long * len, void * (*erealloc)(void *ptr, size_t size, int allow_failure ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC));
#ifdef __cplusplus
} // end of extern "C" {
#endif
#endif /* PHP_PDO_NUODB_C_CPP_COMMON_H */