[PHP-CVS] cvs: php-src(PHP_5_1) /ext/pdo pdo_dbh.c php_pdo_driver.h
wez Mon Nov 28 00:23:23 2005 EDT Modified files: (Branch: PHP_5_1) /php-src/ext/pdopdo_dbh.c php_pdo_driver.h Log: API for connection dependent objects to add/del refs to dbh's. http://cvs.php.net/diff.php/php-src/ext/pdo/pdo_dbh.c?r1=1.82.2.18r2=1.82.2.19ty=u Index: php-src/ext/pdo/pdo_dbh.c diff -u php-src/ext/pdo/pdo_dbh.c:1.82.2.18 php-src/ext/pdo/pdo_dbh.c:1.82.2.19 --- php-src/ext/pdo/pdo_dbh.c:1.82.2.18 Thu Nov 24 19:20:12 2005 +++ php-src/ext/pdo/pdo_dbh.c Mon Nov 28 00:23:21 2005 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: pdo_dbh.c,v 1.82.2.18 2005/11/25 00:20:12 wez Exp $ */ +/* $Id: pdo_dbh.c,v 1.82.2.19 2005/11/28 05:23:21 wez Exp $ */ /* The PDO Database Handle Class */ @@ -1371,6 +1371,16 @@ pefree(dbh, dbh-is_persistent); } +PDO_API void php_pdo_dbh_addref(pdo_dbh_t *dbh TSRMLS_DC) +{ + dbh-refcount++; +} + +PDO_API void php_pdo_dbh_delref(pdo_dbh_t *dbh TSRMLS_DC) +{ + dbh_free(dbh TSRMLS_CC); +} + static void pdo_dbh_free_storage(pdo_dbh_t *dbh TSRMLS_DC) { if (dbh-in_txn dbh-methods dbh-methods-rollback) { http://cvs.php.net/diff.php/php-src/ext/pdo/php_pdo_driver.h?r1=1.66.2.6r2=1.66.2.7ty=u Index: php-src/ext/pdo/php_pdo_driver.h diff -u php-src/ext/pdo/php_pdo_driver.h:1.66.2.6 php-src/ext/pdo/php_pdo_driver.h:1.66.2.7 --- php-src/ext/pdo/php_pdo_driver.h:1.66.2.6 Sun Oct 30 21:07:37 2005 +++ php-src/ext/pdo/php_pdo_driver.hMon Nov 28 00:23:22 2005 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: php_pdo_driver.h,v 1.66.2.6 2005/10/31 02:07:37 wez Exp $ */ +/* $Id: php_pdo_driver.h,v 1.66.2.7 2005/11/28 05:23:22 wez Exp $ */ #ifndef PHP_PDO_DRIVER_H #define PHP_PDO_DRIVER_H @@ -44,7 +44,7 @@ # define FALSE 0 #endif -#define PDO_DRIVER_API 20051031 +#define PDO_DRIVER_API 20051128 enum pdo_param_type { PDO_PARAM_NULL, @@ -645,6 +645,9 @@ PDO_API void pdo_raise_impl_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *sqlstate, const char *supp TSRMLS_DC); +PDO_API void php_pdo_dbh_addref(pdo_dbh_t *dbh TSRMLS_DC); +PDO_API void php_pdo_dbh_delref(pdo_dbh_t *dbh TSRMLS_DC); + PDO_API void php_pdo_stmt_addref(pdo_stmt_t *stmt TSRMLS_DC); PDO_API void php_pdo_stmt_delref(pdo_stmt_t *stmt TSRMLS_DC); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src(PHP_5_1) /ext/pdo pdo_dbh.c php_pdo_driver.h /ext/pdo/tests pdo_030.phpt
helly Sun Oct 2 16:07:11 2005 EDT Added files: (Branch: PHP_5_1) /php-src/ext/pdo/tests pdo_030.phpt Modified files: /php-src/ext/pdopdo_dbh.c php_pdo_driver.h Log: - Add PDO::setAttribute(PDO::ATTR_STATEMENT_CLASS) http://cvs.php.net/diff.php/php-src/ext/pdo/pdo_dbh.c?r1=1.82.2.5r2=1.82.2.6ty=u Index: php-src/ext/pdo/pdo_dbh.c diff -u php-src/ext/pdo/pdo_dbh.c:1.82.2.5 php-src/ext/pdo/pdo_dbh.c:1.82.2.6 --- php-src/ext/pdo/pdo_dbh.c:1.82.2.5 Fri Sep 30 22:48:11 2005 +++ php-src/ext/pdo/pdo_dbh.c Sun Oct 2 16:07:11 2005 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: pdo_dbh.c,v 1.82.2.5 2005/10/01 02:48:11 wez Exp $ */ +/* $Id: pdo_dbh.c,v 1.82.2.6 2005/10/02 20:07:11 helly Exp $ */ /* The PDO Database Handle Class */ @@ -539,8 +539,8 @@ ctor_args = NULL; } } else { - dbstmt_ce = pdo_dbstmt_ce; - ctor_args = NULL; + dbstmt_ce = dbh-def_stmt_ce; + ctor_args = dbh-def_stmt_ctor_args; } if (!pdo_stmt_instantiate(dbh, return_value, dbstmt_ce, ctor_args TSRMLS_CC)) { @@ -708,6 +708,62 @@ dbh-stringify = Z_LVAL_P(value) ? 1 : 0; RETURN_TRUE; + case PDO_ATTR_STATEMENT_CLASS: { + /* array(string classname, array(mixed ctor_args)) */ + zend_class_entry **pce; + zval **item; + + if (dbh-is_persistent) { + pdo_raise_impl_error(dbh, NULL, HY000, + PDO_ATTR_STATEMENT_CLASS cannot be used with persistent PDO instances + TSRMLS_CC); + PDO_HANDLE_DBH_ERR(); + RETURN_FALSE; + } + if (Z_TYPE_P(value) != IS_ARRAY + || zend_hash_index_find(Z_ARRVAL_P(value), 0, (void**)item) == FAILURE + || Z_TYPE_PP(item) != IS_STRING + || zend_lookup_class(Z_STRVAL_PP(item), Z_STRLEN_PP(item), pce TSRMLS_CC) == FAILURE + ) { + pdo_raise_impl_error(dbh, NULL, HY000, + PDO_ATTR_STATEMENT_CLASS requires format array(classname, array(ctor_args)); + the classname must be a string specifying an existing class + TSRMLS_CC); + PDO_HANDLE_DBH_ERR(); + RETURN_FALSE; + } + if (!instanceof_function(*pce, pdo_dbstmt_ce TSRMLS_CC)) { + pdo_raise_impl_error(dbh, NULL, HY000, + user-supplied statement class must be derived from PDOStatement TSRMLS_CC); + PDO_HANDLE_DBH_ERR(); + RETURN_FALSE; + } + if ((*pce)-constructor !((*pce)-constructor-common.fn_flags (ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED))) { + pdo_raise_impl_error(dbh, NULL, HY000, + user-supplied statement class cannot have a public constructor TSRMLS_CC); + PDO_HANDLE_DBH_ERR(); + RETURN_FALSE; + } + dbh-def_stmt_ce = *pce; + if (dbh-def_stmt_ctor_args) { + zval_ptr_dtor(dbh-def_stmt_ctor_args); + dbh-def_stmt_ctor_args = NULL; + } + if (zend_hash_index_find(Z_ARRVAL_P(value), 1, (void**)item) == SUCCESS) { + if (Z_TYPE_PP(item) != IS_ARRAY) { + pdo_raise_impl_error(dbh, NULL, HY000, + PDO_ATTR_STATEMENT_CLASS requires format array(classname, array(ctor_args)); + ctor_args must be an array + TSRMLS_CC); + PDO_HANDLE_DBH_ERR(); + RETURN_FALSE; + } + (*item)-refcount++; + dbh-def_stmt_ctor_args = *item; + } + RETURN_TRUE; + } + default: ; } @@ -763,6 +819,15 @@ case PDO_ATTR_DRIVER_NAME:
[PHP-CVS] cvs: php-src(PHP_5_1) /ext/pdo pdo_dbh.c php_pdo_driver.h php_pdo_int.h /ext/pdo/tests bug_34687.phpt
wez Sun Oct 2 18:11:19 2005 EDT Added files: (Branch: PHP_5_1) /php-src/ext/pdo/tests bug_34687.phpt Modified files: /php-src/ext/pdopdo_dbh.c php_pdo_driver.h php_pdo_int.h Log: Fix Bug #34687; error information from query() not passed back http://cvs.php.net/diff.php/php-src/ext/pdo/pdo_dbh.c?r1=1.82.2.7r2=1.82.2.8ty=u Index: php-src/ext/pdo/pdo_dbh.c diff -u php-src/ext/pdo/pdo_dbh.c:1.82.2.7 php-src/ext/pdo/pdo_dbh.c:1.82.2.8 --- php-src/ext/pdo/pdo_dbh.c:1.82.2.7 Sun Oct 2 16:38:18 2005 +++ php-src/ext/pdo/pdo_dbh.c Sun Oct 2 18:11:17 2005 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: pdo_dbh.c,v 1.82.2.7 2005/10/02 20:38:18 helly Exp $ */ +/* $Id: pdo_dbh.c,v 1.82.2.8 2005/10/02 22:11:17 wez Exp $ */ /* The PDO Database Handle Class */ @@ -919,6 +919,10 @@ } PDO_CONSTRUCT_CHECK; + if (dbh-query_stmt) { + RETURN_STRING(dbh-query_stmt-error_code, 1); + } + RETURN_STRING(dbh-error_code, 1); } /* }}} */ @@ -935,10 +939,14 @@ PDO_CONSTRUCT_CHECK; array_init(return_value); - add_next_index_string(return_value, dbh-error_code, 1); + if (dbh-query_stmt) { + add_next_index_string(return_value, dbh-query_stmt-error_code, 1); + } else { + add_next_index_string(return_value, dbh-error_code, 1); + } if (dbh-methods-fetch_err) { - dbh-methods-fetch_err(dbh, NULL, return_value TSRMLS_CC); + dbh-methods-fetch_err(dbh, dbh-query_stmt, return_value TSRMLS_CC); } } /* }}} */ @@ -981,8 +989,6 @@ if (dbh-methods-preparer(dbh, statement, statement_len, stmt, NULL TSRMLS_CC)) { if (ZEND_NUM_ARGS() == 1 || SUCCESS == pdo_stmt_setup_fetch_mode(INTERNAL_FUNCTION_PARAM_PASSTHRU, stmt, 1)) { - PDO_STMT_CLEAR_ERR(); - /* now execute the statement */ PDO_STMT_CLEAR_ERR(); if (stmt-methods-executer(stmt TSRMLS_CC)) { @@ -1000,13 +1006,14 @@ } } /* something broke */ + dbh-query_stmt = stmt; + dbh-query_stmt_zval = *return_value; + PDO_HANDLE_STMT_ERR(); + } else { + PDO_HANDLE_DBH_ERR(); + zval_dtor(return_value); } - PDO_HANDLE_STMT_ERR(); - - /* kill the object handle for the stmt here */ - zval_dtor(return_value); - RETURN_FALSE; } /* }}} */ http://cvs.php.net/diff.php/php-src/ext/pdo/php_pdo_driver.h?r1=1.66.2.2r2=1.66.2.3ty=u Index: php-src/ext/pdo/php_pdo_driver.h diff -u php-src/ext/pdo/php_pdo_driver.h:1.66.2.2 php-src/ext/pdo/php_pdo_driver.h:1.66.2.3 --- php-src/ext/pdo/php_pdo_driver.h:1.66.2.2 Sun Oct 2 16:07:11 2005 +++ php-src/ext/pdo/php_pdo_driver.hSun Oct 2 18:11:17 2005 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: php_pdo_driver.h,v 1.66.2.2 2005/10/02 20:07:11 helly Exp $ */ +/* $Id: php_pdo_driver.h,v 1.66.2.3 2005/10/02 22:11:17 wez Exp $ */ #ifndef PHP_PDO_DRIVER_H #define PHP_PDO_DRIVER_H @@ -44,7 +44,7 @@ # define FALSE 0 #endif -#define PDO_DRIVER_API 20050711 +#define PDO_DRIVER_API 20051002 enum pdo_param_type { PDO_PARAM_NULL, @@ -477,8 +477,14 @@ pdo_driver_t *driver; zend_class_entry *def_stmt_ce; - zval *def_stmt_ctor_args; + + /* when calling PDO::query(), we need to keep the error +* context from the statement around until we next clear it. +* This will allow us to report the correct error message +* when PDO::query() fails */ + pdo_stmt_t *query_stmt; + zval query_stmt_zval; }; /* describes a column */ http://cvs.php.net/diff.php/php-src/ext/pdo/php_pdo_int.h?r1=1.17.2.3r2=1.17.2.4ty=u Index: php-src/ext/pdo/php_pdo_int.h diff -u php-src/ext/pdo/php_pdo_int.h:1.17.2.3 php-src/ext/pdo/php_pdo_int.h:1.17.2.4 --- php-src/ext/pdo/php_pdo_int.h:1.17.2.3 Sun Oct 2 16:38:18 2005 +++ php-src/ext/pdo/php_pdo_int.h Sun Oct 2 18:11:17 2005 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: php_pdo_int.h,v 1.17.2.3 2005/10/02 20:38:18 helly Exp $ */ +/* $Id: php_pdo_int.h,v 1.17.2.4 2005/10/02 22:11:17 wez Exp $ */ /* Stuff private to the PDO extension and not for consumption by PDO drivers * */ @@ -57,7 +57,13 @@ extern void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt TSRMLS_DC); -#define PDO_DBH_CLEAR_ERR()strcpy(dbh-error_code, PDO_ERR_NONE) +#define PDO_DBH_CLEAR_ERR()do { \ + strcpy(dbh-error_code, PDO_ERR_NONE); \ + if (dbh-query_stmt) { \ + dbh-query_stmt = NULL; \