From f4009b52a31544ca188dd9679478f273e335de54 Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Fri, 10 Jun 2011 17:38:07 +0000 Subject: [PATCH] Add oci_client_version() returning the runtime Oracle client library version - predominantly useful for the test suite --- NEWS | 4 ++++ ext/oci8/oci8.c | 36 ++++++++++++++++++++++++++++ ext/oci8/oci8_interface.c | 11 +++++++++ ext/oci8/php_oci8_int.h | 1 + ext/oci8/tests/clientversion.phpt | 20 ++++++++++++++++ ext/oci8/tests/clientversion_92.phpt | 20 ++++++++++++++++ 6 files changed, 92 insertions(+) create mode 100644 ext/oci8/tests/clientversion.phpt create mode 100644 ext/oci8/tests/clientversion_92.phpt diff --git a/NEWS b/NEWS index 0d97408ff8..9093236001 100644 --- a/NEWS +++ b/NEWS @@ -125,6 +125,10 @@ PHP NEWS . Fixed bug #54992 (Stream not closed and error not returned when SSL CN_match fails). (Gustavo, laird_ngrps at dodo dot com dot au) +- Oracle Database extension (OCI8): + . Added oci_client_version() returning the runtime Oracle client library + version (Chris Jones) + - PDO extension: . Fixed bug #54929 (Parse error with single quote in sql comment). (Felipe) . Fixed bug #52104 (bindColumn creates Warning regardless of ATTR_ERRMODE diff --git a/ext/oci8/oci8.c b/ext/oci8/oci8.c index 6e8edf21c8..e1b0077c68 100644 --- a/ext/oci8/oci8.c +++ b/ext/oci8/oci8.c @@ -447,6 +447,9 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_oci_result, 0, 0, 2) ZEND_ARG_INFO(0, column_number_or_name) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO(arginfo_oci_client_version, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_oci_server_version, 0, 0, 1) ZEND_ARG_INFO(0, connection_resource) ZEND_END_ARG_INFO() @@ -681,6 +684,7 @@ static unsigned char arginfo_oci_bind_array_by_name[] = { 3, BYREF_NONE, BYREF_N #define arginfo_oci_password_change NULL #define arginfo_oci_new_cursor NULL #define arginfo_oci_result NULL +#define arginfo_oci_client_version NULL #define arginfo_oci_server_version NULL #define arginfo_oci_statement_type NULL #define arginfo_oci_num_rows NULL @@ -761,6 +765,7 @@ PHP_FUNCTION(oci_num_fields); PHP_FUNCTION(oci_parse); PHP_FUNCTION(oci_new_cursor); PHP_FUNCTION(oci_result); +PHP_FUNCTION(oci_client_version); PHP_FUNCTION(oci_server_version); PHP_FUNCTION(oci_statement_type); PHP_FUNCTION(oci_num_rows); @@ -836,6 +841,7 @@ zend_function_entry php_oci_functions[] = { PHP_FE(oci_parse, arginfo_oci_parse) PHP_FE(oci_new_cursor, arginfo_oci_new_cursor) PHP_FE(oci_result, arginfo_oci_result) + PHP_FE(oci_client_version, arginfo_oci_client_version) PHP_FE(oci_server_version, arginfo_oci_server_version) PHP_FE(oci_statement_type, arginfo_oci_statement_type) PHP_FE(oci_num_rows, arginfo_oci_num_rows) @@ -1295,6 +1301,7 @@ PHP_RSHUTDOWN_FUNCTION(oci) PHP_MINFO_FUNCTION(oci) { char buf[32]; + char *ver; php_info_print_table_start(); php_info_print_table_row(2, "OCI8 Support", "enabled"); @@ -1306,6 +1313,11 @@ PHP_MINFO_FUNCTION(oci) snprintf(buf, sizeof(buf), "%ld", OCI_G(num_links)); php_info_print_table_row(2, "Active Connections", buf); +#if ((OCI_MAJOR_VERSION > 10) || ((OCI_MAJOR_VERSION == 10) && (OCI_MINOR_VERSION >= 2))) + php_oci_client_get_version(&ver TSRMLS_DC); + php_info_print_table_row(2, "Oracle Run-time Client Library Version", ver); + efree(ver); +#endif #if defined(OCI_MAJOR_VERSION) && defined(OCI_MINOR_VERSION) snprintf(buf, sizeof(buf), "%d.%d", OCI_MAJOR_VERSION, OCI_MINOR_VERSION); #elif defined(PHP_OCI8_ORACLE_VERSION) @@ -2384,6 +2396,30 @@ int php_oci_password_change(php_oci_connection *connection, char *user, int user return 0; } /* }}} */ + +/* {{{ php_oci_client_get_version() + * + * Get Oracle client library version + */ +void php_oci_client_get_version(char **version TSRMLS_DC) +{ + char version_buff[256]; + sword major_version = 0; + sword minor_version = 0; + sword update_num = 0; + sword patch_num = 0; + sword port_update_num = 0; + +#if ((OCI_MAJOR_VERSION > 10) || ((OCI_MAJOR_VERSION == 10) && (OCI_MINOR_VERSION >= 2))) /* OCIClientVersion only available 10.2 onwards */ + PHP_OCI_CALL(OCIClientVersion, (&major_version, &minor_version, &update_num, &patch_num, &port_update_num)); + snprintf(version_buff, sizeof(version_buff), "%d.%d.%d.%d.%d", major_version, minor_version, update_num, patch_num, port_update_num); +#else + memcpy(version_buff, "Unknown", sizeof("Unknown")); +#endif + *version = estrdup(version_buff); +} /* }}} */ + + /* {{{ php_oci_server_get_version() * * Get Oracle server version diff --git a/ext/oci8/oci8_interface.c b/ext/oci8/oci8_interface.c index 954604bf2b..21ef7eae95 100644 --- a/ext/oci8/oci8_interface.c +++ b/ext/oci8/oci8_interface.c @@ -2002,6 +2002,17 @@ PHP_FUNCTION(oci_result) } /* }}} */ +/* {{{ proto string oci_client_version() + Return a string containing runtime client library version information */ +PHP_FUNCTION(oci_client_version) +{ + char *version = NULL; + + php_oci_client_get_version(&version TSRMLS_CC); + RETURN_STRING(version, 0); +} +/* }}} */ + /* {{{ proto string oci_server_version(resource connection) Return a string containing server version information */ PHP_FUNCTION(oci_server_version) diff --git a/ext/oci8/php_oci8_int.h b/ext/oci8/php_oci8_int.h index e65d2734c1..ba45260673 100644 --- a/ext/oci8/php_oci8_int.h +++ b/ext/oci8/php_oci8_int.h @@ -385,6 +385,7 @@ int php_oci_connection_commit(php_oci_connection * TSRMLS_DC); int php_oci_connection_release(php_oci_connection *connection TSRMLS_DC); int php_oci_password_change(php_oci_connection *, char *, int, char *, int, char *, int TSRMLS_DC); +void php_oci_client_get_version(char ** TSRMLS_DC); int php_oci_server_get_version(php_oci_connection *, char ** TSRMLS_DC); void php_oci_fetch_row(INTERNAL_FUNCTION_PARAMETERS, int, int); diff --git a/ext/oci8/tests/clientversion.phpt b/ext/oci8/tests/clientversion.phpt new file mode 100644 index 0000000000..db70b5affc --- /dev/null +++ b/ext/oci8/tests/clientversion.phpt @@ -0,0 +1,20 @@ +--TEST-- +oci_client_version() +--SKIPIF-- + +--FILE-- + +===DONE=== + +--EXPECTF-- +%d.%d.%d.%d.%d +===DONE=== diff --git a/ext/oci8/tests/clientversion_92.phpt b/ext/oci8/tests/clientversion_92.phpt new file mode 100644 index 0000000000..d4b92cd354 --- /dev/null +++ b/ext/oci8/tests/clientversion_92.phpt @@ -0,0 +1,20 @@ +--TEST-- +oci_client_version() for Oracle 9.2 client libraries +--SKIPIF-- + +--FILE-- + +===DONE=== + +--EXPECTF-- +Unknown +===DONE=== -- 2.40.0