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 | https://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 /* Structure for SQLite function. */ 44 typedef struct _php_sqlite3_func { 45 struct _php_sqlite3_func *next; 46 47 const char *func_name; 48 int argc; 49 50 zend_fcall_info_cache func; 51 zend_fcall_info_cache step; 52 zend_fcall_info_cache fini; 53 } php_sqlite3_func; 54 55 /* Structure for SQLite collation function */ 56 typedef struct _php_sqlite3_collation { 57 struct _php_sqlite3_collation *next; 58 59 const char *collation_name; 60 zend_fcall_info_cache cmp_func; 61 } php_sqlite3_collation; 62 63 /* Structure for SQLite Database object. */ 64 typedef struct _php_sqlite3_db_object { 65 int initialised; 66 sqlite3 *db; 67 php_sqlite3_func *funcs; 68 php_sqlite3_collation *collations; 69 zend_fcall_info_cache authorizer_fcc; 70 71 bool exception; 72 73 zend_llist free_list; 74 zend_object zo; 75 } php_sqlite3_db_object; 76 php_sqlite3_db_from_obj(zend_object * obj)77static inline php_sqlite3_db_object *php_sqlite3_db_from_obj(zend_object *obj) { 78 return (php_sqlite3_db_object*)((char*)(obj) - XtOffsetOf(php_sqlite3_db_object, zo)); 79 } 80 81 #define Z_SQLITE3_DB_P(zv) php_sqlite3_db_from_obj(Z_OBJ_P((zv))) 82 83 /* Structure for SQLite Database object. */ 84 typedef struct _php_sqlite3_agg_context { 85 zval zval_context; 86 zend_long row_count; 87 } php_sqlite3_agg_context; 88 89 typedef struct _php_sqlite3_stmt_object php_sqlite3_stmt; 90 typedef struct _php_sqlite3_result_object php_sqlite3_result; 91 92 /* sqlite3 objects to be destroyed */ 93 typedef struct _php_sqlite3_free_list { 94 zval stmt_obj_zval; 95 php_sqlite3_stmt *stmt_obj; 96 } php_sqlite3_free_list; 97 98 /* Structure for SQLite Result object. */ 99 struct _php_sqlite3_result_object { 100 php_sqlite3_db_object *db_obj; 101 php_sqlite3_stmt *stmt_obj; 102 zval stmt_obj_zval; 103 104 /* Cache of column names to speed up repeated fetchArray(SQLITE3_ASSOC) calls. 105 * Cache is cleared on reset() and finalize() calls. */ 106 int column_count; 107 zend_string **column_names; 108 109 int is_prepared_statement; 110 zend_object zo; 111 }; 112 php_sqlite3_result_from_obj(zend_object * obj)113static inline php_sqlite3_result *php_sqlite3_result_from_obj(zend_object *obj) { 114 return (php_sqlite3_result*)((char*)(obj) - XtOffsetOf(php_sqlite3_result, zo)); 115 } 116 117 #define Z_SQLITE3_RESULT_P(zv) php_sqlite3_result_from_obj(Z_OBJ_P((zv))) 118 119 /* Structure for SQLite Statement object. */ 120 struct _php_sqlite3_stmt_object { 121 sqlite3_stmt *stmt; 122 php_sqlite3_db_object *db_obj; 123 zval db_obj_zval; 124 125 int initialised; 126 127 /* Keep track of the zvals for bound parameters */ 128 HashTable *bound_params; 129 zend_object zo; 130 }; 131 php_sqlite3_stmt_from_obj(zend_object * obj)132static inline php_sqlite3_stmt *php_sqlite3_stmt_from_obj(zend_object *obj) { 133 return (php_sqlite3_stmt*)((char*)(obj) - XtOffsetOf(php_sqlite3_stmt, zo)); 134 } 135 136 #define Z_SQLITE3_STMT_P(zv) php_sqlite3_stmt_from_obj(Z_OBJ_P((zv))) 137 138 #endif 139