From 991a29cfd6005006c88c7376766f68f910411ea6 Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Sun, 2 Oct 2005 20:38:18 +0000 Subject: [PATCH] - MFH PDOException base --- ext/pdo/pdo.c | 32 ++++++++++++++++++++++++++++++++ ext/pdo/pdo_dbh.c | 9 ++++++--- ext/pdo/php_pdo.h | 4 ++++ ext/pdo/php_pdo_int.h | 1 + 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/ext/pdo/pdo.c b/ext/pdo/pdo.c index 76f1139b7f..76082774c9 100755 --- a/ext/pdo/pdo.c +++ b/ext/pdo/pdo.c @@ -60,10 +60,42 @@ PDO_API zend_class_entry *php_pdo_get_exception(void) return pdo_exception_ce; } +PDO_API zend_class_entry *php_pdo_get_exception_base(int root TSRMLS_DC) +{ +#if can_handle_soft_dependency_on_SPL && defined(HAVE_SPL) && ((PHP_MAJOR_VERSION > 5) || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1)) + if (!root) { + return spl_ce_RuntimeException; + } +#endif +#if (PHP_MAJOR_VERSION < 6) + return zend_exception_get_default(); +#else + return zend_exception_get_default(TSRMLS_C); +#endif +} + zend_class_entry *pdo_dbh_ce, *pdo_dbstmt_ce, *pdo_row_ce; +/* proto array pdo_drivers() + Return array of available PDO drivers */ +PHP_FUNCTION(pdo_drivers) +{ + HashPosition pos; + pdo_driver_t **pdriver; + + array_init(return_value); + + zend_hash_internal_pointer_reset_ex(&pdo_driver_hash, &pos); + while (SUCCESS == zend_hash_get_current_data_ex(&pdo_driver_hash, (void**)&pdriver, &pos)) { + add_next_index_stringl(return_value, (char*)(*pdriver)->driver_name, (*pdriver)->driver_name_len, 1); + zend_hash_move_forward_ex(&pdo_driver_hash, &pos); + } +} +/* }}} */ + /* {{{ pdo_functions[] */ function_entry pdo_functions[] = { + PHP_FE(pdo_drivers, NULL) {NULL, NULL, NULL} }; /* }}} */ diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 110a0af5b0..c2ed2508c7 100755 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -84,7 +84,7 @@ void pdo_raise_impl_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *sqlstate } } else { zval *ex; - zend_class_entry *def_ex = zend_exception_get_default(), *pdo_ex = php_pdo_get_exception(); + zend_class_entry *def_ex = php_pdo_get_exception_base(1 TSRMLS_CC), *pdo_ex = php_pdo_get_exception(); MAKE_STD_ZVAL(ex); object_init_ex(ex, pdo_ex); @@ -165,7 +165,7 @@ void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt TSRMLS_DC) } } else if (EG(exception) == NULL) { zval *ex; - zend_class_entry *def_ex = zend_exception_get_default(), *pdo_ex = php_pdo_get_exception(); + zend_class_entry *def_ex = php_pdo_get_exception_base(1 TSRMLS_CC), *pdo_ex = php_pdo_get_exception(); MAKE_STD_ZVAL(ex); object_init_ex(ex, pdo_ex); @@ -1074,7 +1074,6 @@ static PHP_METHOD(PDO, getAvailableDrivers) } /* }}} */ - function_entry pdo_dbh_functions[] = { ZEND_MALIAS(PDO, __construct, dbh_constructor, NULL, ZEND_ACC_PUBLIC) PHP_ME(PDO, prepare, NULL, ZEND_ACC_PUBLIC) @@ -1348,6 +1347,10 @@ static void dbh_free(pdo_dbh_t *dbh TSRMLS_DC) pefree(dbh->password, dbh->is_persistent); } + if (dbh->def_stmt_ctor_args) { + zval_ptr_dtor(&dbh->def_stmt_ctor_args); + } + pefree(dbh, dbh->is_persistent); } diff --git a/ext/pdo/php_pdo.h b/ext/pdo/php_pdo.h index 7754dba2b3..e4bc15943f 100755 --- a/ext/pdo/php_pdo.h +++ b/ext/pdo/php_pdo.h @@ -23,6 +23,10 @@ #include "zend.h" +#if PHP_MAJOR_VERSION > 5 || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1) +#define can_handle_soft_dependency_on_SPL 1 +#endif + extern zend_module_entry pdo_module_entry; #define phpext_pdo_ptr &pdo_module_entry diff --git a/ext/pdo/php_pdo_int.h b/ext/pdo/php_pdo_int.h index eb399cb812..b0b6525412 100755 --- a/ext/pdo/php_pdo_int.h +++ b/ext/pdo/php_pdo_int.h @@ -25,6 +25,7 @@ extern HashTable pdo_driver_hash; extern zend_class_entry *pdo_exception_ce; +PDO_API zend_class_entry *php_pdo_get_exception_base(int root TSRMLS_DC); int php_pdo_list_entry(void); void pdo_dbh_init(TSRMLS_D); -- 2.40.0