Refactored sqlite3 (all tests passes)

This commit is contained in:
Xinchen Hui 2014-04-23 00:17:29 +08:00
parent c0b49a701a
commit 97381369a3
2 changed files with 242 additions and 274 deletions

View file

@ -43,7 +43,7 @@ struct php_sqlite3_bound_param {
int name_len;
long type;
zval *parameter;
zval parameter;
};
struct php_sqlite3_fci {
@ -58,7 +58,7 @@ typedef struct _php_sqlite3_func {
const char *func_name;
int argc;
zval *func, *step, *fini;
zval func, step, fini;
struct php_sqlite3_fci afunc, astep, afini;
} php_sqlite3_func;
@ -67,13 +67,12 @@ typedef struct _php_sqlite3_collation {
struct _php_sqlite3_collation *next;
const char *collation_name;
zval *cmp_func;
zval cmp_func;
struct php_sqlite3_fci fci;
} php_sqlite3_collation;
/* Structure for SQLite Database object. */
typedef struct _php_sqlite3_db_object {
zend_object zo;
int initialised;
sqlite3 *db;
php_sqlite3_func *funcs;
@ -82,11 +81,18 @@ typedef struct _php_sqlite3_db_object {
zend_bool exception;
zend_llist free_list;
zend_object zo;
} php_sqlite3_db_object;
static inline php_sqlite3_db_object *php_sqlite3_db_from_obj(zend_object *obj) {
return (php_sqlite3_db_object*)((char*)(obj) - XtOffsetOf(php_sqlite3_db_object, zo));
}
#define Z_SQLITE3_DB_P(zv) php_sqlite3_db_from_obj(Z_OBJ_P((zv)))
/* Structure for SQLite Database object. */
typedef struct _php_sqlite3_agg_context {
zval *zval_context;
zval zval_context;
long row_count;
} php_sqlite3_agg_context;
@ -95,34 +101,46 @@ typedef struct _php_sqlite3_result_object php_sqlite3_result;
/* sqlite3 objects to be destroyed */
typedef struct _php_sqlite3_free_list {
zval *stmt_obj_zval;
zval stmt_obj_zval;
php_sqlite3_stmt *stmt_obj;
} php_sqlite3_free_list;
/* Structure for SQLite Result object. */
struct _php_sqlite3_result_object {
zend_object zo;
php_sqlite3_db_object *db_obj;
php_sqlite3_stmt *stmt_obj;
zval *stmt_obj_zval;
zval stmt_obj_zval;
int is_prepared_statement;
int complete;
zend_object zo;
};
static inline php_sqlite3_result *php_sqlite3_result_from_obj(zend_object *obj) {
return (php_sqlite3_result*)((char*)(obj) - XtOffsetOf(php_sqlite3_result, zo));
}
#define Z_SQLITE3_RESULT_P(zv) php_sqlite3_result_from_obj(Z_OBJ_P((zv)))
/* Structure for SQLite Statement object. */
struct _php_sqlite3_stmt_object {
zend_object zo;
sqlite3_stmt *stmt;
php_sqlite3_db_object *db_obj;
zval *db_obj_zval;
zval db_obj_zval;
int initialised;
/* Keep track of the zvals for bound parameters */
HashTable *bound_params;
zend_object zo;
};
static inline php_sqlite3_stmt *php_sqlite3_stmt_from_obj(zend_object *obj) {
return (php_sqlite3_stmt*)((char*)(obj) - XtOffsetOf(php_sqlite3_stmt, zo));
}
#define Z_SQLITE3_STMT_P(zv) php_sqlite3_stmt_from_obj(Z_OBJ_P((zv)))
#endif