xref: /PHP-7.4/ext/sqlite3/php_sqlite3_structs.h (revision f133f002)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 7                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) The PHP Group                                          |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 3.01 of the PHP license,      |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | http://www.php.net/license/3_01.txt                                  |
11    | If you did not receive a copy of the PHP license and are unable to   |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@php.net so we can mail you a copy immediately.               |
14    +----------------------------------------------------------------------+
15    | Authors: Scott MacVicar <scottmac@php.net>                           |
16    +----------------------------------------------------------------------+
17 */
18 
19 #ifndef PHP_SQLITE_STRUCTS_H
20 #define PHP_SQLITE_STRUCTS_H
21 
22 #include <sqlite3.h>
23 
24 /* for backwards compatibility reasons */
25 #ifndef SQLITE_OPEN_READONLY
26 #define SQLITE_OPEN_READONLY 0x00000001
27 #endif
28 
29 #ifndef SQLITE_OPEN_READWRITE
30 #define SQLITE_OPEN_READWRITE 0x00000002
31 #endif
32 
33 #ifndef SQLITE_OPEN_CREATE
34 #define SQLITE_OPEN_CREATE 0x00000004
35 #endif
36 
37 /* Structure for SQLite Statement Parameter. */
38 struct php_sqlite3_bound_param  {
39 	zend_long param_number;
40 	zend_string *name;
41 	zend_long type;
42 	zval parameter;
43 };
44 
45 struct php_sqlite3_fci {
46 	zend_fcall_info fci;
47 	zend_fcall_info_cache fcc;
48 };
49 
50 /* Structure for SQLite function. */
51 typedef struct _php_sqlite3_func {
52 	struct _php_sqlite3_func *next;
53 
54 	const char *func_name;
55 	int argc;
56 
57 	zval func, step, fini;
58 	struct php_sqlite3_fci afunc, astep, afini;
59 } php_sqlite3_func;
60 
61 /* Structure for SQLite collation function */
62 typedef struct _php_sqlite3_collation {
63 	struct _php_sqlite3_collation *next;
64 
65 	const char *collation_name;
66 	zval cmp_func;
67 	struct php_sqlite3_fci fci;
68 } php_sqlite3_collation;
69 
70 /* Structure for SQLite Database object. */
71 typedef struct _php_sqlite3_db_object  {
72 	int initialised;
73 	sqlite3 *db;
74 	php_sqlite3_func *funcs;
75 	php_sqlite3_collation *collations;
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 	int complete; // unused
112 	zend_object zo;
113 };
114 
php_sqlite3_result_from_obj(zend_object * obj)115 static inline php_sqlite3_result *php_sqlite3_result_from_obj(zend_object *obj) {
116 	return (php_sqlite3_result*)((char*)(obj) - XtOffsetOf(php_sqlite3_result, zo));
117 }
118 
119 #define Z_SQLITE3_RESULT_P(zv)  php_sqlite3_result_from_obj(Z_OBJ_P((zv)))
120 
121 /* Structure for SQLite Statement object. */
122 struct _php_sqlite3_stmt_object  {
123 	sqlite3_stmt *stmt;
124 	php_sqlite3_db_object *db_obj;
125 	zval db_obj_zval;
126 
127 	int initialised;
128 
129 	/* Keep track of the zvals for bound parameters */
130 	HashTable *bound_params;
131 	zend_object zo;
132 };
133 
php_sqlite3_stmt_from_obj(zend_object * obj)134 static inline php_sqlite3_stmt *php_sqlite3_stmt_from_obj(zend_object *obj) {
135 	return (php_sqlite3_stmt*)((char*)(obj) - XtOffsetOf(php_sqlite3_stmt, zo));
136 }
137 
138 #define Z_SQLITE3_STMT_P(zv)  php_sqlite3_stmt_from_obj(Z_OBJ_P((zv)))
139 
140 #endif
141