summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Jones <sixd@php.net>2007-08-31 21:08:48 +0000
committerChristopher Jones <sixd@php.net>2007-08-31 21:08:48 +0000
commitaf387e49ba6297c90fd1c05b5de452194a4bf940 (patch)
tree4300dc0417e5280c497187cc5d7e9a6f4c901c7a
parent90d58d466880e16df63d0ebe00b4c4db60b01184 (diff)
downloadphp-git-af387e49ba6297c90fd1c05b5de452194a4bf940.tar.gz
Add $dbh->getAttribute() support for ATTR_SERVER_VERSION, ATTR_SERVER_INFO, ATTR_CLIENT_VERSION, ATTR_AUTOCOMMIT. Sync WS between PHP 5 & 6 and add a couple of casts.
-rwxr-xr-xext/pdo_oci/config.m410
-rwxr-xr-xext/pdo_oci/oci_driver.c88
-rwxr-xr-xext/pdo_oci/oci_statement.c10
-rwxr-xr-xext/pdo_oci/php_pdo_oci_int.h19
4 files changed, 105 insertions, 22 deletions
diff --git a/ext/pdo_oci/config.m4 b/ext/pdo_oci/config.m4
index 0326a1ff76..ec6747ea6f 100755
--- a/ext/pdo_oci/config.m4
+++ b/ext/pdo_oci/config.m4
@@ -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
diff --git a/ext/pdo_oci/oci_driver.c b/ext/pdo_oci/oci_driver.c
index ac9d0e35c7..379ab03d1a 100755
--- a/ext/pdo_oci/oci_driver.c
+++ b/ext/pdo_oci/oci_driver.c
@@ -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
diff --git a/ext/pdo_oci/oci_statement.c b/ext/pdo_oci/oci_statement.c
index 963957fa13..29b730a045 100755
--- a/ext/pdo_oci/oci_statement.c
+++ b/ext/pdo_oci/oci_statement.c
@@ -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;
diff --git a/ext/pdo_oci/php_pdo_oci_int.h b/ext/pdo_oci/php_pdo_oci_int.h
index 2aaafd0853..b8bcf50748 100755
--- a/ext/pdo_oci/php_pdo_oci_int.h
+++ b/ext/pdo_oci/php_pdo_oci_int.h
@@ -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