Commit:    85b66e9e2184eda9f2882684b5e8d7cfe3b348ce
Author:    Christopher Jones <s...@php.net>         Fri, 26 Jul 2013 13:34:45 
-0700
Parents:   fc410f6ecec9b4b096cf44ea1f86354e258da67c
Branches:  master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=85b66e9e2184eda9f2882684b5e8d7cfe3b348ce

Log:
OCI8 extension: Allow Implicit Result Set statement resources to inherit the 
parent's current prefetch count

Changed paths:
  M  ext/oci8/oci8.c
  M  ext/oci8/oci8_interface.c
  M  ext/oci8/oci8_statement.c
  M  ext/oci8/package.xml
  M  ext/oci8/php_oci8_int.h


Diff:
diff --git a/ext/oci8/oci8.c b/ext/oci8/oci8.c
index fe22c6f..cd1b0a0 100644
--- a/ext/oci8/oci8.c
+++ b/ext/oci8/oci8.c
@@ -2685,12 +2685,11 @@ void php_oci_fetch_row (INTERNAL_FUNCTION_PARAMETERS, 
int mode, int expected_arg
                if (invokedstatement->impres_count > 0) {
                        /* Make it so the fetch occurs on the first Implicit 
Result Set */
                        statement = 
php_oci_get_implicit_resultset(invokedstatement TSRMLS_CC);
-                       if (!statement)
+                       if (!statement || php_oci_statement_execute(statement, 
(ub4)OCI_DEFAULT TSRMLS_CC))
                                RETURN_FALSE;
                        invokedstatement->impres_count--;
                        invokedstatement->impres_child_stmt = (struct 
php_oci_statement *)statement;
                        invokedstatement->impres_flag = 
PHP_OCI_IMPRES_HAS_CHILDREN;
-                       php_oci_statement_execute(statement, (ub4)OCI_DEFAULT 
TSRMLS_CC);
                } else {
                        statement = invokedstatement; /* didn't find Implicit 
Result Sets */
                        invokedstatement->impres_flag = 
PHP_OCI_IMPRES_NO_CHILDREN;  /* Don't bother checking again */
@@ -2702,11 +2701,10 @@ void php_oci_fetch_row (INTERNAL_FUNCTION_PARAMETERS, 
int mode, int expected_arg
                if (invokedstatement->impres_count > 0) {
                        /* Check next Implicit Result Set */
                statement = php_oci_get_implicit_resultset(invokedstatement 
TSRMLS_CC);
-                       if (!statement)
+                       if (!statement || php_oci_statement_execute(statement, 
(ub4)OCI_DEFAULT TSRMLS_CC))
                                RETURN_FALSE;
-               invokedstatement->impres_count--;
+                       invokedstatement->impres_count--;
                        invokedstatement->impres_child_stmt = (struct 
php_oci_statement *)statement;
-                       php_oci_statement_execute(statement, (ub4)OCI_DEFAULT 
TSRMLS_CC);
                        if (php_oci_statement_fetch(statement, nrows 
TSRMLS_CC)) {
                                /* End of all fetches */
                    RETURN_FALSE;
diff --git a/ext/oci8/oci8_interface.c b/ext/oci8/oci8_interface.c
index 483ddcf..70ec4b5 100644
--- a/ext/oci8/oci8_interface.c
+++ b/ext/oci8/oci8_interface.c
@@ -1744,7 +1744,12 @@ PHP_FUNCTION(oci_set_prefetch)
 
        PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
 
-       if (php_oci_statement_set_prefetch(statement, size TSRMLS_CC)) {
+       if (size < 0) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of rows to 
be prefetched has to be greater than or equal to 0");
+               return;
+       }
+
+       if (php_oci_statement_set_prefetch(statement, (ub4)size TSRMLS_CC)) {
                RETURN_FALSE;
        }
        RETURN_TRUE;
diff --git a/ext/oci8/oci8_statement.c b/ext/oci8/oci8_statement.c
index 2662623..561abab 100644
--- a/ext/oci8/oci8_statement.c
+++ b/ext/oci8/oci8_statement.c
@@ -107,7 +107,9 @@ php_oci_statement 
*php_oci_statement_create(php_oci_connection *connection, char
        zend_list_addref(statement->connection->id);
 
        if (OCI_G(default_prefetch) >= 0) {
-               php_oci_statement_set_prefetch(statement, 
OCI_G(default_prefetch) TSRMLS_CC);
+               php_oci_statement_set_prefetch(statement, 
(ub4)OCI_G(default_prefetch) TSRMLS_CC);
+       } else {
+               php_oci_statement_set_prefetch(statement, (ub4)100 TSRMLS_CC); 
/* semi-arbitrary, "sensible default" */
        }
        
        PHP_OCI_REGISTER_RESOURCE(statement, le_statement);
@@ -164,9 +166,7 @@ php_oci_statement 
*php_oci_get_implicit_resultset(php_oci_statement *statement T
                zend_list_addref(statement->id);
                zend_list_addref(statement2->connection->id);
 
-               if (OCI_G(default_prefetch) >= 0) {
-                       php_oci_statement_set_prefetch(statement2, 
OCI_G(default_prefetch) TSRMLS_CC);
-               }
+               php_oci_statement_set_prefetch(statement2, 
statement->prefetch_count TSRMLS_CC);
                
                PHP_OCI_REGISTER_RESOURCE(statement2, le_statement);
        
@@ -179,24 +179,22 @@ php_oci_statement 
*php_oci_get_implicit_resultset(php_oci_statement *statement T
 /* }}} */
 
 /* {{{ php_oci_statement_set_prefetch()
- Set prefetch buffer size for the statement (we're assuming that one row is 
~1K sized) */
-int php_oci_statement_set_prefetch(php_oci_statement *statement, long size 
TSRMLS_DC)
+ Set prefetch buffer size for the statement */
+int php_oci_statement_set_prefetch(php_oci_statement *statement, ub4 prefetch  
TSRMLS_DC)
 {
-       ub4 prefetch = size;
-
-       if (size < 0) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of rows to 
be prefetched has to be greater than or equal to 0");
-               return 1;
+       if (prefetch > 20000) {
+               prefetch = 20000;               /* keep it somewhat sane */
        }
-       
+
        PHP_OCI_CALL_RETURN(OCIATTRSET, statement->errcode, OCIAttrSet, 
(statement->stmt, OCI_HTYPE_STMT, &prefetch, 0, OCI_ATTR_PREFETCH_ROWS, 
statement->err));
        
        if (statement->errcode != OCI_SUCCESS) {
                statement->errcode = php_oci_error(statement->err, 
statement->errcode TSRMLS_CC);
                PHP_OCI_HANDLE_ERROR(statement->connection, statement->errcode);
+               statement->prefetch_count = 0;
                return 1;
        }
-
+       statement->prefetch_count = prefetch;
        return 0;
 }
 /* }}} */
diff --git a/ext/oci8/package.xml b/ext/oci8/package.xml
index 44358f0..4dc78d4 100644
--- a/ext/oci8/package.xml
+++ b/ext/oci8/package.xml
@@ -53,7 +53,8 @@ http://pear.php.net/dtd/package-2.0.xsd";>
   </stability>
   <license uri="http://www.php.net/license";>PHP</license>
   <notes> 
-    - Fix --enable-maintainer-zts mode
+    Fixed --enable-maintainer-zts mode
+    Allow Implicit Result Set statement resources to inherit the parent's 
current prefetch count
   </notes>
  <contents>
   <dir name="/">
diff --git a/ext/oci8/php_oci8_int.h b/ext/oci8/php_oci8_int.h
index 98c2368..d1aa1ae 100644
--- a/ext/oci8/php_oci8_int.h
+++ b/ext/oci8/php_oci8_int.h
@@ -210,7 +210,7 @@ typedef struct {
 typedef struct { 
        int                                      id;
        int                                      parent_stmtid;                 
/* parent statement id */
-       struct php_oci_statement *impres_child_stmt; /* child of current 
Implicit Result Set statement handle */
+       struct php_oci_statement *impres_child_stmt;/* child of current 
Implicit Result Set statement handle */
        ub4                  impres_count;          /* count of remaining 
Implicit Result children on parent statement handle */
        php_oci_connection      *connection;                    /* parent 
connection handle */
        sword                            errcode;                               
/* last errcode*/
@@ -227,6 +227,7 @@ typedef struct {
        unsigned                         has_data:1;                    /* 
statement has more data flag */
        unsigned                         has_descr:1;                   /* 
statement has at least one descriptor or cursor column */
        ub2                                      stmttype;                      
        /* statement type */
+       ub4                  prefetch_count;        /* current prefetch count */
 } php_oci_statement;
 /* }}} */
 
@@ -496,7 +497,7 @@ int php_oci_collection_append_string(php_oci_collection 
*collection, char *eleme
 
 php_oci_statement *php_oci_statement_create(php_oci_connection *connection, 
char *query, int query_len TSRMLS_DC);
 php_oci_statement *php_oci_get_implicit_resultset(php_oci_statement *statement 
TSRMLS_DC);
-int php_oci_statement_set_prefetch(php_oci_statement *statement, long size 
TSRMLS_DC);
+int php_oci_statement_set_prefetch(php_oci_statement *statement, ub4 prefetch 
TSRMLS_DC);
 int php_oci_statement_fetch(php_oci_statement *statement, ub4 nrows TSRMLS_DC);
 php_oci_out_column *php_oci_statement_get_column(php_oci_statement *statement, 
long column_index, char *column_name, int column_name_len TSRMLS_DC);
 int php_oci_statement_execute(php_oci_statement *statement, ub4 mode 
TSRMLS_DC);


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

Reply via email to