version 1.1, 2012/02/21 23:47:58
|
version 1.1.1.2, 2012/05/29 12:34:40
|
Line 1333 static PHP_METHOD(PDOStatement, fetchObject)
|
Line 1333 static PHP_METHOD(PDOStatement, fetchObject)
|
long how = PDO_FETCH_CLASS; |
long how = PDO_FETCH_CLASS; |
long ori = PDO_FETCH_ORI_NEXT; |
long ori = PDO_FETCH_ORI_NEXT; |
long off = 0; |
long off = 0; |
char *class_name; | char *class_name = NULL; |
int class_name_len; |
int class_name_len; |
zend_class_entry *old_ce; |
zend_class_entry *old_ce; |
zval *old_ctor_args, *ctor_args; | zval *old_ctor_args, *ctor_args = NULL; |
int error = 0, old_arg_count; |
int error = 0, old_arg_count; |
|
|
PHP_STMT_GET_OBJ; |
PHP_STMT_GET_OBJ; |
|
|
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sz", | if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!a", &class_name, &class_name_len, &ctor_args)) { |
&class_name, &class_name_len, &ctor_args)) { | |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
Line 1357 static PHP_METHOD(PDOStatement, fetchObject)
|
Line 1356 static PHP_METHOD(PDOStatement, fetchObject)
|
old_arg_count = stmt->fetch.cls.fci.param_count; |
old_arg_count = stmt->fetch.cls.fci.param_count; |
|
|
do_fetch_opt_finish(stmt, 0 TSRMLS_CC); |
do_fetch_opt_finish(stmt, 0 TSRMLS_CC); |
| |
switch(ZEND_NUM_ARGS()) { | if (ctor_args) { |
case 0: | |
stmt->fetch.cls.ce = zend_standard_class_def; | |
break; | |
case 2: | |
if (Z_TYPE_P(ctor_args) != IS_NULL && Z_TYPE_P(ctor_args) != IS_ARRAY) { | |
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "ctor_args must be either NULL or an array" TSRMLS_CC); | |
error = 1; | |
break; | |
} | |
if (Z_TYPE_P(ctor_args) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(ctor_args))) { |
if (Z_TYPE_P(ctor_args) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(ctor_args))) { |
ALLOC_ZVAL(stmt->fetch.cls.ctor_args); |
ALLOC_ZVAL(stmt->fetch.cls.ctor_args); |
*stmt->fetch.cls.ctor_args = *ctor_args; |
*stmt->fetch.cls.ctor_args = *ctor_args; |
Line 1375 static PHP_METHOD(PDOStatement, fetchObject)
|
Line 1365 static PHP_METHOD(PDOStatement, fetchObject)
|
} else { |
} else { |
stmt->fetch.cls.ctor_args = NULL; |
stmt->fetch.cls.ctor_args = NULL; |
} |
} |
/* no break */ | } |
case 1: | if (class_name && !error) { |
stmt->fetch.cls.ce = zend_fetch_class(class_name, class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC); |
stmt->fetch.cls.ce = zend_fetch_class(class_name, class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC); |
|
|
if (!stmt->fetch.cls.ce) { |
if (!stmt->fetch.cls.ce) { |
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Could not find user-supplied class" TSRMLS_CC); |
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Could not find user-supplied class" TSRMLS_CC); |
error = 1; |
error = 1; |
break; |
|
} |
} |
|
} else if (!error) { |
|
stmt->fetch.cls.ce = zend_standard_class_def; |
} |
} |
|
|
if (!error && !do_fetch(stmt, TRUE, return_value, how, ori, off, 0 TSRMLS_CC)) { |
if (!error && !do_fetch(stmt, TRUE, return_value, how, ori, off, 0 TSRMLS_CC)) { |
Line 2244 const zend_function_entry pdo_dbstmt_functions[] = {
|
Line 2235 const zend_function_entry pdo_dbstmt_functions[] = {
|
}; |
}; |
|
|
/* {{{ overloaded handlers for PDOStatement class */ |
/* {{{ overloaded handlers for PDOStatement class */ |
static void dbstmt_prop_write(zval *object, zval *member, zval *value TSRMLS_DC) | static void dbstmt_prop_write(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC) |
{ |
{ |
pdo_stmt_t * stmt = (pdo_stmt_t *) zend_object_store_get_object(object TSRMLS_CC); |
pdo_stmt_t * stmt = (pdo_stmt_t *) zend_object_store_get_object(object TSRMLS_CC); |
|
|
Line 2253 static void dbstmt_prop_write(zval *object, zval *memb
|
Line 2244 static void dbstmt_prop_write(zval *object, zval *memb
|
if(strcmp(Z_STRVAL_P(member), "queryString") == 0) { |
if(strcmp(Z_STRVAL_P(member), "queryString") == 0) { |
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "property queryString is read only" TSRMLS_CC); |
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "property queryString is read only" TSRMLS_CC); |
} else { |
} else { |
std_object_handlers.write_property(object, member, value TSRMLS_CC); | std_object_handlers.write_property(object, member, value, key TSRMLS_CC); |
} |
} |
} |
} |
|
|
static void dbstmt_prop_delete(zval *object, zval *member TSRMLS_DC) | static void dbstmt_prop_delete(zval *object, zval *member, const zend_literal *key TSRMLS_DC) |
{ |
{ |
pdo_stmt_t * stmt = (pdo_stmt_t *) zend_object_store_get_object(object TSRMLS_CC); |
pdo_stmt_t * stmt = (pdo_stmt_t *) zend_object_store_get_object(object TSRMLS_CC); |
|
|
Line 2266 static void dbstmt_prop_delete(zval *object, zval *mem
|
Line 2257 static void dbstmt_prop_delete(zval *object, zval *mem
|
if(strcmp(Z_STRVAL_P(member), "queryString") == 0) { |
if(strcmp(Z_STRVAL_P(member), "queryString") == 0) { |
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "property queryString is read only" TSRMLS_CC); |
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "property queryString is read only" TSRMLS_CC); |
} else { |
} else { |
std_object_handlers.unset_property(object, member TSRMLS_CC); | std_object_handlers.unset_property(object, member, key TSRMLS_CC); |
} |
} |
} |
} |
|
|
Line 2276 static union _zend_function *dbstmt_method_get(
|
Line 2267 static union _zend_function *dbstmt_method_get(
|
#else |
#else |
zval *object, |
zval *object, |
#endif |
#endif |
char *method_name, int method_len TSRMLS_DC) | char *method_name, int method_len, const zend_literal *key TSRMLS_DC) |
{ |
{ |
zend_function *fbc = NULL; |
zend_function *fbc = NULL; |
char *lc_method_name; |
char *lc_method_name; |
Line 2325 static int dbstmt_compare(zval *object1, zval *object2
|
Line 2316 static int dbstmt_compare(zval *object1, zval *object2
|
static zend_object_value dbstmt_clone_obj(zval *zobject TSRMLS_DC) |
static zend_object_value dbstmt_clone_obj(zval *zobject TSRMLS_DC) |
{ |
{ |
zend_object_value retval; |
zend_object_value retval; |
zval *tmp; |
|
pdo_stmt_t *stmt; |
pdo_stmt_t *stmt; |
pdo_stmt_t *old_stmt; |
pdo_stmt_t *old_stmt; |
zend_object_handle handle = Z_OBJ_HANDLE_P(zobject); |
zend_object_handle handle = Z_OBJ_HANDLE_P(zobject); |
|
|
stmt = ecalloc(1, sizeof(*stmt)); |
stmt = ecalloc(1, sizeof(*stmt)); |
stmt->ce = Z_OBJCE_P(zobject); | zend_object_std_init(&stmt->std, Z_OBJCE_P(zobject) TSRMLS_CC); |
| object_properties_init(&stmt->std, Z_OBJCE_P(zobject)); |
stmt->refcount = 1; |
stmt->refcount = 1; |
ALLOC_HASHTABLE(stmt->properties); |
|
zend_hash_init(stmt->properties, 0, NULL, ZVAL_PTR_DTOR, 0); |
|
zend_hash_copy(stmt->properties, &stmt->ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); |
|
|
|
old_stmt = (pdo_stmt_t *)zend_object_store_get_object(zobject TSRMLS_CC); |
old_stmt = (pdo_stmt_t *)zend_object_store_get_object(zobject TSRMLS_CC); |
|
|
Line 2380 void pdo_stmt_init(TSRMLS_D)
|
Line 2368 void pdo_stmt_init(TSRMLS_D)
|
|
|
static void free_statement(pdo_stmt_t *stmt TSRMLS_DC) |
static void free_statement(pdo_stmt_t *stmt TSRMLS_DC) |
{ |
{ |
if (stmt->properties) { |
|
zend_hash_destroy(stmt->properties); |
|
efree(stmt->properties); |
|
stmt->properties = NULL; |
|
} |
|
|
|
if (stmt->bound_params) { |
if (stmt->bound_params) { |
zend_hash_destroy(stmt->bound_params); |
zend_hash_destroy(stmt->bound_params); |
FREE_HASHTABLE(stmt->bound_params); |
FREE_HASHTABLE(stmt->bound_params); |
Line 2434 static void free_statement(pdo_stmt_t *stmt TSRMLS_DC)
|
Line 2416 static void free_statement(pdo_stmt_t *stmt TSRMLS_DC)
|
if (stmt->dbh) { |
if (stmt->dbh) { |
php_pdo_dbh_delref(stmt->dbh TSRMLS_CC); |
php_pdo_dbh_delref(stmt->dbh TSRMLS_CC); |
} |
} |
|
zend_object_std_dtor(&stmt->std TSRMLS_CC); |
efree(stmt); |
efree(stmt); |
} |
} |
|
|
Line 2457 void pdo_dbstmt_free_storage(pdo_stmt_t *stmt TSRMLS_D
|
Line 2440 void pdo_dbstmt_free_storage(pdo_stmt_t *stmt TSRMLS_D
|
zend_object_value pdo_dbstmt_new(zend_class_entry *ce TSRMLS_DC) |
zend_object_value pdo_dbstmt_new(zend_class_entry *ce TSRMLS_DC) |
{ |
{ |
zend_object_value retval; |
zend_object_value retval; |
zval *tmp; |
|
|
|
pdo_stmt_t *stmt; |
pdo_stmt_t *stmt; |
stmt = emalloc(sizeof(*stmt)); |
stmt = emalloc(sizeof(*stmt)); |
memset(stmt, 0, sizeof(*stmt)); |
memset(stmt, 0, sizeof(*stmt)); |
stmt->ce = ce; | zend_object_std_init(&stmt->std, ce TSRMLS_CC); |
| object_properties_init(&stmt->std, ce); |
stmt->refcount = 1; |
stmt->refcount = 1; |
ALLOC_HASHTABLE(stmt->properties); |
|
zend_hash_init(stmt->properties, 0, NULL, ZVAL_PTR_DTOR, 0); |
|
zend_hash_copy(stmt->properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); |
|
|
|
retval.handle = zend_objects_store_put(stmt, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)pdo_dbstmt_free_storage, (zend_objects_store_clone_t)dbstmt_clone_obj TSRMLS_CC); |
retval.handle = zend_objects_store_put(stmt, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)pdo_dbstmt_free_storage, (zend_objects_store_clone_t)dbstmt_clone_obj TSRMLS_CC); |
retval.handlers = &pdo_dbstmt_object_handlers; |
retval.handlers = &pdo_dbstmt_object_handlers; |
Line 2601 const zend_function_entry pdo_row_functions[] = {
|
Line 2581 const zend_function_entry pdo_row_functions[] = {
|
{NULL, NULL, NULL} |
{NULL, NULL, NULL} |
}; |
}; |
|
|
static zval *row_prop_or_dim_read(zval *object, zval *member, int type TSRMLS_DC) | static zval *row_prop_read(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC) |
{ |
{ |
zval *return_value; |
zval *return_value; |
pdo_stmt_t * stmt = (pdo_stmt_t *) zend_object_store_get_object(object TSRMLS_CC); |
pdo_stmt_t * stmt = (pdo_stmt_t *) zend_object_store_get_object(object TSRMLS_CC); |
Line 2629 static zval *row_prop_or_dim_read(zval *object, zval *
|
Line 2609 static zval *row_prop_or_dim_read(zval *object, zval *
|
} |
} |
if (strcmp(Z_STRVAL_P(member), "queryString") == 0) { |
if (strcmp(Z_STRVAL_P(member), "queryString") == 0) { |
zval_ptr_dtor(&return_value); |
zval_ptr_dtor(&return_value); |
return std_object_handlers.read_property(object, member, type TSRMLS_CC); | return std_object_handlers.read_property(object, member, type, key TSRMLS_CC); |
} |
} |
} |
} |
} |
} |
Line 2640 static zval *row_prop_or_dim_read(zval *object, zval *
|
Line 2620 static zval *row_prop_or_dim_read(zval *object, zval *
|
return return_value; |
return return_value; |
} |
} |
|
|
static void row_prop_or_dim_write(zval *object, zval *member, zval *value TSRMLS_DC) | static zval *row_dim_read(zval *object, zval *member, int type TSRMLS_DC) |
{ |
{ |
|
return row_prop_read(object, member, type, NULL TSRMLS_CC); |
|
} |
|
|
|
static void row_prop_write(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC) |
|
{ |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "This PDORow is not from a writable result set"); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "This PDORow is not from a writable result set"); |
} |
} |
|
|
static int row_prop_or_dim_exists(zval *object, zval *member, int check_empty TSRMLS_DC) | static void row_dim_write(zval *object, zval *member, zval *value TSRMLS_DC) |
{ |
{ |
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "This PDORow is not from a writable result set"); |
|
} |
|
|
|
static int row_prop_exists(zval *object, zval *member, int check_empty, const zend_literal *key TSRMLS_DC) |
|
{ |
pdo_stmt_t * stmt = (pdo_stmt_t *) zend_object_store_get_object(object TSRMLS_CC); |
pdo_stmt_t * stmt = (pdo_stmt_t *) zend_object_store_get_object(object TSRMLS_CC); |
int colno = -1; |
int colno = -1; |
|
|
Line 2669 static int row_prop_or_dim_exists(zval *object, zval *
|
Line 2659 static int row_prop_or_dim_exists(zval *object, zval *
|
return 0; |
return 0; |
} |
} |
|
|
static void row_prop_or_dim_delete(zval *object, zval *offset TSRMLS_DC) | static int row_dim_exists(zval *object, zval *member, int check_empty TSRMLS_DC) |
{ |
{ |
|
return row_prop_exists(object, member, check_empty, NULL TSRMLS_CC); |
|
} |
|
|
|
static void row_prop_delete(zval *object, zval *offset, const zend_literal *key TSRMLS_DC) |
|
{ |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot delete properties from a PDORow"); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot delete properties from a PDORow"); |
} |
} |
|
|
|
static void row_dim_delete(zval *object, zval *offset TSRMLS_DC) |
|
{ |
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot delete properties from a PDORow"); |
|
} |
|
|
static HashTable *row_get_properties(zval *object TSRMLS_DC) |
static HashTable *row_get_properties(zval *object TSRMLS_DC) |
{ |
{ |
pdo_stmt_t * stmt = (pdo_stmt_t *) zend_object_store_get_object(object TSRMLS_CC); |
pdo_stmt_t * stmt = (pdo_stmt_t *) zend_object_store_get_object(object TSRMLS_CC); |
Line 2683 static HashTable *row_get_properties(zval *object TSRM
|
Line 2683 static HashTable *row_get_properties(zval *object TSRM
|
return NULL; |
return NULL; |
} |
} |
|
|
|
if (!stmt->std.properties) { |
|
rebuild_object_properties(&stmt->std); |
|
} |
for (i = 0; i < stmt->column_count; i++) { |
for (i = 0; i < stmt->column_count; i++) { |
zval *val; |
zval *val; |
MAKE_STD_ZVAL(val); |
MAKE_STD_ZVAL(val); |
fetch_value(stmt, val, i, NULL TSRMLS_CC); |
fetch_value(stmt, val, i, NULL TSRMLS_CC); |
|
|
zend_hash_update(stmt->properties, stmt->columns[i].name, stmt->columns[i].namelen + 1, (void *)&val, sizeof(zval *), NULL); | zend_hash_update(stmt->std.properties, stmt->columns[i].name, stmt->columns[i].namelen + 1, (void *)&val, sizeof(zval *), NULL); |
} |
} |
|
|
return stmt->properties; | return stmt->std.properties; |
} |
} |
|
|
static union _zend_function *row_method_get( |
static union _zend_function *row_method_get( |
Line 2700 static union _zend_function *row_method_get(
|
Line 2703 static union _zend_function *row_method_get(
|
#else |
#else |
zval *object, |
zval *object, |
#endif |
#endif |
char *method_name, int method_len TSRMLS_DC) | char *method_name, int method_len, const zend_literal *key TSRMLS_DC) |
{ |
{ |
zend_function *fbc; |
zend_function *fbc; |
char *lc_method_name; |
char *lc_method_name; |
Line 2717 static union _zend_function *row_method_get(
|
Line 2720 static union _zend_function *row_method_get(
|
return fbc; |
return fbc; |
} |
} |
|
|
static int row_call_method(char *method, INTERNAL_FUNCTION_PARAMETERS) | static int row_call_method(const char *method, INTERNAL_FUNCTION_PARAMETERS) |
{ |
{ |
return FAILURE; |
return FAILURE; |
} |
} |
Line 2739 static zend_class_entry *row_get_ce(const zval *object
|
Line 2742 static zend_class_entry *row_get_ce(const zval *object
|
return pdo_row_ce; |
return pdo_row_ce; |
} |
} |
|
|
static int row_get_classname(const zval *object, char **class_name, zend_uint *class_name_len, int parent TSRMLS_DC) | static int row_get_classname(const zval *object, const char **class_name, zend_uint *class_name_len, int parent TSRMLS_DC) |
{ |
{ |
if (parent) { |
if (parent) { |
return FAILURE; |
return FAILURE; |
Line 2756 static int row_compare(zval *object1, zval *object2 TS
|
Line 2759 static int row_compare(zval *object1, zval *object2 TS
|
} |
} |
|
|
zend_object_handlers pdo_row_object_handlers = { |
zend_object_handlers pdo_row_object_handlers = { |
ZEND_OBJECTS_STORE_HANDLERS, | zend_objects_store_add_ref, |
row_prop_or_dim_read, | zend_objects_store_del_ref, |
row_prop_or_dim_write, | |
row_prop_or_dim_read, | |
row_prop_or_dim_write, | |
NULL, |
NULL, |
|
row_prop_read, |
|
row_prop_write, |
|
row_dim_read, |
|
row_dim_write, |
NULL, |
NULL, |
NULL, |
NULL, |
row_prop_or_dim_exists, | NULL, |
row_prop_or_dim_delete, | row_prop_exists, |
row_prop_or_dim_exists, | row_prop_delete, |
row_prop_or_dim_delete, | row_dim_exists, |
| row_dim_delete, |
row_get_properties, |
row_get_properties, |
row_method_get, |
row_method_get, |
row_call_method, |
row_call_method, |