]> granicus.if.org Git - php/commitdiff
- MFH PDOException base
authorMarcus Boerger <helly@php.net>
Sun, 2 Oct 2005 20:38:18 +0000 (20:38 +0000)
committerMarcus Boerger <helly@php.net>
Sun, 2 Oct 2005 20:38:18 +0000 (20:38 +0000)
ext/pdo/pdo.c
ext/pdo/pdo_dbh.c
ext/pdo/php_pdo.h
ext/pdo/php_pdo_int.h

index 76f1139b7f5ebbbe3644039d8a4c06fe175a860e..76082774c9711e4449818fd3814da607b33de796 100755 (executable)
@@ -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}
 };
 /* }}} */
index 110a0af5b0a607aecec19f1d9235a4771215cd03..c2ed2508c7ce2b8e32bf591658e781d9aae5fa86 100755 (executable)
@@ -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);
 }
 
index 7754dba2b35d70d383c21e33efd7b0e8094d20fa..e4bc15943ff10ff8ae197d82e8cc5d437fbab49e 100755 (executable)
 
 #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
 
index eb399cb812ed2f3c90a5d00508a0344e424ef432..b0b6525412b7a9d9be466c7e4ac726a7a46b2f44 100755 (executable)
@@ -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);