]> granicus.if.org Git - php/commitdiff
MFB Add $dbh->getAttribute() support for ATTR_SERVER_VERSION, ATTR_SERVER_INFO, ATTR_...
authorChristopher Jones <sixd@php.net>
Fri, 31 Aug 2007 21:11:03 +0000 (21:11 +0000)
committerChristopher Jones <sixd@php.net>
Fri, 31 Aug 2007 21:11:03 +0000 (21:11 +0000)
ext/pdo_oci/config.m4
ext/pdo_oci/oci_driver.c
ext/pdo_oci/oci_statement.c
ext/pdo_oci/php_pdo_oci_int.h

index fd4305e284ada9185d22d628918e36bf7672587a..0e82c4e3b2dee6a5ae4956f3d2f63fb2b9cfedfe 100755 (executable)
@@ -24,7 +24,7 @@ AC_DEFUN([AC_PDO_OCI_VERSION],[
       PDO_OCI_VERSION=8.1
     fi
   else
-    AC_MSG_ERROR(Oracle-OCI needed libraries not found under $PDO_OCI_DIR)
+    AC_MSG_ERROR(Oracle OCI libraries not found under $PDO_OCI_DIR)
   fi
   AC_MSG_RESULT($PDO_OCI_VERSION)
 ])                                                                                                                                                                
@@ -54,7 +54,7 @@ AC_DEFUN([AC_PDO_OCI_CHECK_LIB_DIR],[
 ])
 
 PHP_ARG_WITH(pdo-oci, Oracle OCI support for PDO,
-[  --with-pdo-oci[=DIR]      PDO: Oracle-OCI support. DIR defaults to \$ORACLE_HOME.
+[  --with-pdo-oci[=DIR]      PDO: Oracle OCI support. DIR defaults to \$ORACLE_HOME.
                             Use --with-pdo-oci=instantclient,prefix,version 
                             for an Oracle Instant Client SDK. 
                             For Linux with 10.2.0.3 RPMs (for example) use:
@@ -67,12 +67,12 @@ if test "$PHP_PDO_OCI" != "no"; then
   else
     PDO_OCI_DIR=$PHP_PDO_OCI
   fi
-  AC_MSG_RESULT($PDO_OCI_DIR :$PHP_PDO_OCI:)
+  AC_MSG_RESULT($PHP_PDO_OCI)
 
   AC_MSG_CHECKING([if that is sane])
   if test -z "$PDO_OCI_DIR"; then
     AC_MSG_ERROR([
-You need to tell me where to find your oracle SDK, or set ORACLE_HOME.
+You need to tell me where to find your Oracle Instant Client SDK, or set ORACLE_HOME.
 ])
   else
     AC_MSG_RESULT([yes])
@@ -251,6 +251,8 @@ You need to tell me where to find your oracle SDK, or set ORACLE_HOME.
   [
     PHP_ADD_EXTENSION_DEP(pdo_oci, pdo)
   ])
+
+  AC_DEFINE_UNQUOTED(PHP_PDO_OCI_CLIENT_VERSION, "$PDO_OCI_VERSION", [ ])
 fi
 
 fi
index d4d154244ca91c3313e77a9ecd2b31ccae5fa357..f4fc0a5757960886ae5953216959bc52e98af794 100755 (executable)
@@ -31,6 +31,8 @@
 #include "php_pdo_oci_int.h"
 #include "Zend/zend_exceptions.h"
 
+static inline ub4 pdo_oci_sanitize_prefetch(long prefetch);
+
 static int pdo_oci_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info TSRMLS_DC) /* {{{ */
 {
        pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data;
@@ -282,14 +284,14 @@ static int oci_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, pd
 
        }
 
-       prefetch = 1024 * pdo_attr_lval(driver_options, PDO_ATTR_PREFETCH, 100 TSRMLS_CC);
+       prefetch = pdo_oci_sanitize_prefetch(pdo_attr_lval(driver_options, PDO_ATTR_PREFETCH, PDO_OCI_PREFETCH_DEFAULT TSRMLS_CC));
        if (prefetch) {
                H->last_err = OCIAttrSet(S->stmt, OCI_HTYPE_STMT, &prefetch, 0,
-                       OCI_ATTR_PREFETCH_MEMORY, H->err);
+                                                                OCI_ATTR_PREFETCH_ROWS, H->err);
                if (!H->last_err) {
-                       prefetch /= 1024;
+                       prefetch *= PDO_OCI_PREFETCH_ROWSIZE;
                        H->last_err = OCIAttrSet(S->stmt, OCI_HTYPE_STMT, &prefetch, 0,
-                               OCI_ATTR_PREFETCH_ROWS, H->err);
+                                                                        OCI_ATTR_PREFETCH_MEMORY, H->err);
                }
        }
 
@@ -448,6 +450,69 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, long attr, zval *val TSRMLS_
 }
 /* }}} */
 
+static int oci_handle_get_attribute(pdo_dbh_t *dbh, long attr, zval *return_value TSRMLS_DC)  /* {{{ */
+{
+       pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data;
+
+       switch (attr) {
+               case PDO_ATTR_SERVER_VERSION:
+               case PDO_ATTR_SERVER_INFO:
+               {
+                       text infostr[512];
+                       char verstr[15];
+                       ub4  vernum;
+                       
+                       if (OCIServerRelease(H->svc, H->err, infostr, (ub4)sizeof(infostr), (ub1)OCI_HTYPE_SVCCTX, &vernum))
+                       {
+                               ZVAL_STRING(return_value, "<<Unknown>>", 1);
+                       } else {
+                               if (attr == PDO_ATTR_SERVER_INFO) {
+                                       ZVAL_STRING(return_value, (char *)infostr, 1);
+                               } else {
+                                       slprintf(verstr, sizeof(verstr), "%d.%d.%d.%d.%d", 
+                                                        (int)((vernum>>24) & 0xFF),  /* version number */
+                                                        (int)((vernum>>20) & 0x0F),  /* release number*/
+                                                        (int)((vernum>>12) & 0xFF),  /* update number */
+                                                        (int)((vernum>>8)  & 0x0F),  /* port release number */
+                                                        (int)((vernum>>0)  & 0xFF)); /* port update number */
+                                       
+                                       ZVAL_STRING(return_value, verstr, 1);
+                               }
+                       }
+                       return TRUE;
+               }
+
+               case PDO_ATTR_CLIENT_VERSION:
+               {
+#if OCI_MAJOR_VERSION > 10 || (OCI_MAJOR_VERSION == 10 && OCI_MINOR_VERSION >= 2)
+                       /* Run time client version */
+                       sword major, minor, update, patch, port_update;
+                       char verstr[15];
+
+                       OCIClientVersion(&major, &minor, &update, &patch, &port_update);
+                       slprintf(verstr, sizeof(verstr), "%d.%d.%d.%d.%d", major, minor, update, patch, port_update);
+                       ZVAL_STRING(return_value, verstr, 1);
+#else
+                       /* Compile time client version */
+                       ZVAL_STRING(return_value, PHP_PDO_OCI_CLIENT_VERSION, 1);
+#endif /* Check for OCIClientVersion() support */
+
+                       return TRUE;
+               }
+
+               case PDO_ATTR_AUTOCOMMIT:
+                       ZVAL_BOOL(return_value, dbh->auto_commit);
+                       return TRUE;
+
+               default:
+                       return FALSE;
+
+       }
+       return FALSE;
+
+}
+/* }}} */
+
 static struct pdo_dbh_methods oci_methods = {
        oci_handle_closer,
        oci_handle_preparer,
@@ -459,7 +524,7 @@ static struct pdo_dbh_methods oci_methods = {
        oci_handle_set_attribute,
        NULL,
        pdo_oci_fetch_error_func,
-       NULL,   /* get_attr */
+       oci_handle_get_attribute,
        NULL,   /* check_liveness */
        NULL    /* get_driver_methods */
 };
@@ -481,7 +546,7 @@ static int pdo_oci_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_DC
        /* allocate an environment */
 #if HAVE_OCIENVNLSCREATE
        if (vars[0].optval) {
-               H->charset = OCINlsCharSetNameToId(pdo_oci_Env, vars[0].optval);
+               H->charset = OCINlsCharSetNameToId(pdo_oci_Env, (const oratext *)vars[0].optval);
                if (!H->charset) {
                        oci_init_error("OCINlsCharSetNameToId: unknown character set name");
                        goto cleanup;
@@ -596,6 +661,17 @@ pdo_driver_t pdo_oci_driver = {
        pdo_oci_handle_factory
 };
 
+static inline ub4 pdo_oci_sanitize_prefetch(long prefetch) /* {{{ */
+{
+       if (prefetch < 0) {
+               prefetch = 0;
+       } else if (prefetch > UB4MAXVAL / PDO_OCI_PREFETCH_ROWSIZE) {
+               prefetch = PDO_OCI_PREFETCH_DEFAULT;
+       }
+       return ((ub4)prefetch);
+}
+/* }}} */
+
 /*
  * Local variables:
  * tab-width: 4
index dad6223be6485cd7ea25a45dc2b19e34637c0a99..dc25891d71fecf60a256e070b1f5257e0e1eea47 100755 (executable)
@@ -395,7 +395,7 @@ static int oci_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC) /* {{{ */
        col->precision = scale;
        col->maxlen = data_size;
        col->namelen = namelen;
-       col->name = estrndup(colname, namelen);
+       col->name = estrndup((char *)colname, namelen);
 
        /* how much room do we need to store the field */
        switch (dtype) {
index 91c82a74b0a20ed2e939b558d958fb7fb8b4f3d5..f77d7314cb406768a3d76df207dbd01feded6fb5 100755 (executable)
@@ -31,9 +31,9 @@ typedef struct {
 typedef struct {
        OCIServer       *server;
        OCISession      *session;
-       OCIEnv          *env;
+       OCIEnv          *env;
        OCIError        *err;
-       OCISvcCtx       *svc;
+       OCISvcCtx       *svc;
        /* OCI9; 0 == use NLS_LANG */
        ub2                     charset;
        sword           last_err;
@@ -67,7 +67,7 @@ typedef struct {
 } pdo_oci_stmt;
 
 typedef struct {
-       OCIBind         *bind;  /* allocated by OCI */
+       OCIBind         *bind;  /* allocated by OCI */
        sb2                     oci_type;
        sb2                     indicator;
        ub2                     retcode;
@@ -90,3 +90,8 @@ ub4 _oci_error(OCIError *err, pdo_dbh_t *dbh, pdo_stmt_t *stmt, char *what, swor
 
 extern struct pdo_stmt_methods oci_stmt_methods;
 
+/* Default prefetch size in number of rows */
+#define PDO_OCI_PREFETCH_DEFAULT 100
+
+/* Arbitrary assumed row length for prefetch memory limit calcuation */
+#define PDO_OCI_PREFETCH_ROWSIZE 1024