]> granicus.if.org Git - php/commitdiff
Add support for scrollable cursors.
authorWez Furlong <wez@php.net>
Wed, 12 Jan 2005 05:47:03 +0000 (05:47 +0000)
committerWez Furlong <wez@php.net>
Wed, 12 Jan 2005 05:47:03 +0000 (05:47 +0000)
Enable PDO_ATTR_PREFETCH and default it to 100Kb of prefetch buffer.

ext/pdo_oci/config.m4
ext/pdo_oci/config.w32
ext/pdo_oci/oci_driver.c
ext/pdo_oci/oci_statement.c
ext/pdo_oci/pdo_oci.c
ext/pdo_oci/php_pdo_oci.h
ext/pdo_oci/php_pdo_oci_int.h

index 7b31a953fc0553a19a30fbab04a744c08a99d1b0..40f8df4ea1a8870bf53353a6260eefeedc30e6e2 100755 (executable)
@@ -131,7 +131,13 @@ if test "$PHP_PDO_OCI" != "no"; then
     -L$PDO_OCI_DIR/lib $PDO_OCI_SHARED_LIBADD
   ])
 
-
+  dnl Scrollable cursors?
+  PHP_CHECK_LIBRARY(clntsh, OCIStmtFetch2,
+  [
+        AC_DEFINE(HAVE_OCISTMTFETCH2,1,[ ])
+  ], [], [
+    -L$PDO_OCI_DIR/lib $PDO_OCI_SHARED_LIBADD
+  ])
 
   PHP_NEW_EXTENSION(pdo_oci, pdo_oci.c oci_driver.c oci_statement.c, $ext_shared,,-I\$prefix/include/php/ext)
 
index 353e28f711039366f6fe9cc52c7e41a6bd4cad54..a1d3a25a3067fbeaa7b112ee683d63f5782f3d5c 100755 (executable)
@@ -32,6 +32,7 @@ if (PHP_PDO_OCI != "no") {
                /* probe for some functions not present in older versions */
                pdo_oci_inc_dir = FSO.GetFolder(pdo_oci_header);
                CHECK_FUNC_IN_HEADER('oci.h', 'OCIEnvCreate', pdo_oci_inc_dir);
+               CHECK_FUNC_IN_HEADER('oci.h', 'OCIStmtFetch2', pdo_oci_inc_dir);
                CHECK_FUNC_IN_HEADER('ociap.h', 'OCIEnvNlsCreate', pdo_oci_inc_dir);
 
        } else {
index 4f089e82198fce1a72165750f7e760a90f0fb471..1d72d2c55dd2cedeee26c328872d2c1c1d546365 100755 (executable)
@@ -2,7 +2,7 @@
   +----------------------------------------------------------------------+
   | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
-  | Copyright (c) 1997-2004 The PHP Group                                |
+  | Copyright (c) 1997-2005 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.0 of the PHP license,       |
   | that is bundled with this package in the file LICENSE, and is        |
@@ -195,9 +195,18 @@ static int oci_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, pd
 {
        pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data;
        pdo_oci_stmt *S = ecalloc(1, sizeof(*S));
+       ub4 prefetch;
+
+#if HAVE_OCISTMTFETCH2
+       S->exec_type = pdo_attr_lval(driver_options, PDO_ATTR_SCROLL,
+               0 TSRMLS_CC) ? OCI_STMT_SCROLLABLE_READONLY : OCI_DEFAULT;
+#else
+       S->exec_type = OCI_DEFAULT;
+#endif
 
        S->H = H;
        
+
        /* create an OCI statement handle */
        OCIHandleAlloc(H->env, (dvoid*)&S->stmt, OCI_HTYPE_STMT, 0, NULL);
 
@@ -214,6 +223,18 @@ static int oci_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, pd
                        efree(S);
                        return 0;
                }
+
+       }
+
+       prefetch = 1024 * pdo_attr_lval(driver_options, PDO_ATTR_PREFETCH, 100 TSRMLS_CC);
+       if (prefetch) {
+               H->last_err = OCIAttrSet(S->stmt, OCI_HTYPE_STMT, &prefetch, 0,
+                       OCI_ATTR_PREFETCH_MEMORY, H->err);
+               if (!H->last_err) {
+                       prefetch /= 1024;
+                       H->last_err = OCIAttrSet(S->stmt, OCI_HTYPE_STMT, &prefetch, 0,
+                               OCI_ATTR_PREFETCH_ROWS, H->err);
+               }
        }
 
        stmt->driver_data = S;
index b35462c9d8f6571da007ec6b75bf2c5bb133136f..e8550c8e2e5b9dfadebf2be6e102289012c272fb 100755 (executable)
@@ -2,7 +2,7 @@
   +----------------------------------------------------------------------+
   | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
-  | Copyright (c) 1997-2004 The PHP Group                                |
+  | Copyright (c) 1997-2005 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.0 of the PHP license,       |
   | that is bundled with this package in the file LICENSE, and is        |
@@ -109,7 +109,7 @@ static int oci_stmt_execute(pdo_stmt_t *stmt TSRMLS_DC)
 
        STMT_CALL(OCIStmtExecute, (S->H->svc, S->stmt, S->err,
                                S->stmt_type == OCI_STMT_SELECT ? 0 : 1, 0, NULL, NULL,
-                               (stmt->dbh->auto_commit && !stmt->dbh->in_txn) ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT));
+                               (stmt->dbh->auto_commit && !stmt->dbh->in_txn) ? OCI_COMMIT_ON_SUCCESS : S->exec_type));
 
        if (!stmt->executed) {
                ub4 colcount;
@@ -284,11 +284,27 @@ static int oci_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *pa
        return 1;
 }
 
-static int oci_stmt_fetch(pdo_stmt_t *stmt TSRMLS_DC)
+static int oci_stmt_fetch(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori,
+       long offset TSRMLS_DC)
 {
+#if HAVE_OCISTMTFETCH2
+       ub4 ociori;
+#endif
        pdo_oci_stmt *S = (pdo_oci_stmt*)stmt->driver_data;
 
+#if HAVE_OCISTMTFETCH2
+       switch (ori) {
+               case PDO_FETCH_ORI_NEXT:        ociori = OCI_FETCH_NEXT; break;
+               case PDO_FETCH_ORI_PRIOR:       ociori = OCI_FETCH_PRIOR; break;
+               case PDO_FETCH_ORI_FIRST:       ociori = OCI_FETCH_FIRST; break;
+               case PDO_FETCH_ORI_LAST:        ociori = OCI_FETCH_LAST; break;
+               case PDO_FETCH_ORI_ABS:         ociori = OCI_FETCH_ABSOLUTE; break;
+               case PDO_FETCH_ORI_REL:         ociori = OCI_FETCH_RELATIVE; break;
+       }
+       S->last_err = OCIStmtFetch2(S->stmt, S->err, 1, ociori, offset, OCI_DEFAULT);
+#else
        S->last_err = OCIStmtFetch(S->stmt, S->err, 1, OCI_FETCH_NEXT, OCI_DEFAULT);
+#endif
 
        if (S->last_err == OCI_NO_DATA) {
                /* no (more) data */
index 5712f8634d7d76a94beeddb62e80059436faab14..757877454e58181dec586f13dca91c59494b6aa5 100755 (executable)
@@ -2,7 +2,7 @@
   +----------------------------------------------------------------------+
   | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
-  | Copyright (c) 1997-2004 The PHP Group                                |
+  | Copyright (c) 1997-2005 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.0 of the PHP license,       |
   | that is bundled with this package in the file LICENSE, and is        |
index fe9f24749fe0847a3fc2e19958e88ec08376db3e..7e37c3e60cedebd3dfa16e4a2789fdd0dbdf7390 100755 (executable)
@@ -2,7 +2,7 @@
   +----------------------------------------------------------------------+
   | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
-  | Copyright (c) 1997-2004 The PHP Group                                |
+  | Copyright (c) 1997-2005 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.0 of the PHP license,       |
   | that is bundled with this package in the file LICENSE, and is        |
index d20baba47ca36128d7c9d1316403ad8811cc05f1..2ebd4f22261082f4020aeae5e2c18d150ef0e223 100755 (executable)
@@ -2,7 +2,7 @@
   +----------------------------------------------------------------------+
   | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
-  | Copyright (c) 1997-2004 The PHP Group                                |
+  | Copyright (c) 1997-2005 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.0 of the PHP license,       |
   | that is bundled with this package in the file LICENSE, and is        |
@@ -60,8 +60,8 @@ typedef struct {
        OCIStmt         *stmt;
        OCIError        *err;
        sword           last_err;
-       ub2                     stmt_type;
-
+       ub2             stmt_type;
+       ub4             exec_type;
        pdo_oci_column *cols;
        pdo_oci_error_info einfo;
 } pdo_oci_stmt;