From: Christopher Jones Date: Mon, 10 Feb 2014 23:00:42 +0000 (-0800) Subject: Add Oracle PL/SQL BOOLEAN type support to oci_bind_by_name() X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2cbd8572835a07ca2a1f3a2a302e78c7ce998e9a;p=php Add Oracle PL/SQL BOOLEAN type support to oci_bind_by_name() --- diff --git a/ext/oci8/oci8.c b/ext/oci8/oci8.c index c3ca7a8172..a890c94dab 100644 --- a/ext/oci8/oci8.c +++ b/ext/oci8/oci8.c @@ -26,8 +26,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -1251,6 +1249,9 @@ PHP_MINIT_FUNCTION(oci) REGISTER_LONG_CONSTANT("SQLT_BDOUBLE",SQLT_BDOUBLE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SQLT_BFLOAT",SQLT_BFLOAT, CONST_CS | CONST_PERSISTENT); #endif +#if defined(OCI_MAJOR_VERSION) && OCI_MAJOR_VERSION >= 12 + REGISTER_LONG_CONSTANT("SQLT_BOL",SQLT_BOL, CONST_CS | CONST_PERSISTENT); +#endif REGISTER_LONG_CONSTANT("OCI_B_NTY",SQLT_NTY, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SQLT_NTY",SQLT_NTY, CONST_CS | CONST_PERSISTENT); @@ -1265,6 +1266,9 @@ PHP_MINIT_FUNCTION(oci) REGISTER_LONG_CONSTANT("OCI_B_BIN",SQLT_BIN, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_B_INT",SQLT_INT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_B_NUM",SQLT_NUM, CONST_CS | CONST_PERSISTENT); +#if defined(OCI_MAJOR_VERSION) && OCI_MAJOR_VERSION >= 12 + REGISTER_LONG_CONSTANT("OCI_B_BOL",SQLT_BOL, CONST_CS | CONST_PERSISTENT); +#endif /* for OCIFetchStatement */ REGISTER_LONG_CONSTANT("OCI_FETCHSTATEMENT_BY_COLUMN", PHP_OCI_FETCHSTATEMENT_BY_COLUMN, CONST_CS | CONST_PERSISTENT); diff --git a/ext/oci8/oci8_statement.c b/ext/oci8/oci8_statement.c index 56882cf908..520809c81d 100644 --- a/ext/oci8/oci8_statement.c +++ b/ext/oci8/oci8_statement.c @@ -928,19 +928,16 @@ int php_oci_bind_pre_exec(void *data, void *result TSRMLS_DC) } break; + case SQLT_CHR: + case SQLT_AFC: case SQLT_INT: case SQLT_NUM: - if (Z_TYPE_P(bind->zval) == IS_RESOURCE || Z_TYPE_P(bind->zval) == IS_OBJECT) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid variable used for bind"); - *(int *)result = 1; - } - break; - +#if defined(OCI_MAJOR_VERSION) && OCI_MAJOR_VERSION >= 12 + case SQLT_BOL: +#endif case SQLT_LBI: case SQLT_BIN: case SQLT_LNG: - case SQLT_AFC: - case SQLT_CHR: if (Z_TYPE_P(bind->zval) == IS_RESOURCE || Z_TYPE_P(bind->zval) == IS_OBJECT) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid variable used for bind"); *(int *)result = 1; @@ -955,7 +952,7 @@ int php_oci_bind_pre_exec(void *data, void *result TSRMLS_DC) break; } - /* reset all bind stuff to a normal state..-. */ + /* reset all bind stuff to a normal state... */ bind->indicator = 0; return 0; @@ -1185,6 +1182,20 @@ int php_oci_bind_by_name(php_oci_statement *statement, char *name, int name_len, } break; +#if defined(OCI_MAJOR_VERSION) && OCI_MAJOR_VERSION >= 12 + case SQLT_BOL: + if (Z_TYPE_P(var) == IS_RESOURCE || Z_TYPE_P(var) == IS_OBJECT) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid variable used for bind"); + return 1; + } + convert_to_boolean(var); + bind_data = (int *)&Z_LVAL_P(var); + value_sz = sizeof(int); + + mode = OCI_DEFAULT; + break; +#endif + default: php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown or unsupported datatype given: %d", (int)type); return 1; diff --git a/ext/oci8/package.xml b/ext/oci8/package.xml index 8e55b9abd5..d81d896f13 100644 --- a/ext/oci8/package.xml +++ b/ext/oci8/package.xml @@ -45,7 +45,7 @@ libraries are available. no - 2013-10-22 + 2014-02-10 @@ -58,7 +58,8 @@ libraries are available. PHP - Build change: Fix source variable definition for C89 compatibility +Added oci_bind_by_name() support for PL/SQL BOOLEAN type +Build change: Fix source variable definition for C89 compatibility @@ -91,6 +92,7 @@ libraries are available. + @@ -268,6 +270,8 @@ libraries are available. + + diff --git a/ext/oci8/php_oci8.h b/ext/oci8/php_oci8.h index 63924eca01..17061066d2 100644 --- a/ext/oci8/php_oci8.h +++ b/ext/oci8/php_oci8.h @@ -45,7 +45,7 @@ */ #undef PHP_OCI8_VERSION #endif -#define PHP_OCI8_VERSION "2.0.7-dev" +#define PHP_OCI8_VERSION "2.0.7" extern zend_module_entry oci8_module_entry; #define phpext_oci8_ptr &oci8_module_entry diff --git a/ext/oci8/tests/bind_boolean_1.phpt b/ext/oci8/tests/bind_boolean_1.phpt new file mode 100644 index 0000000000..49ac03c882 --- /dev/null +++ b/ext/oci8/tests/bind_boolean_1.phpt @@ -0,0 +1,138 @@ +--TEST-- +Basic PL/SQL "BOOLEAN" (SQLT_BOL) bind test +--SKIPIF-- += 12)) { + die("skip expected output only valid when using Oracle Database 12c or greater"); +} +preg_match('/^[[:digit:]]+/', oci_client_version(), $matches); +if (!(isset($matches[0]) && $matches[0] >= 12)) { + die("skip works only with Oracle 12c or greater version of Oracle client libraries"); +} +?> +--FILE-- + +===DONE=== + +--EXPECTF-- +Test 1 +bool(true) +bool(false) +Test 2 +bool(true) +Test 3 +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +Test 4 +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +bool(true) +Test 5 +bool(true) +bool(false) +bool(false) +bool(true) +===DONE=== diff --git a/ext/oci8/tests/error_bind_2.phpt b/ext/oci8/tests/error_bind_2.phpt new file mode 100644 index 0000000000..642716887e --- /dev/null +++ b/ext/oci8/tests/error_bind_2.phpt @@ -0,0 +1,63 @@ +--TEST-- +Test some more oci_bind_by_name error conditions +--SKIPIF-- + true, 'timesten' => true); // test runs on these DBs +require(dirname(__FILE__).'/skipif.inc'); +preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches); +if (!(isset($matches[0]) && $matches[1] >= 12)) { + die("skip expected output only valid when using Oracle Database 12c or greater"); +} +preg_match('/^[[:digit:]]+/', oci_client_version(), $matches); +if (!(isset($matches[0]) && $matches[0] >= 12)) { + die("skip works only with Oracle 12c or greater version of Oracle client libraries"); +} +?> +--FILE-- + +--EXPECTF-- +Test 1 - SQLT_BOL + +Warning: oci_execute(): Invalid variable used for bind in %s on line %d +bool(false) +Test 2 - SQLT_BOL + +Warning: oci_bind_by_name(): Invalid variable used for bind in %s on line %d +Done diff --git a/ext/oci8/tests/error_bind_3.phpt b/ext/oci8/tests/error_bind_3.phpt new file mode 100644 index 0000000000..7522dfe60a --- /dev/null +++ b/ext/oci8/tests/error_bind_3.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test some more oci_bind_by_name error conditions +--SKIPIF-- + true, 'timesten' => true); // test runs on these DBs +require(dirname(__FILE__).'/skipif.inc'); +preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches); +if (!(isset($matches[0]) && $matches[1] >= 12)) { + die("skip expected output only valid when using Oracle Database 12c or greater"); +} +preg_match('/^[[:digit:]]+/', oci_client_version(), $matches); +if (!(isset($matches[0]) && $matches[0] >= 12)) { + die("skip works only with Oracle 12c or greater version of Oracle client libraries"); +} +?> +--FILE-- + +--EXPECTF-- +Warning: oci_execute(): ORA-06550: line %d, column %d: +PLS-00382: %s +ORA-06550: line %d, column %d: +PL/SQL: %s +ORA-06550: line %d, column %d: +PLS-00382: %s +ORA-06550: line %d, column %d: +PL/SQL: %s in %s on line %d +bool(false) +bool(false) +Done