Browse Source

- MFH PDOException base

PHP-5.1
Marcus Boerger 21 years ago
parent
commit
991a29cfd6
  1. 32
      ext/pdo/pdo.c
  2. 9
      ext/pdo/pdo_dbh.c
  3. 4
      ext/pdo/php_pdo.h
  4. 1
      ext/pdo/php_pdo_int.h

32
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}
};
/* }}} */

9
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);
}

4
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

1
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);

Loading…
Cancel
Save