]> granicus.if.org Git - php/commitdiff
- Fix PDOException base
authorMarcus Boerger <helly@php.net>
Sun, 2 Oct 2005 20:32:17 +0000 (20:32 +0000)
committerMarcus Boerger <helly@php.net>
Sun, 2 Oct 2005 20:32:17 +0000 (20:32 +0000)
- MFH PDO::getAvailableDrivers()
- Fix compiler warnings

ext/pdo/pdo.c
ext/pdo/pdo_dbh.c
ext/pdo/php_pdo.h
ext/pdo/php_pdo_int.h

index c965c87141c7982b91352f5ce52960dd2144b50c..eb541dfdc4032ba5f3c34a5a47cdabc844df6e88 100755 (executable)
@@ -42,7 +42,7 @@ ZEND_DECLARE_MODULE_GLOBALS(pdo)
 /* True global resources - no need for thread safety here */
 
 /* the registry of PDO drivers */
-static HashTable pdo_driver_hash;
+HashTable pdo_driver_hash;
 
 /* we use persistent resources for the driver connection stuff */
 static int le_ppdo;
@@ -317,7 +317,11 @@ PHP_MINIT_FUNCTION(pdo)
                "PDO persistent database", module_number);
 
        INIT_CLASS_ENTRY(ce, "PDOException", NULL);
-       pdo_exception_ce = zend_register_internal_class_ex(&ce, php_pdo_get_exception_base(0 TSRMLS_CC), NULL TSRMLS_CC);
+#if can_handle_soft_dependency_on_SPL && defined(HAVE_SPL) && ((PHP_MAJOR_VERSION > 5) || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1))
+       pdo_exception_ce = zend_register_internal_class_ex(&ce, spl_ce_RuntimeException, NULL TSRMLS_CC);
+#else
+       pdo_exception_ce = zend_register_internal_class_ex(&ce, zend_exception_get_default(TSRMLS_C), NULL TSRMLS_CC);
+#endif
        zend_declare_property_null(pdo_exception_ce, "errorInfo", sizeof("errorInfo")-1, ZEND_ACC_PUBLIC TSRMLS_CC);
 
        pdo_dbh_init(TSRMLS_C);
index a066241aa01c916b44c39aef7dd893ef69dc65a6..d0a09533940ba711ce511293d73b9738e1c971c9 100755 (executable)
@@ -823,7 +823,7 @@ static PHP_METHOD(PDO, getAttribute)
                        RETURN_LONG(dbh->error_mode);
 
                case PDO_ATTR_DRIVER_NAME:
-                       RETURN_STRINGL(dbh->driver->driver_name, dbh->driver->driver_name_len, 1);
+                       RETURN_STRINGL((char*)dbh->driver->driver_name, dbh->driver->driver_name_len, 1);
 
                case PDO_ATTR_STATEMENT_CLASS:
                        array_init(return_value);
@@ -1062,6 +1062,23 @@ static PHP_METHOD(PDO, __sleep)
 }
 /* }}} */
 
+/* {{{ proto array pdo_drivers()
+   Return array of available PDO drivers */
+static PHP_METHOD(PDO, getAvailableDrivers)
+{
+       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);
+       }
+}
+/* }}} */
+
 function_entry pdo_dbh_functions[] = {
        ZEND_MALIAS(PDO, __construct, dbh_constructor,  NULL,                   ZEND_ACC_PUBLIC)
        PHP_ME(PDO, prepare,            NULL,                                   ZEND_ACC_PUBLIC)
@@ -1075,9 +1092,10 @@ function_entry pdo_dbh_functions[] = {
        PHP_ME(PDO, errorCode,          NULL,                                   ZEND_ACC_PUBLIC)
        PHP_ME(PDO, errorInfo,          NULL,                                   ZEND_ACC_PUBLIC)
        PHP_ME(PDO, getAttribute,       NULL,                                   ZEND_ACC_PUBLIC)
+       PHP_ME(PDO, quote,                      NULL,                                   ZEND_ACC_PUBLIC)
        PHP_ME(PDO, __wakeup,           NULL,                                   ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
        PHP_ME(PDO, __sleep,            NULL,                                   ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
-       PHP_ME(PDO, quote,                      NULL,                                   ZEND_ACC_PUBLIC)
+       PHP_ME(PDO, getAvailableDrivers, NULL,                          ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
        {NULL, NULL, NULL}
 };
 
index c4b9c94c68177a730c1c02d115f7769ead35e8df..7f9b85ceb2f4ea9f7ba2a913d8598a9cc83fc073 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
+#endif
+
 extern zend_module_entry pdo_module_entry;
 #define phpext_pdo_ptr &pdo_module_entry
 
index 3f35c99603f7e13457dd5fcac12bead35d1a3844..6bca408d542219afad00b2825df21c17e82cc413 100755 (executable)
@@ -24,6 +24,8 @@
 
 /* Stuff private to the PDO extension and not for consumption by PDO drivers
  * */
+
+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);