mirror of
https://github.com/bdnugget/php-src.git
synced 2026-11-27 02:45:42 +00:00
Merge branch 'refactoring2' of github.com:zendtech/php into refactoring2
This commit is contained in:
commit
0ca57dd1d3
9 files changed
+208
-210
No files matched your search
+1
-1
@@ -187,7 +187,7 @@ PDO_API int php_pdo_register_driver(pdo_driver_t *driver)
|
||||
return FAILURE; /* NOTREACHED */
|
||||
}
|
||||
|
||||
return zend_hash_str_add_mem(&pdo_driver_hash, (char*)driver->driver_name, driver->driver_name_len, (void**)&driver, sizeof(pdo_driver_t *)) != NULL;
|
||||
return zend_hash_str_add_ptr(&pdo_driver_hash, (char*)driver->driver_name, driver->driver_name_len, driver) != NULL;
|
||||
}
|
||||
|
||||
PDO_API void php_pdo_unregister_driver(pdo_driver_t *driver)
|
||||
|
||||
+22
-6
@@ -197,7 +197,7 @@ static PHP_METHOD(PDO, dbh_constructor)
|
||||
{
|
||||
zval *object = getThis();
|
||||
pdo_dbh_t *dbh = NULL;
|
||||
zend_bool is_persistent = FALSE;
|
||||
zend_bool is_persistent = 0;
|
||||
char *data_source;
|
||||
int data_source_len;
|
||||
char *colon;
|
||||
@@ -207,6 +207,7 @@ static PHP_METHOD(PDO, dbh_constructor)
|
||||
zval *options = NULL;
|
||||
char alt_dsn[512];
|
||||
int call_factory = 1;
|
||||
char tmp;
|
||||
|
||||
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!s!a!", &data_source, &data_source_len,
|
||||
&username, &usernamelen, &password, &passwordlen, &options)) {
|
||||
@@ -254,8 +255,10 @@ static PHP_METHOD(PDO, dbh_constructor)
|
||||
}
|
||||
}
|
||||
|
||||
tmp = data_source[colon - data_source];
|
||||
data_source[colon - data_source] = '\0';
|
||||
driver = pdo_find_driver(data_source, colon - data_source);
|
||||
|
||||
data_source[colon - data_source] = tmp;
|
||||
if (!driver) {
|
||||
/* NB: don't want to include the data_source in the error message as
|
||||
* it might contain a password */
|
||||
@@ -274,6 +277,8 @@ static PHP_METHOD(PDO, dbh_constructor)
|
||||
zend_resource *le;
|
||||
pdo_dbh_t *pdbh = NULL;
|
||||
|
||||
//?? let's delay the persistent supports later
|
||||
#if 0
|
||||
if ((v = zend_hash_index_find(Z_ARRVAL_P(options), PDO_ATTR_PERSISTENT)) != NULL) {
|
||||
if (Z_TYPE_P(v) == IS_STRING &&
|
||||
!is_numeric_string(Z_STRVAL_P(v), Z_STRLEN_P(v), NULL, NULL, 0) && Z_STRLEN_P(v) > 0) {
|
||||
@@ -291,6 +296,7 @@ static PHP_METHOD(PDO, dbh_constructor)
|
||||
password ? password : "");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (is_persistent) {
|
||||
/* let's see if we have one cached.... */
|
||||
@@ -445,6 +451,7 @@ static void pdo_stmt_construct(pdo_stmt_t *stmt, zval *object, zend_class_entry
|
||||
ZVAL_STRINGL(&z_key, "queryString", sizeof("queryString") - 1);
|
||||
std_object_handlers.write_property(object, &z_key, &query_string, -1 TSRMLS_CC);
|
||||
zval_ptr_dtor(&query_string);
|
||||
zval_ptr_dtor(&z_key);
|
||||
|
||||
if (dbstmt_ce->constructor) {
|
||||
zend_fcall_info fci;
|
||||
@@ -576,7 +583,7 @@ static PHP_METHOD(PDO, prepare)
|
||||
php_pdo_dbh_addref(dbh TSRMLS_CC);
|
||||
ZVAL_COPY_VALUE(&stmt->database_object_handle, getThis());
|
||||
/* we haven't created a lazy object yet */
|
||||
ZVAL_NULL(&stmt->lazy_object_ref);
|
||||
ZVAL_UNDEF(&stmt->lazy_object_ref);
|
||||
|
||||
if (dbh->methods->preparer(dbh, statement, statement_len, stmt, options TSRMLS_CC)) {
|
||||
pdo_stmt_construct(stmt, return_value, dbstmt_ce, &ctor_args TSRMLS_CC);
|
||||
@@ -1115,7 +1122,7 @@ static PHP_METHOD(PDO, query)
|
||||
php_pdo_dbh_addref(dbh TSRMLS_CC);
|
||||
stmt->database_object_handle = *getThis();
|
||||
/* we haven't created a lazy object yet */
|
||||
ZVAL_NULL(&stmt->lazy_object_ref);
|
||||
ZVAL_UNDEF(&stmt->lazy_object_ref);
|
||||
|
||||
if (dbh->methods->preparer(dbh, statement, statement_len, stmt, NULL TSRMLS_CC)) {
|
||||
PDO_STMT_CLEAR_ERR();
|
||||
@@ -1275,6 +1282,14 @@ const zend_function_entry pdo_dbh_functions[] = {
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
static void cls_method_dtor(zval *el) {
|
||||
zend_function *func = (zend_function*)Z_PTR_P(el);
|
||||
if (func->common.function_name) {
|
||||
STR_RELEASE(func->common.function_name);
|
||||
}
|
||||
efree(func);
|
||||
}
|
||||
|
||||
/* {{{ overloaded object handlers for PDO class */
|
||||
int pdo_hash_methods(pdo_dbh_t *dbh, int kind TSRMLS_DC)
|
||||
{
|
||||
@@ -1295,7 +1310,7 @@ int pdo_hash_methods(pdo_dbh_t *dbh, int kind TSRMLS_DC)
|
||||
if (!(dbh->cls_methods[kind] = pemalloc(sizeof(HashTable), dbh->is_persistent))) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_ERROR, "out of memory while allocating PDO methods.");
|
||||
}
|
||||
zend_hash_init_ex(dbh->cls_methods[kind], 8, NULL, NULL, dbh->is_persistent, 0);
|
||||
zend_hash_init_ex(dbh->cls_methods[kind], 8, NULL, cls_method_dtor, dbh->is_persistent, 0);
|
||||
|
||||
while (funcs->fname) {
|
||||
ifunc->type = ZEND_INTERNAL_FUNCTION;
|
||||
@@ -1529,7 +1544,7 @@ static void dbh_free(pdo_dbh_t *dbh TSRMLS_DC)
|
||||
}
|
||||
}
|
||||
|
||||
pefree(dbh, dbh->is_persistent);
|
||||
//???pefree(dbh, dbh->is_persistent);
|
||||
}
|
||||
|
||||
PDO_API void php_pdo_dbh_addref(pdo_dbh_t *dbh TSRMLS_DC)
|
||||
@@ -1554,6 +1569,7 @@ static void pdo_dbh_free_storage(zend_object *std TSRMLS_DC)
|
||||
dbh->methods->persistent_shutdown(dbh TSRMLS_CC);
|
||||
}
|
||||
zend_object_std_dtor(std TSRMLS_CC);
|
||||
dbh_free(dbh);
|
||||
}
|
||||
|
||||
zend_object *pdo_dbh_new(zend_class_entry *ce TSRMLS_DC)
|
||||
|
||||
@@ -319,7 +319,7 @@ int pdo_sqlstate_init_error_table(void)
|
||||
for (i = 0; i < sizeof(err_initializer)/sizeof(err_initializer[0]); i++) {
|
||||
info = &err_initializer[i];
|
||||
|
||||
zend_hash_str_add_mem(&err_hash, info->state, sizeof(info->state) - 1, &info, sizeof(info));
|
||||
zend_hash_str_add_ptr(&err_hash, info->state, sizeof(info->state), info);
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
@@ -328,7 +328,7 @@ int pdo_sqlstate_init_error_table(void)
|
||||
const char *pdo_sqlstate_state_to_description(char *state)
|
||||
{
|
||||
const struct pdo_sqlstate_info *info;
|
||||
if ((info = zend_hash_str_find_ptr(&err_hash, state, sizeof(err_initializer[0].state) - 1)) != NULL) {
|
||||
if ((info = zend_hash_str_find_ptr(&err_hash, state, sizeof(err_initializer[0].state))) != NULL) {
|
||||
return info->desc;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
+55
-69
@@ -256,13 +256,13 @@ int pdo_stmt_describe_columns(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */
|
||||
|
||||
static void get_lazy_object(pdo_stmt_t *stmt, zval *return_value TSRMLS_DC) /* {{{ */
|
||||
{
|
||||
if (Z_TYPE(stmt->lazy_object_ref) == IS_NULL) {
|
||||
if (ZVAL_IS_UNDEF(&stmt->lazy_object_ref)) {
|
||||
pdo_row_t *row = ecalloc(1, sizeof(pdo_row_t));
|
||||
row->stmt = stmt;
|
||||
zend_object_std_init(&row->std, pdo_row_ce TSRMLS_CC);
|
||||
ZVAL_OBJ(&stmt->lazy_object_ref, &row->std);
|
||||
zend_objects_store_put(&row->std TSRMLS_CC);
|
||||
row->std.handlers = &pdo_row_object_handlers;
|
||||
stmt->refcount++;
|
||||
stmt->std.gc.refcount++;
|
||||
}
|
||||
ZVAL_COPY(return_value, &stmt->lazy_object_ref);
|
||||
}
|
||||
@@ -289,6 +289,7 @@ static void param_dtor(zval *el) /* {{{ */
|
||||
if (!ZVAL_IS_UNDEF(¶m->driver_params)) {
|
||||
zval_ptr_dtor(¶m->driver_params);
|
||||
}
|
||||
efree(param);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@@ -357,7 +358,7 @@ static int really_register_bound_param(struct pdo_bound_param_data *param, pdo_s
|
||||
if (is_param && param->name->val[0] != ':') {
|
||||
zend_string *temp = STR_ALLOC(param->name->len + 1, 0);
|
||||
temp->val[0] = ':';
|
||||
memmove(temp->val + 1, param->name->val, param->name->len);
|
||||
memmove(temp->val + 1, param->name->val, param->name->len + 1);
|
||||
param->name = temp;
|
||||
} else {
|
||||
param->name = STR_INIT(param->name->val, param->name->len, 0);
|
||||
@@ -742,7 +743,7 @@ static int do_fetch_class_prepare(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */
|
||||
zval *val;
|
||||
|
||||
fci->param_count = 0;
|
||||
fci->params = safe_emalloc(sizeof(zval*), ht->nNumOfElements, 0);
|
||||
fci->params = safe_emalloc(sizeof(zval), ht->nNumOfElements, 0);
|
||||
ZEND_HASH_FOREACH_VAL(ht, val) {
|
||||
ZVAL_COPY_VALUE(&fci->params[fci->param_count++], val);
|
||||
} ZEND_HASH_FOREACH_END();
|
||||
@@ -785,7 +786,7 @@ static int make_callable_ex(pdo_stmt_t *stmt, zval *callable, zend_fcall_info *
|
||||
}
|
||||
|
||||
fci->param_count = num_args; /* probably less */
|
||||
fci->params = safe_emalloc(sizeof(zval**), num_args, 0);
|
||||
fci->params = safe_emalloc(sizeof(zval), num_args, 0);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -793,8 +794,8 @@ static int make_callable_ex(pdo_stmt_t *stmt, zval *callable, zend_fcall_info *
|
||||
|
||||
static int do_fetch_func_prepare(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */
|
||||
{
|
||||
zend_fcall_info * fci = &stmt->fetch.cls.fci;
|
||||
zend_fcall_info_cache * fcc = &stmt->fetch.cls.fcc;
|
||||
zend_fcall_info *fci = &stmt->fetch.cls.fci;
|
||||
zend_fcall_info_cache *fcc = &stmt->fetch.cls.fcc;
|
||||
|
||||
if (!make_callable_ex(stmt, &stmt->fetch.func.function, fci, fcc, stmt->column_count TSRMLS_CC)) {
|
||||
return 0;
|
||||
@@ -812,6 +813,7 @@ static int do_fetch_opt_finish(pdo_stmt_t *stmt, int free_ctor_agrs TSRMLS_DC) /
|
||||
efree(stmt->fetch.cls.fci.params);
|
||||
stmt->fetch.cls.fci.params = NULL;
|
||||
}
|
||||
|
||||
stmt->fetch.cls.fci.size = 0;
|
||||
if (!ZVAL_IS_UNDEF(&stmt->fetch.cls.ctor_args) && free_ctor_agrs) {
|
||||
zval_ptr_dtor(&stmt->fetch.cls.ctor_args);
|
||||
@@ -1428,7 +1430,11 @@ static PHP_METHOD(PDOStatement, fetchAll)
|
||||
}
|
||||
/* no break */
|
||||
case 2:
|
||||
ZVAL_COPY_VALUE(&stmt->fetch.cls.ctor_args, ctor_args); /* we're not going to free these */
|
||||
if (ctor_args) {
|
||||
ZVAL_COPY_VALUE(&stmt->fetch.cls.ctor_args, ctor_args); /* we're not going to free these */
|
||||
} else {
|
||||
ZVAL_UNDEF(&stmt->fetch.cls.ctor_args);
|
||||
}
|
||||
if (Z_TYPE_P(arg2) != IS_STRING) {
|
||||
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Invalid class name (should be a string)" TSRMLS_CC);
|
||||
error = 1;
|
||||
@@ -1547,14 +1553,15 @@ static int register_bound_param(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt,
|
||||
{
|
||||
struct pdo_bound_param_data param = {0};
|
||||
long param_type = PDO_PARAM_STR;
|
||||
zval *parameter;
|
||||
|
||||
param.paramno = -1;
|
||||
|
||||
if (FAILURE == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC,
|
||||
"lz|llz!", ¶m.paramno, ¶m.parameter, ¶m_type, ¶m.max_value_len,
|
||||
"lz|llz!", ¶m.paramno, ¶meter, ¶m_type, ¶m.max_value_len,
|
||||
¶m.driver_params)) {
|
||||
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sz|llz!", ¶m.name,
|
||||
¶m.parameter, ¶m_type, ¶m.max_value_len,
|
||||
¶meter, ¶m_type, ¶m.max_value_len,
|
||||
¶m.driver_params)) {
|
||||
return 0;
|
||||
}
|
||||
@@ -1569,9 +1576,7 @@ static int register_bound_param(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (Z_REFCOUNTED(param.parameter)) {
|
||||
Z_ADDREF(param.parameter);
|
||||
}
|
||||
ZVAL_COPY(¶m.parameter, parameter);
|
||||
if (!really_register_bound_param(¶m, stmt, is_param TSRMLS_CC)) {
|
||||
if (!ZVAL_IS_UNDEF(¶m.parameter)) {
|
||||
zval_ptr_dtor(&(param.parameter));
|
||||
@@ -1588,14 +1593,15 @@ static PHP_METHOD(PDOStatement, bindValue)
|
||||
{
|
||||
struct pdo_bound_param_data param = {0};
|
||||
long param_type = PDO_PARAM_STR;
|
||||
zval *parameter;
|
||||
PHP_STMT_GET_OBJ;
|
||||
|
||||
param.paramno = -1;
|
||||
|
||||
if (FAILURE == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC,
|
||||
"lz/|l", ¶m.paramno, ¶m.parameter, ¶m_type)) {
|
||||
"lz/|l", ¶m.paramno, ¶meter, ¶m_type)) {
|
||||
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sz/|l", ¶m.name,
|
||||
¶m.parameter, ¶m_type)) {
|
||||
¶meter, ¶m_type)) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
@@ -1609,9 +1615,7 @@ static PHP_METHOD(PDOStatement, bindValue)
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (Z_REFCOUNTED(param.parameter)) {
|
||||
Z_ADDREF(param.parameter);
|
||||
}
|
||||
ZVAL_COPY(¶m.parameter, parameter);
|
||||
if (!really_register_bound_param(¶m, stmt, TRUE TSRMLS_CC)) {
|
||||
if (!ZVAL_IS_UNDEF(¶m.parameter)) {
|
||||
zval_ptr_dtor(&(param.parameter));
|
||||
@@ -1867,7 +1871,7 @@ int pdo_stmt_setup_fetch_mode(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, in
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
args = safe_emalloc(ZEND_NUM_ARGS(), sizeof(zval*), 0);
|
||||
args = safe_emalloc(ZEND_NUM_ARGS(), sizeof(zval), 0);
|
||||
|
||||
retval = zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args);
|
||||
|
||||
@@ -2133,7 +2137,8 @@ static PHP_METHOD(PDOStatement, debugDumpParams)
|
||||
}
|
||||
|
||||
php_stream_printf(out TSRMLS_CC, "paramno=%ld\nname=[%d] \"%.*s\"\nis_param=%d\nparam_type=%d\n",
|
||||
param->paramno, param->name->len, param->name->len, param->name ? param->name->val : "",
|
||||
param->paramno, param->name? param->name->len : 0, param->name? param->name->len : 0,
|
||||
param->name ? param->name->val : "",
|
||||
param->is_param,
|
||||
param->param_type);
|
||||
|
||||
@@ -2192,7 +2197,7 @@ static void dbstmt_prop_write(zval *object, zval *member, zval *value, zend_uint
|
||||
|
||||
convert_to_string(member);
|
||||
|
||||
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);
|
||||
} else {
|
||||
std_object_handlers.write_property(object, member, value, cache_slot TSRMLS_CC);
|
||||
@@ -2261,7 +2266,6 @@ static zend_object *dbstmt_clone_obj(zval *zobject TSRMLS_DC)
|
||||
stmt = ecalloc(1, sizeof(pdo_stmt_t) + sizeof(zval) * (Z_OBJCE_P(zobject)->default_properties_count - 1));
|
||||
zend_object_std_init(&stmt->std, Z_OBJCE_P(zobject) TSRMLS_CC);
|
||||
object_properties_init(&stmt->std, Z_OBJCE_P(zobject));
|
||||
stmt->refcount = 1;
|
||||
|
||||
old_stmt = Z_PDO_STMT_P(zobject);
|
||||
|
||||
@@ -2353,25 +2357,12 @@ static void free_statement(pdo_stmt_t *stmt TSRMLS_DC)
|
||||
php_pdo_dbh_delref(stmt->dbh TSRMLS_CC);
|
||||
}
|
||||
zend_object_std_dtor(&stmt->std TSRMLS_CC);
|
||||
efree(stmt);
|
||||
}
|
||||
|
||||
PDO_API void php_pdo_stmt_addref(pdo_stmt_t *stmt TSRMLS_DC)
|
||||
{
|
||||
stmt->refcount++;
|
||||
}
|
||||
|
||||
PDO_API void php_pdo_stmt_delref(pdo_stmt_t *stmt TSRMLS_DC)
|
||||
{
|
||||
if (--stmt->refcount == 0) {
|
||||
free_statement(stmt TSRMLS_CC);
|
||||
}
|
||||
}
|
||||
|
||||
void pdo_dbstmt_free_storage(zend_object *std TSRMLS_DC)
|
||||
{
|
||||
pdo_stmt_t *stmt = php_pdo_stmt_fetch_object(std);
|
||||
php_pdo_stmt_delref(stmt TSRMLS_CC);
|
||||
free_statement(stmt TSRMLS_CC);
|
||||
}
|
||||
|
||||
zend_object *pdo_dbstmt_new(zend_class_entry *ce TSRMLS_DC)
|
||||
@@ -2381,7 +2372,6 @@ zend_object *pdo_dbstmt_new(zend_class_entry *ce TSRMLS_DC)
|
||||
stmt = ecalloc(1, sizeof(pdo_stmt_t) + sizeof(zval) * (ce->default_properties_count - 1));
|
||||
zend_object_std_init(&stmt->std, ce TSRMLS_CC);
|
||||
object_properties_init(&stmt->std, ce);
|
||||
stmt->refcount = 1;
|
||||
|
||||
stmt->std.handlers = &pdo_dbstmt_object_handlers;
|
||||
|
||||
@@ -2393,36 +2383,31 @@ zend_object *pdo_dbstmt_new(zend_class_entry *ce TSRMLS_DC)
|
||||
|
||||
struct php_pdo_iterator {
|
||||
zend_object_iterator iter;
|
||||
pdo_stmt_t *stmt;
|
||||
ulong key;
|
||||
zval fetch_ahead;
|
||||
};
|
||||
|
||||
static void pdo_stmt_iter_dtor(zend_object_iterator *iter TSRMLS_DC)
|
||||
{
|
||||
struct php_pdo_iterator *I = (struct php_pdo_iterator*)Z_PTR(iter->data);
|
||||
struct php_pdo_iterator *I = (struct php_pdo_iterator*)iter;
|
||||
|
||||
if (--I->stmt->refcount == 0) {
|
||||
free_statement(I->stmt TSRMLS_CC);
|
||||
}
|
||||
zval_ptr_dtor(&I->iter.data);
|
||||
|
||||
if (!ZVAL_IS_UNDEF(&I->fetch_ahead)) {
|
||||
zval_ptr_dtor(&I->fetch_ahead);
|
||||
}
|
||||
|
||||
efree(I);
|
||||
}
|
||||
|
||||
static int pdo_stmt_iter_valid(zend_object_iterator *iter TSRMLS_DC)
|
||||
{
|
||||
struct php_pdo_iterator *I = (struct php_pdo_iterator*)Z_PTR(iter->data);
|
||||
struct php_pdo_iterator *I = (struct php_pdo_iterator*)iter;
|
||||
|
||||
return ZVAL_IS_UNDEF(&I->fetch_ahead) ? FAILURE : SUCCESS;
|
||||
}
|
||||
|
||||
static zval *pdo_stmt_iter_get_data(zend_object_iterator *iter TSRMLS_DC)
|
||||
{
|
||||
struct php_pdo_iterator *I = (struct php_pdo_iterator*)Z_PTR(iter->data);
|
||||
struct php_pdo_iterator *I = (struct php_pdo_iterator*)iter;
|
||||
|
||||
/* sanity */
|
||||
if (ZVAL_IS_UNDEF(&I->fetch_ahead)) {
|
||||
@@ -2434,7 +2419,7 @@ static zval *pdo_stmt_iter_get_data(zend_object_iterator *iter TSRMLS_DC)
|
||||
|
||||
static void pdo_stmt_iter_get_key(zend_object_iterator *iter, zval *key TSRMLS_DC)
|
||||
{
|
||||
struct php_pdo_iterator *I = (struct php_pdo_iterator*)Z_PTR(iter->data);
|
||||
struct php_pdo_iterator *I = (struct php_pdo_iterator*)iter;
|
||||
|
||||
if (I->key == (ulong)-1) {
|
||||
ZVAL_NULL(key);
|
||||
@@ -2445,19 +2430,19 @@ static void pdo_stmt_iter_get_key(zend_object_iterator *iter, zval *key TSRMLS_D
|
||||
|
||||
static void pdo_stmt_iter_move_forwards(zend_object_iterator *iter TSRMLS_DC)
|
||||
{
|
||||
struct php_pdo_iterator *I = (struct php_pdo_iterator*)Z_PTR(iter->data);
|
||||
struct php_pdo_iterator *I = (struct php_pdo_iterator*)iter;
|
||||
pdo_stmt_t *stmt = Z_PDO_STMT_P(&I->iter.data); /* for PDO_HANDLE_STMT_ERR() */
|
||||
|
||||
if (!ZVAL_IS_UNDEF(&I->fetch_ahead)) {
|
||||
zval_ptr_dtor(&I->fetch_ahead);
|
||||
}
|
||||
|
||||
if (!do_fetch(I->stmt, TRUE, &I->fetch_ahead, PDO_FETCH_USE_DEFAULT,
|
||||
if (!do_fetch(stmt, TRUE, &I->fetch_ahead, PDO_FETCH_USE_DEFAULT,
|
||||
PDO_FETCH_ORI_NEXT, 0, 0 TSRMLS_CC)) {
|
||||
pdo_stmt_t *stmt = I->stmt; /* for PDO_HANDLE_STMT_ERR() */
|
||||
|
||||
PDO_HANDLE_STMT_ERR();
|
||||
I->key = (ulong)-1;
|
||||
ZVAL_UNREF(&I->fetch_ahead);
|
||||
ZVAL_UNDEF(&I->fetch_ahead);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -2484,12 +2469,11 @@ zend_object_iterator *pdo_stmt_iter_get(zend_class_entry *ce, zval *object, int
|
||||
}
|
||||
|
||||
I = ecalloc(1, sizeof(struct php_pdo_iterator));
|
||||
zend_iterator_init(&I->iter TSRMLS_CC);
|
||||
I->iter.funcs = &pdo_stmt_iter_funcs;
|
||||
ZVAL_PTR(&I->iter.data, I);
|
||||
I->stmt = stmt;
|
||||
stmt->refcount++;
|
||||
ZVAL_COPY(&I->iter.data, object);
|
||||
|
||||
if (!do_fetch(I->stmt, 1, &I->fetch_ahead, PDO_FETCH_USE_DEFAULT,
|
||||
if (!do_fetch(stmt, 1, &I->fetch_ahead, PDO_FETCH_USE_DEFAULT,
|
||||
PDO_FETCH_ORI_NEXT, 0, 0 TSRMLS_CC)) {
|
||||
PDO_HANDLE_STMT_ERR();
|
||||
I->key = (ulong)-1;
|
||||
@@ -2509,8 +2493,10 @@ const zend_function_entry pdo_row_functions[] = {
|
||||
|
||||
static zval *row_prop_read(zval *object, zval *member, int type, zend_uint cache_slot, zval *rv TSRMLS_DC)
|
||||
{
|
||||
pdo_stmt_t *stmt = Z_PDO_STMT_P(object);
|
||||
pdo_row_t *row = (pdo_row_t *)Z_OBJ_P(object);
|
||||
pdo_stmt_t *stmt = row->stmt;
|
||||
int colno = -1;
|
||||
zval zobj;
|
||||
|
||||
ZVAL_NULL(rv);
|
||||
if (stmt) {
|
||||
@@ -2532,8 +2518,9 @@ static zval *row_prop_read(zval *object, zval *member, int type, zend_uint cache
|
||||
}
|
||||
}
|
||||
if (strcmp(Z_STRVAL_P(member), "queryString") == 0) {
|
||||
zval_ptr_dtor(rv);
|
||||
return std_object_handlers.read_property(object, member, type, cache_slot, rv TSRMLS_CC);
|
||||
ZVAL_OBJ(&zobj, &stmt->std);
|
||||
//zval_ptr_dtor(rv);
|
||||
return std_object_handlers.read_property(&zobj, member, type, cache_slot, rv TSRMLS_CC);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2562,7 +2549,8 @@ static void row_dim_write(zval *object, zval *member, zval *value TSRMLS_DC)
|
||||
|
||||
static int row_prop_exists(zval *object, zval *member, int check_empty, zend_uint cache_slot TSRMLS_DC)
|
||||
{
|
||||
pdo_stmt_t *stmt = Z_PDO_STMT_P(object);
|
||||
pdo_row_t *row = (pdo_row_t *)Z_OBJ_P(object);
|
||||
pdo_stmt_t *stmt = row->stmt;
|
||||
int colno = -1;
|
||||
|
||||
if (stmt) {
|
||||
@@ -2601,7 +2589,8 @@ static void row_dim_delete(zval *object, zval *offset TSRMLS_DC)
|
||||
|
||||
static HashTable *row_get_properties(zval *object TSRMLS_DC)
|
||||
{
|
||||
pdo_stmt_t *stmt = Z_PDO_STMT_P(object);
|
||||
pdo_row_t *row = (pdo_row_t *)Z_OBJ_P(object);
|
||||
pdo_stmt_t *stmt = row->stmt;
|
||||
int i;
|
||||
|
||||
if (stmt == NULL) {
|
||||
@@ -2706,20 +2695,17 @@ zend_object_handlers pdo_row_object_handlers = {
|
||||
|
||||
void pdo_row_free_storage(zend_object *std TSRMLS_DC)
|
||||
{
|
||||
pdo_stmt_t *stmt = php_pdo_stmt_fetch_object(std);
|
||||
if (stmt) {
|
||||
ZVAL_NULL(&stmt->lazy_object_ref);
|
||||
|
||||
if (--stmt->refcount == 0) {
|
||||
free_statement(stmt TSRMLS_CC);
|
||||
}
|
||||
pdo_row_t *row = (pdo_row_t *)std;
|
||||
if (row->stmt) {
|
||||
ZVAL_UNDEF(&row->stmt->lazy_object_ref);
|
||||
OBJ_RELEASE(&row->stmt->std);
|
||||
}
|
||||
}
|
||||
|
||||
zend_object *pdo_row_new(zend_class_entry *ce TSRMLS_DC)
|
||||
{
|
||||
pdo_row_t *row = ecalloc(1, sizeof(pdo_row_t));
|
||||
zend_objects_store_put(&row->std TSRMLS_CC);
|
||||
zend_object_std_init(&row->std, ce TSRMLS_CC);
|
||||
row->std.handlers = &pdo_row_object_handlers;
|
||||
|
||||
return &row->std;
|
||||
|
||||
@@ -606,6 +606,7 @@ struct _pdo_stmt_t {
|
||||
int column;
|
||||
struct {
|
||||
zend_class_entry *ce;
|
||||
void *_reserved;
|
||||
zval ctor_args; /* freed */
|
||||
zval retval;
|
||||
zend_fcall_info fci;
|
||||
|
||||
@@ -38,7 +38,7 @@ struct pdo_sqlite_fci {
|
||||
struct pdo_sqlite_func {
|
||||
struct pdo_sqlite_func *next;
|
||||
|
||||
zval *func, *step, *fini;
|
||||
zval func, step, fini;
|
||||
int argc;
|
||||
const char *funcname;
|
||||
|
||||
@@ -50,7 +50,7 @@ struct pdo_sqlite_collation {
|
||||
struct pdo_sqlite_collation *next;
|
||||
|
||||
const char *name;
|
||||
zval *callback;
|
||||
zval callback;
|
||||
struct pdo_sqlite_fci fc;
|
||||
};
|
||||
|
||||
|
||||
@@ -118,13 +118,13 @@ static void pdo_sqlite_cleanup_callbacks(pdo_sqlite_db_handle *H TSRMLS_DC)
|
||||
}
|
||||
|
||||
efree((char*)func->funcname);
|
||||
if (func->func) {
|
||||
if (!ZVAL_IS_UNDEF(&func->func)) {
|
||||
zval_ptr_dtor(&func->func);
|
||||
}
|
||||
if (func->step) {
|
||||
if (!ZVAL_IS_UNDEF(&func->step)) {
|
||||
zval_ptr_dtor(&func->step);
|
||||
}
|
||||
if (func->fini) {
|
||||
if (!ZVAL_IS_UNDEF(&func->fini)) {
|
||||
zval_ptr_dtor(&func->fini);
|
||||
}
|
||||
efree(func);
|
||||
@@ -145,7 +145,7 @@ static void pdo_sqlite_cleanup_callbacks(pdo_sqlite_db_handle *H TSRMLS_DC)
|
||||
}
|
||||
|
||||
efree((char*)collation->name);
|
||||
if (collation->callback) {
|
||||
if (!ZVAL_IS_UNDEF(&collation->callback)) {
|
||||
zval_ptr_dtor(&collation->callback);
|
||||
}
|
||||
efree(collation);
|
||||
@@ -285,7 +285,7 @@ static int pdo_sqlite_get_attribute(pdo_dbh_t *dbh, long attr, zval *return_valu
|
||||
switch (attr) {
|
||||
case PDO_ATTR_CLIENT_VERSION:
|
||||
case PDO_ATTR_SERVER_VERSION:
|
||||
ZVAL_STRING(return_value, (char *)sqlite3_libversion(), 1);
|
||||
ZVAL_STRING(return_value, (char *)sqlite3_libversion());
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -312,12 +312,12 @@ static int do_callback(struct pdo_sqlite_fci *fc, zval *cb,
|
||||
int argc, sqlite3_value **argv, sqlite3_context *context,
|
||||
int is_agg TSRMLS_DC)
|
||||
{
|
||||
zval ***zargs = NULL;
|
||||
zval *retval = NULL;
|
||||
zval *zargs = NULL;
|
||||
zval retval;
|
||||
int i;
|
||||
int ret;
|
||||
int fake_argc;
|
||||
zval **agg_context = NULL;
|
||||
zval *agg_context = NULL;
|
||||
|
||||
if (is_agg) {
|
||||
is_agg = 2;
|
||||
@@ -327,55 +327,51 @@ static int do_callback(struct pdo_sqlite_fci *fc, zval *cb,
|
||||
|
||||
fc->fci.size = sizeof(fc->fci);
|
||||
fc->fci.function_table = EG(function_table);
|
||||
fc->fci.function_name = cb;
|
||||
ZVAL_COPY_VALUE(&fc->fci.function_name, cb);
|
||||
fc->fci.symbol_table = NULL;
|
||||
fc->fci.object_ptr = NULL;
|
||||
fc->fci.retval_ptr_ptr = &retval;
|
||||
fc->fci.object = NULL;
|
||||
fc->fci.retval = &retval;
|
||||
fc->fci.param_count = fake_argc;
|
||||
|
||||
/* build up the params */
|
||||
|
||||
if (fake_argc) {
|
||||
zargs = (zval ***)safe_emalloc(fake_argc, sizeof(zval **), 0);
|
||||
zargs = (zval *)safe_emalloc(fake_argc, sizeof(zval), 0);
|
||||
}
|
||||
|
||||
if (is_agg) {
|
||||
/* summon the aggregation context */
|
||||
agg_context = (zval**)sqlite3_aggregate_context(context, sizeof(zval*));
|
||||
if (!*agg_context) {
|
||||
/* ????
|
||||
agg_context = (zval*)sqlite3_aggregate_context(context, sizeof(zval));
|
||||
if (!agg_context) {
|
||||
MAKE_STD_ZVAL(*agg_context);
|
||||
ZVAL_NULL(*agg_context);
|
||||
}
|
||||
zargs[0] = agg_context;
|
||||
|
||||
zargs[1] = emalloc(sizeof(zval*));
|
||||
MAKE_STD_ZVAL(*zargs[1]);
|
||||
ZVAL_LONG(*zargs[1], sqlite3_aggregate_count(context));
|
||||
*/
|
||||
ZVAL_NULL(&zargs[0]);
|
||||
ZVAL_LONG(&zargs[1], sqlite3_aggregate_count(context));
|
||||
}
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
zargs[i + is_agg] = emalloc(sizeof(zval *));
|
||||
MAKE_STD_ZVAL(*zargs[i + is_agg]);
|
||||
|
||||
/* get the value */
|
||||
switch (sqlite3_value_type(argv[i])) {
|
||||
case SQLITE_INTEGER:
|
||||
ZVAL_LONG(*zargs[i + is_agg], sqlite3_value_int(argv[i]));
|
||||
ZVAL_LONG(&zargs[i + is_agg], sqlite3_value_int(argv[i]));
|
||||
break;
|
||||
|
||||
case SQLITE_FLOAT:
|
||||
ZVAL_DOUBLE(*zargs[i + is_agg], sqlite3_value_double(argv[i]));
|
||||
ZVAL_DOUBLE(&zargs[i + is_agg], sqlite3_value_double(argv[i]));
|
||||
break;
|
||||
|
||||
case SQLITE_NULL:
|
||||
ZVAL_NULL(*zargs[i + is_agg]);
|
||||
ZVAL_NULL(&zargs[i + is_agg]);
|
||||
break;
|
||||
|
||||
case SQLITE_BLOB:
|
||||
case SQLITE3_TEXT:
|
||||
default:
|
||||
ZVAL_STRINGL(*zargs[i + is_agg], (char*)sqlite3_value_text(argv[i]),
|
||||
sqlite3_value_bytes(argv[i]), 1);
|
||||
ZVAL_STRINGL(&zargs[i + is_agg], (char*)sqlite3_value_text(argv[i]), sqlite3_value_bytes(argv[i]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -391,12 +387,10 @@ static int do_callback(struct pdo_sqlite_fci *fc, zval *cb,
|
||||
/* clean up the params */
|
||||
if (zargs) {
|
||||
for (i = is_agg; i < fake_argc; i++) {
|
||||
zval_ptr_dtor(zargs[i]);
|
||||
efree(zargs[i]);
|
||||
zval_ptr_dtor(&zargs[i]);
|
||||
}
|
||||
if (is_agg) {
|
||||
zval_ptr_dtor(zargs[1]);
|
||||
efree(zargs[1]);
|
||||
zval_ptr_dtor(&zargs[1]);
|
||||
}
|
||||
efree(zargs);
|
||||
}
|
||||
@@ -404,10 +398,10 @@ static int do_callback(struct pdo_sqlite_fci *fc, zval *cb,
|
||||
if (!is_agg || !argv) {
|
||||
/* only set the sqlite return value if we are a scalar function,
|
||||
* or if we are finalizing an aggregate */
|
||||
if (retval) {
|
||||
switch (Z_TYPE_P(retval)) {
|
||||
if (!ZVAL_IS_UNDEF(&retval)) {
|
||||
switch (Z_TYPE(retval)) {
|
||||
case IS_LONG:
|
||||
sqlite3_result_int(context, Z_LVAL_P(retval));
|
||||
sqlite3_result_int(context, Z_LVAL(retval));
|
||||
break;
|
||||
|
||||
case IS_NULL:
|
||||
@@ -415,13 +409,12 @@ static int do_callback(struct pdo_sqlite_fci *fc, zval *cb,
|
||||
break;
|
||||
|
||||
case IS_DOUBLE:
|
||||
sqlite3_result_double(context, Z_DVAL_P(retval));
|
||||
sqlite3_result_double(context, Z_DVAL(retval));
|
||||
break;
|
||||
|
||||
default:
|
||||
convert_to_string_ex(&retval);
|
||||
sqlite3_result_text(context, Z_STRVAL_P(retval),
|
||||
Z_STRLEN_P(retval), SQLITE_TRANSIENT);
|
||||
sqlite3_result_text(context, Z_STRVAL(retval), Z_STRLEN(retval), SQLITE_TRANSIENT);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@@ -436,16 +429,16 @@ static int do_callback(struct pdo_sqlite_fci *fc, zval *cb,
|
||||
* the context */
|
||||
if (agg_context) {
|
||||
zval_ptr_dtor(agg_context);
|
||||
}
|
||||
}/* ???
|
||||
if (retval) {
|
||||
*agg_context = retval;
|
||||
retval = NULL;
|
||||
} else {
|
||||
*agg_context = NULL;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
if (retval) {
|
||||
if (!ZVAL_IS_UNDEF(&retval)) {
|
||||
zval_ptr_dtor(&retval);
|
||||
}
|
||||
|
||||
@@ -458,7 +451,7 @@ static void php_sqlite3_func_callback(sqlite3_context *context, int argc,
|
||||
struct pdo_sqlite_func *func = (struct pdo_sqlite_func*)sqlite3_user_data(context);
|
||||
TSRMLS_FETCH();
|
||||
|
||||
do_callback(&func->afunc, func->func, argc, argv, context, 0 TSRMLS_CC);
|
||||
do_callback(&func->afunc, &func->func, argc, argv, context, 0 TSRMLS_CC);
|
||||
}
|
||||
|
||||
static void php_sqlite3_func_step_callback(sqlite3_context *context, int argc,
|
||||
@@ -467,7 +460,7 @@ static void php_sqlite3_func_step_callback(sqlite3_context *context, int argc,
|
||||
struct pdo_sqlite_func *func = (struct pdo_sqlite_func*)sqlite3_user_data(context);
|
||||
TSRMLS_FETCH();
|
||||
|
||||
do_callback(&func->astep, func->step, argc, argv, context, 1 TSRMLS_CC);
|
||||
do_callback(&func->astep, &func->step, argc, argv, context, 1 TSRMLS_CC);
|
||||
}
|
||||
|
||||
static void php_sqlite3_func_final_callback(sqlite3_context *context)
|
||||
@@ -475,7 +468,7 @@ static void php_sqlite3_func_final_callback(sqlite3_context *context)
|
||||
struct pdo_sqlite_func *func = (struct pdo_sqlite_func*)sqlite3_user_data(context);
|
||||
TSRMLS_FETCH();
|
||||
|
||||
do_callback(&func->afini, func->fini, 0, NULL, context, 1 TSRMLS_CC);
|
||||
do_callback(&func->afini, &func->fini, 0, NULL, context, 1 TSRMLS_CC);
|
||||
}
|
||||
|
||||
static int php_sqlite3_collation_callback(void *context,
|
||||
@@ -483,48 +476,41 @@ static int php_sqlite3_collation_callback(void *context,
|
||||
int string2_len, const void *string2)
|
||||
{
|
||||
int ret;
|
||||
zval *zstring1, *zstring2;
|
||||
zval **zargs[2];
|
||||
zval *retval = NULL;
|
||||
zval zargs[2];
|
||||
zval retval;
|
||||
struct pdo_sqlite_collation *collation = (struct pdo_sqlite_collation*) context;
|
||||
TSRMLS_FETCH();
|
||||
|
||||
collation->fc.fci.size = sizeof(collation->fc.fci);
|
||||
collation->fc.fci.function_table = EG(function_table);
|
||||
collation->fc.fci.function_name = collation->callback;
|
||||
ZVAL_COPY_VALUE(&collation->fc.fci.function_name, &collation->callback);
|
||||
collation->fc.fci.symbol_table = NULL;
|
||||
collation->fc.fci.object_ptr = NULL;
|
||||
collation->fc.fci.retval_ptr_ptr = &retval;
|
||||
collation->fc.fci.object = NULL;
|
||||
collation->fc.fci.retval = &retval;
|
||||
|
||||
// Prepare the arguments.
|
||||
MAKE_STD_ZVAL(zstring1);
|
||||
ZVAL_STRINGL(zstring1, (char *) string1, string1_len, 1);
|
||||
zargs[0] = &zstring1;
|
||||
MAKE_STD_ZVAL(zstring2);
|
||||
ZVAL_STRINGL(zstring2, (char *) string2, string2_len, 1);
|
||||
zargs[1] = &zstring2;
|
||||
ZVAL_STRINGL(&zargs[0], (char *) string1, string1_len);
|
||||
ZVAL_STRINGL(&zargs[1], (char *) string2, string2_len);
|
||||
collation->fc.fci.param_count = 2;
|
||||
collation->fc.fci.params = zargs;
|
||||
|
||||
if ((ret = zend_call_function(&collation->fc.fci, &collation->fc.fcc TSRMLS_CC)) == FAILURE) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "An error occurred while invoking the callback");
|
||||
}
|
||||
else if (retval) {
|
||||
if (Z_TYPE_P(retval) != IS_LONG) {
|
||||
} else if (!ZVAL_IS_UNDEF(&retval)) {
|
||||
if (Z_TYPE(retval) != IS_LONG) {
|
||||
convert_to_long_ex(&retval);
|
||||
}
|
||||
ret = 0;
|
||||
if (Z_LVAL_P(retval) > 0) {
|
||||
if (Z_LVAL(retval) > 0) {
|
||||
ret = 1;
|
||||
}
|
||||
else if (Z_LVAL_P(retval) < 0) {
|
||||
} else if (Z_LVAL(retval) < 0) {
|
||||
ret = -1;
|
||||
}
|
||||
zval_ptr_dtor(&retval);
|
||||
}
|
||||
|
||||
zval_ptr_dtor(zargs[0]);
|
||||
zval_ptr_dtor(zargs[1]);
|
||||
zval_ptr_dtor(&zargs[0]);
|
||||
zval_ptr_dtor(&zargs[1]);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -538,7 +524,7 @@ static PHP_METHOD(SQLite, sqliteCreateFunction)
|
||||
char *func_name;
|
||||
int func_name_len;
|
||||
long argc = -1;
|
||||
char *cbname = NULL;
|
||||
zend_string *cbname = NULL;
|
||||
pdo_dbh_t *dbh;
|
||||
pdo_sqlite_db_handle *H;
|
||||
int ret;
|
||||
@@ -548,15 +534,15 @@ static PHP_METHOD(SQLite, sqliteCreateFunction)
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
dbh = zend_object_store_get_object(getThis() TSRMLS_CC);
|
||||
dbh = Z_PDO_DBH_P(getThis() TSRMLS_CC);
|
||||
PDO_CONSTRUCT_CHECK;
|
||||
|
||||
if (!zend_is_callable(callback, 0, &cbname TSRMLS_CC)) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "function '%s' is not callable", cbname);
|
||||
efree(cbname);
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "function '%s' is not callable", cbname->val);
|
||||
STR_RELEASE(cbname);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
efree(cbname);
|
||||
STR_RELEASE(cbname);
|
||||
|
||||
H = (pdo_sqlite_db_handle *)dbh->driver_data;
|
||||
|
||||
@@ -567,8 +553,7 @@ static PHP_METHOD(SQLite, sqliteCreateFunction)
|
||||
if (ret == SQLITE_OK) {
|
||||
func->funcname = estrdup(func_name);
|
||||
|
||||
MAKE_STD_ZVAL(func->func);
|
||||
MAKE_COPY_ZVAL(&callback, func->func);
|
||||
ZVAL_COPY(&func->func, callback);
|
||||
|
||||
func->argc = argc;
|
||||
|
||||
@@ -609,7 +594,7 @@ static PHP_METHOD(SQLite, sqliteCreateAggregate)
|
||||
char *func_name;
|
||||
int func_name_len;
|
||||
long argc = -1;
|
||||
char *cbname = NULL;
|
||||
zend_string *cbname = NULL;
|
||||
pdo_dbh_t *dbh;
|
||||
pdo_sqlite_db_handle *H;
|
||||
int ret;
|
||||
@@ -619,21 +604,21 @@ static PHP_METHOD(SQLite, sqliteCreateAggregate)
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
dbh = zend_object_store_get_object(getThis() TSRMLS_CC);
|
||||
dbh = Z_PDO_DBH_P(getThis() TSRMLS_CC);
|
||||
PDO_CONSTRUCT_CHECK;
|
||||
|
||||
if (!zend_is_callable(step_callback, 0, &cbname TSRMLS_CC)) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "function '%s' is not callable", cbname);
|
||||
efree(cbname);
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "function '%s' is not callable", cbname->val);
|
||||
STR_RELEASE(cbname);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
efree(cbname);
|
||||
STR_RELEASE(cbname);
|
||||
if (!zend_is_callable(fini_callback, 0, &cbname TSRMLS_CC)) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "function '%s' is not callable", cbname);
|
||||
efree(cbname);
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "function '%s' is not callable", cbname->val);
|
||||
STR_RELEASE(cbname);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
efree(cbname);
|
||||
STR_RELEASE(cbname);
|
||||
|
||||
H = (pdo_sqlite_db_handle *)dbh->driver_data;
|
||||
|
||||
@@ -644,11 +629,9 @@ static PHP_METHOD(SQLite, sqliteCreateAggregate)
|
||||
if (ret == SQLITE_OK) {
|
||||
func->funcname = estrdup(func_name);
|
||||
|
||||
MAKE_STD_ZVAL(func->step);
|
||||
MAKE_COPY_ZVAL(&step_callback, func->step);
|
||||
ZVAL_COPY(&func->step, step_callback);
|
||||
|
||||
MAKE_STD_ZVAL(func->fini);
|
||||
MAKE_COPY_ZVAL(&fini_callback, func->fini);
|
||||
ZVAL_COPY(&func->fini, fini_callback);
|
||||
|
||||
func->argc = argc;
|
||||
|
||||
@@ -671,7 +654,7 @@ static PHP_METHOD(SQLite, sqliteCreateCollation)
|
||||
zval *callback;
|
||||
char *collation_name;
|
||||
int collation_name_len;
|
||||
char *cbname = NULL;
|
||||
zend_string *cbname = NULL;
|
||||
pdo_dbh_t *dbh;
|
||||
pdo_sqlite_db_handle *H;
|
||||
int ret;
|
||||
@@ -681,15 +664,15 @@ static PHP_METHOD(SQLite, sqliteCreateCollation)
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
dbh = zend_object_store_get_object(getThis() TSRMLS_CC);
|
||||
dbh = Z_PDO_DBH_P(getThis());
|
||||
PDO_CONSTRUCT_CHECK;
|
||||
|
||||
if (!zend_is_callable(callback, 0, &cbname TSRMLS_CC)) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "function '%s' is not callable", cbname);
|
||||
efree(cbname);
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "function '%s' is not callable", cbname->val);
|
||||
STR_RELEASE(cbname);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
efree(cbname);
|
||||
STR_RELEASE(cbname);
|
||||
|
||||
H = (pdo_sqlite_db_handle *)dbh->driver_data;
|
||||
|
||||
@@ -699,8 +682,7 @@ static PHP_METHOD(SQLite, sqliteCreateCollation)
|
||||
if (ret == SQLITE_OK) {
|
||||
collation->name = estrdup(collation_name);
|
||||
|
||||
MAKE_STD_ZVAL(collation->callback);
|
||||
MAKE_COPY_ZVAL(&callback, collation->callback);
|
||||
ZVAL_COPY(&collation->callback, callback);
|
||||
|
||||
collation->next = H->collations;
|
||||
H->collations = collation;
|
||||
|
||||
@@ -79,6 +79,7 @@ static int pdo_sqlite_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_d
|
||||
enum pdo_param_event event_type TSRMLS_DC)
|
||||
{
|
||||
pdo_sqlite_stmt *S = (pdo_sqlite_stmt*)stmt->driver_data;
|
||||
zval *parameter;
|
||||
|
||||
switch (event_type) {
|
||||
case PDO_PARAM_EVT_EXEC_PRE:
|
||||
@@ -90,7 +91,7 @@ static int pdo_sqlite_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_d
|
||||
if (param->is_param) {
|
||||
|
||||
if (param->paramno == -1) {
|
||||
param->paramno = sqlite3_bind_parameter_index(S->stmt, param->name) - 1;
|
||||
param->paramno = sqlite3_bind_parameter_index(S->stmt, param->name->val) - 1;
|
||||
}
|
||||
|
||||
switch (PDO_PARAM_TYPE(param->param_type)) {
|
||||
@@ -106,18 +107,23 @@ static int pdo_sqlite_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_d
|
||||
|
||||
case PDO_PARAM_INT:
|
||||
case PDO_PARAM_BOOL:
|
||||
if (Z_TYPE_P(param->parameter) == IS_NULL) {
|
||||
if (Z_ISREF(param->parameter)) {
|
||||
parameter = Z_REFVAL(param->parameter);
|
||||
} else {
|
||||
parameter = ¶m->parameter;
|
||||
}
|
||||
if (Z_TYPE_P(parameter) == IS_NULL) {
|
||||
if (sqlite3_bind_null(S->stmt, param->paramno + 1) == SQLITE_OK) {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
convert_to_long(param->parameter);
|
||||
convert_to_long(parameter);
|
||||
#if LONG_MAX > 2147483647
|
||||
if (SQLITE_OK == sqlite3_bind_int64(S->stmt, param->paramno + 1, Z_LVAL_P(param->parameter))) {
|
||||
if (SQLITE_OK == sqlite3_bind_int64(S->stmt, param->paramno + 1, Z_LVAL_P(parameter))) {
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
if (SQLITE_OK == sqlite3_bind_int(S->stmt, param->paramno + 1, Z_LVAL_P(param->parameter))) {
|
||||
if (SQLITE_OK == sqlite3_bind_int(S->stmt, param->paramno + 1, Z_LVAL_P(parameter))) {
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
@@ -126,48 +132,55 @@ static int pdo_sqlite_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_d
|
||||
return 0;
|
||||
|
||||
case PDO_PARAM_LOB:
|
||||
if (Z_TYPE_P(param->parameter) == IS_RESOURCE) {
|
||||
if (Z_ISREF(param->parameter)) {
|
||||
parameter = Z_REFVAL(param->parameter);
|
||||
} else {
|
||||
parameter = ¶m->parameter;
|
||||
}
|
||||
if (Z_TYPE_P(parameter) == IS_RESOURCE) {
|
||||
php_stream *stm;
|
||||
php_stream_from_zval_no_verify(stm, ¶m->parameter);
|
||||
php_stream_from_zval_no_verify(stm, parameter);
|
||||
if (stm) {
|
||||
SEPARATE_ZVAL(¶m->parameter);
|
||||
Z_TYPE_P(param->parameter) = IS_STRING;
|
||||
Z_STRLEN_P(param->parameter) = php_stream_copy_to_mem(stm,
|
||||
&Z_STRVAL_P(param->parameter), PHP_STREAM_COPY_ALL, 0);
|
||||
zval_ptr_dtor(parameter);
|
||||
ZVAL_STR(parameter, php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0));
|
||||
} else {
|
||||
pdo_raise_impl_error(stmt->dbh, stmt, "HY105", "Expected a stream resource" TSRMLS_CC);
|
||||
return 0;
|
||||
}
|
||||
} else if (Z_TYPE_P(param->parameter) == IS_NULL) {
|
||||
} else if (Z_TYPE_P(parameter) == IS_NULL) {
|
||||
if (sqlite3_bind_null(S->stmt, param->paramno + 1) == SQLITE_OK) {
|
||||
return 1;
|
||||
}
|
||||
pdo_sqlite_error_stmt(stmt);
|
||||
return 0;
|
||||
} else {
|
||||
convert_to_string(param->parameter);
|
||||
convert_to_string(parameter);
|
||||
}
|
||||
|
||||
if (SQLITE_OK == sqlite3_bind_blob(S->stmt, param->paramno + 1,
|
||||
Z_STRVAL_P(param->parameter),
|
||||
Z_STRLEN_P(param->parameter),
|
||||
Z_STRVAL_P(parameter),
|
||||
Z_STRLEN_P(parameter),
|
||||
SQLITE_STATIC)) {
|
||||
return 1;
|
||||
}
|
||||
pdo_sqlite_error_stmt(stmt);
|
||||
return 0;
|
||||
|
||||
case PDO_PARAM_STR:
|
||||
default:
|
||||
if (Z_TYPE_P(param->parameter) == IS_NULL) {
|
||||
if (Z_ISREF(param->parameter)) {
|
||||
parameter = Z_REFVAL(param->parameter);
|
||||
} else {
|
||||
parameter = ¶m->parameter;
|
||||
}
|
||||
if (Z_TYPE_P(parameter) == IS_NULL) {
|
||||
if (sqlite3_bind_null(S->stmt, param->paramno + 1) == SQLITE_OK) {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
convert_to_string(param->parameter);
|
||||
if(SQLITE_OK == sqlite3_bind_text(S->stmt, param->paramno + 1,
|
||||
Z_STRVAL_P(param->parameter),
|
||||
Z_STRLEN_P(param->parameter),
|
||||
convert_to_string(parameter);
|
||||
if (SQLITE_OK == sqlite3_bind_text(S->stmt, param->paramno + 1,
|
||||
Z_STRVAL_P(parameter),
|
||||
Z_STRLEN_P(parameter),
|
||||
SQLITE_STATIC)) {
|
||||
return 1;
|
||||
}
|
||||
@@ -279,7 +292,7 @@ static int pdo_sqlite_stmt_col_meta(pdo_stmt_t *stmt, long colno, zval *return_v
|
||||
{
|
||||
pdo_sqlite_stmt *S = (pdo_sqlite_stmt*)stmt->driver_data;
|
||||
const char *str;
|
||||
zval *flags;
|
||||
zval flags;
|
||||
|
||||
if (!S->stmt) {
|
||||
return FAILURE;
|
||||
@@ -291,8 +304,7 @@ static int pdo_sqlite_stmt_col_meta(pdo_stmt_t *stmt, long colno, zval *return_v
|
||||
}
|
||||
|
||||
array_init(return_value);
|
||||
MAKE_STD_ZVAL(flags);
|
||||
array_init(flags);
|
||||
array_init(&flags);
|
||||
|
||||
switch (sqlite3_column_type(S->stmt, colno)) {
|
||||
case SQLITE_NULL:
|
||||
@@ -304,7 +316,7 @@ static int pdo_sqlite_stmt_col_meta(pdo_stmt_t *stmt, long colno, zval *return_v
|
||||
break;
|
||||
|
||||
case SQLITE_BLOB:
|
||||
add_next_index_string(flags, "blob");
|
||||
add_next_index_string(&flags, "blob");
|
||||
case SQLITE_TEXT:
|
||||
add_assoc_string(return_value, "native_type", "string");
|
||||
break;
|
||||
@@ -326,7 +338,7 @@ static int pdo_sqlite_stmt_col_meta(pdo_stmt_t *stmt, long colno, zval *return_v
|
||||
}
|
||||
#endif
|
||||
|
||||
add_assoc_zval(return_value, "flags", flags);
|
||||
add_assoc_zval(return_value, "flags", &flags);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
+17
-16
@@ -1455,48 +1455,49 @@ PHP_METHOD(sqlite3stmt, execute)
|
||||
|
||||
if (stmt_obj->bound_params) {
|
||||
ZEND_HASH_FOREACH_PTR(stmt_obj->bound_params, param) {
|
||||
zval parameter;
|
||||
ZVAL_COPY_VALUE(¶meter, ¶m->parameter);
|
||||
|
||||
if (Z_ISREF_P(¶meter)) {
|
||||
ZVAL_DUP(¶meter, Z_REFVAL(parameter));
|
||||
zval *parameter;
|
||||
/* parameter must be a reference? */
|
||||
if (Z_ISREF(param->parameter)) {
|
||||
parameter = Z_REFVAL(param->parameter);
|
||||
} else {
|
||||
parameter = ¶m->parameter;
|
||||
}
|
||||
|
||||
/* If the ZVAL is null then it should be bound as that */
|
||||
if (Z_TYPE(parameter) == IS_NULL) {
|
||||
if (Z_TYPE_P(parameter) == IS_NULL) {
|
||||
sqlite3_bind_null(stmt_obj->stmt, param->param_number);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (param->type) {
|
||||
case SQLITE_INTEGER:
|
||||
convert_to_long(¶meter);
|
||||
convert_to_long(parameter);
|
||||
#if LONG_MAX > 2147483647
|
||||
sqlite3_bind_int64(stmt_obj->stmt, param->param_number, Z_LVAL(parameter));
|
||||
sqlite3_bind_int64(stmt_obj->stmt, param->param_number, Z_LVAL_P(parameter));
|
||||
#else
|
||||
sqlite3_bind_int(stmt_obj->stmt, param->param_number, Z_LVAL(parameter));
|
||||
sqlite3_bind_int(stmt_obj->stmt, param->param_number, Z_LVAL_P(parameter));
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SQLITE_FLOAT:
|
||||
/* convert_to_double(parameter);*/
|
||||
sqlite3_bind_double(stmt_obj->stmt, param->param_number, Z_DVAL(parameter));
|
||||
sqlite3_bind_double(stmt_obj->stmt, param->param_number, Z_DVAL_P(parameter));
|
||||
break;
|
||||
|
||||
case SQLITE_BLOB:
|
||||
{
|
||||
php_stream *stream = NULL;
|
||||
zend_string *buffer;
|
||||
if (Z_TYPE(parameter) == IS_RESOURCE) {
|
||||
php_stream_from_zval_no_verify(stream, ¶meter);
|
||||
if (Z_TYPE_P(parameter) == IS_RESOURCE) {
|
||||
php_stream_from_zval_no_verify(stream, parameter);
|
||||
if (stream == NULL) {
|
||||
php_sqlite3_error(stmt_obj->db_obj, "Unable to read stream for parameter %ld", param->param_number);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
buffer = php_stream_copy_to_mem(stream, PHP_STREAM_COPY_ALL, 0);
|
||||
} else {
|
||||
convert_to_string(¶meter);
|
||||
buffer = Z_STR(parameter);
|
||||
convert_to_string(parameter);
|
||||
buffer = Z_STR_P(parameter);
|
||||
}
|
||||
|
||||
sqlite3_bind_blob(stmt_obj->stmt, param->param_number, buffer->val, buffer->len, SQLITE_TRANSIENT);
|
||||
@@ -1508,8 +1509,8 @@ PHP_METHOD(sqlite3stmt, execute)
|
||||
}
|
||||
|
||||
case SQLITE3_TEXT:
|
||||
convert_to_string(¶meter);
|
||||
sqlite3_bind_text(stmt_obj->stmt, param->param_number, Z_STRVAL(parameter), Z_STRLEN(parameter), SQLITE_STATIC);
|
||||
convert_to_string(parameter);
|
||||
sqlite3_bind_text(stmt_obj->stmt, param->param_number, Z_STRVAL_P(parameter), Z_STRLEN_P(parameter), SQLITE_STATIC);
|
||||
break;
|
||||
|
||||
case SQLITE_NULL:
|
||||
|
||||
Reference in new issue
Block a user