]> granicus.if.org Git - php/commitdiff
Add $dbh->getAttribute() support for ATTR_SERVER_VERSION, ATTR_SERVER_INFO, ATTR_CLIE...
authorChristopher Jones <sixd@php.net>
Fri, 31 Aug 2007 21:08:48 +0000 (21:08 +0000)
committerChristopher Jones <sixd@php.net>
Fri, 31 Aug 2007 21:08:48 +0000 (21:08 +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 0326a1ff760318cc9e8905b1513843fbc0f6f7d1..ec6747ea6f656e32d8140e1ead8793f3820202a1 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 ac9d0e35c7d18b00a06b04c66fbf621837b81ac6..379ab03d1a2a55c942e63bb260d0f105267863b8 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;
@@ -285,14 +287,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);
                }
        }
 
@@ -446,6 +448,69 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, long attr, zval *val TSRMLS_
        } else {
                return 0;
        }
+       
+}
+/* }}} */
+
+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;
 
 }
 /* }}} */
@@ -461,7 +526,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 */
 };
@@ -483,7 +548,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;
@@ -598,6 +663,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 963957fa13bc1015fddc22f144c8f296b98ecc29..29b730a045766d6e63c6398651ff85e1b8410732 100755 (executable)
@@ -31,8 +31,8 @@
 #include "php_pdo_oci_int.h"
 #include "Zend/zend_extensions.h"
 
-#define STMT_CALL(name, params)        \
-       do { \
+#define STMT_CALL(name, params)                                                                                        \
+       do {                                                                                                                            \
                S->last_err = name params;                                                                              \
                S->last_err = _oci_error(S->err, stmt->dbh, stmt, #name, S->last_err, FALSE, __FILE__, __LINE__ TSRMLS_CC); \
                if (S->last_err) {                                                                                              \
@@ -40,8 +40,8 @@
                }                                                                                                                               \
        } while(0)
 
-#define STMT_CALL_MSG(name, msg, params)       \
-       do { \
+#define STMT_CALL_MSG(name, msg, params)                                                               \
+       do {                                                                                                                            \
                S->last_err = name params;                                                                              \
                S->last_err = _oci_error(S->err, stmt->dbh, stmt, #name ": " #msg, S->last_err, FALSE, __FILE__, __LINE__ TSRMLS_CC); \
                if (S->last_err) {                                                                                              \
@@ -529,7 +529,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);
 
        S->cols[colno].dtype = dtype;
 
index 2aaafd0853b557c6896264e1a885a59f696ac0bf..b8bcf5074809ad08a183b77a98e9c4336f7a2d2d 100755 (executable)
@@ -31,15 +31,15 @@ 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;
 
-       unsigned attached:1;
-       unsigned _reserved:31;
+       unsigned        attached:1;
+       unsigned        _reserved:31;
 
        pdo_oci_error_info einfo;
 } pdo_oci_db_handle;
@@ -62,15 +62,15 @@ typedef struct {
        OCIStmt         *stmt;
        OCIError        *err;
        sword           last_err;
-       ub2             stmt_type;
-       ub4             exec_type;
+       ub2                     stmt_type;
+       ub4                     exec_type;
        pdo_oci_column *cols;
        pdo_oci_error_info einfo;
        unsigned int have_blobs:1;
 } pdo_oci_stmt;
 
 typedef struct {
-       OCIBind         *bind;  /* allocated by OCI */
+       OCIBind         *bind;  /* allocated by OCI */
        sb2                     oci_type;
        sb2                     indicator;
        ub2                     retcode;
@@ -93,3 +93,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