]> granicus.if.org Git - php/commitdiff
Add oci_client_version() returning the runtime Oracle client library version - predom...
authorChristopher Jones <sixd@php.net>
Fri, 10 Jun 2011 17:38:07 +0000 (17:38 +0000)
committerChristopher Jones <sixd@php.net>
Fri, 10 Jun 2011 17:38:07 +0000 (17:38 +0000)
NEWS
ext/oci8/oci8.c
ext/oci8/oci8_interface.c
ext/oci8/php_oci8_int.h
ext/oci8/tests/clientversion.phpt [new file with mode: 0644]
ext/oci8/tests/clientversion_92.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 0d97408ff8ee67f1520c7a7b2972cc7fb8fbe06e..9093236001dfe8bcd7e0d19fc8b036871143f235 100644 (file)
--- 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 
index 6e8edf21c8ae94ce8e142156a482b311376d35be..e1b0077c68f9c3e0a50b0f6114b166ff3d4a9fbd 100644 (file)
@@ -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
index 954604bf2b2c7f61b32a96d3025855265d267884..21ef7eae959be34b83444a8380c6c94fe23d05da 100644 (file)
@@ -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)
index e65d2734c1ff8e20628d9d27251d1fcd3224a4b6..ba45260673f350c3d926ec57225e2a5dc828b45b 100644 (file)
@@ -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 (file)
index 0000000..db70b5a
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+oci_client_version()
+--SKIPIF--
+<?php
+if (!extension_loaded('oci8')) die("skip no oci8 extension");
+if (preg_match('/^1[012]\./', oci_client_version()) != 1) {
+    die("skip test expected to work only with Oracle 10g or greater version of client");
+}
+?>
+--FILE--
+<?php
+
+echo oci_client_version(), "\n";
+
+?>
+===DONE===
+<?php exit(0); ?>
+--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 (file)
index 0000000..d4b92cd
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+oci_client_version() for Oracle 9.2 client libraries
+--SKIPIF--
+<?php
+if (!extension_loaded('oci8')) die("skip no oci8 extension");
+if (preg_match('/Unknown/', oci_client_version()) != 1) {
+    die("skip test expected to work only with Oracle 9gR2 client libraries");
+}
+?>
+--FILE--
+<?php
+
+echo oci_client_version(), "\n";
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECTF--
+Unknown
+===DONE===