1 /*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | http://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Authors: Scott MacVicar <scottmac@php.net> |
14 +----------------------------------------------------------------------+
15 */
16
17 #ifndef PHP_SQLITE_STRUCTS_H
18 #define PHP_SQLITE_STRUCTS_H
19
20 #include <sqlite3.h>
21
22 /* for backwards compatibility reasons */
23 #ifndef SQLITE_OPEN_READONLY
24 #define SQLITE_OPEN_READONLY 0x00000001
25 #endif
26
27 #ifndef SQLITE_OPEN_READWRITE
28 #define SQLITE_OPEN_READWRITE 0x00000002
29 #endif
30
31 #ifndef SQLITE_OPEN_CREATE
32 #define SQLITE_OPEN_CREATE 0x00000004
33 #endif
34
35 /* Structure for SQLite Statement Parameter. */
36 struct php_sqlite3_bound_param {
37 zend_long param_number;
38 zend_string *name;
39 zend_long type;
40 zval parameter;
41 };
42
43 struct php_sqlite3_fci {
44 zend_fcall_info fci;
45 zend_fcall_info_cache fcc;
46 };
47
48 /* Structure for SQLite function. */
49 typedef struct _php_sqlite3_func {
50 struct _php_sqlite3_func *next;
51
52 const char *func_name;
53 int argc;
54
55 zval func, step, fini;
56 struct php_sqlite3_fci afunc, astep, afini;
57 } php_sqlite3_func;
58
59 /* Structure for SQLite collation function */
60 typedef struct _php_sqlite3_collation {
61 struct _php_sqlite3_collation *next;
62
63 const char *collation_name;
64 zval cmp_func;
65 struct php_sqlite3_fci fci;
66 } php_sqlite3_collation;
67
68 /* Structure for SQLite Database object. */
69 typedef struct _php_sqlite3_db_object {
70 int initialised;
71 sqlite3 *db;
72 php_sqlite3_func *funcs;
73 php_sqlite3_collation *collations;
74 zend_fcall_info authorizer_fci;
75 zend_fcall_info_cache authorizer_fcc;
76
77 zend_bool exception;
78
79 zend_llist free_list;
80 zend_object zo;
81 } php_sqlite3_db_object;
82
php_sqlite3_db_from_obj(zend_object * obj)83 static inline php_sqlite3_db_object *php_sqlite3_db_from_obj(zend_object *obj) {
84 return (php_sqlite3_db_object*)((char*)(obj) - XtOffsetOf(php_sqlite3_db_object, zo));
85 }
86
87 #define Z_SQLITE3_DB_P(zv) php_sqlite3_db_from_obj(Z_OBJ_P((zv)))
88
89 /* Structure for SQLite Database object. */
90 typedef struct _php_sqlite3_agg_context {
91 zval zval_context;
92 zend_long row_count;
93 } php_sqlite3_agg_context;
94
95 typedef struct _php_sqlite3_stmt_object php_sqlite3_stmt;
96 typedef struct _php_sqlite3_result_object php_sqlite3_result;
97
98 /* sqlite3 objects to be destroyed */
99 typedef struct _php_sqlite3_free_list {
100 zval stmt_obj_zval;
101 php_sqlite3_stmt *stmt_obj;
102 } php_sqlite3_free_list;
103
104 /* Structure for SQLite Result object. */
105 struct _php_sqlite3_result_object {
106 php_sqlite3_db_object *db_obj;
107 php_sqlite3_stmt *stmt_obj;
108 zval stmt_obj_zval;
109
110 int is_prepared_statement;
111 zend_object zo;
112 };
113
php_sqlite3_result_from_obj(zend_object * obj)114 static inline php_sqlite3_result *php_sqlite3_result_from_obj(zend_object *obj) {
115 return (php_sqlite3_result*)((char*)(obj) - XtOffsetOf(php_sqlite3_result, zo));
116 }
117
118 #define Z_SQLITE3_RESULT_P(zv) php_sqlite3_result_from_obj(Z_OBJ_P((zv)))
119
120 /* Structure for SQLite Statement object. */
121 struct _php_sqlite3_stmt_object {
122 sqlite3_stmt *stmt;
123 php_sqlite3_db_object *db_obj;
124 zval db_obj_zval;
125
126 int initialised;
127
128 /* Keep track of the zvals for bound parameters */
129 HashTable *bound_params;
130 zend_object zo;
131 };
132
php_sqlite3_stmt_from_obj(zend_object * obj)133 static inline php_sqlite3_stmt *php_sqlite3_stmt_from_obj(zend_object *obj) {
134 return (php_sqlite3_stmt*)((char*)(obj) - XtOffsetOf(php_sqlite3_stmt, zo));
135 }
136
137 #define Z_SQLITE3_STMT_P(zv) php_sqlite3_stmt_from_obj(Z_OBJ_P((zv)))
138
139 #endif
140