]> granicus.if.org Git - php/commitdiff
Some definitions for cursors.
authorWez Furlong <wez@php.net>
Tue, 25 May 2004 17:43:24 +0000 (17:43 +0000)
committerWez Furlong <wez@php.net>
Tue, 25 May 2004 17:43:24 +0000 (17:43 +0000)
Define a mechanism for driver-specific attributes.
Use a refcount for the stmt structure.

ext/pdo/pdo.c
ext/pdo/pdo_dbh.c
ext/pdo/pdo_stmt.c
ext/pdo/php_pdo_driver.h

index 28b4d2c5c91a561fdfe18ba4752e0dd31a1694f7..580ee5a755ad0af2a5c68df595d22b58516a9b0f 100755 (executable)
@@ -226,6 +226,8 @@ PHP_MINIT_FUNCTION(pdo)
        REGISTER_LONG_CONSTANT("PDO_ATTR_SERVER_INFO",          (long)PDO_ATTR_SERVER_INFO,     CONST_CS|CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("PDO_ATTR_CONNECTION_STATUS",    (long)PDO_ATTR_CONNECTION_STATUS,               CONST_CS|CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("PDO_ATTR_CASE",                 (long)PDO_ATTR_CASE,            CONST_CS|CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("PDO_ATTR_CURSOR_NAME",  (long)PDO_ATTR_CURSOR_NAME,             CONST_CS|CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("PDO_ATTR_CURSOR",               (long)PDO_ATTR_CURSOR,          CONST_CS|CONST_PERSISTENT);
        
        REGISTER_LONG_CONSTANT("PDO_ERRMODE_SILENT",    (long)PDO_ERRMODE_SILENT,               CONST_CS|CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("PDO_ERRMODE_WARNING",   (long)PDO_ERRMODE_WARNING,              CONST_CS|CONST_PERSISTENT);
index 62a6357e48b20b0cefdcf9dcbca67a4db117e279..6e5e632c6bee1df6f2d4befda962428798c8ab97 100755 (executable)
@@ -183,11 +183,7 @@ static PHP_FUNCTION(dbh_constructor)
        dbh->username = username ? pestrdup(username, is_persistent) : NULL;
        dbh->password = password ? pestrdup(password, is_persistent) : NULL;
 
-       if (driver_options) {
-               dbh->auto_commit = pdo_attr_lval(driver_options, PDO_ATTR_AUTOCOMMIT, 1 TSRMLS_CC);
-       } else {
-               dbh->auto_commit = 1;
-       }
+       dbh->auto_commit = pdo_attr_lval(driver_options, PDO_ATTR_AUTOCOMMIT, 1 TSRMLS_CC);
        
        if (driver->db_handle_factory(dbh, driver_options TSRMLS_CC)) {
                /* all set */
@@ -246,6 +242,8 @@ static PHP_METHOD(PDO, prepare)
 
                /* we haven't created a lazy object yet */
                ZVAL_NULL(&stmt->lazy_object_ref);
+
+               stmt->refcount = 1;
                return;
        }
        efree(stmt);
index a1fa9bf2bee5b8ee69f9eee084d8f594672864f6..2f0cf60e0519d1f759dba25f1fd266f2ddec3b7f 100755 (executable)
@@ -169,6 +169,7 @@ static void get_lazy_object(pdo_stmt_t *stmt, zval *return_value TSRMLS_DC)
                Z_TYPE(stmt->lazy_object_ref) = IS_OBJECT;
                Z_OBJ_HANDLE(stmt->lazy_object_ref) = zend_objects_store_put(stmt, NULL, pdo_row_free_storage, NULL TSRMLS_CC);
                Z_OBJ_HT(stmt->lazy_object_ref) = &pdo_row_object_handlers;
+               stmt->refcount++;
        }
        Z_TYPE_P(return_value) = IS_OBJECT;
        Z_OBJ_HANDLE_P(return_value) = Z_OBJ_HANDLE(stmt->lazy_object_ref);
@@ -788,10 +789,8 @@ zend_object_handlers pdo_dbstmt_object_handlers = {
        NULL
 };
 
-void pdo_dbstmt_free_storage(zend_object *object TSRMLS_DC)
+static void free_statement(pdo_stmt_t *stmt TSRMLS_DC)
 {
-       pdo_stmt_t *stmt = (pdo_stmt_t*)object;
-
        if (stmt->methods && stmt->methods->dtor) {
                stmt->methods->dtor(stmt TSRMLS_CC);
        }
@@ -821,14 +820,18 @@ void pdo_dbstmt_free_storage(zend_object *object TSRMLS_DC)
        }
        
        zend_objects_store_del_ref(&stmt->database_object_handle TSRMLS_CC);
-/* XXX: Does not appear to be needed and causes problems according to valgrind
-       if (&stmt->lazy_object_ref) {
-               zend_objects_store_del_ref(&stmt->lazy_object_ref TSRMLS_CC);
-       }
-*/
        efree(stmt);
 }
 
+void pdo_dbstmt_free_storage(zend_object *object TSRMLS_DC)
+{
+       pdo_stmt_t *stmt = (pdo_stmt_t*)object;
+
+       if (--stmt->refcount == 0) {
+               free_statement(stmt TSRMLS_CC);
+       }
+}
+
 zend_object_value pdo_dbstmt_new(zend_class_entry *ce TSRMLS_DC)
 {
        zend_object_value retval;
@@ -1010,7 +1013,11 @@ void pdo_row_free_storage(zend_object *object TSRMLS_DC)
 {
        pdo_stmt_t *stmt = (pdo_stmt_t*)object;
 
-       /* nothing to do here */
+       ZVAL_NULL(&stmt->lazy_object_ref);
+       
+       if (--stmt->refcount == 0) {
+               free_statement(stmt TSRMLS_CC);
+       }
 }
 
 zend_object_value pdo_row_new(zend_class_entry *ce TSRMLS_DC)
index 058bee253a7e43ff23ddda8f976e4814cb95629e..58327804a6eae48f56dc57b0ebfc6d5c0e97bb72 100755 (executable)
@@ -65,6 +65,18 @@ enum pdo_attribute_type {
        PDO_ATTR_SERVER_INFO,           /* server information */
        PDO_ATTR_CONNECTION_STATUS,     /* connection status */
        PDO_ATTR_CASE,                          /* control case folding for portability */
+       PDO_ATTR_CURSOR_NAME,           /* name a cursor for use in "WHERE CURRENT OF <name>" */
+       PDO_ATTR_CURSOR,                        /* cursor type */
+
+       /* this defines the start of the range for driver specific options.
+        * Drivers should define their own attribute constants beginning with this
+        * value. */
+       PDO_ATTR_DRIVER_SPECIFIC = 1000
+};
+
+enum pdo_cursor_type {
+       PDO_CURSOR_FWDONLY,             /* forward only cursor (default) */
+       PDO_CURSOR_SCROLL,              /* scrollable cursor */
 };
 
 /* generic error code values.
@@ -100,7 +112,7 @@ static inline long pdo_attr_lval(zval *options, enum pdo_fetch_type option_name,
 {
        zval **v;
 
-       if (SUCCESS == zend_hash_index_find(Z_ARRVAL_P(options), option_name, (void**)&v)) {
+       if (options && SUCCESS == zend_hash_index_find(Z_ARRVAL_P(options), option_name, (void**)&v)) {
                convert_to_long_ex(v);
                return Z_LVAL_PP(v);
        }
@@ -356,6 +368,7 @@ struct _pdo_stmt_t {
        /* for lazy fetches, we always return the same lazy object handle.
         * Let's keep it here. */
        zval lazy_object_ref;
+       unsigned long refcount;
 };
 
 /* call this in MINIT to register your PDO driver */