summaryrefslogtreecommitdiff
path: root/ext/pdo_oci
diff options
context:
space:
mode:
Diffstat (limited to 'ext/pdo_oci')
-rw-r--r--ext/pdo_oci/oci_driver.c142
-rw-r--r--ext/pdo_oci/oci_statement.c45
-rw-r--r--ext/pdo_oci/pdo_oci.c4
3 files changed, 96 insertions, 95 deletions
diff --git a/ext/pdo_oci/oci_driver.c b/ext/pdo_oci/oci_driver.c
index 096a26575e..dd4a7bb171 100644
--- a/ext/pdo_oci/oci_driver.c
+++ b/ext/pdo_oci/oci_driver.c
@@ -29,7 +29,7 @@
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) /* {{{ */
+static void pdo_oci_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) /* {{{ */
{
pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data;
pdo_oci_error_info *einfo;
@@ -48,8 +48,6 @@ static int pdo_oci_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info
add_next_index_long(info, einfo->errcode);
add_next_index_string(info, einfo->errmsg);
}
-
- return 1;
}
/* }}} */
@@ -185,7 +183,7 @@ ub4 _oci_error(OCIError *err, pdo_dbh_t *dbh, pdo_stmt_t *stmt, char *what, swor
}
/* }}} */
-static int oci_handle_closer(pdo_dbh_t *dbh) /* {{{ */
+static void oci_handle_closer(pdo_dbh_t *dbh) /* {{{ */
{
pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data;
@@ -233,18 +231,15 @@ static int oci_handle_closer(pdo_dbh_t *dbh) /* {{{ */
}
pefree(H, dbh->is_persistent);
-
- return 0;
}
/* }}} */
-static int oci_handle_preparer(pdo_dbh_t *dbh, const char *sql, size_t sql_len, pdo_stmt_t *stmt, zval *driver_options) /* {{{ */
+static bool oci_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options) /* {{{ */
{
pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data;
pdo_oci_stmt *S = ecalloc(1, sizeof(*S));
ub4 prefetch;
- char *nsql = NULL;
- size_t nsql_len = 0;
+ zend_string *nsql = NULL;
int ret;
#ifdef HAVE_OCISTMTFETCH2
@@ -257,17 +252,16 @@ static int oci_handle_preparer(pdo_dbh_t *dbh, const char *sql, size_t sql_len,
S->H = H;
stmt->supports_placeholders = PDO_PLACEHOLDER_NAMED;
- ret = pdo_parse_params(stmt, (char*)sql, sql_len, &nsql, &nsql_len);
+ ret = pdo_parse_params(stmt, sql, &nsql);
if (ret == 1) {
/* query was re-written */
sql = nsql;
- sql_len = nsql_len;
} else if (ret == -1) {
/* couldn't grok it */
strcpy(dbh->error_code, stmt->error_code);
efree(S);
- return 0;
+ return false;
}
/* create an OCI statement handle */
@@ -276,10 +270,10 @@ static int oci_handle_preparer(pdo_dbh_t *dbh, const char *sql, size_t sql_len,
/* and our own private error handle */
OCIHandleAlloc(H->env, (dvoid*)&S->err, OCI_HTYPE_ERROR, 0, NULL);
- if (sql_len) {
- H->last_err = OCIStmtPrepare(S->stmt, H->err, (text*)sql, (ub4) sql_len, OCI_NTV_SYNTAX, OCI_DEFAULT);
+ if (ZSTR_LEN(sql) != 0) {
+ H->last_err = OCIStmtPrepare(S->stmt, H->err, (text*) ZSTR_VAL(sql), (ub4) ZSTR_LEN(sql), OCI_NTV_SYNTAX, OCI_DEFAULT);
if (nsql) {
- efree(nsql);
+ zend_string_release(nsql);
nsql = NULL;
}
if (H->last_err) {
@@ -287,7 +281,7 @@ static int oci_handle_preparer(pdo_dbh_t *dbh, const char *sql, size_t sql_len,
OCIHandleFree(S->stmt, OCI_HTYPE_STMT);
OCIHandleFree(S->err, OCI_HTYPE_ERROR);
efree(S);
- return 0;
+ return false;
}
}
@@ -304,15 +298,15 @@ static int oci_handle_preparer(pdo_dbh_t *dbh, const char *sql, size_t sql_len,
stmt->driver_data = S;
stmt->methods = &oci_stmt_methods;
if (nsql) {
- efree(nsql);
+ zend_string_release(nsql);
nsql = NULL;
}
- return 1;
+ return true;
}
/* }}} */
-static zend_long oci_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sql_len) /* {{{ */
+static zend_long oci_handle_doer(pdo_dbh_t *dbh, const zend_string *sql) /* {{{ */
{
pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data;
OCIStmt *stmt;
@@ -322,7 +316,7 @@ static zend_long oci_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sql_len
OCIHandleAlloc(H->env, (dvoid*)&stmt, OCI_HTYPE_STMT, 0, NULL);
- H->last_err = OCIStmtPrepare(stmt, H->err, (text*)sql, (ub4) sql_len, OCI_NTV_SYNTAX, OCI_DEFAULT);
+ H->last_err = OCIStmtPrepare(stmt, H->err, (text*)ZSTR_VAL(sql), (ub4) ZSTR_LEN(sql), OCI_NTV_SYNTAX, OCI_DEFAULT);
if (H->last_err) {
H->last_err = oci_drv_error("OCIStmtPrepare");
OCIHandleFree(stmt, OCI_HTYPE_STMT);
@@ -356,51 +350,52 @@ static zend_long oci_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sql_len
}
/* }}} */
-static int oci_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype ) /* {{{ */
+static zend_string* oci_handle_quoter(pdo_dbh_t *dbh, const zend_string *unquoted, enum pdo_param_type paramtype ) /* {{{ */
{
int qcount = 0;
char const *cu, *l, *r;
- char *c;
+ char *c, *quoted;
+ size_t quotedlen;
+ zend_string *quoted_str;
- if (!unquotedlen) {
- *quotedlen = 2;
- *quoted = emalloc(*quotedlen+1);
- strcpy(*quoted, "''");
- return 1;
+ if (ZSTR_LEN(unquoted) == 0) {
+ return zend_string_init("''", 2, 0);
}
/* count single quotes */
- for (cu = unquoted; (cu = strchr(cu,'\'')); qcount++, cu++)
+ for (cu = ZSTR_VAL(unquoted); (cu = strchr(cu,'\'')); qcount++, cu++)
; /* empty loop */
- *quotedlen = unquotedlen + qcount + 2;
- *quoted = c = emalloc(*quotedlen+1);
+ quotedlen = ZSTR_LEN(unquoted) + qcount + 2;
+ quoted = c = emalloc(quotedlen+1);
*c++ = '\'';
/* foreach (chunk that ends in a quote) */
- for (l = unquoted; (r = strchr(l,'\'')); l = r+1) {
+ for (l = ZSTR_VAL(unquoted); (r = strchr(l,'\'')); l = r+1) {
strncpy(c, l, r-l+1);
c += (r-l+1);
*c++ = '\''; /* add second quote */
}
/* Copy remainder and add enclosing quote */
- strncpy(c, l, *quotedlen-(c-*quoted)-1);
- (*quoted)[*quotedlen-1] = '\'';
- (*quoted)[*quotedlen] = '\0';
+ strncpy(c, l, quotedlen-(c-quoted)-1);
+ quoted[quotedlen-1] = '\'';
+ quoted[quotedlen] = '\0';
- return 1;
+ quoted_str = zend_string_init(quoted, quotedlen, 0);
+ efree(quoted);
+ return quoted_str;
}
/* }}} */
-static int oci_handle_begin(pdo_dbh_t *dbh) /* {{{ */
+static bool oci_handle_begin(pdo_dbh_t *dbh) /* {{{ */
{
/* with Oracle, there is nothing special to be done */
- return 1;
+ return true;
}
/* }}} */
-static int oci_handle_commit(pdo_dbh_t *dbh) /* {{{ */
+static bool oci_handle_commit(pdo_dbh_t *dbh) /* {{{ */
{
pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data;
@@ -408,13 +403,13 @@ static int oci_handle_commit(pdo_dbh_t *dbh) /* {{{ */
if (H->last_err) {
H->last_err = oci_drv_error("OCITransCommit");
- return 0;
+ return false;
}
- return 1;
+ return true;
}
/* }}} */
-static int oci_handle_rollback(pdo_dbh_t *dbh) /* {{{ */
+static bool oci_handle_rollback(pdo_dbh_t *dbh) /* {{{ */
{
pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data;
@@ -422,13 +417,13 @@ static int oci_handle_rollback(pdo_dbh_t *dbh) /* {{{ */
if (H->last_err) {
H->last_err = oci_drv_error("OCITransRollback");
- return 0;
+ return false;
}
- return 1;
+ return true;
}
/* }}} */
-static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /* {{{ */
+static bool oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /* {{{ */
{
zend_long lval = zval_get_long(val);
pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data;
@@ -442,25 +437,25 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /
if (H->last_err) {
H->last_err = oci_drv_error("OCITransCommit");
- return 0;
+ return false;
}
- dbh->in_txn = 0;
+ dbh->in_txn = false;
}
dbh->auto_commit = (unsigned int)lval? 1 : 0;
- return 1;
+ return true;
}
case PDO_ATTR_PREFETCH:
{
H->prefetch = pdo_oci_sanitize_prefetch(lval);
- return 1;
+ return true;
}
case PDO_OCI_ATTR_ACTION:
{
#if (OCI_MAJOR_VERSION >= 10)
zend_string *action = zval_try_get_string(val);
if (UNEXPECTED(!action)) {
- return 0;
+ return false;
}
H->last_err = OCIAttrSet(H->session, OCI_HTYPE_SESSION,
@@ -468,12 +463,12 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /
OCI_ATTR_ACTION, H->err);
if (H->last_err) {
oci_drv_error("OCIAttrSet: OCI_ATTR_ACTION");
- return 0;
+ return false;
}
- return 1;
+ return true;
#else
oci_drv_error("Unsupported attribute type");
- return 0;
+ return false;
#endif
}
case PDO_OCI_ATTR_CLIENT_INFO:
@@ -481,7 +476,7 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /
#if (OCI_MAJOR_VERSION >= 10)
zend_string *client_info = zval_try_get_string(val);
if (UNEXPECTED(!client_info)) {
- return 0;
+ return false;
}
H->last_err = OCIAttrSet(H->session, OCI_HTYPE_SESSION,
@@ -489,12 +484,12 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /
OCI_ATTR_CLIENT_INFO, H->err);
if (H->last_err) {
oci_drv_error("OCIAttrSet: OCI_ATTR_CLIENT_INFO");
- return 0;
+ return false;
}
- return 1;
+ return true;
#else
oci_drv_error("Unsupported attribute type");
- return 0;
+ return false;
#endif
}
case PDO_OCI_ATTR_CLIENT_IDENTIFIER:
@@ -502,7 +497,7 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /
#if (OCI_MAJOR_VERSION >= 10)
zend_string *identifier = zval_try_get_string(val);
if (UNEXPECTED(!identifier)) {
- return 0;
+ return false;
}
H->last_err = OCIAttrSet(H->session, OCI_HTYPE_SESSION,
@@ -510,12 +505,12 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /
OCI_ATTR_CLIENT_IDENTIFIER, H->err);
if (H->last_err) {
oci_drv_error("OCIAttrSet: OCI_ATTR_CLIENT_IDENTIFIER");
- return 0;
+ return false;
}
- return 1;
+ return true;
#else
oci_drv_error("Unsupported attribute type");
- return 0;
+ return false;
#endif
}
case PDO_OCI_ATTR_MODULE:
@@ -523,7 +518,7 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /
#if (OCI_MAJOR_VERSION >= 10)
zend_string *module = zval_try_get_string(val);
if (UNEXPECTED(!module)) {
- return 0;
+ return false;
}
H->last_err = OCIAttrSet(H->session, OCI_HTYPE_SESSION,
@@ -531,12 +526,12 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /
OCI_ATTR_MODULE, H->err);
if (H->last_err) {
oci_drv_error("OCIAttrSet: OCI_ATTR_MODULE");
- return 0;
+ return false;
}
- return 1;
+ return true;
#else
oci_drv_error("Unsupported attribute type");
- return 0;
+ return false;
#endif
}
case PDO_OCI_ATTR_CALL_TIMEOUT:
@@ -549,16 +544,16 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /
OCI_ATTR_CALL_TIMEOUT, H->err);
if (H->last_err) {
oci_drv_error("OCIAttrSet: OCI_ATTR_CALL_TIMEOUT");
- return 0;
+ return false;
}
- return 1;
+ return true;
#else
oci_drv_error("Unsupported attribute type");
- return 0;
+ return false;
#endif
}
default:
- return 0;
+ return false;
}
}
@@ -653,7 +648,7 @@ static int oci_handle_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return
}
/* }}} */
-static int pdo_oci_check_liveness(pdo_dbh_t *dbh) /* {{{ */
+static zend_result pdo_oci_check_liveness(pdo_dbh_t *dbh) /* {{{ */
{
pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data;
sb4 error_code = 0;
@@ -701,13 +696,14 @@ static const struct pdo_dbh_methods oci_methods = {
oci_handle_commit,
oci_handle_rollback,
oci_handle_set_attribute,
- NULL,
+ NULL, /* last_id not supported */
pdo_oci_fetch_error_func,
oci_handle_get_attribute,
pdo_oci_check_liveness, /* check_liveness */
- NULL, /* get_driver_methods */
- NULL,
- NULL
+ NULL, /* get_driver_methods */
+ NULL, /* request_shutdown */
+ NULL, /* in transaction, use PDO's internal tracking mechanism */
+ NULL /* get_gc */
};
static int pdo_oci_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{ */
diff --git a/ext/pdo_oci/oci_statement.c b/ext/pdo_oci/oci_statement.c
index 0ab043f041..de021e76fb 100644
--- a/ext/pdo_oci/oci_statement.c
+++ b/ext/pdo_oci/oci_statement.c
@@ -235,10 +235,11 @@ static sb4 oci_bind_output_cb(dvoid *ctx, OCIBind *bindp, ub4 iter, ub4 index, d
ZEND_ASSERT(param);
- if (Z_ISREF(param->parameter))
- parameter = Z_REFVAL(param->parameter);
- else
- parameter = &param->parameter;
+ if (Z_ISREF(param->parameter)) {
+ parameter = Z_REFVAL(param->parameter);
+ } else {
+ parameter = &param->parameter;
+ }
if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB) {
P->actual_len = sizeof(OCILobLocator*);
@@ -517,7 +518,7 @@ static int oci_stmt_describe(pdo_stmt_t *stmt, int colno) /* {{{ */
ub2 dtype, data_size, precis;
ub4 namelen;
struct pdo_column_data *col = &stmt->columns[colno];
- zend_bool dyn = FALSE;
+ bool dyn = FALSE;
/* describe the column */
STMT_CALL(OCIParamGet, (S->stmt, OCI_HTYPE_STMT, S->err, (dvoid*)&param, colno+1));
@@ -555,12 +556,10 @@ static int oci_stmt_describe(pdo_stmt_t *stmt, int colno) /* {{{ */
}
S->cols[colno].datalen = 512; /* XXX should be INT_MAX and fetched by pieces */
S->cols[colno].data = emalloc(S->cols[colno].datalen + 1);
- col->param_type = PDO_PARAM_STR;
break;
case SQLT_BLOB:
case SQLT_CLOB:
- col->param_type = PDO_PARAM_LOB;
STMT_CALL(OCIDescriptorAlloc, (S->H->env, (dvoid**)&S->cols[colno].data, OCI_DTYPE_LOB, 0, NULL));
S->cols[colno].datalen = sizeof(OCILobLocator*);
dyn = TRUE;
@@ -590,9 +589,6 @@ static int oci_stmt_describe(pdo_stmt_t *stmt, int colno) /* {{{ */
S->cols[colno].data = emalloc(S->cols[colno].datalen + 1);
dtype = SQLT_CHR;
-
- /* returning data as a string */
- col->param_type = PDO_PARAM_STR;
}
STMT_CALL(OCIDefineByPos, (S->stmt, &S->cols[colno].def, S->err, colno+1,
@@ -742,7 +738,7 @@ static php_stream *oci_create_lob_stream(zval *dbh, pdo_stmt_t *stmt, OCILobLoca
return NULL;
}
-static int oci_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, size_t *len, int *caller_frees) /* {{{ */
+static int oci_stmt_get_col(pdo_stmt_t *stmt, int colno, zval *result, enum pdo_param_type *type) /* {{{ */
{
pdo_oci_stmt *S = (pdo_oci_stmt*)stmt->driver_data;
pdo_oci_column *C = &S->cols[colno];
@@ -750,30 +746,27 @@ static int oci_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, size_t *len
/* check the indicator to ensure that the data is intact */
if (C->indicator == -1) {
/* A NULL value */
- *ptr = NULL;
- *len = 0;
+ ZVAL_NULL(result);
return 1;
} else if (C->indicator == 0) {
/* it was stored perfectly */
if (C->dtype == SQLT_BLOB || C->dtype == SQLT_CLOB) {
if (C->data) {
- *ptr = (char*)oci_create_lob_stream(&stmt->database_object_handle, stmt, (OCILobLocator*)C->data);
+ php_stream *stream = oci_create_lob_stream(&stmt->database_object_handle, stmt, (OCILobLocator*)C->data);
OCILobOpen(S->H->svc, S->err, (OCILobLocator*)C->data, OCI_LOB_READONLY);
+ php_stream_to_zval(stream, result);
+ return 1;
}
- *len = (size_t) 0;
- return *ptr ? 1 : 0;
+ return 0;
}
- *ptr = C->data;
- *len = (size_t) C->fetched_len;
+ ZVAL_STRINGL_FAST(result, C->data, C->fetched_len);
return 1;
} else {
/* it was truncated */
php_error_docref(NULL, E_WARNING, "Column %d data was too large for buffer and was truncated to fit it", colno);
-
- *ptr = C->data;
- *len = (size_t) C->fetched_len;
+ ZVAL_STRINGL(result, C->data, C->fetched_len);
return 1;
}
} /* }}} */
@@ -943,6 +936,16 @@ static int oci_stmt_col_meta(pdo_stmt_t *stmt, zend_long colno, zval *return_val
add_assoc_string(return_value, "native_type", "NULL");
}
+ switch (dtype) {
+ case SQLT_BLOB:
+ case SQLT_CLOB:
+ add_assoc_long(return_value, "pdo_type", PDO_PARAM_LOB);
+ break;
+ default:
+ add_assoc_long(return_value, "pdo_type", PDO_PARAM_STR);
+ break;
+ }
+
/* column can be null */
STMT_CALL_MSG(OCIAttrGet, "OCI_ATTR_IS_NULL",
(param, OCI_DTYPE_PARAM, &isnull, 0, OCI_ATTR_IS_NULL, S->err));
diff --git a/ext/pdo_oci/pdo_oci.c b/ext/pdo_oci/pdo_oci.c
index efa7c1caf6..5ae28a50df 100644
--- a/ext/pdo_oci/pdo_oci.c
+++ b/ext/pdo_oci/pdo_oci.c
@@ -87,7 +87,9 @@ PHP_MINIT_FUNCTION(pdo_oci)
REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_MODULE", (zend_long)PDO_OCI_ATTR_MODULE);
REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_CALL_TIMEOUT", (zend_long)PDO_OCI_ATTR_CALL_TIMEOUT);
- php_pdo_register_driver(&pdo_oci_driver);
+ if (FAILURE == php_pdo_register_driver(&pdo_oci_driver)) {
+ return FAILURE;
+ }
// Defer OCI init to PHP_RINIT_FUNCTION because with php-fpm,
// NLS_LANG is not yet available here.