iliaa           Tue Sep 20 15:52:05 2005 EDT

  Modified files:              
    /php-src/ext/pdo    php_pdo.h pdo_dbh.c 
    /php-src/ext/pdo_sqlite     sqlite_driver.c 
  Log:
  Allow overloading of PDO constructor.
  
  
http://cvs.php.net/diff.php/php-src/ext/pdo/php_pdo.h?r1=1.8&r2=1.9&ty=u
Index: php-src/ext/pdo/php_pdo.h
diff -u php-src/ext/pdo/php_pdo.h:1.8 php-src/ext/pdo/php_pdo.h:1.9
--- php-src/ext/pdo/php_pdo.h:1.8       Mon Sep 19 20:33:39 2005
+++ php-src/ext/pdo/php_pdo.h   Tue Sep 20 15:52:03 2005
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: php_pdo.h,v 1.8 2005/09/20 00:33:39 iliaa Exp $ */
+/* $Id: php_pdo.h,v 1.9 2005/09/20 19:52:03 iliaa Exp $ */
 
 #ifndef PHP_PDO_H
 #define PHP_PDO_H
@@ -70,6 +70,13 @@
 #define REGISTER_PDO_CLASS_CONST_STRING(const_name, value) \
        zend_declare_class_constant_stringl(pdo_dbh_ce, const_name, 
sizeof(const_name)-1, value, sizeof(value)-1 TSRMLS_CC);
 
+#define PDO_CONSTRUCT_CHECK    \
+       if (!dbh->driver) {     \
+               pdo_raise_impl_error(dbh, NULL, "00000", "PDO constructor was 
not called" TSRMLS_CC);   \
+               return; \
+       }       \
+
+
 #endif /* PHP_PDO_H */
 
 
http://cvs.php.net/diff.php/php-src/ext/pdo/pdo_dbh.c?r1=1.93&r2=1.94&ty=u
Index: php-src/ext/pdo/pdo_dbh.c
diff -u php-src/ext/pdo/pdo_dbh.c:1.93 php-src/ext/pdo/pdo_dbh.c:1.94
--- php-src/ext/pdo/pdo_dbh.c:1.93      Tue Sep 20 14:46:15 2005
+++ php-src/ext/pdo/pdo_dbh.c   Tue Sep 20 15:52:03 2005
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: pdo_dbh.c,v 1.93 2005/09/20 18:46:15 helly Exp $ */
+/* $Id: pdo_dbh.c,v 1.94 2005/09/20 19:52:03 iliaa Exp $ */
 
 /* The PDO Database Handle Class */
 
@@ -205,7 +205,7 @@
 
 /* {{{ proto object PDO::__construct(string dsn, string username, string 
passwd [, array options])
    */
-static PHP_FUNCTION(dbh_constructor)
+static PHP_METHOD(PDO, dbh_constructor)
 {
        zval *object = getThis();
        pdo_dbh_t *dbh = NULL;
@@ -503,6 +503,7 @@
        }
        
        PDO_DBH_CLEAR_ERR();
+       PDO_CONSTRUCT_CHECK;
 
        if (ZEND_NUM_ARGS() > 1 && SUCCESS == 
zend_hash_index_find(Z_ARRVAL_P(options), PDO_ATTR_STATEMENT_CLASS, 
(void**)&opt)) {
                if (zend_hash_index_find(Z_ARRVAL_PP(opt), 0, (void**)&item) == 
FAILURE
@@ -587,6 +588,8 @@
 {
        pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC);
 
+       PDO_CONSTRUCT_CHECK;
+
        if (dbh->in_txn) {
                zend_throw_exception_ex(php_pdo_get_exception(TSRMLS_C), 0 
TSRMLS_CC, "There is already an active transaction");
                RETURN_FALSE;
@@ -615,6 +618,8 @@
 {
        pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC);
 
+       PDO_CONSTRUCT_CHECK;
+
        if (!dbh->in_txn) {
                zend_throw_exception_ex(php_pdo_get_exception(TSRMLS_C), 0 
TSRMLS_CC, "There is no active transaction");
                RETURN_FALSE;
@@ -636,6 +641,8 @@
 {
        pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC);
 
+       PDO_CONSTRUCT_CHECK;
+
        if (!dbh->in_txn) {
                zend_throw_exception_ex(php_pdo_get_exception(TSRMLS_C), 0 
TSRMLS_CC, "There is no active transaction");
                RETURN_FALSE;
@@ -663,6 +670,8 @@
                RETURN_FALSE;
        }
 
+       PDO_CONSTRUCT_CHECK;
+
        switch (attr) {
                case PDO_ATTR_ERRMODE:
                        convert_to_long(value);
@@ -741,6 +750,7 @@
        }
 
        PDO_DBH_CLEAR_ERR();
+       PDO_CONSTRUCT_CHECK;
 
        /* handle generic PDO-level atributes */
        switch (attr) {
@@ -797,6 +807,7 @@
                RETURN_FALSE;
        }
        PDO_DBH_CLEAR_ERR();
+       PDO_CONSTRUCT_CHECK;
        ret = dbh->methods->doer(dbh, statement, statement_len TSRMLS_CC);
        if(ret == -1) {
                PDO_HANDLE_DBH_ERR();
@@ -821,6 +832,7 @@
        }
 
        PDO_DBH_CLEAR_ERR();
+       PDO_CONSTRUCT_CHECK;
        if (!dbh->methods->last_id) {
                pdo_raise_impl_error(dbh, NULL, "IM001", "driver does not 
support lastInsertId()" TSRMLS_CC);
                RETURN_FALSE;
@@ -845,6 +857,7 @@
        if (ZEND_NUM_ARGS()) {
                RETURN_FALSE;
        }
+       PDO_CONSTRUCT_CHECK;
 
        RETURN_STRING(dbh->error_code, 1);
 }
@@ -859,6 +872,7 @@
        if (ZEND_NUM_ARGS()) {
                RETURN_FALSE;
        }
+       PDO_CONSTRUCT_CHECK;
 
        array_init(return_value);
        add_next_index_string(return_value, dbh->error_code, 1);
@@ -884,6 +898,7 @@
        }
        
        PDO_DBH_CLEAR_ERR();
+       PDO_CONSTRUCT_CHECK;
 
        if (!pdo_stmt_instantiate(dbh, return_value, 
U_CLASS_ENTRY(pdo_dbstmt_ce), NULL TSRMLS_CC)) {
                pdo_raise_impl_error(dbh, NULL, "HY000", "failed to instantiate 
user supplied statement class" TSRMLS_CC);
@@ -953,6 +968,7 @@
        }
        
        PDO_DBH_CLEAR_ERR();
+       PDO_CONSTRUCT_CHECK;
        if (!dbh->methods->quoter) {
                pdo_raise_impl_error(dbh, NULL, "IM001", "driver does not 
support quoting" TSRMLS_CC);
                RETURN_FALSE;
@@ -982,7 +998,7 @@
 /* }}} */
 
 function_entry pdo_dbh_functions[] = {
-       PHP_ME_MAPPING(__construct, dbh_constructor,    NULL)
+       ZEND_MALIAS(PDO, __construct, dbh_constructor,  NULL,                   
ZEND_ACC_PUBLIC)
        PHP_ME(PDO, prepare,            NULL,                                   
ZEND_ACC_PUBLIC)
        PHP_ME(PDO, beginTransaction,NULL,                                      
ZEND_ACC_PUBLIC)
        PHP_ME(PDO, commit,                     NULL,                           
        ZEND_ACC_PUBLIC)
@@ -1120,7 +1136,6 @@
        INIT_CLASS_ENTRY(ce, "PDO", pdo_dbh_functions);
        pdo_dbh_ce = zend_register_internal_class(&ce TSRMLS_CC);
        pdo_dbh_ce->create_object = pdo_dbh_new;
-       pdo_dbh_ce->constructor->common.fn_flags |= ZEND_ACC_FINAL;
 
        memcpy(&pdo_dbh_object_handlers, &std_object_handlers, 
sizeof(zend_object_handlers));
        pdo_dbh_object_handlers.get_method = dbh_method_get;
http://cvs.php.net/diff.php/php-src/ext/pdo_sqlite/sqlite_driver.c?r1=1.23&r2=1.24&ty=u
Index: php-src/ext/pdo_sqlite/sqlite_driver.c
diff -u php-src/ext/pdo_sqlite/sqlite_driver.c:1.23 
php-src/ext/pdo_sqlite/sqlite_driver.c:1.24
--- php-src/ext/pdo_sqlite/sqlite_driver.c:1.23 Sun Sep 11 01:08:49 2005
+++ php-src/ext/pdo_sqlite/sqlite_driver.c      Tue Sep 20 15:52:05 2005
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: sqlite_driver.c,v 1.23 2005/09/11 05:08:49 wez Exp $ */
+/* $Id: sqlite_driver.c,v 1.24 2005/09/20 19:52:05 iliaa Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -472,6 +472,7 @@
        }
        
        dbh = zend_object_store_get_object(getThis() TSRMLS_CC);
+       PDO_CONSTRUCT_CHECK;
 
        if (!zend_is_callable(callback, 0, &cbname)) {
 #ifdef IS_UNICODE
@@ -556,6 +557,7 @@
        }
        
        dbh = zend_object_store_get_object(getThis() TSRMLS_CC);
+       PDO_CONSTRUCT_CHECK;
 
        if (!zend_is_callable(step_callback, 0, &cbname)) {
 #ifdef IS_UNICODE

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to