diff options
| author | Ondřej Surý <ondrej@sury.org> | 2010-03-09 11:57:54 +0100 |
|---|---|---|
| committer | Ondřej Surý <ondrej@sury.org> | 2010-03-09 11:57:54 +0100 |
| commit | 855a09f4eded707941180c9d90acd17c25e29447 (patch) | |
| tree | a40947efaa9876f31b6ee3956c3f3775768143bb /ext/oci8 | |
| parent | c852c28a88fccf6e34a2cb091fdfa72bce2b59c7 (diff) | |
| download | php-upstream/5.3.2.tar.gz | |
Imported Upstream version 5.3.2upstream/5.3.2
Diffstat (limited to 'ext/oci8')
71 files changed, 4557 insertions, 1303 deletions
diff --git a/ext/oci8/README b/ext/oci8/README index e725a30be..037d54952 100644 --- a/ext/oci8/README +++ b/ext/oci8/README @@ -1,454 +1,12 @@ -Installing OCI8 ---------------- +The OCI8 Extension +------------------ -0. Overview -1. Common requirements -2. Installing as a shared extension -3. Installing as a statically compiled extension -4. Installing from PECL to an existing PHP -5. Testing OCI8 -6. Oracle DRCP and FAN Support +The OCI8 extension allows PHP to access Oracle databases. It can be +built using Oracle 9.2, 10, or 11 client libraries. It allows Oracle's +standard cross-version connectivity, for example PHP using Oracle 10.2 +libraries can connect to Oracle Database 9.2 onwards. +This release of OCI8 can be used with PHP versions 4.3.9 to 5.x. -0. Overview ------------ - -The OCI8 extension allows you to access Oracle databases. It can be -built using Oracle 9.2, 10.2 or 11.1 client libraries, and allows -Oracle's standard cross-version connectivity. This release can be -used with PHP versions 4.3.9 to 5.x. - -The OCI8 extension is not related to, or used by, PDO_OCI, the PHP -Data Objects (PDO) extension for Oracle. - -1. Common requirements ----------------------- - -This version of PHP OCI8: - - - Will build with Oracle 9.2 (or more recent) client libraries. The - same (or more recent) version of Oracle libraries used when - building OCI8 must also be used at runtime. - - - Can be used with PHP versions 4.3.9 to 5.x. - -If you build PHP with the "ORACLE_HOME" Oracle database or full Oracle -client libraries: - - - you MUST set at least the ORACLE_HOME environment variable and - make it visible for your web server BEFORE it starts. - - - the Oracle software must be readable by the web server. With - Oracle 10.2, see the $ORACLE_HOME/install/changePerm.sh script - included in patch releases. - -If you build PHP with Oracle Instant Client libraries from -http://www.oracle.com/technology/tech/oci/instantclient/index.html - - - either the "basic" or "basic-lite" package is required. - - - the "devel" package is required. - - - you don't have to set ORACLE_HOME and many of the other - environment variables to build PHP with OCI8 support. - -For both ORACLE_HOME and Instant Client installs you may have to set: - - - LD_LIBRARY_PATH: it must include the $ORACLE_HOME/lib or Instant - Client library directory - - - NLS_LANG: if you want to change the default encoding used during - interaction with Oracle servers - -The most appropriate places to add the environment variables are: - - /etc/profile - /etc/profile.local - /etc/profile.d - - -2. Installing as a shared extension ------------------------------------ - -Configure OCI8 using one of the the following configure options: - - a) if you use an Oracle server or Oracle Client installation: - - ./configure --with-oci8=shared,$ORACLE_HOME - - b) with Oracle Instant Client: - - ./configure --with-oci8=shared,instantclient,/path/to/instant/client/lib - - If you use an RPM-based installation of Oracle Instant Client, - your configure line will look like this: - - ./configure --with-oci8=shared,instantclient,/usr/lib/oracle/<version>/client/lib - -Follow the usual building procedure, e.g. "make install". The OCI8 -shared extension oci8.so will be created. It may need to be manually -moved to the PHP extension directory, specified by the extension_dir -option in your php.ini file. - -Edit php.ini file and add the line: - - extension=oci8.so - - -3. Installing as a statically compiled extension ------------------------------------------------- - -Configure OCI8 using one of the the following configure options: - - a) with a common Oracle server or full Oracle client installation - - ./configure --with-oci8=$ORACLE_HOME - - b) with Oracle Instant Client - - ./configure --with-oci8=instantclient,/path/to/instant/client/lib - -Run "make install". - -After successful compile, you do not need to add oci8.so to php.ini. -The module will be usable without any additional actions. - - -4. Installing from PECL to an existing PHP ------------------------------------------- - -The OCI8 extension is also available as a PECL module on -http://pecl.php.net/package/oci8. - -Install using either (a) or (b) below. - - a) Do an automated download and install: - - Set PEARs proxy, if necessary: - - pear config-set http_proxy http://my-proxy.example.com:80/ - - Run - - pecl install oci8 - - When prompted, enter either the value of $ORACLE_HOME, or - "instantclient,/path/to/instant/client/lib" (without quotes). - - b) Alternatively, manually download the PECL package, e.g. oci8-1.3.5.tgz - - Extract the package: - - tar -zxf oci8-1.3.5.tgz - cd oci8-1.3.5 - - Prepare the package: - - phpize - - Configure the package, either using $ORACLE_HOME or Instant Client - - ./configure -with-oci8=shared,$ORACLE_HOME - - or - - ./configure -with-oci8=shared,instantclient,/path/to/instant/client/lib - - Install the package: - - make install - -After either install, edit your php.ini file, e.g. /etc/php.ini, and -add the line: - - extension=oci8.so - -Make sure php.ini's "extension_dir" includes the directory that -oci8.so was installed in. - - -5. Testing OCI8 ---------------- - -OCI8 tests are in ext/oci8/tests. When OCI8 tests are run this -directory will contain logs of any failures. - -5.1. Running OCI8 tests on Linux - -5.1.1. Edit ext/oci8/tests/details.inc - - Set the username, password and connection string for the database. - Most tests have been developed using the SYSTEM account: some tests - might fail unless the user has permissions to create necessary - tables, views, procedures etc. - - If the database is on the same machine as PHP, set - $oracle_on_localhost to TRUE. - - If Oracle 11g Database Resident Connection Pooling is being tested, - set $test_drcp to TRUE and ensure the connection string uses an - appropriate pooled server (see section 6.2.2). - - An alternative to editing details.inc is the set the environment - variables - - PHP_OCI8_TEST_USER - PHP_OCI8_TEST_PASS - PHP_OCI8_TEST_DB - PHP_OCI8_TEST_DB_ON_LOCALHOST - PHP_OCI8_TEST_DRCP - - for example: - - $ export PHP_OCI8_TEST_USER=system - $ export PHP_OCI8_TEST_PASS=oracle - $ export PHP_OCI8_TEST_DB=localhost/XE - $ export PHP_OCI8_TEST_DB_ON_LOCALHOST=TRUE - $ export PHP_OCI8_TEST_DRCP=FALSE - -5.1.2. Set any necessary environment variables for the Oracle - database. With Oracle 10g XE do: - - $ . /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/oracle_env.sh - - For other versions of the Oracle database do: - - $ . /usr/local/bin/oraenv - -5.1.3. Check your php.ini has E in the variables_order parameter, for - example: - - variables_order = "EGPCS" - -5.1.4. Run the tests: - - $ cd <your php src directory> - $ make test TESTS=ext/oci8 - -5.2. The tests execute rapidly. On fast machines with a local - database configured for light load (e.g. Oracle 10g XE) you might - see random tests fail with ORA-12516 or ORA-12520 errors. To - prevent this, increase the database PROCESSES parameter using the - following steps. - -5.2.1. Connect as the oracle software owner: - - $ su - oracle - -5.2.2. Set the necessary environment variables as in 5.1.2. - -5.2.3. Start the SQL*Plus command line tool and increase PROCESSES - - $ sqlplus / as sysdba - SQL> alter system set processes=100 scope=spfile - -5.2.4. Restart the database: - - SQL> startup force - - -6. Oracle DRCP and FAN Support ------------------------------- - -The PHP OCI8 extension has support for the Oracle Database Resident -Connection Pool (DRCP) and Fast Application Notification (FAN). - -Questions and issues can be raised on the Oracle OTN forum (free -registration required): -http://www.oracle.com/technology/forums/php.html - - -6.1. Oracle Version Compatibility - -The OCI8 extension will compile with Oracle libraries from version -9iR2 onwards. However, full functionality (e.g. DRCP support) is only -available when Oracle 11g is used. - -For general database functionality the version of the Oracle libraries -used by PHP does not necessarily have to match the version of the -database. - - -6.2. Database Resident Connection Pooling (DRCP) - -DRCP allows more efficient use of database machine memory and provides -high scalability. - -For DRCP to be available in OCI8, Oracle client libraries used by PHP -and the version of the Oracle Database must both be 11g. - -Documentation on DRCP is found in several Oracle manuals. For example, -see "Configuring Database Resident Connection Pooling" in the Oracle -Database Administrator's Guide 11g Release 1 (11.1) -http://download.oracle.com/docs/cd/B28359_01/server.111/b28310/manproc004.htm#CHDGIDBA -for usage information. A whitepaper -http://www.oracle.com/technology/tech/oci/pdf/oracledrcp11g.pdf -contains background information on DRCP. - -After building PHP with the OCI8 extension and 11g libraries, follow -these steps: - -6.2.0 Important: if Oracle Database 11.1.0.6 with DRCP connections is - used, then the Oracle database patch for bug 6474441 must be - applied (see section 6.5). Without this patch, "ORA-01000: - maximum open cursors exceeded", "ORA-01001 invalid cursor" or - "ORA-01002 fetch out of sequence" errors may occur. - - If the Oracle 11.1.0.6 database patch cannot be applied, one of - the following three workarounds can be used to disable statement - caching instead: - - (i) Connect using Oracle dedicated or shared servers instead of DRCP. - - (ii) Set PHP's oci8.statement_cache_size to 0. - - (iii) Set an event in the database initialization parameter file: - event="56699 trace name context forever, level 128". - - -6.2.1. As a privileged database administrator, use a program like - SQL*Plus to start the connection pool in the database: - - SQL> execute dbms_connection_pool.start_pool; - - Optional settings control the size and characteristics of the - pool. - -6.2.2. For PHP applications that currently connect using a Network Alias - like: - - $c = oci_pconnect("myuser", "mypassword", "MYDB"); - - Modify your tnsnames.ora file and add the "(SERVER=POOLED)" - clause, for example: - - MYDB = (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp) (HOST=myhost.dom.com) - (PORT=1521))(CONNECT_DATA=(SERVICE_NAME=sales) - (SERVER=POOLED))) - - Alternatively, modify the Easy Connect syntax in PHP and add - ":POOLED" after the service name: - - $c = oci_pconnect("myuser", "mypassword", - "myhost.dom.com:1521/sales:POOLED"); - -6.2.3. Edit php.ini and choose a connection class name. This name - indicates a logical division of the connection pool and can be - used to isolate pooling for separate applications. Any PHP - instance with the same connection class value will share - connections in the pool. - - oci8.connection_class = "MY_APPLICATION_NAME" - -6.2.4. Run your application, connecting to the 11g database. - - -6.3. Fast Application Notification (FAN) Support - -FAN support gives fast connection failover, a high availability -feature. This allows PHP OCI8 scripts to be notified when a database -machine or database instance becomes unavailable. Without FAN, OCI8 -can hang until a TCP timeout occurs and an error is returned, which -might be several minutes. Enabling FAN in OCI8 can allow your -applications to detect errors and re-connect to an available database -instance without the web user being aware of an outage. - -FAN support is available when the Oracle client libraries that PHP -links with and the Oracle Database are either version 10gR2 or 11g. - -FAN benefits users of Oracle's clustering technology (RAC) because -connections to surviving database instances can be immediately made. -Users of Oracle's Data Guard with a broker will see the FAN events -generated when the standby database goes online. Standalone databases -will send FAN events when the database restarts. - -For active connections, when a machine or database instance becomes -unavailable, a connection failure error will be returned by the OCI8 -extension function currently being called. On a subsequent PHP script -re-connect, a connection to a surviving database instance will be -established. The OCI8 extension also transparently cleans up any idle -connections affected by a database machine or instance failure so PHP -connect calls will establish a fresh connection without the script -being aware of any service disruption. - -When oci8.events is On, it is suggested to set oci8.ping_interval to --1 to disable pinging, since enabling FAN events provide pro-active -connection management of idle connections made invalid by a service -disruption. - -To enable FAN support in PHP, after building PHP with Oracle 10gR2 or -11g libraries follow these steps: - -6.3.1. As a privileged database administrator, use a program like - SQL*Plus to enable the database service to post FAN events, for - example: - - SQL> execute dbms_service.modify_service( - SERVICE_NAME => 'sales', - AQ_HA_NOTIFICATIONS => TRUE); - -6.3.2. Edit php.ini and add - - oci8.events = On - -6.3.3. If your application does not already handle OCI8 error - conditions, modify it to detect failures and take appropriate - action. This may include re-connecting and re-executing - statements. - -6.3.4. Run your application, connecting to a 10gR2 or 11g database. - - -6.4. Recommendations and Known Limitations - -6.4.1 Changing Password for DRCP connections - -Changing a password over DRCP connections will fail with the error -"ORA-56609: Usage not supported with DRCP". This is an documented -restriction of Oracle Database 11g. - -6.4.2 Closing Connections - -With the PHP OCI8 extension, persistent connections can now be closed -by the user, allowing greater control over connection resource usage. -Persistent connections will now also be closed automatically when -there is no PHP variable referencing them, such as at the end of scope -of a PHP user function. This will rollback any uncommitted -transaction. These changes to persistent connections make them behave -similarly to non-persistent connections, simplifying the interface, -allowing for greater application consistency and predictability. Use -oci8.old_oci_close_semantics=1 to retain the historical behavior. - -6.4.3 LOGON Triggers can be used to set session properties - -The patch for Oracle Database 11.1.0.6 bug 6474441 (see section 6.5) -allows PHP applications with DRCP connection to use a database LOGON -trigger to set session properties at the time of session creation. -Examples of such settings are the NLS language and the date format. - -If the Oracle 11.1.0.6 database patch cannot be applied, one of the -following workarounds can be used: - -(i) After logon, explicitly set the session properties using PHP -application code. - -(ii) Connect using Oracle dedicated or shared servers instead of DRCP. - -With DRCP there is an connection management relationship between (i) -DRCP's automatic pool expansion and reduction, (ii) PHP's persistent -connection caching, (iii) with the way LOGON triggers fire with DRCP -authentication. Because of this interplay, LOGON triggers in PHP -(when DRCP is used) are only recommended for setting session -attributes and not for per-PHP connection events. - - -6.5. Patching Oracle Database 11g - -The patch for bug 6474441 is available from Oracle Support's Metalink -system. - -The bug is specific to Oracle 11.1.0.6 with DRCP connections. The -issues it fixes do not affect connections using Oracle's dedicated -(the default connection mode) or shared servers. They do not affect -earlier versions of Oracle. The bug is intended to be fixed in Oracle -Database 11.1.0.7 (as yet unreleased). +OCI8 installation instructions and documentation is available at +http://www.php.net/oci8 diff --git a/ext/oci8/oci8.c b/ext/oci8/oci8.c index ec0ebdf70..589b5fd67 100644 --- a/ext/oci8/oci8.c +++ b/ext/oci8/oci8.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | + | Copyright (c) 1997-2010 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -26,7 +26,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: oci8.c 289423 2009-10-09 14:44:43Z pajoye $ */ +/* $Id: oci8.c 294447 2010-02-03 20:08:42Z pajoye $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -91,7 +91,7 @@ zend_class_entry *oci_coll_class_entry_ptr; #define SQLT_CFILEE 115 #endif -#define PHP_OCI_ERRBUF_LEN 512 +#define PHP_OCI_ERRBUF_LEN 1024 #if ZEND_MODULE_API_NO > 20020429 #define ONUPDATELONGFUNC OnUpdateLong @@ -407,6 +407,30 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_oci_set_prefetch, 0, 0, 2) ZEND_ARG_INFO(0, number_of_rows) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_oci_set_client_identifier, 0, 0, 2) + ZEND_ARG_INFO(0, connection_resource) + ZEND_ARG_INFO(0, client_identifier) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_oci_set_edition, 0, 0, 1) + ZEND_ARG_INFO(0, edition_name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_oci_set_module_name, 0, 0, 2) + ZEND_ARG_INFO(0, connection_resource) + ZEND_ARG_INFO(0, module_name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_oci_set_action, 0, 0, 2) + ZEND_ARG_INFO(0, connection_resource) + ZEND_ARG_INFO(0, action) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_oci_set_client_info, 0, 0, 2) + ZEND_ARG_INFO(0, connection_resource) + ZEND_ARG_INFO(0, client_information) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_oci_password_change, 0, 0, 4) ZEND_ARG_INFO(0, connection_resource_or_connection_string) ZEND_ARG_INFO(0, username) @@ -649,6 +673,11 @@ static unsigned char arginfo_oci_bind_array_by_name[] = { 3, BYREF_NONE, BYREF_N #define arginfo_oci_num_fields NULL #define arginfo_oci_parse NULL #define arginfo_oci_set_prefetch NULL +#define arginfo_oci_set_client_identifier NULL +#define arginfo_oci_set_edition NULL +#define arginfo_oci_set_module_name NULL +#define arginfo_oci_set_action NULL +#define arginfo_oci_set_client_info NULL #define arginfo_oci_password_change NULL #define arginfo_oci_new_cursor NULL #define arginfo_oci_result NULL @@ -736,6 +765,11 @@ PHP_FUNCTION(oci_server_version); PHP_FUNCTION(oci_statement_type); PHP_FUNCTION(oci_num_rows); PHP_FUNCTION(oci_set_prefetch); +PHP_FUNCTION(oci_set_client_identifier); +PHP_FUNCTION(oci_set_edition); +PHP_FUNCTION(oci_set_module_name); +PHP_FUNCTION(oci_set_action); +PHP_FUNCTION(oci_set_client_info); PHP_FUNCTION(oci_password_change); PHP_FUNCTION(oci_lob_save); PHP_FUNCTION(oci_lob_import); @@ -834,6 +868,11 @@ zend_function_entry php_oci_functions[] = { PHP_FE(oci_rollback, arginfo_oci_rollback) PHP_FE(oci_new_descriptor, arginfo_oci_new_descriptor) PHP_FE(oci_set_prefetch, arginfo_oci_set_prefetch) + PHP_FE(oci_set_client_identifier, arginfo_oci_set_client_identifier) + PHP_FE(oci_set_edition, arginfo_oci_set_edition) + PHP_FE(oci_set_module_name, arginfo_oci_set_module_name) + PHP_FE(oci_set_action, arginfo_oci_set_action) + PHP_FE(oci_set_client_info, arginfo_oci_set_client_info) PHP_FE(oci_password_change, arginfo_oci_password_change) PHP_FE(oci_free_collection, arginfo_oci_free_collection) PHP_FE(oci_collection_append, arginfo_oci_collection_append) @@ -1128,6 +1167,7 @@ PHP_MINIT_FUNCTION(oci) REGISTER_LONG_CONSTANT("OCI_CRED_EXT",PHP_OCI_CRED_EXT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_DESCRIBE_ONLY",OCI_DESCRIBE_ONLY, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_COMMIT_ON_SUCCESS",OCI_COMMIT_ON_SUCCESS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("OCI_NO_AUTO_COMMIT",OCI_DEFAULT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_EXACT_FETCH",OCI_EXACT_FETCH, CONST_CS | CONST_PERSISTENT); /* for $LOB->seek() */ @@ -1210,6 +1250,7 @@ PHP_RINIT_FUNCTION(oci) OCI_G(debug_mode) = 0; /* start "fresh" */ OCI_G(num_links) = OCI_G(num_persistent); OCI_G(errcode) = 0; + OCI_G(edition) = NULL; return SUCCESS; } @@ -1238,6 +1279,10 @@ PHP_RSHUTDOWN_FUNCTION(oci) */ zend_hash_apply(&EG(persistent_list), (apply_func_t) php_oci_persistent_helper TSRMLS_CC); + if (OCI_G(edition)) { + efree(OCI_G(edition)); + } + return SUCCESS; } @@ -1248,7 +1293,7 @@ PHP_MINFO_FUNCTION(oci) php_info_print_table_start(); php_info_print_table_row(2, "OCI8 Support", "enabled"); php_info_print_table_row(2, "Version", PHP_OCI8_VERSION); - php_info_print_table_row(2, "Revision", "$Revision: 289423 $"); + php_info_print_table_row(2, "Revision", "$Revision: 294447 $"); snprintf(buf, sizeof(buf), "%ld", OCI_G(num_persistent)); php_info_print_table_row(2, "Active Persistent Connections", buf); @@ -1485,23 +1530,21 @@ void php_oci_descriptor_flush_hash_dtor(void *data) } /* }}} */ -/* {{{ php_oci_descriptor_delete_from_hash() +/* }}} */ + +/* {{{ php_oci_connection_descriptors_free() * - * Delete descriptor from the hash + * Free descriptors for a connection */ -int php_oci_descriptor_delete_from_hash(void *data, void *id TSRMLS_DC) +void php_oci_connection_descriptors_free(php_oci_connection *connection TSRMLS_DC) { - php_oci_descriptor *descriptor = *(php_oci_descriptor **)data; - int *desc_id = (int *) id; - - if (descriptor && desc_id && descriptor->id == *desc_id) { - return 1; - } - return 0; + zend_hash_destroy(connection->descriptors); + efree(connection->descriptors); + connection->descriptors = NULL; + connection->descriptor_count = 0; } /* }}} */ -/* }}} */ /* {{{ php_oci_error() * @@ -1571,8 +1614,6 @@ sb4 php_oci_fetch_errmsg(OCIError *error_handle, text **error_buf TSRMLS_DC) sb4 error_code = 0; text err_buf[PHP_OCI_ERRBUF_LEN]; - err_buf[0] = '\0'; - memset(err_buf, 0, sizeof(err_buf)); PHP_OCI_CALL(OCIErrorGet, (error_handle, (ub4)1, NULL, &error_code, err_buf, (ub4)PHP_OCI_ERRBUF_LEN, (ub4)OCI_HTYPE_ERROR)); @@ -1735,6 +1776,12 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char } smart_str_appendl_ex(&hashed_details, "**", sizeof("**") - 1, 0); + /* Add edition attribute to the hash */ + if (OCI_G(edition)){ + smart_str_appendl_ex(&hashed_details, OCI_G(edition), strlen(OCI_G(edition)), 0); + } + smart_str_appendl_ex(&hashed_details, "**", sizeof("**") - 1, 0); + if (password_len) { ulong password_hash; password_hash = zend_inline_hash_func(password, password_len); @@ -2220,9 +2267,7 @@ int php_oci_connection_release(php_oci_connection *connection TSRMLS_DC) } if (connection->descriptors) { - zend_hash_destroy(connection->descriptors); - efree(connection->descriptors); - connection->descriptors = NULL; + php_oci_connection_descriptors_free(connection TSRMLS_CC); } if (connection->svc) { @@ -2555,6 +2600,7 @@ static php_oci_spool *php_oci_create_spool(char *username, int username_len, cha php_oci_spool *session_pool = NULL; zend_bool iserror = 0; ub4 poolmode = OCI_DEFAULT; /* Mode to be passed to OCISessionPoolCreate */ + OCIAuthInfo *spoolAuth = NULL; /*Allocate sessionpool out of persistent memory */ session_pool = (php_oci_spool *) calloc(1, sizeof(php_oci_spool)); @@ -2598,6 +2644,46 @@ static php_oci_spool *php_oci_create_spool(char *username, int username_len, cha poolmode = OCI_SPC_HOMOGENEOUS; #endif +#if ((OCI_MAJOR_VERSION > 11) || ((OCI_MAJOR_VERSION == 11) && (OCI_MINOR_VERSION >= 2))) + /* Allocate auth handle for session pool {{{ */ + PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIHandleAlloc, (session_pool->env, (dvoid **)&(spoolAuth), OCI_HTYPE_AUTHINFO, 0, NULL)); + + if (OCI_G(errcode) != OCI_SUCCESS) { + php_oci_error(OCI_G(err), OCI_G(errcode) TSRMLS_CC); + iserror = 1; + goto exit_create_spool; + } /* }}} */ + + /* Set the edition attribute on the auth handle {{{ */ + if (OCI_G(edition)) { + PHP_OCI_CALL_RETURN(OCI_G(errcode),OCIAttrSet, ((dvoid *) spoolAuth, (ub4) OCI_HTYPE_AUTHINFO, (dvoid *) OCI_G(edition), (ub4)(strlen(OCI_G(edition))), (ub4)OCI_ATTR_EDITION, OCI_G(err))); + + if (OCI_G(errcode) != OCI_SUCCESS) { + php_oci_error(OCI_G(err), OCI_G(errcode) TSRMLS_CC); + iserror = 1; + goto exit_create_spool; + } + } /* }}} */ + + /* Set the driver name attribute on the auth handle {{{ */ + PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIAttrSet, ((dvoid *) spoolAuth, (ub4) OCI_HTYPE_AUTHINFO, (dvoid *) PHP_OCI8_DRIVER_NAME, (ub4) sizeof(PHP_OCI8_DRIVER_NAME)-1, (ub4) OCI_ATTR_DRIVER_NAME, OCI_G(err))); + + if (OCI_G(errcode) != OCI_SUCCESS) { + php_oci_error(OCI_G(err), OCI_G(errcode) TSRMLS_CC); + iserror = 1; + goto exit_create_spool; + } /* }}} */ + + /* Set the auth handle on the session pool {{{ */ + PHP_OCI_CALL_RETURN(OCI_G(errcode),OCIAttrSet, ((dvoid *) (session_pool->poolh),(ub4) OCI_HTYPE_SPOOL, (dvoid *) spoolAuth, (ub4)0, (ub4)OCI_ATTR_SPOOL_AUTH, OCI_G(err))); + + if (OCI_G(errcode) != OCI_SUCCESS) { + php_oci_error(OCI_G(err), OCI_G(errcode) TSRMLS_CC); + iserror = 1; + goto exit_create_spool; + } /* }}} */ +#endif + /* Create the homogeneous session pool - We have different session pools for every different * username, password, charset and dbname. */ @@ -2628,6 +2714,10 @@ exit_create_spool: session_pool = NULL; } + if (spoolAuth) { + PHP_OCI_CALL(OCIHandleFree, ((dvoid *) spoolAuth, (ub4) OCI_HTYPE_AUTHINFO)); + } + if (OCI_G(debug_mode)) { php_printf ("OCI8 DEBUG L1: create_spool: (%p) at (%s:%d) \n", session_pool, __FILE__, __LINE__); } @@ -2652,6 +2742,11 @@ static php_oci_spool *php_oci_get_spool(char *username, int username_len, char * smart_str_appendl_ex(&spool_hashed_details, "oci8spool***", sizeof("oci8spool***") - 1, 0); smart_str_appendl_ex(&spool_hashed_details, username, username_len, 0); smart_str_appendl_ex(&spool_hashed_details, "**", sizeof("**") - 1, 0); + /* Add edition attribute to the hash */ + if (OCI_G(edition)){ + smart_str_appendl_ex(&spool_hashed_details, OCI_G(edition), strlen(OCI_G(edition)), 0); + } + smart_str_appendl_ex(&spool_hashed_details, "**", sizeof("**") - 1, 0); if (password_len) { ulong password_hash; password_hash = zend_inline_hash_func(password, password_len); @@ -2666,7 +2761,7 @@ static php_oci_spool *php_oci_get_spool(char *username, int username_len, char * smart_str_append_unsigned_ex(&spool_hashed_details, charsetid, 0); - /* Session Pool Hash Key : oci8spool***username**hashedpassword**dbname**charset */ + /* Session Pool Hash Key : oci8spool***username**edition**hashedpassword**dbname**charset */ smart_str_0(&spool_hashed_details); php_strtolower(spool_hashed_details.c, spool_hashed_details.len); @@ -2803,6 +2898,28 @@ static int php_oci_old_create_session(php_oci_connection *connection, char *dbna } }/* }}} */ + /* Set the edition attribute on the session handle {{{ */ +#if ((OCI_MAJOR_VERSION > 11) || ((OCI_MAJOR_VERSION == 11) && (OCI_MINOR_VERSION >= 2))) + if (OCI_G(edition)) { + PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIAttrSet, ((dvoid *) connection->session, (ub4) OCI_HTYPE_SESSION, (dvoid *) OCI_G(edition), (ub4) (strlen(OCI_G(edition))), (ub4) OCI_ATTR_EDITION, OCI_G(err))); + + if (OCI_G(errcode) != OCI_SUCCESS) { + php_oci_error(OCI_G(err), OCI_G(errcode) TSRMLS_CC); + return 1; + } + } +#endif /* }}} */ + + /* Set the driver name attribute on the session handle {{{ */ +#if (OCI_MAJOR_VERSION >= 11) + PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIAttrSet, ((dvoid *) connection->session, (ub4) OCI_HTYPE_SESSION, (dvoid *) PHP_OCI8_DRIVER_NAME, (ub4) sizeof(PHP_OCI8_DRIVER_NAME)-1, (ub4) OCI_ATTR_DRIVER_NAME, OCI_G(err))); + + if (OCI_G(errcode) != OCI_SUCCESS) { + php_oci_error(OCI_G(err), OCI_G(errcode) TSRMLS_CC); + return 1; + } +#endif /* }}} */ + /* Set the server handle in the service handle {{{ */ PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIAttrSet, (connection->svc, OCI_HTYPE_SVCCTX, connection->server, 0, OCI_ATTR_SERVER, OCI_G(err))); diff --git a/ext/oci8/oci8_collection.c b/ext/oci8/oci8_collection.c index 7e514df73..a06b61bad 100644 --- a/ext/oci8/oci8_collection.c +++ b/ext/oci8/oci8_collection.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | + | Copyright (c) 1997-2010 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -25,7 +25,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: oci8_collection.c 272370 2008-12-31 11:15:49Z sebastian $ */ +/* $Id: oci8_collection.c 293036 2010-01-03 09:23:27Z sebastian $ */ diff --git a/ext/oci8/oci8_interface.c b/ext/oci8/oci8_interface.c index b5ed50187..1c20b84a8 100644 --- a/ext/oci8/oci8_interface.c +++ b/ext/oci8/oci8_interface.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | + | Copyright (c) 1997-2010 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -25,7 +25,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: oci8_interface.c 276933 2009-03-09 20:20:07Z sixd $ */ +/* $Id: oci8_interface.c 294441 2010-02-03 19:37:35Z pajoye $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -1066,9 +1066,7 @@ PHP_FUNCTION(oci_rollback) PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection); if (connection->descriptors) { - zend_hash_destroy(connection->descriptors); - efree(connection->descriptors); - connection->descriptors = NULL; + php_oci_connection_descriptors_free(connection TSRMLS_CC); } if (php_oci_connection_rollback(connection TSRMLS_CC)) { @@ -1092,9 +1090,7 @@ PHP_FUNCTION(oci_commit) PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection); if (connection->descriptors) { - zend_hash_destroy(connection->descriptors); - efree(connection->descriptors); - connection->descriptors = NULL; + php_oci_connection_descriptors_free(connection TSRMLS_CC); } if (php_oci_connection_commit(connection TSRMLS_CC)) { @@ -1584,7 +1580,7 @@ PHP_FUNCTION(oci_pconnect) Return the last error of stmt|connection|global. If no error happened returns false. */ PHP_FUNCTION(oci_error) { - zval *arg; + zval *arg = NULL; php_oci_statement *statement; php_oci_connection *connection; text *errbuf; @@ -1716,12 +1712,162 @@ PHP_FUNCTION(oci_set_prefetch) } /* }}} */ +/* {{{ proto bool oci_set_client_identifier(resource connection, string value) + Sets the client identifier attribute on the connection */ +PHP_FUNCTION(oci_set_client_identifier) +{ + zval *z_connection; + php_oci_connection *connection; + char *client_id; + long client_id_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_connection, &client_id, &client_id_len) == FAILURE) { + return; + } + + PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection); + + PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIAttrSet, ((dvoid *) connection->session, (ub4) OCI_HTYPE_SESSION, (dvoid *) client_id, (ub4) client_id_len, (ub4) OCI_ATTR_CLIENT_IDENTIFIER, OCI_G(err))); + + if (OCI_G(errcode) != OCI_SUCCESS) { + php_oci_error(OCI_G(err), OCI_G(errcode) TSRMLS_CC); + RETURN_FALSE; + } + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto bool oci_set_edition(string value) + Sets the edition attribute for all subsequent connections created */ +PHP_FUNCTION(oci_set_edition) +{ +#if ((OCI_MAJOR_VERSION > 11) || ((OCI_MAJOR_VERSION == 11) && (OCI_MINOR_VERSION >= 2))) + char *edition; + long edition_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &edition, &edition_len) == FAILURE) { + return; + } + + if (OCI_G(edition)) { + efree(OCI_G(edition)); + OCI_G(edition) = NULL; + } + + if (edition) { + OCI_G(edition) = (char *)safe_emalloc(edition_len+1, sizeof(text), 0); + memcpy(OCI_G(edition), edition, edition_len); + OCI_G(edition)[edition_len] = '\0'; + } + + RETURN_TRUE; +#else + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unsupported attribute type"); + RETURN_FALSE; +#endif +} +/* }}} */ + +/* {{{ proto bool oci_set_module_name(resource connection, string value) + Sets the module attribute on the connection */ +PHP_FUNCTION(oci_set_module_name) +{ +#if (OCI_MAJOR_VERSION >= 10) + zval *z_connection; + php_oci_connection *connection; + char *module; + long module_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_connection, &module, &module_len) == FAILURE) { + return; + } + + PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection); + + PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIAttrSet, ((dvoid *) connection->session, (ub4) OCI_HTYPE_SESSION, (dvoid *) module, (ub4) module_len, (ub4) OCI_ATTR_MODULE, OCI_G(err))); + + if (OCI_G(errcode) != OCI_SUCCESS) { + php_oci_error(OCI_G(err), OCI_G(errcode) TSRMLS_CC); + RETURN_FALSE; + } + + RETURN_TRUE; +#else + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unsupported attribute type"); + RETURN_FALSE; +#endif +} +/* }}} */ + +/* {{{ proto bool oci_set_action(resource connection, string value) + Sets the action attribute on the connection */ +PHP_FUNCTION(oci_set_action) +{ +#if (OCI_MAJOR_VERSION >= 10) + zval *z_connection; + php_oci_connection *connection; + char *action; + long action_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_connection, &action, &action_len) == FAILURE) { + return; + } + + PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection); + + PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIAttrSet, ((dvoid *) connection->session, (ub4) OCI_HTYPE_SESSION, (dvoid *) action, (ub4) action_len, (ub4) OCI_ATTR_ACTION, OCI_G(err))); + + if (OCI_G(errcode) != OCI_SUCCESS) { + php_oci_error(OCI_G(err), OCI_G(errcode) TSRMLS_CC); + RETURN_FALSE; + } + + RETURN_TRUE; +#else + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unsupported attribute type"); + RETURN_FALSE; +#endif +} +/* }}} */ + +/* {{{ proto bool oci_set_client_info(resource connection, string value) + Sets the client info attribute on the connection */ +PHP_FUNCTION(oci_set_client_info) +{ +#if (OCI_MAJOR_VERSION >= 10) + zval *z_connection; + php_oci_connection *connection; + char *client_info; + long client_info_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_connection, &client_info, &client_info_len) == FAILURE) { + return; + } + + PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection); + + PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIAttrSet, ((dvoid *) connection->session, (ub4) OCI_HTYPE_SESSION, (dvoid *) client_info, (ub4) client_info_len, (ub4) OCI_ATTR_CLIENT_INFO, OCI_G(err))); + + if (OCI_G(errcode) != OCI_SUCCESS) { + php_oci_error(OCI_G(err), OCI_G(errcode) TSRMLS_CC); + RETURN_FALSE; + } + + RETURN_TRUE; +#else + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unsupported attribute type"); + RETURN_FALSE; +#endif +} +/* }}} */ + /* {{{ proto bool oci_password_change(resource connection, string username, string old_password, string new_password) Changes the password of an account */ PHP_FUNCTION(oci_password_change) { zval *z_connection; - text *user, *pass_old, *pass_new, *dbname; + char *user, *pass_old, *pass_new, *dbname; int user_len, pass_old_len, pass_new_len, dbname_len; php_oci_connection *connection; @@ -1747,7 +1893,7 @@ PHP_FUNCTION(oci_password_change) RETURN_FALSE; } - if (php_oci_password_change(connection, (char *)user, user_len, (char *)pass_old, pass_old_len, (char *)pass_new, pass_new_len TSRMLS_CC)) { + if (php_oci_password_change(connection, user, user_len, pass_old, pass_old_len, pass_new, pass_new_len TSRMLS_CC)) { RETURN_FALSE; } RETURN_TRUE; @@ -1766,7 +1912,7 @@ PHP_FUNCTION(oci_password_change) RETURN_FALSE; } - connection = php_oci_do_connect_ex((char *)user, user_len, (char *)pass_old, pass_old_len, (char *)pass_new, pass_new_len, (char *)dbname, dbname_len, NULL, OCI_DEFAULT, 0, 0 TSRMLS_CC); + connection = php_oci_do_connect_ex(user, user_len, pass_old, pass_old_len, pass_new, pass_new_len, dbname, dbname_len, NULL, OCI_DEFAULT, 0, 0 TSRMLS_CC); if (!connection) { RETURN_FALSE; } diff --git a/ext/oci8/oci8_lob.c b/ext/oci8/oci8_lob.c index 521174029..6388e85b7 100644 --- a/ext/oci8/oci8_lob.c +++ b/ext/oci8/oci8_lob.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | + | Copyright (c) 1997-2010 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -25,7 +25,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: oci8_lob.c 272370 2008-12-31 11:15:49Z sebastian $ */ +/* $Id: oci8_lob.c 294441 2010-02-03 19:37:35Z pajoye $ */ @@ -95,9 +95,17 @@ php_oci_descriptor *php_oci_lob_create (php_oci_connection *connection, long typ if (!connection->descriptors) { ALLOC_HASHTABLE(connection->descriptors); zend_hash_init(connection->descriptors, 0, NULL, php_oci_descriptor_flush_hash_dtor, 0); + connection->descriptor_count = 0; + } + + descriptor->index = (connection->descriptor_count)++; + if (connection->descriptor_count == LONG_MAX) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Internal descriptor counter has reached limit"); + php_oci_connection_descriptors_free(connection TSRMLS_CC); + return NULL; } - zend_hash_next_index_insert(connection->descriptors,&descriptor,sizeof(php_oci_descriptor *),NULL); + zend_hash_index_update(connection->descriptors,descriptor->index,&descriptor,sizeof(php_oci_descriptor *),NULL); } return descriptor; @@ -669,7 +677,25 @@ void php_oci_lob_free (php_oci_descriptor *descriptor TSRMLS_DC) if (descriptor->connection->descriptors) { /* delete descriptor from the hash */ - zend_hash_apply_with_argument(descriptor->connection->descriptors, php_oci_descriptor_delete_from_hash, (void *)&descriptor->id TSRMLS_CC); + zend_hash_index_del(descriptor->connection->descriptors, descriptor->index); + if (zend_hash_num_elements(descriptor->connection->descriptors) == 0) { + descriptor->connection->descriptor_count = 0; + } else { + if (descriptor->index + 1 == descriptor->connection->descriptor_count) { + /* If the descriptor being freed is the end-most one + * allocated, then the descriptor_count is reduced so + * a future descriptor can reuse the hash table index. + * This can prevent the hash index range increasing in + * the common case that each descriptor is + * allocated/used/freed before another descriptor is + * needed. However it is possible that a script frees + * descriptors in arbitrary order which would prevent + * descriptor_count ever being reduced to zero until + * zend_hash_num_elements() returns 0. + */ + descriptor->connection->descriptor_count--; + } + } } /* flushing Lobs & Files with buffering enabled */ diff --git a/ext/oci8/oci8_statement.c b/ext/oci8/oci8_statement.c index 00c6079d9..bdba6dcce 100644 --- a/ext/oci8/oci8_statement.c +++ b/ext/oci8/oci8_statement.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | + | Copyright (c) 1997-2010 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -25,7 +25,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: oci8_statement.c 277003 2009-03-11 16:47:14Z sixd $ */ +/* $Id: oci8_statement.c 294441 2010-02-03 19:37:35Z pajoye $ */ #ifdef HAVE_CONFIG_H @@ -93,10 +93,11 @@ php_oci_statement *php_oci_statement_create (php_oci_connection *connection, cha statement->connection = connection; statement->has_data = 0; + statement->has_descr = 0; statement->parent_stmtid = 0; zend_list_addref(statement->connection->rsrc_id); - if (OCI_G(default_prefetch) > 0) { + if (OCI_G(default_prefetch) >= 0) { php_oci_statement_set_prefetch(statement, OCI_G(default_prefetch) TSRMLS_CC); } @@ -114,8 +115,8 @@ int php_oci_statement_set_prefetch(php_oci_statement *statement, long size TSRML { ub4 prefetch = size; - if (size < 1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of rows has to be greater than or equal to 1"); + if (size < 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of rows to be prefetched has to be greater than or equal to 0"); return 1; } @@ -131,6 +132,40 @@ int php_oci_statement_set_prefetch(php_oci_statement *statement, long size TSRML } /* }}} */ +/* {{{ php_oci_cleanup_pre_fetch() + Helper function to cleanup ref-cursors and descriptors from the previous row */ +int php_oci_cleanup_pre_fetch(void *data TSRMLS_DC) +{ + php_oci_out_column *outcol = data; + + if (!outcol->is_descr && !outcol->is_cursor) + return ZEND_HASH_APPLY_KEEP; + + switch(outcol->data_type) { + case SQLT_CLOB: + case SQLT_BLOB: + case SQLT_RDD: + case SQLT_BFILE: + if (outcol->descid) { + zend_list_delete(outcol->descid); + outcol->descid = 0; + } + break; + case SQLT_RSET: + if (outcol->stmtid) { + zend_list_delete(outcol->stmtid); + outcol->stmtid = 0; + outcol->nested_statement = NULL; + } + break; + default: + break; + } + return ZEND_HASH_APPLY_KEEP; + +} /* }}} */ + + /* {{{ php_oci_statement_fetch() Fetch a row from the statement */ int php_oci_statement_fetch(php_oci_statement *statement, ub4 nrows TSRMLS_DC) @@ -143,6 +178,10 @@ int php_oci_statement_fetch(php_oci_statement *statement, ub4 nrows TSRMLS_DC) php_oci_out_column *column; + if (statement->has_descr && statement->columns) { + zend_hash_apply(statement->columns, (apply_func_t) php_oci_cleanup_pre_fetch TSRMLS_CC); + } + PHP_OCI_CALL_RETURN(statement->errcode, OCIStmtFetch, (statement->stmt, statement->err, nrows, OCI_FETCH_NEXT, OCI_DEFAULT)); if ( statement->errcode == OCI_NO_DATA || nrows == 0 ) { @@ -413,7 +452,11 @@ int php_oci_statement_execute(php_oci_statement *statement, ub4 mode TSRMLS_DC) we don't want to execute!!! */ if (statement->binds) { - zend_hash_apply(statement->binds, (apply_func_t) php_oci_bind_pre_exec TSRMLS_CC); + int result = 0; + zend_hash_apply_with_argument(statement->binds, (apply_func_arg_t) php_oci_bind_pre_exec, (void *)&result TSRMLS_CC); + if (result) { + return 1; + } } /* execute statement */ @@ -566,6 +609,7 @@ int php_oci_statement_execute(php_oci_statement *statement, ub4 mode TSRMLS_DC) define_type = SQLT_RSET; outcol->is_cursor = 1; + outcol->statement->has_descr = 1; outcol->storage_size4 = -1; outcol->retlen = -1; dynamic = OCI_DYNAMIC_FETCH; @@ -579,6 +623,7 @@ int php_oci_statement_execute(php_oci_statement *statement, ub4 mode TSRMLS_DC) define_type = outcol->data_type; outcol->is_descr = 1; + outcol->statement->has_descr = 1; outcol->storage_size4 = -1; dynamic = OCI_DYNAMIC_FETCH; break; @@ -763,10 +808,51 @@ void php_oci_statement_free(php_oci_statement *statement TSRMLS_DC) /* {{{ php_oci_bind_pre_exec() Helper function */ -int php_oci_bind_pre_exec(void *data TSRMLS_DC) +int php_oci_bind_pre_exec(void *data, void *result TSRMLS_DC) { php_oci_bind *bind = (php_oci_bind *) data; + *(int *)result = 0; + switch (bind->type) { + case SQLT_NTY: + case SQLT_BFILEE: + case SQLT_CFILEE: + case SQLT_CLOB: + case SQLT_BLOB: + case SQLT_RDD: + if (Z_TYPE_P(bind->zval) != IS_OBJECT) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid variable used for bind"); + *(int *)result = 1; + } + break; + + 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; + + 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; + } + break; + + case SQLT_RSET: + if (Z_TYPE_P(bind->zval) != IS_RESOURCE) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid variable used for bind"); + *(int *)result = 1; + } + break; + } + /* reset all bind stuff to a normal state..-. */ bind->indicator = 0; @@ -942,6 +1028,10 @@ int php_oci_bind_by_name(php_oci_statement *statement, char *name, int name_len, case SQLT_INT: case SQLT_NUM: + 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_long(var); bind_data = (ub4 *)&Z_LVAL_P(var); value_sz = sizeof(ub4); @@ -953,6 +1043,10 @@ int php_oci_bind_by_name(php_oci_statement *statement, char *name, int name_len, case SQLT_LNG: case SQLT_AFC: case SQLT_CHR: /* SQLT_CHR is the default value when type was not specified */ + 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; + } if (Z_TYPE_P(var) != IS_NULL) { convert_to_string(var); } @@ -964,6 +1058,10 @@ int php_oci_bind_by_name(php_oci_statement *statement, char *name, int name_len, break; case SQLT_RSET: + if (Z_TYPE_P(var) != IS_RESOURCE) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid variable used for bind"); + return 1; + } PHP_OCI_ZVAL_TO_STATEMENT_EX(var, bind_statement); value_sz = sizeof(void*); @@ -1003,6 +1101,7 @@ int php_oci_bind_by_name(php_oci_statement *statement, char *name, int name_len, bindp->statement = oci_stmt; bindp->parent_statement = statement; bindp->zval = var; + bindp->type = type; zval_add_ref(&var); PHP_OCI_CALL_RETURN(statement->errcode, diff --git a/ext/oci8/package.xml b/ext/oci8/package.xml index 329d14329..92faa15a9 100644 --- a/ext/oci8/package.xml +++ b/ext/oci8/package.xml @@ -6,7 +6,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> <name>oci8</name> <channel>pecl.php.net</channel> <summary>Extension for Oracle Database</summary> - <description>This extension allows you to access Oracle databases using the Oracle Call Interface (OCI8). It can be built with PHP 4.3.9 to 5.x. It can be linked with Oracle 9.2, 10.2 or 11.1 client libraries. + <description>This extension allows you to access Oracle databases using the Oracle Call Interface (OCI8). It can be built with PHP 4.3.9 to 5.x. It can be linked with Oracle 9.2, 10.2, 11.1, or 11.2 client libraries. </description> <lead> <name>Christopher Jones</name> @@ -33,25 +33,21 @@ http://pear.php.net/dtd/package-2.0.xsd"> <active>no</active> </lead> - <date>2009-03-16</date> - <time>10:00:00</time> + <date>2010-??-??</date> + <time>15:00:00</time> <version> - <release>1.3.5</release> - <api>1.3.4</api> + <release>1.4.1</release> + <api>1.4.1</api> </version> <stability> <release>stable</release> <api>stable</api> </stability> <license uri="http://www.php.net/license">PHP</license> - <notes>Fixed Bug #47243 (Crash at end of request shutdown on Windows) -Fixed Bug #46994 (CLOB size does not update when using CLOB IN OUT param in stored procedure) -Fixed Bug #46623 (phpinfo doesn't show compile time ORACLE_HOME with phpize) -Fixed bug #45458 (Numeric keys for associative arrays are not handled properly) Note: not fixed when building with PHP 4 due to lack of PHP internal helper. -Fixed PECL Bug #16035 (oci_connect without ORACLE_HOME defined causes segfault) -Fixed PECL Bug #15988 (sqlnet.ora isn't read with older Oracle libraries) -Fixed PECL Bug #14268 (Allow "pecl install oci8" command to "autodetect" an Instant Client RPM install) + <notes> +Fixed bug #49560 (Using LOBs causes slow PHP shutdown) +Fixed bug #47281 ($php_errormsg is limited in size of characters) </notes> <contents> <dir name="/"> @@ -86,6 +82,7 @@ Fixed PECL Bug #14268 (Allow "pecl install oci8" command to "autodetect" an Inst <file name="bind_char_3.phpt" role="test" /> <file name="bind_char_4.phpt" role="test" /> <file name="bind_empty.phpt" role="test" /> + <file name="bind_error.phpt" role="test" /> <file name="bind_long.phpt" role="test" /> <file name="bind_long_raw.phpt" role="test" /> <file name="bind_raw.phpt" role="test" /> @@ -98,6 +95,7 @@ Fixed PECL Bug #14268 (Allow "pecl install oci8" command to "autodetect" an Inst <file name="bug35973.phpt" role="test" /> <file name="bug36010.phpt" role="test" /> <file name="bug36096.phpt" role="test" /> + <file name="bug36403.phpt" role="test" /> <file name="bug37220.phpt" role="test" /> <file name="bug37581.phpt" role="test" /> <file name="bug38161.phpt" role="test" /> @@ -120,6 +118,7 @@ Fixed PECL Bug #14268 (Allow "pecl install oci8" command to "autodetect" an Inst <file name="bug45458.phpt" role="test" /> <file name="bug46994.phpt" role="test" /> <file name="bug47189.phpt" role="test" /> + <file name="bug47281.phpt" role="test" /> <file name="bug6109.phpt" role="test" /> <file name="close.phpt" role="test" /> <file name="coll_001.phpt" role="test" /> @@ -156,6 +155,12 @@ Fixed PECL Bug #14268 (Allow "pecl install oci8" command to "autodetect" an Inst <file name="coll_019.phpt" role="test" /> <file name="commit_old.phpt" role="test" /> <file name="commit.phpt" role="test" /> + <file name="conn_attr_1.phpt" role="test" /> + <file name="conn_attr_2.phpt" role="test" /> + <file name="conn_attr_3.phpt" role="test" /> + <file name="conn_attr_4.phpt" role="test" /> + <file name="conn_attr_5.phpt" role="test" /> + <file name="conn_attr.inc" role="test" /> <file name="connect_1_old.phpt" role="test" /> <file name="connect_1.phpt" role="test" /> <file name="connect.inc" role="test" /> @@ -207,8 +212,11 @@ Fixed PECL Bug #14268 (Allow "pecl install oci8" command to "autodetect" an Inst <file name="drcp_scope3.phpt" role="test" /> <file name="drcp_scope4.phpt" role="test" /> <file name="drcp_scope5.phpt" role="test" /> + <file name="driver_name.phpt" role="test" /> <file name="drop_table.inc" role="test" /> <file name="drop_type.inc" role="test" /> + <file name="edition_1.phpt" role="test" /> + <file name="edition_2.phpt" role="test" /> <file name="error1.phpt" role="test" /> <file name="error2.phpt" role="test" /> <file name="error_old.phpt" role="test" /> @@ -221,12 +229,15 @@ Fixed PECL Bug #14268 (Allow "pecl install oci8" command to "autodetect" an Inst <file name="extauth_04.phpt" role="test" /> <file name="fetch_all2.phpt" role="test" /> <file name="fetch_all3.phpt" role="test" /> + <file name="fetch_all4.phpt" role="test" /> + <file name="fetch_all5.phpt" role="test" /> <file name="fetch_all.phpt" role="test" /> <file name="fetch_array.phpt" role="test" /> <file name="fetch_assoc.phpt" role="test" /> <file name="fetch_into1.phpt" role="test" /> <file name="fetch_into2.phpt" role="test" /> <file name="fetch_into.phpt" role="test" /> + <file name="fetch_object_2.phpt" role="test" /> <file name="fetch_object.phpt" role="test" /> <file name="fetch.phpt" role="test" /> <file name="fetch_row.phpt" role="test" /> @@ -278,6 +289,7 @@ Fixed PECL Bug #14268 (Allow "pecl install oci8" command to "autodetect" an Inst <file name="lob_040.phpt" role="test" /> <file name="lob_041.phpt" role="test" /> <file name="lob_042.phpt" role="test" /> + <file name="lob_043.phpt" role="test" /> <file name="lob_aliases.phpt" role="test" /> <file name="lob_null.phpt" role="test" /> <file name="lob_temp1.phpt" role="test" /> @@ -297,12 +309,16 @@ Fixed PECL Bug #14268 (Allow "pecl install oci8" command to "autodetect" an Inst <file name="pecl_bug10194_blob.phpt" role="test" /> <file name="pecl_bug10194.phpt" role="test" /> <file name="pecl_bug16035.phpt" role="test" /> + <file name="pecl_bug16842.phpt" role="test" /> <file name="pecl_bug8816.phpt" role="test" /> <file name="persistent.phpt" role="test" /> <file name="prefetch_old.phpt" role="test" /> <file name="prefetch.phpt" role="test" /> <file name="privileged_connect1.phpt" role="test" /> <file name="privileged_connect.phpt" role="test" /> + <file name="refcur_prefetch_1.phpt" role="test" /> + <file name="refcur_prefetch_2.phpt" role="test" /> + <file name="refcur_prefetch_3.phpt" role="test" /> <file name="reflection1.phpt" role="test" /> <file name="reflection2.phpt" role="test" /> <file name="rowid_bind.phpt" role="test" /> @@ -317,6 +333,7 @@ Fixed PECL Bug #14268 (Allow "pecl install oci8" command to "autodetect" an Inst <file name="test.txt" role="test" /> <file name="uncommitted.phpt" role="test" /> <file name="xmltype_01.phpt" role="test" /> + <file name="xmltype_02.phpt" role="test" /> </dir> <!-- //tests --> <file name="config.m4" role="src" /> <file name="config.w32" role="src" /> @@ -352,6 +369,77 @@ Fixed PECL Bug #14268 (Allow "pecl install oci8" command to "autodetect" an Inst <release> <version> + <release>1.4.0</release> + <api>1.4.0</api> + </version> + <stability> + <release>alpha</release> + <api>alpha</api> + </stability> + <license uri="http://www.php.net/license">PHP</license> + <notes> + 1. Introduce connection attribute functions: + + oci_set_module_name + oci_set_action + oci_set_client_info + oci_set_client_identifier + + These set values that are visible/used by the database. They + are useful for tracing, authentication and auditing. + + 2. Introduce connection attribute function: + + oci_set_edition + + Oracle 11g R2 "editions" allow multiple versions of DB objects + to exist at one time. By setting different editions, two + different versions of an application can run concurrently, + making upgrading easier and faster. + + 3. Set the DRIVER_NAME attribute of Oracle Database 11gR2 + connections to aid application tracing. The value used is to + "PHP OCI8" followed by the OCI8 version number. Note the + version number may get truncated in DB views such as + v$session_connect_info. + + 4. Allow the oci_set_prefetch value to be 0. This is important in + some cases using REF CURSORS in Oracle 11gR2. + + 5. Introduce OCI_NO_AUTO_COMMIT as an alias for the OCI_DEFAULT + constant (which is not the default value) used by oci_execute(). + + 6. Generate an error if an invalid resource type is used in + oci_bind_by_name + + 7. Bug fixes: + PECL bug #16842 (oci_error returns false when NO_DATA_FOUND is raised) + </notes> +</release> + +<release> + <version> + <release>1.3.5</release> + <api>1.3.4</api> + </version> + <stability> + <release>stable</release> + <api>stable</api> + </stability> + <license uri="http://www.php.net/license">PHP</license> + <notes> +Fixed bug #47243 (Crash at end of request shutdown on Windows) +Fixed bug #46994 (CLOB size does not update when using CLOB IN OUT param in stored procedure) +Fixed bug #46623 (phpinfo doesn't show compile time ORACLE_HOME with phpize) +Fixed bug #45458 (Numeric keys for associative arrays are not handled properly) Note: not fixed when building with PHP 4 due to lack of PHP internal helper. +Fixed PECL bug #16035 (oci_connect without ORACLE_HOME defined causes segfault) +Fixed PECL bug #15988 (sqlnet.ora isn't read with older Oracle libraries) +Fixed PECL bug #14268 (Allow "pecl install oci8" command to "autodetect" an Instant Client RPM install) + </notes> +</release> + +<release> + <version> <release>1.3.4</release> <api>1.3.4</api> </version> diff --git a/ext/oci8/php_oci8.h b/ext/oci8/php_oci8.h index bb4cfea1c..dfc667260 100644 --- a/ext/oci8/php_oci8.h +++ b/ext/oci8/php_oci8.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | + | Copyright (c) 1997-2010 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -25,7 +25,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_oci8.h 277243 2009-03-16 05:44:49Z sixd $ */ +/* $Id: php_oci8.h 294445 2010-02-03 20:00:49Z pajoye $ */ #if HAVE_OCI8 # ifndef PHP_OCI8_H @@ -46,7 +46,7 @@ */ #undef PHP_OCI8_VERSION #endif -#define PHP_OCI8_VERSION "1.3.5" +#define PHP_OCI8_VERSION "1.4.1" extern zend_module_entry oci8_module_entry; #define phpext_oci8_ptr &oci8_module_entry diff --git a/ext/oci8/php_oci8_int.h b/ext/oci8/php_oci8_int.h index 6e8d565b9..eb594392c 100644 --- a/ext/oci8/php_oci8_int.h +++ b/ext/oci8/php_oci8_int.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | + | Copyright (c) 1997-2010 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -25,7 +25,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_oci8_int.h 276935 2009-03-09 20:58:51Z sixd $ */ +/* $Id: php_oci8_int.h 294441 2010-02-03 19:37:35Z pajoye $ */ #if HAVE_OCI8 # ifndef PHP_OCI8_INT_H @@ -101,6 +101,12 @@ extern zend_class_entry *oci_coll_class_entry_ptr; #error Invalid value for PHP_OCI_CRED_EXT #endif +/* + * Name passed to Oracle for tracing. Note some DB views only show + * the first nine characters of the driver name. + */ +#define PHP_OCI8_DRIVER_NAME "PHP OCI8 " PHP_OCI8_VERSION + /* }}} */ typedef struct { /* php_oci_spool {{{ */ @@ -124,6 +130,7 @@ typedef struct { /* php_oci_connection {{{ */ sword errcode; /* last errcode */ HashTable *descriptors; /* descriptors hash, used to flush all the LOBs using this connection on commit */ + ulong descriptor_count; /* used to index the descriptors hash table. Not an accurate count */ unsigned is_open:1; /* hels to determine if the connection is dead or not */ unsigned is_attached:1; /* hels to determine if we should detach from the server when closing/freeing the connection */ unsigned is_persistent:1; /* self-descriptive */ @@ -140,6 +147,7 @@ typedef struct { /* php_oci_connection {{{ */ typedef struct { /* php_oci_descriptor {{{ */ int id; + ulong index; /* descriptors hash table index */ php_oci_connection *connection; /* parent connection handle */ dvoid *descriptor; /* OCI descriptor handle */ ub4 type; /* descriptor type (FILE/LOB) */ @@ -191,6 +199,7 @@ typedef struct { /* php_oci_statement {{{ */ int ncolumns; /* number of columns in the result */ unsigned executed:1; /* statement executed flag */ unsigned has_data:1; /* statement has more data flag */ + unsigned has_descr:1; /* statement has at least one descriptor or cursor column */ ub2 stmttype; /* statement type */ } php_oci_statement; /* }}} */ @@ -200,6 +209,7 @@ typedef struct { /* php_oci_bind {{{ */ dvoid *descriptor; /* used for binding of LOBS etc */ OCIStmt *statement; /* used for binding REFCURSORs */ php_oci_statement *parent_statement; /* pointer to the parent statement */ + ub2 type; /* bind type */ struct { void *elements; sb2 *indicators; @@ -360,7 +370,8 @@ void php_oci_column_hash_dtor (void *data); void php_oci_define_hash_dtor (void *data); void php_oci_bind_hash_dtor (void *data); void php_oci_descriptor_flush_hash_dtor (void *data); -int php_oci_descriptor_delete_from_hash(void *data, void *id TSRMLS_DC); + +void php_oci_connection_descriptors_free(php_oci_connection *connection TSRMLS_DC); sb4 php_oci_error (OCIError *, sword TSRMLS_DC); sb4 php_oci_fetch_errmsg(OCIError *, text ** TSRMLS_DC); @@ -439,12 +450,13 @@ php_oci_out_column * php_oci_statement_get_column (php_oci_statement *, long, ch int php_oci_statement_execute (php_oci_statement *, ub4 TSRMLS_DC); int php_oci_statement_cancel (php_oci_statement * TSRMLS_DC); void php_oci_statement_free (php_oci_statement * TSRMLS_DC); -int php_oci_bind_pre_exec(void *data TSRMLS_DC); +int php_oci_bind_pre_exec(void *data, void *result TSRMLS_DC); int php_oci_bind_post_exec(void *data TSRMLS_DC); int php_oci_bind_by_name(php_oci_statement *, char *, int, zval*, long, ub2 TSRMLS_DC); sb4 php_oci_bind_in_callback(dvoid *, OCIBind *, ub4, ub4, dvoid **, ub4 *, ub1 *, dvoid **); sb4 php_oci_bind_out_callback(dvoid *, OCIBind *, ub4, ub4, dvoid **, ub4 **, ub1 *, dvoid **, ub2 **); php_oci_out_column *php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAMETERS, int need_data); +int php_oci_cleanup_pre_fetch(void *data TSRMLS_DC); int php_oci_statement_get_type(php_oci_statement *, ub2 * TSRMLS_DC); int php_oci_statement_get_numrows(php_oci_statement *, ub4 * TSRMLS_DC); @@ -480,6 +492,7 @@ ZEND_BEGIN_MODULE_GLOBALS(oci) /* {{{ */ zend_bool in_call; char *connection_class; zend_bool events; + char *edition; ZEND_END_MODULE_GLOBALS(oci) /* }}} */ #ifdef ZTS diff --git a/ext/oci8/tests/bind_char_1.phpt b/ext/oci8/tests/bind_char_1.phpt index d2dddc908..36574dbfb 100644 --- a/ext/oci8/tests/bind_char_1.phpt +++ b/ext/oci8/tests/bind_char_1.phpt @@ -5,9 +5,9 @@ SELECT oci_bind_by_name with SQLT_AFC aka CHAR if (!extension_loaded('oci8')) die ("skip no oci8 extension"); require(dirname(__FILE__)."/connect.inc"); $sv = oci_server_version($c); -$sv = preg_match('/11.1/', $sv, $matches); +$sv = preg_match('/Release 1[12]\./', $sv, $matches); if ($sv !== 1) { - die ("skip expected output only valid when using Oracle 11g database"); + die ("skip expected output only valid when using Oracle 11g+ database"); } ?> --FILE-- diff --git a/ext/oci8/tests/bind_char_2.phpt b/ext/oci8/tests/bind_char_2.phpt index 183c09acb..f0f41663f 100644 --- a/ext/oci8/tests/bind_char_2.phpt +++ b/ext/oci8/tests/bind_char_2.phpt @@ -5,9 +5,9 @@ SELECT oci_bind_by_name with SQLT_AFC aka CHAR and dates if (!extension_loaded('oci8')) die ("skip no oci8 extension"); require(dirname(__FILE__)."/connect.inc"); $sv = oci_server_version($c); -$sv = preg_match('/11.1/', $sv, $matches); +$sv = preg_match('/Release 1[12]\./', $sv, $matches); if ($sv !== 1) { - die ("skip expected output only valid when using Oracle 11g database"); + die ("skip expected output only valid when using Oracle 11g+ database"); } ?> --FILE-- diff --git a/ext/oci8/tests/bind_char_3.phpt b/ext/oci8/tests/bind_char_3.phpt index f1e6a93c0..6d1b31150 100644 --- a/ext/oci8/tests/bind_char_3.phpt +++ b/ext/oci8/tests/bind_char_3.phpt @@ -5,9 +5,9 @@ PL/SQL oci_bind_by_name with SQLT_AFC aka CHAR to CHAR parameter if (!extension_loaded('oci8')) die ("skip no oci8 extension"); require(dirname(__FILE__)."/connect.inc"); $sv = oci_server_version($c); -$sv = preg_match('/11.1/', $sv, $matches); +$sv = preg_match('/Release 1[12]\./', $sv, $matches); if ($sv !== 1) { - die ("skip expected output only valid when using Oracle 11g database"); + die ("skip expected output only valid when using Oracle 11g+ database"); } ?> --FILE-- diff --git a/ext/oci8/tests/bind_char_4.phpt b/ext/oci8/tests/bind_char_4.phpt index ddd07dcb2..7377604b0 100644 --- a/ext/oci8/tests/bind_char_4.phpt +++ b/ext/oci8/tests/bind_char_4.phpt @@ -5,9 +5,9 @@ PL/SQL oci_bind_by_name with SQLT_AFC aka CHAR to VARCHAR2 parameter if (!extension_loaded('oci8')) die ("skip no oci8 extension"); require(dirname(__FILE__)."/connect.inc"); $sv = oci_server_version($c); -$sv = preg_match('/11.1/', $sv, $matches); +$sv = preg_match('/Release 1[12]\./', $sv, $matches); if ($sv !== 1) { - die ("skip expected output only valid when using Oracle 11g database"); + die ("skip expected output only valid when using Oracle 11g+ database"); } ?> --FILE-- diff --git a/ext/oci8/tests/bind_error.phpt b/ext/oci8/tests/bind_error.phpt new file mode 100644 index 000000000..ad66ad59f --- /dev/null +++ b/ext/oci8/tests/bind_error.phpt @@ -0,0 +1,70 @@ +--TEST-- +Test some oci_bind_by_name error conditions +--SKIPIF-- +<?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); ?> +--FILE-- +<?php + +require(dirname(__FILE__).'/connect.inc'); + +$drop = "drop table bind_test"; +$statement = oci_parse($c, $drop); +@oci_execute($statement); + +$create = "create table bind_test(name varchar(10))"; +$statement = oci_parse($c, $create); +oci_execute($statement); + + +echo "Insert value\n"; + +$name = 'abc'; +$stmt = oci_parse($c, "insert into bind_test values (:name)"); +oci_bind_by_name($stmt, ":name", $name, 10, SQLT_CHR); +var_dump(oci_execute($stmt)); + +echo "Test 1 - Assign a resource to the bind variable and execute \n"; +$name=$c; +var_dump(oci_execute($stmt)); + +echo "Test 2 - Re-bind a resource\n"; +oci_bind_by_name($stmt, ":name", $c); +var_dump(oci_execute($stmt)); +var_dump($c); + +// Use a connection resource instead of a ROWID. +echo "Test 3 - Resource mismatch !!\n"; +$stmt = oci_parse($c, "update bind_test set name='xyz' returning rowid into :r_id"); +oci_bind_by_name($stmt, ":r_id", $c); +var_dump(oci_execute($stmt)); + +// Clean up + +$drop = "drop table bind_test"; +$statement = oci_parse($c, $drop); +@oci_execute($statement); + +echo "Done\n"; + +?> +--EXPECTF-- +Insert value +bool(true) +Test 1 - Assign a resource to the bind variable and execute + +Warning: oci_execute(): Invalid variable used for bind in %s on line %d +bool(false) +Test 2 - Re-bind a resource + +Warning: oci_bind_by_name(): Invalid variable used for bind in %s on line %d + +Warning: oci_execute(): Invalid variable used for bind in %s on line %d +bool(false) +resource(%d) of type (oci8 connection) +Test 3 - Resource mismatch !! + +Warning: oci_bind_by_name(): Invalid variable used for bind in %s on line %d + +Warning: oci_execute(): ORA-01008: %s on line %d +bool(false) +Done diff --git a/ext/oci8/tests/bug26133.phpt b/ext/oci8/tests/bug26133.phpt index df319feb0..2463e70c7 100644 --- a/ext/oci8/tests/bug26133.phpt +++ b/ext/oci8/tests/bug26133.phpt @@ -5,30 +5,58 @@ Bug #26133 (ocifreedesc() segfault) --FILE-- <?php - require dirname(__FILE__).'/connect.inc'; - require dirname(__FILE__).'/create_table.inc'; - - if ($c) { - $ora_sql = "INSERT INTO - ".$schema.$table_name." (id, value) - VALUES ('1','1') - RETURNING - ROWID - INTO :v_rowid "; - - $statement = OCIParse($c,$ora_sql); - $rowid = OCINewDescriptor($c,OCI_D_ROWID); - OCIBindByName($statement,":v_rowid", $rowid,-1,OCI_B_ROWID); - if (OCIExecute($statement)) { - OCICommit($c); - } - OCIFreeStatement($statement); - $rowid->free(); - } - - require dirname(__FILE__).'/drop_table.inc'; - - echo "Done\n"; +require(dirname(__FILE__).'/connect.inc'); + +// Initialize + +$stmtarray = array( + "drop table bug26133_tab", + "create table bug26133_tab (id number, value number)", +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } + } +} + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} + +// Run Test + +$ora_sql = "INSERT INTO bug26133_tab (id, value) VALUES ('1','1') RETURNING ROWID INTO :v_rowid "; + +$statement = OCIParse($c,$ora_sql); +$rowid = OCINewDescriptor($c,OCI_D_ROWID); +OCIBindByName($statement,":v_rowid", $rowid,-1,OCI_B_ROWID); +if (OCIExecute($statement)) { + OCICommit($c); +} +OCIFreeStatement($statement); +$rowid->free(); + +// Cleanup + +$stmtarray = array( + "drop table bug26133_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} + +echo "Done\n"; ?> --EXPECT-- Done diff --git a/ext/oci8/tests/bug27303.phpt b/ext/oci8/tests/bug27303.phpt index 2cc63d662..4dce84463 100644 --- a/ext/oci8/tests/bug27303.phpt +++ b/ext/oci8/tests/bug27303.phpt @@ -5,9 +5,9 @@ Bug #27303 (OCIBindByName binds numeric PHP values as characters) if (!extension_loaded('oci8')) die ("skip no oci8 extension"); require(dirname(__FILE__)."/connect.inc"); $sv = oci_server_version($c); -$sv = preg_match('/11.1/', $sv, $matches); +$sv = preg_match('/Release 1[12]\./', $sv, $matches); if ($sv !== 1) { - die ("skip expected output only valid when using Oracle 11g database"); + die ("skip expected output only valid when using Oracle 11g+ database"); } ?> --FILE-- diff --git a/ext/oci8/tests/bug27303_2.phpt b/ext/oci8/tests/bug27303_2.phpt index 3520b1ea3..63200ed52 100644 --- a/ext/oci8/tests/bug27303_2.phpt +++ b/ext/oci8/tests/bug27303_2.phpt @@ -5,9 +5,9 @@ Bug #27303 (OCIBindByName binds numeric PHP values as characters) if (!extension_loaded('oci8')) die ("skip no oci8 extension"); require(dirname(__FILE__)."/connect.inc"); $sv = oci_server_version($c); -$sv = preg_match('/11.1/', $sv, $matches); +$sv = preg_match('/Release 1[12]\./', $sv, $matches); if ($sv !== 1) { - die ("skip expected output only valid when using Oracle 11g database"); + die ("skip expected output only valid when using Oracle 11g+ database"); } ?> --FILE-- diff --git a/ext/oci8/tests/bug27303_4.phpt b/ext/oci8/tests/bug27303_4.phpt index f0c960e93..031f0d1e1 100644 --- a/ext/oci8/tests/bug27303_4.phpt +++ b/ext/oci8/tests/bug27303_4.phpt @@ -5,9 +5,9 @@ Bug #27303 (OCIBindByName binds numeric PHP values as characters) if (!extension_loaded('oci8')) die ("skip no oci8 extension"); require(dirname(__FILE__)."/connect.inc"); $sv = oci_server_version($c); -$sv = preg_match('/11.1/', $sv, $matches); +$sv = preg_match('/Release 1[12]\./', $sv, $matches); if ($sv !== 1) { - die ("skip expected output only valid when using Oracle 11g database"); + die ("skip expected output only valid when using Oracle 11g+ database"); } ?> --FILE-- diff --git a/ext/oci8/tests/bug32325.phpt b/ext/oci8/tests/bug32325.phpt index 00054f51e..257c6977b 100644 --- a/ext/oci8/tests/bug32325.phpt +++ b/ext/oci8/tests/bug32325.phpt @@ -1,21 +1,37 @@ --TEST-- -Bug #32325 (Can't retrieve collection using OCI8) +Bug #32325 (Cannot retrieve collection using OCI8) --SKIPIF-- <?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); ?> --FILE-- <?php -require dirname(__FILE__).'/connect.inc'; -require dirname(__FILE__).'/create_table.inc'; - -$create_stmt = oci_parse($c, "create or replace type ut_num_list_t as table of number"); -oci_execute($create_stmt); - -$collection = oci_new_collection($c, "UT_NUM_LIST_T"); - -$sql = " - begin - select ut_num_list_t(1,2,3,4) into :list from dual; +require(dirname(__FILE__).'/connect.inc'); + +// Initialize + +$stmtarray = array( + "create or replace type bug32325_t as table of number" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } + } +} + +// Run test + +$collection = oci_new_collection($c, "BUG32325_T"); + +$sql = "begin + select bug32325_t(1,2,3,4) into :list from dual; end;"; $stmt = oci_parse($c, $sql); @@ -27,12 +43,20 @@ var_dump($collection->size()); var_dump($collection->getelem(1)); var_dump($collection->getelem(2)); -$drop_stmt = oci_parse($c, "drop type ut_num_list_t"); -oci_execute($drop_stmt); +// Cleanup + +$stmtarray = array( + "drop type bug32325_t" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- int(4) float(2) float(3) diff --git a/ext/oci8/tests/bug36403.phpt b/ext/oci8/tests/bug36403.phpt new file mode 100644 index 000000000..68c5f7b0a --- /dev/null +++ b/ext/oci8/tests/bug36403.phpt @@ -0,0 +1,76 @@ +--TEST-- +Bug #36403 (oci_execute no longer supports OCI_DESCRIBE_ONLY) +--SKIPIF-- +<?php if (!extension_loaded('oci8')) die ("skip no oci8 extension"); ?> +--FILE-- +<?php + +require(dirname(__FILE__).'/connect.inc'); + +// Initialization + +$stmtarray = array( + "drop table bug36403_tab", + "create table bug36403_tab (c1 number, col2 number, column3 number, col4 number)" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + , 2289 // sequence does not exist + , 4080 // trigger does not exist + , 38802 // edition does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } + } +} + +// Run Test + +echo "Test 1\n"; + +$s = oci_parse($c, "select * from bug36403_tab"); +oci_execute($s, OCI_DESCRIBE_ONLY); +for ($i = oci_num_fields($s); $i > 0; $i--) { + echo oci_field_name($s, $i) . "\n"; +} + +echo "Test 2\n"; + +// Should generate an error: ORA-24338: statement handle not executed +// since the statement handle was only described and not executed +$row = oci_fetch_array($s); + +// Clean up + +//require(dirname(__FILE__).'/drop_table.inc'); + +$stmtarray = array( + "drop table bug36403_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} + +oci_close($c); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +Test 1 +COL4 +COLUMN3 +COL2 +C1 +Test 2 + +Warning: oci_fetch_array(): ORA-24338: %sbug36403.php on line %d +===DONE=== diff --git a/ext/oci8/tests/bug43497.phpt b/ext/oci8/tests/bug43497.phpt index 0fc6a97b3..1ea46b40d 100644 --- a/ext/oci8/tests/bug43497.phpt +++ b/ext/oci8/tests/bug43497.phpt @@ -157,7 +157,7 @@ for ($i = 1; $i <= 10; $i++) { readxmltab_im($c); } -echo "\nExplicit LOB with no free (i.e. a temp lob leak)\n"; +echo "\nExplicit LOB with no free\n"; for ($i = 1; $i <= 10; $i++) { echo "\nRun = " . $i . "\n"; echo "Temporary LOBs = " . templobs($c, $sid) . "\n"; @@ -259,45 +259,45 @@ Run = 10 Temporary LOBs = 0 Loop count check = 100 -Explicit LOB with no free (i.e. a temp lob leak) +Explicit LOB with no free Run = 1 Temporary LOBs = 0 Loop count check = 100 Run = 2 -Temporary LOBs = 99 +Temporary LOBs = 0 Loop count check = 100 Run = 3 -Temporary LOBs = 198 +Temporary LOBs = 0 Loop count check = 100 Run = 4 -Temporary LOBs = 297 +Temporary LOBs = 0 Loop count check = 100 Run = 5 -Temporary LOBs = 396 +Temporary LOBs = 0 Loop count check = 100 Run = 6 -Temporary LOBs = 495 +Temporary LOBs = 0 Loop count check = 100 Run = 7 -Temporary LOBs = 594 +Temporary LOBs = 0 Loop count check = 100 Run = 8 -Temporary LOBs = 693 +Temporary LOBs = 0 Loop count check = 100 Run = 9 -Temporary LOBs = 792 +Temporary LOBs = 0 Loop count check = 100 Run = 10 -Temporary LOBs = 891 +Temporary LOBs = 0 Loop count check = 100 Done diff --git a/ext/oci8/tests/bug47281.phpt b/ext/oci8/tests/bug47281.phpt new file mode 100644 index 000000000..710246738 --- /dev/null +++ b/ext/oci8/tests/bug47281.phpt @@ -0,0 +1,73 @@ +--TEST-- +Bug #47281 ($php_errormsg is limited in size of characters) +--SKIPIF-- +<?php if (!extension_loaded('oci8')) die ("skip no oci8 extension"); ?> +--ENV-- +NLS_LANG=.AL32UTF8 +--FILE-- +<?php + +require(dirname(__FILE__).'/connect.inc'); + +// Initialization + +$stmtarray = array( + "create or replace procedure bug47281_sp as + begin + raise_application_error(-20000, + 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaBcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccDeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeFggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhIjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjKlllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllM'); + end;" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + , 2289 // sequence does not exist + , 4080 // trigger does not exist + , 38802 // edition does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } + } +} + +// Run Test + +echo "Test 1\n"; + +$s = oci_parse($c, 'begin bug47281_sp; end;'); +$r = @oci_execute($s); + +if (!$r) { + $m = oci_error($s); + echo $m['message'], "\n"; +} + +echo "Test 2\n"; + +echo $php_errormsg. "\n"; + +// Clean up + +$stmtarray = array( + "drop procedure bug47281_sp" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +Test 1 +ORA-20000: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaBcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccDeeeeeeeeeeee +Test 2 +oci_execute(): ORA-20000: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaBcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc +===DONE=== diff --git a/ext/oci8/tests/commit.phpt b/ext/oci8/tests/commit.phpt index 3bef318c8..836d2cd1d 100644 --- a/ext/oci8/tests/commit.phpt +++ b/ext/oci8/tests/commit.phpt @@ -1,28 +1,36 @@ --TEST-- -oci_commit()/oci_rollback() +Test OCI_NO_AUTO_COMMIT constant --SKIPIF-- <?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); ?> --FILE-- <?php -require dirname(__FILE__)."/connect.inc"; -require dirname(__FILE__).'/create_table.inc'; +require(dirname(__FILE__)."/connect.inc"); +require(dirname(__FILE__).'/create_table.inc'); -$insert_sql = "INSERT INTO ".$schema.$table_name." (id, value) VALUES (1,1)"; +$insert_sql = "insert into ".$schema.$table_name." (id, value) values (1,1)"; if (!($s = oci_parse($c, $insert_sql))) { die("oci_parse(insert) failed!\n"); } +/* check with OCI_NO_AUTO_COMMIT mode */ +for ($i = 0; $i<3; $i++) { + if (!oci_execute($s, OCI_NO_AUTO_COMMIT)) { + die("oci_execute(insert) failed!\n"); + } +} + for ($i = 0; $i<3; $i++) { if (!oci_execute($s, OCI_DEFAULT)) { die("oci_execute(insert) failed!\n"); } } + var_dump(oci_rollback($c)); -$select_sql = "SELECT * FROM ".$schema.$table_name.""; +$select_sql = "select * from ".$schema.$table_name.""; if (!($select = oci_parse($c, $select_sql))) { die("oci_parse(select) failed!\n"); @@ -40,7 +48,7 @@ if (!oci_execute($s)) { die("oci_execute(select) failed!\n"); } -$insert_sql = "INSERT INTO ".$schema.$table_name." (id, value) VALUES (1,1)"; +$insert_sql = "insert into ".$schema.$table_name." (id, value) values (1,1)"; if (!($s = oci_parse($c, $insert_sql))) { die("oci_parse(insert) failed!\n"); @@ -62,56 +70,56 @@ var_dump(oci_fetch_all($select, $all)); var_dump($all); -require dirname(__FILE__).'/drop_table.inc'; +require(dirname(__FILE__).'/drop_table.inc'); echo "Done\n"; ?> ---EXPECT-- +--EXPECTF-- bool(true) int(0) array(5) { - ["ID"]=> + [%u|b%"ID"]=> array(0) { } - ["VALUE"]=> + [%u|b%"VALUE"]=> array(0) { } - ["BLOB"]=> + [%u|b%"BLOB"]=> array(0) { } - ["CLOB"]=> + [%u|b%"CLOB"]=> array(0) { } - ["STRING"]=> + [%u|b%"STRING"]=> array(0) { } } bool(true) int(4) array(5) { - ["ID"]=> + [%u|b%"ID"]=> array(4) { [0]=> - string(1) "1" + %string|unicode%(1) "1" [1]=> - string(1) "1" + %string|unicode%(1) "1" [2]=> - string(1) "1" + %string|unicode%(1) "1" [3]=> - string(1) "1" + %string|unicode%(1) "1" } - ["VALUE"]=> + [%u|b%"VALUE"]=> array(4) { [0]=> - string(1) "1" + %string|unicode%(1) "1" [1]=> - string(1) "1" + %string|unicode%(1) "1" [2]=> - string(1) "1" + %string|unicode%(1) "1" [3]=> - string(1) "1" + %string|unicode%(1) "1" } - ["BLOB"]=> + [%u|b%"BLOB"]=> array(4) { [0]=> NULL @@ -122,7 +130,7 @@ array(5) { [3]=> NULL } - ["CLOB"]=> + [%u|b%"CLOB"]=> array(4) { [0]=> NULL @@ -133,7 +141,7 @@ array(5) { [3]=> NULL } - ["STRING"]=> + [%u|b%"STRING"]=> array(4) { [0]=> NULL diff --git a/ext/oci8/tests/conn_attr.inc b/ext/oci8/tests/conn_attr.inc new file mode 100644 index 000000000..2c086b189 --- /dev/null +++ b/ext/oci8/tests/conn_attr.inc @@ -0,0 +1,151 @@ +<?php + +require(dirname(__FILE__)."/connect.inc"); + +$sv = oci_server_version($c); +$sv = preg_match('/Release (11\.2|12)\./', $sv, $matches); +if ($sv == 1) { + // Server is Oracle 11.2+ + $stmtarray = array( + "drop user testuser cascade", + "create user testuser identified by testuser", + "grant connect,resource,dba to testuser", + "alter user testuser enable editions", + "drop edition myedition1", + "drop edition myedition", + "grant create any edition to testuser", + "create edition myedition", + "create edition myedition1 as child of myedition", + "grant use on edition myedition to testuser", + "grant use on edition myedition1 to testuser", + ); +} +else { + // Server is Pre 11.2 + $stmtarray = array( + "drop user testuser cascade", + "create user testuser identified by testuser", + "grant connect,resource,dba to testuser", + ); +} + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + , 1918 // user does not exist + , 2289 // sequence does not exist + , 4080 // trigger does not exist + , 38802 // edition does not exist + ))) { + echo "Error:" . $stmt . PHP_EOL . $m['message'] . PHP_EOL; + if ($m['code'] == 38807) { + echo "You appear to already have an edition in use that prevents this PHP test from running. Query DBA_EDITIONS to see existing editions.". PHP_EOL; + } + die; + } + } +} + +function get_attr($conn,$attr) +{ + $sel_stmt="select " .$attr. " from v\$session where sid = + (select sid from v\$session where audsid = + sys_context('userenv','sessionid')) order by 1"; + $s2 = oci_parse($conn,$sel_stmt); + oci_execute($s2,OCI_DEFAULT); + while (oci_fetch($s2)) { + echo "The value of ".$attr ." is ".oci_result($s2,1)."\n"; + } +} + +/* Pass $conn_type=1 for a connection with oci_connect() + Pass $conn_type=2 for ooci_pconnect + Default will give a oci_new_connect */ + +function get_conn($conn_type) +{ + $user = 'testuser'; + $password = 'testuser'; + $dbase = $GLOBALS['dbase']; + switch($conn_type) { + case 1: + echo "Testing with oci_connect()\n"; + return(oci_connect($user,$password,$dbase)); + break; + case 2: + echo "Testing with oci_pconnect()\n"; + return(oci_pconnect($user,$password,$dbase)); + break; + default: + echo "Testing with oci_new_connect()\n"; + return(oci_new_connect($user,$password,$dbase)); + break; + } +} + +function set_attr($conn,$attr,$sufix) +{ + if (!strcmp($attr,'MODULE')) + $r = oci_set_module_name($conn,'PHP TEST'.$sufix); + else if (!strcmp($attr,'ACTION')) + $r = oci_set_action($conn,'TASK'.$sufix); + else if (!strcmp($attr,'CLIENT_INFO')) + $r = oci_set_client_info($conn,'INFO1'.$sufix); + else if (!strcmp($attr,'CLIENT_IDENTIFIER')) + $r = oci_set_client_identifier($conn,'ID00'.$sufix); + else + echo "Pass one of the above four attibutes!!!\n"; + if ($r) { + echo "Value of $attr has been set successfully\n"; + } + + //Do a round-trip here + oci_server_version($conn); + return $r; +} + +function set_edit_attr($value) +{ + $r = oci_set_edition($value); + if ($r) { + echo " The value of edition has been successfully set\n"; + } + return $r; +} + +function get_edit_attr ($conn) { + $sel_stmt = "select sys_context('USERENV', 'CURRENT_EDITION_NAME') from dual"; + $s2 = oci_parse($conn,$sel_stmt); + oci_execute($s2,OCI_DEFAULT); + while (oci_fetch($s2)) { + echo "The value of current EDITION is ".oci_result($s2,1)."\n"; + } +} + +function get_sys_attr($conn,$attr) +{ + $sel_stmt="select " .$attr. " from v\$session where sid = + (select sid from v\$session where audsid = sys_context('userenv','sessionid')) order by 1"; + $s2 = oci_parse($conn,$sel_stmt); + oci_execute($s2,OCI_DEFAULT); + while (oci_fetch($s2)) { + echo "The value of ".$attr ." is ".oci_result($s2,1)."\n"; + } +} + +function clean_up($c) { + $stmtarray = array( + "drop user testuser cascade", + "drop edition myedition1", + "drop edition myedition", + ); + + foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + @oci_execute($s); + } +} diff --git a/ext/oci8/tests/conn_attr_1.phpt b/ext/oci8/tests/conn_attr_1.phpt new file mode 100644 index 000000000..c7c1b870e --- /dev/null +++ b/ext/oci8/tests/conn_attr_1.phpt @@ -0,0 +1,104 @@ +--TEST-- +Set and get of connection attributes with all types of connections. +--SKIPIF-- +<?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); +require(dirname(__FILE__)."/connect.inc"); +if (strcasecmp($user, "system") && strcasecmp($user, "sys")) + die("skip needs to be run as a DBA user"); +if ($test_drcp) die("skip output might vary with DRCP"); + +$sv = oci_server_version($c); +$sv = preg_match('/Release 1[012]\./', $sv, $matches); +if ($sv == 1) { + ob_start(); + phpinfo(INFO_MODULES); + $phpinfo = ob_get_clean(); + $iv = preg_match('/Oracle .*Version => 1[012]\./', $phpinfo); + if ($iv != 1) { + die ("skip test expected to work only with Oracle 10g or greater client "); + } +} +else { + die ("skip test expected to work only with Oracle 10g or greater server"); +} + +?> +--FILE-- +<?php +require(dirname(__FILE__)."/conn_attr.inc"); + +$attr_array = array('MODULE','ACTION','CLIENT_INFO','CLIENT_IDENTIFIER'); + +echo"**Test 1.1 - Default values for the attributes **************\n"; +$c = get_conn(1); +foreach($attr_array as $attr) { + get_attr($c,$attr); +} + +echo"**Test 1.2 - Set and get values for the attributes **************\n"; + +// With oci_connect, oci_pconnect, oci_new_connect + +$conn1 = get_conn(1); //oci_connect() +foreach($attr_array as $attr) { + set_attr($conn1,$attr,1); + get_attr($conn1,$attr); +} + +$conn2 = get_conn(2); //oci_pconnect() +foreach($attr_array as $attr) { + set_attr($conn2,$attr,2); + get_attr($conn2,$attr); +} + +$conn3 = get_conn(3); //oci_new_connect() +foreach($attr_array as $attr) { + set_attr($conn3,$attr,3); + get_attr($conn3,$attr); +} + +// clean up +oci_close($conn1); +oci_close($conn2); +oci_close($conn3); +clean_up($c); + +echo "Done\n"; + +?> +--EXPECTF-- +**Test 1.1 - Default values for the attributes ************** +Testing with oci_connect() +The value of MODULE is %s +The value of ACTION is +The value of CLIENT_INFO is +The value of CLIENT_IDENTIFIER is +**Test 1.2 - Set and get values for the attributes ************** +Testing with oci_connect() +Value of MODULE has been set successfully +The value of MODULE is PHP TEST1 +Value of ACTION has been set successfully +The value of ACTION is TASK1 +Value of CLIENT_INFO has been set successfully +The value of CLIENT_INFO is INFO11 +Value of CLIENT_IDENTIFIER has been set successfully +The value of CLIENT_IDENTIFIER is ID001 +Testing with oci_pconnect() +Value of MODULE has been set successfully +The value of MODULE is PHP TEST2 +Value of ACTION has been set successfully +The value of ACTION is TASK2 +Value of CLIENT_INFO has been set successfully +The value of CLIENT_INFO is INFO12 +Value of CLIENT_IDENTIFIER has been set successfully +The value of CLIENT_IDENTIFIER is ID002 +Testing with oci_new_connect() +Value of MODULE has been set successfully +The value of MODULE is PHP TEST3 +Value of ACTION has been set successfully +The value of ACTION is TASK3 +Value of CLIENT_INFO has been set successfully +The value of CLIENT_INFO is INFO13 +Value of CLIENT_IDENTIFIER has been set successfully +The value of CLIENT_IDENTIFIER is ID003 +Done diff --git a/ext/oci8/tests/conn_attr_2.phpt b/ext/oci8/tests/conn_attr_2.phpt new file mode 100644 index 000000000..4765d5eb7 --- /dev/null +++ b/ext/oci8/tests/conn_attr_2.phpt @@ -0,0 +1,111 @@ +--TEST-- +Set and get of connection attributes across persistent connections and sysdba connection. +--SKIPIF-- +<?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); +require(dirname(__FILE__)."/connect.inc"); +if (strcasecmp($user, "system") && strcasecmp($user, "sys")) die("skip needs to be run as a DBA user"); +if ($test_drcp) die("skip output might vary with DRCP"); + +$sv = oci_server_version($c); +$sv = preg_match('/Release 1[012]\./', $sv, $matches); +if ($sv == 1) { + ob_start(); + phpinfo(INFO_MODULES); + $phpinfo = ob_get_clean(); + $iv = preg_match('/Oracle .*Version => 1[012]\./', $phpinfo); + if ($iv != 1) { + die ("skip test expected to work only with Oracle 10g or greater version of client"); + } +} +else { + die ("skip test expected to work only with Oracle 10g or greater version of server"); +} +?> +--INI-- +oci8.privileged_connect = On +--FILE-- + +<?php +require(dirname(__FILE__)."/conn_attr.inc"); +$user='testuser'; +$password='testuser'; +$attr_array = array('MODULE','ACTION','CLIENT_INFO','CLIENT_IDENTIFIER'); + +echo"**Set values using pconnect-1**\n"; + +var_dump($pc1 = oci_pconnect($user,$password,$dbase)); +foreach($attr_array as $attr) { + set_attr($pc1,$attr,100); +} + +// using pc1 again +echo"\n**Get values using pconnect-2**\n"; +var_dump($pc3 = oci_pconnect($user,$password,$dbase)); +foreach($attr_array as $attr) { + get_attr($pc3,$attr); +} + +// Get with different pconnect +echo"\n**Get values using pconnect-3**\n"; +var_dump($pc2 = oci_pconnect($user,$password,$dbase,'UTF8')); +foreach($attr_array as $attr) { + get_attr($pc2,$attr); +} + +oci_close($pc1); +oci_close($pc2); +oci_close($pc3); + +// Re-open a persistent connection and check for the attr values. +echo "\n**Re-open a pconnect()**\n"; +var_dump($pc4 = oci_pconnect($user,$password,$dbase)); +foreach($attr_array as $attr) { + get_attr($pc4,$attr); +} +oci_close($pc4); + +// Test with SYSDBA connection. +var_dump($sys_c1 = oci_pconnect($user,$password,$dbase,false,OCI_SYSDBA)); +if ($sys_c1) { + set_attr($sys_c1,'ACTION',10); + get_sys_attr($sys_c1,'ACTION'); + get_attr($pc2,'ACTION'); + oci_close($sys_c1); +} + +clean_up($c); + +echo "Done\n"; +?> +--EXPECTF-- +**Set values using pconnect-1** +resource(%d) of type (oci8 persistent connection) +Value of MODULE has been set successfully +Value of ACTION has been set successfully +Value of CLIENT_INFO has been set successfully +Value of CLIENT_IDENTIFIER has been set successfully + +**Get values using pconnect-2** +resource(%d) of type (oci8 persistent connection) +The value of MODULE is PHP TEST100 +The value of ACTION is TASK100 +The value of CLIENT_INFO is INFO1100 +The value of CLIENT_IDENTIFIER is ID00100 + +**Get values using pconnect-3** +resource(%d) of type (oci8 persistent connection) +The value of MODULE is %s +The value of ACTION is +The value of CLIENT_INFO is +The value of CLIENT_IDENTIFIER is + +**Re-open a pconnect()** +resource(%d) of type (oci8 persistent connection) +The value of MODULE is PHP TEST100 +The value of ACTION is TASK100 +The value of CLIENT_INFO is INFO1100 +The value of CLIENT_IDENTIFIER is ID00100 + +Warning: oci_pconnect(): ORA-01031: %s on line %d +bool(false) +Done diff --git a/ext/oci8/tests/conn_attr_3.phpt b/ext/oci8/tests/conn_attr_3.phpt new file mode 100644 index 000000000..8b6d92123 --- /dev/null +++ b/ext/oci8/tests/conn_attr_3.phpt @@ -0,0 +1,94 @@ +--TEST-- +Set and get of connection attributes with oci_close(). +--SKIPIF-- +<?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); +require(dirname(__FILE__)."/connect.inc"); +if (strcasecmp($user, "system") && strcasecmp($user, "sys")) die("skip needs to be run as a DBA user"); +if ($test_drcp) die("skip output might vary with DRCP"); + +$sv = oci_server_version($c); +$sv = preg_match('/Release 1[012]\./', $sv, $matches); +if ($sv == 1) { + ob_start(); + phpinfo(INFO_MODULES); + $phpinfo = ob_get_clean(); + $iv = preg_match('/Oracle .*Version => 1[012]\./', $phpinfo); + if ($iv != 1) { + die ("skip test expected to work only with Oracle 10g or greater version of client"); + } +} +else { + die ("skip test expected to work only with Oracle 10g or greater version of server"); +} +?> +--FILE-- +<?php +require(dirname(__FILE__)."/conn_attr.inc"); + +echo"**Test Set and get values for the attributes with oci_close() ************\n"; +// With oci_connect ,oci_pconnect ,oci_new_connect + +var_dump($conn1 = get_conn(1)); //oci_connect() +set_attr($conn1,'ACTION',1); +get_attr($conn1,'ACTION'); +oci_close($conn1); + +// Open another connect and verify the value. +var_dump($conn1 = get_conn(1)); //oci_connect() +get_attr($conn1,'ACTION'); +oci_close($conn1); + +var_dump($pconn1 = get_conn(2)); //oci_pconnect() +set_attr($pconn1,'MODULE',2); +get_attr($pconn1,'MODULE'); +oci_close($pconn1); + +// Open another connect and verify the value. +var_dump($pconn1 = get_conn(2)); //oci_pconnect() +get_attr($pconn1,'MODULE'); +oci_close($pconn1); + +var_dump($nconn1 = get_conn(3)); //oci_new_connect() +set_attr($nconn1,'CLIENT_INFO',3); +set_attr($nconn1,'CLIENT_IDENTIFIER',3); +get_attr($nconn1,'CLIENT_INFO'); +get_attr($nconn1,'CLIENT_IDENTIFIER'); +oci_close($nconn1); + +// Open another connect and verify the value. +var_dump($nconn1 = get_conn(3)); //oci_new_connect() +get_attr($nconn1,'CLIENT_INFO'); +get_attr($nconn1,'CLIENT_IDENTIFIER'); +oci_close($nconn1); + +clean_up($c); +echo "Done\n"; + +?> +--EXPECTF-- +**Test Set and get values for the attributes with oci_close() ************ +Testing with oci_connect() +resource(%d) of type (oci8 connection) +Value of ACTION has been set successfully +The value of ACTION is TASK1 +Testing with oci_connect() +resource(%d) of type (oci8 connection) +The value of ACTION is +Testing with oci_pconnect() +resource(%d) of type (oci8 persistent connection) +Value of MODULE has been set successfully +The value of MODULE is PHP TEST2 +Testing with oci_pconnect() +resource(%d) of type (oci8 persistent connection) +The value of MODULE is PHP TEST2 +Testing with oci_new_connect() +resource(%d) of type (oci8 connection) +Value of CLIENT_INFO has been set successfully +Value of CLIENT_IDENTIFIER has been set successfully +The value of CLIENT_INFO is INFO13 +The value of CLIENT_IDENTIFIER is ID003 +Testing with oci_new_connect() +resource(%d) of type (oci8 connection) +The value of CLIENT_INFO is +The value of CLIENT_IDENTIFIER is +Done diff --git a/ext/oci8/tests/conn_attr_4.phpt b/ext/oci8/tests/conn_attr_4.phpt new file mode 100644 index 000000000..2ef2673fd --- /dev/null +++ b/ext/oci8/tests/conn_attr_4.phpt @@ -0,0 +1,121 @@ +--TEST-- +Set and get of connection attributes with errors. +--SKIPIF-- +<?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); +require(dirname(__FILE__)."/connect.inc"); +if (strcasecmp($user, "system") && strcasecmp($user, "sys")) die("skip needs to be run as a DBA user"); +if ($test_drcp) die("skip output might vary with DRCP"); + +$sv = oci_server_version($c); +$sv = preg_match('/Release 1[012]\./', $sv, $matches); +if ($sv == 1) { + ob_start(); + phpinfo(INFO_MODULES); + $phpinfo = ob_get_clean(); + $iv = preg_match('/Oracle .*Version => 1[012]\./', $phpinfo); + if ($iv != 1) { + die ("skip test expected to work only with Oracle 10g or greater version of client"); + } +} +else { + die ("skip test expected to work only with Oracle 10g or greater version of server"); +} +?> +--FILE-- +<?php +require(dirname(__FILE__)."/conn_attr.inc"); + +$user='testuser'; +$password='testuser'; +$attr_array = array('MODULE','ACTION','CLIENT_INFO','CLIENT_IDENTIFIER'); + +echo"**Test Negative cases************\n"; + +echo "\nInvalid Connection resource\n"; +$nc1=NULL; +// Invalid connection handle. +var_dump(oci_set_action($nc1,$nc1)); + +// Variable instead of a connection resource. +echo "\nInvalid Connection resource 2\n"; +$str1= 'not a conn'; +var_dump(oci_set_client_info($str1,$str1)); + +// Setting an Invalid value. +echo "\nInvalid Value \n"; +$c1=oci_connect($user,$password,$dbase); +var_dump(oci_set_action($c1,$c1)); + +// Setting values multiple times. +echo "\nSet Values multiple times \n"; +var_dump(oci_set_action($c1,'ACTION1')); +var_dump(oci_set_action($c1,'ACTION1')); +var_dump(oci_set_action($c1,'ACTION2')); +var_dump(oci_set_action($c1,'ACTION1')); +get_attr($c1,'ACTION'); + +// Testing with different types of values +echo "\nSetting to different values \n"; +$values_array = array(1000,NULL,'this is a very huge string with a length > 64 !!!!!this is a very huge string with a length > 64 !!!!!this is a very huge string with a length > 64 !!!!!this is a very huge string with a length > 64 !!!!!'); + +foreach($values_array as $val ) { + oci_set_module_name($c1,$val); + oci_set_client_identifier($c1,$val); + oci_set_client_info($c1,$val); + $r = oci_set_action($c1,$val); + if ($r) { + echo "Values set succesfully to $val\n"; + foreach($attr_array as $attr) { + get_attr($c1,$attr); + } + } +} + +clean_up($c); +echo "Done\n"; +?> +--EXPECTF-- +**Test Negative cases************ + +Invalid Connection resource + +Warning: oci_set_action() expects parameter 1 to be resource, null given in %s on line %d +NULL + +Invalid Connection resource 2 + +Warning: oci_set_client_info() expects parameter 1 to be resource, %s given in %s on line %d +NULL + +Invalid Value + +Warning: oci_set_action() expects parameter 2 to be %s, resource given in %s on line %d +NULL + +Set Values multiple times +bool(true) +bool(true) +bool(true) +bool(true) +The value of ACTION is ACTION1 + +Setting to different values +Values set succesfully to 1000 +The value of MODULE is 1000 +The value of ACTION is 1000 +The value of CLIENT_INFO is 1000 +The value of CLIENT_IDENTIFIER is 1000 +Values set succesfully to +The value of MODULE is +The value of ACTION is +The value of CLIENT_INFO is +The value of CLIENT_IDENTIFIER is + +Warning: oci_set_module_name(): ORA-24960: %s OCI_ATTR_MODULE %s on line %d + +Warning: oci_set_client_identifier(): ORA-24960: %s OCI_ATTR_CLIENT_IDENTIFIER %s on line %d + +Warning: oci_set_client_info(): ORA-24960: %s OCI_ATTR_CLIENT_INFO %s on line %d + +Warning: oci_set_action(): ORA-24960: %s OCI_ATTR_ACTION %s on line %d +Done diff --git a/ext/oci8/tests/conn_attr_5.phpt b/ext/oci8/tests/conn_attr_5.phpt new file mode 100644 index 000000000..9f6b6c724 --- /dev/null +++ b/ext/oci8/tests/conn_attr_5.phpt @@ -0,0 +1,76 @@ +--TEST-- +Set and get connection attributes with scope end. +--SKIPIF-- +<?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); +require(dirname(__FILE__)."/connect.inc"); +if (strcasecmp($user, "system") && strcasecmp($user, "sys")) die("skip needs to be run as a DBA user"); +if ($test_drcp) die("skip output might vary with DRCP"); + +$sv = oci_server_version($c); +$sv = preg_match('/Release 1[012]\./', $sv, $matches); +if ($sv == 1) { + ob_start(); + phpinfo(INFO_MODULES); + $phpinfo = ob_get_clean(); + $iv = preg_match('/Oracle .*Version => 1[012]\./', $phpinfo); + if ($iv != 1) { + die ("skip test expected to work only with Oracle 10g or greater version of client"); + } +} +else { + die ("skip test expected to work only with Oracle 10g or greater version of server"); +} +?> +--FILE-- +<?php +require(dirname(__FILE__)."/conn_attr.inc"); + +echo"**Test - Set and get values for the attributes with scope end ************\n"; + +// Set the attributes in one scope and verify the values from another scope. +set_scope(); + +echo "Get the Values from a different scope \n"; +get_scope(); + +function set_scope() { + $conn1 = get_conn(1); + set_attr($conn1,'CLIENT_INFO',50); + set_attr($conn1,'CLIENT_IDENTIFIER',50); + $conn2 = get_conn(3); + set_attr($conn2,'ACTION',50); + $conn3 = get_conn(2); + set_attr($conn3,'MODULE',50); + +} + +function get_scope() { + $conn1 = get_conn(1); + get_attr($conn1,'CLIENT_INFO'); + get_attr($conn1,'CLIENT_IDENTIFIER'); + $conn2 = get_conn(3); + get_attr($conn2,'ACTION'); + $conn3 = get_conn(2); + get_attr($conn3,'MODULE'); +} +clean_up($c); +echo "Done"; +?> +--EXPECTF-- +**Test - Set and get values for the attributes with scope end ************ +Testing with oci_connect() +Value of CLIENT_INFO has been set successfully +Value of CLIENT_IDENTIFIER has been set successfully +Testing with oci_new_connect() +Value of ACTION has been set successfully +Testing with oci_pconnect() +Value of MODULE has been set successfully +Get the Values from a different scope +Testing with oci_connect() +The value of CLIENT_INFO is +The value of CLIENT_IDENTIFIER is +Testing with oci_new_connect() +The value of ACTION is +Testing with oci_pconnect() +The value of MODULE is PHP TEST50 +Done diff --git a/ext/oci8/tests/cursor_bind_err.phpt b/ext/oci8/tests/cursor_bind_err.phpt index 267c4d94f..33bd04b6d 100644 --- a/ext/oci8/tests/cursor_bind_err.phpt +++ b/ext/oci8/tests/cursor_bind_err.phpt @@ -5,26 +5,39 @@ binding a cursor (with errors) --FILE-- <?php -require dirname(__FILE__)."/connect.inc"; -require dirname(__FILE__)."/create_table.inc"; +require(dirname(__FILE__)."/connect.inc"); -$insert_sql = "INSERT INTO ".$schema.$table_name." (id, value) VALUES (1,1)"; +// Initialize -if (!($s = oci_parse($c, $insert_sql))) { - die("oci_parse(insert) failed!\n"); -} +$stmtarray = array( + "drop table cursor_bind_err_tab", + "create table cursor_bind_err_tab (id number, value number)", + "insert into cursor_bind_err_tab (id, value) values (1,1)", + "insert into cursor_bind_err_tab (id, value) values (1,1)", + "insert into cursor_bind_err_tab (id, value) values (1,1)", +); -for ($i = 0; $i<3; $i++) { - if (!oci_execute($s)) { - die("oci_execute(insert) failed!\n"); +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } } } -if (!oci_commit($c)) { - die("oci_commit() failed!\n"); +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); } -$sql = "select CURSOR(select * from ".$schema.$table_name.") into :cursor from dual"; +// Run Test + +$sql = "select cursor(select * from cursor_bind_err_tab) into :cursor from dual"; $stmt = oci_parse($c, $sql); $cursor = oci_new_cursor($c); @@ -35,14 +48,23 @@ oci_execute($stmt); oci_execute($cursor); var_dump(oci_fetch_assoc($cursor)); -require dirname(__FILE__)."/drop_table.inc"; +// Cleanup + +$stmtarray = array( + "drop table cursor_bind_err_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} echo "Done\n"; ?> --EXPECTF-- -Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in %s on line %d +Warning: oci_bind_by_name(): ORA-01036: %s in %s on line %d -Warning: oci_fetch_assoc(): ORA-24338: statement handle not executed in %s on line %d +Warning: oci_fetch_assoc(): ORA-24338: %s in %s on line %d bool(false) Done diff --git a/ext/oci8/tests/cursors_old.phpt b/ext/oci8/tests/cursors_old.phpt index cf3b5f957..73447c82b 100644 --- a/ext/oci8/tests/cursors_old.phpt +++ b/ext/oci8/tests/cursors_old.phpt @@ -5,26 +5,39 @@ fetching cursor from a statement --FILE-- <?php -require dirname(__FILE__)."/connect.inc"; -require dirname(__FILE__)."/create_table.inc"; +require(dirname(__FILE__)."/connect.inc"); -$insert_sql = "INSERT INTO ".$schema.$table_name." (id, value) VALUES (1,1)"; +// Initialize -if (!($s = ociparse($c, $insert_sql))) { - die("ociparse(insert) failed!\n"); -} +$stmtarray = array( + "drop table cursors_old_tab", + "create table cursors_old_tab (id number, value number)", + "insert into cursors_old_tab (id, value) values (1,1)", + "insert into cursors_old_tab (id, value) values (1,1)", + "insert into cursors_old_tab (id, value) values (1,1)", +); -for ($i = 0; $i<3; $i++) { - if (!ociexecute($s)) { - die("ociexecute(insert) failed!\n"); +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } } } -if (!ocicommit($c)) { - die("ocicommit() failed!\n"); +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); } -$sql = "select CURSOR(select * from ".$schema.$table_name.") as curs FROM dual"; +// Run Test + +$sql = "select cursor(select * from cursors_old_tab) as curs from dual"; $stmt = ociparse($c, $sql); ociexecute($stmt); @@ -39,26 +52,35 @@ while ($result = ocifetchinto($stmt, $data, OCI_ASSOC)) { var_dump(ocicancel($data["CURS"])); } -require dirname(__FILE__)."/drop_table.inc"; +// Cleanup + +$stmtarray = array( + "drop table cursors_old_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} echo "Done\n"; ?> --EXPECTF-- array(2) { - ["ID"]=> - string(1) "1" - ["VALUE"]=> - string(1) "1" + [%u|b%"ID"]=> + %unicode|string%(1) "1" + [%u|b%"VALUE"]=> + %unicode|string%(1) "1" } bool(true) -Warning: ocifetchinto():%sORA-01002: fetch out of sequence in %scursors_old.php on line %d +Warning: ocifetchinto():%sORA-01002: %s in %scursors_old.php on line %d array(2) { - ["ID"]=> - string(1) "1" - ["VALUE"]=> - string(1) "1" + [%u|b%"ID"]=> + %unicode|string%(1) "1" + [%u|b%"VALUE"]=> + %unicode|string%(1) "1" } bool(true) Done diff --git a/ext/oci8/tests/debug.phpt b/ext/oci8/tests/debug.phpt index cdd56a081..49e3d4cfd 100644 --- a/ext/oci8/tests/debug.phpt +++ b/ext/oci8/tests/debug.phpt @@ -6,9 +6,9 @@ if (!extension_loaded('oci8')) die("skip no oci8 extension"); ob_start(); phpinfo(INFO_MODULES); $phpinfo = ob_get_clean(); -$iv = preg_match('/Oracle .*Version => 11/', $phpinfo); +$iv = preg_match('/Oracle .*Version => (11\.2|12\.)/', $phpinfo); if ($iv !== 1) { - die ("skip expected output only valid when using Oracle 11g client libraries"); + die ("skip expected output only valid when using Oracle 11gR2+ client libraries"); } ?> --FILE-- @@ -34,8 +34,12 @@ OCI8 DEBUG L1: Got NO cached connection at (%s:%d) OCI8 DEBUG: OCIEnvNlsCreate at (%s:%d) OCI8 DEBUG: OCIHandleAlloc at (%s:%d) OCI8 DEBUG: OCIHandleAlloc at (%s:%d) +OCI8 DEBUG: OCIHandleAlloc at (%s:%d) +OCI8 DEBUG: OCIAttrSet at (%s:%d) +OCI8 DEBUG: OCIAttrSet at (%s:%d) OCI8 DEBUG: OCISessionPoolCreate at (%s:%d) OCI8 DEBUG: OCIAttrSet at (%s:%d) +OCI8 DEBUG: OCIHandleFree at (%s:%d) OCI8 DEBUG L1: create_spool: (%s:%d) OCI8 DEBUG L1: using shared pool: (%s:%d) OCI8 DEBUG: OCIHandleAlloc at (%s:%d) @@ -44,7 +48,7 @@ OCI8 DEBUG: OCIAttrSet at (%s:%d) OCI8 DEBUG: OCIAttrSet at (%s:%d) OCI8 DEBUG: OCIAttrGet at (%s:%d) OCI8 DEBUG: OCIAttrGet at (%s:%d) -OCI8 DEBUG L1: (%s:%d) +OCI8 DEBUG L1: (numopen=0)(numbusy=0) at (%s:%d) OCI8 DEBUG: OCISessionGet at (%s:%d) OCI8 DEBUG: OCIAttrGet at (%s:%d) OCI8 DEBUG: OCIAttrGet at (%s:%d) diff --git a/ext/oci8/tests/default_prefetch.phpt b/ext/oci8/tests/default_prefetch.phpt index cc02b6a1c..47191c858 100644 --- a/ext/oci8/tests/default_prefetch.phpt +++ b/ext/oci8/tests/default_prefetch.phpt @@ -7,26 +7,39 @@ oci8.default_prefetch=20 --FILE-- <?php -require dirname(__FILE__)."/connect.inc"; -require dirname(__FILE__).'/create_table.inc'; +require(dirname(__FILE__)."/connect.inc"); -$insert_sql = "INSERT INTO ".$schema.$table_name." (id, value) VALUES (1,1)"; +// Initialize -if (!($s = oci_parse($c, $insert_sql))) { - die("oci_parse(insert) failed!\n"); -} +$stmtarray = array( + "drop table default_prefetch_tab", + "create table default_prefetch_tab (id number, value number)", + "insert into default_prefetch_tab (id, value) values (1,1)", + "insert into default_prefetch_tab (id, value) values (1,1)", + "insert into default_prefetch_tab (id, value) values (1,1)", +); -for ($i = 0; $i<3; $i++) { - if (!oci_execute($s)) { - die("oci_execute(insert) failed!\n"); +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } } } -if (!oci_commit($c)) { - die("oci_commit() failed!\n"); +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); } -$select_sql = "SELECT * FROM ".$schema.$table_name.""; +// Run Test + +$select_sql = "select * from default_prefetch_tab"; if (!($s = oci_parse($c, $select_sql))) { die("oci_parse(select) failed!\n"); @@ -40,7 +53,17 @@ var_dump(oci_fetch($s)); var_dump(oci_num_rows($s)); -require dirname(__FILE__).'/drop_table.inc'; +// Cleanup + +$stmtarray = array( + "drop table default_prefetch_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} + echo "Done\n"; ?> diff --git a/ext/oci8/tests/default_prefetch1.phpt b/ext/oci8/tests/default_prefetch1.phpt index aa130e9f9..bcd66fa38 100644 --- a/ext/oci8/tests/default_prefetch1.phpt +++ b/ext/oci8/tests/default_prefetch1.phpt @@ -7,26 +7,39 @@ oci8.default_prefetch=100 --FILE-- <?php -require dirname(__FILE__)."/connect.inc"; -require dirname(__FILE__).'/create_table.inc'; +require(dirname(__FILE__)."/connect.inc"); -$insert_sql = "INSERT INTO ".$schema.$table_name." (id, value) VALUES (1,1)"; +// Initialize -if (!($s = oci_parse($c, $insert_sql))) { - die("oci_parse(insert) failed!\n"); -} +$stmtarray = array( + "drop table default_prefetch1_tab", + "create table default_prefetch1_tab (id number, value number)", + "insert into default_prefetch1_tab (id, value) values (1,1)", + "insert into default_prefetch1_tab (id, value) values (1,1)", + "insert into default_prefetch1_tab (id, value) values (1,1)", +); -for ($i = 0; $i<3; $i++) { - if (!oci_execute($s)) { - die("oci_execute(insert) failed!\n"); +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } } } -if (!oci_commit($c)) { - die("oci_commit() failed!\n"); +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); } -$select_sql = "SELECT * FROM ".$schema.$table_name.""; +// Run Test + +$select_sql = "select * from default_prefetch1_tab"; if (!($s = oci_parse($c, $select_sql))) { die("oci_parse(select) failed!\n"); @@ -37,10 +50,19 @@ if (!oci_execute($s)) { } var_dump(oci_fetch($s)); - var_dump(oci_num_rows($s)); -require dirname(__FILE__).'/drop_table.inc'; + +// Cleanup + +$stmtarray = array( + "drop table default_prefetch1_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} echo "Done\n"; ?> diff --git a/ext/oci8/tests/default_prefetch2.phpt b/ext/oci8/tests/default_prefetch2.phpt index ac623a274..7b3f29f29 100644 --- a/ext/oci8/tests/default_prefetch2.phpt +++ b/ext/oci8/tests/default_prefetch2.phpt @@ -7,26 +7,39 @@ oci8.default_prefetch=100 --FILE-- <?php -require dirname(__FILE__)."/connect.inc"; -require dirname(__FILE__).'/create_table.inc'; +require(dirname(__FILE__)."/connect.inc"); -$insert_sql = "INSERT INTO ".$schema.$table_name." (id, value) VALUES (1,1)"; +// Initialize -if (!($s = oci_parse($c, $insert_sql))) { - die("oci_parse(insert) failed!\n"); -} +$stmtarray = array( + "drop table default_prefetch2_tab", + "create table default_prefetch2_tab (id number, value number)", + "insert into default_prefetch2_tab (id, value) values (1,1)", + "insert into default_prefetch2_tab (id, value) values (1,1)", + "insert into default_prefetch2_tab (id, value) values (1,1)", +); -for ($i = 0; $i<3; $i++) { - if (!oci_execute($s)) { - die("oci_execute(insert) failed!\n"); +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } } } -if (!oci_commit($c)) { - die("oci_commit() failed!\n"); +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); } -$select_sql = "SELECT * FROM ".$schema.$table_name.""; +// Run Test + +$select_sql = "select * from default_prefetch2_tab"; if (!($s = oci_parse($c, $select_sql))) { die("oci_parse(select) failed!\n"); @@ -39,10 +52,18 @@ if (!oci_execute($s)) { } var_dump(oci_fetch($s)); - var_dump(oci_num_rows($s)); -require dirname(__FILE__).'/drop_table.inc'; +// Cleanup + +$stmtarray = array( + "drop table default_prefetch2_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} echo "Done\n"; ?> diff --git a/ext/oci8/tests/define.phpt b/ext/oci8/tests/define.phpt index c76f360f2..d99bc7e1a 100644 --- a/ext/oci8/tests/define.phpt +++ b/ext/oci8/tests/define.phpt @@ -5,24 +5,36 @@ oci_define_by_name() --FILE-- <?php -require dirname(__FILE__)."/connect.inc"; -require dirname(__FILE__)."/create_table.inc"; - -$insert_sql = "INSERT INTO ".$schema.$table_name." (string) VALUES ('some')"; - -if (!($s = oci_parse($c, $insert_sql))) { - die("oci_parse(insert) failed!\n"); +require(dirname(__FILE__)."/connect.inc"); + +// Initialize + +$stmtarray = array( + "drop table define_tab", + "create table define_tab (string varchar(10))", + "insert into define_tab (string) values ('some')", +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } + } } -if (!oci_execute($s)) { - die("oci_execute(insert) failed!\n"); -} +// Run test -$stmt = oci_parse($c, "SELECT string FROM ".$table_name.""); +$stmt = oci_parse($c, "select string from define_tab"); /* the define MUST be done BEFORE ociexecute! */ -$strong = ''; +$string = ''; oci_define_by_name($stmt, "STRING", $string, 20); oci_execute($stmt); @@ -31,11 +43,20 @@ while (oci_fetch($stmt)) { var_dump($string); } -require dirname(__FILE__)."/drop_table.inc"; +// Cleanup + +$stmtarray = array( + "drop table define_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} echo "Done\n"; ?> ---EXPECT-- -string(4) "some" +--EXPECTF-- +%unicode|string%(%d) "some" Done diff --git a/ext/oci8/tests/define1.phpt b/ext/oci8/tests/define1.phpt index f6e04cc18..341bc9ed8 100644 --- a/ext/oci8/tests/define1.phpt +++ b/ext/oci8/tests/define1.phpt @@ -5,24 +5,36 @@ oci_define_by_name() --FILE-- <?php -require dirname(__FILE__)."/connect.inc"; -require dirname(__FILE__)."/create_table.inc"; +require(dirname(__FILE__)."/connect.inc"); -$insert_sql = "INSERT INTO ".$schema.$table_name." (string) VALUES ('some')"; +// Initialize -if (!($s = oci_parse($c, $insert_sql))) { - die("oci_parse(insert) failed!\n"); -} +$stmtarray = array( + "drop table define1_tab", + "create table define1_tab (string varchar(10))", + "insert into define1_tab (string) values ('some')", +); -if (!oci_execute($s)) { - die("oci_execute(insert) failed!\n"); +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } + } } -$stmt = oci_parse($c, "SELECT string FROM ".$table_name.""); +// Run test + +$stmt = oci_parse($c, "select string from define1_tab"); /* the define MUST be done BEFORE ociexecute! */ -$strong = ''; +$string = ''; var_dump(oci_define_by_name($stmt, "STRING", $string, 20)); var_dump(oci_define_by_name($stmt, "STRING", $string, 20)); var_dump(oci_define_by_name($stmt, "", $string, 20)); @@ -34,7 +46,16 @@ while (oci_fetch($stmt)) { var_dump($string); } -require dirname(__FILE__)."/drop_table.inc"; +// Cleanup + +$stmtarray = array( + "drop table define1_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} echo "Done\n"; @@ -48,5 +69,5 @@ bool(false) Warning: oci_define_by_name() expects at least 3 parameters, 2 given in %s on line %d NULL -string(4) "some" +%unicode|string%(4) "some" Done diff --git a/ext/oci8/tests/define4.phpt b/ext/oci8/tests/define4.phpt index 6fd9f5b93..8d83f73ac 100644 --- a/ext/oci8/tests/define4.phpt +++ b/ext/oci8/tests/define4.phpt @@ -5,20 +5,32 @@ oci_define_by_name() on partial number of columns --FILE-- <?php -require dirname(__FILE__)."/connect.inc"; -require dirname(__FILE__)."/create_table.inc"; +require(dirname(__FILE__)."/connect.inc"); -$insert_sql = "INSERT INTO ".$schema.$table_name." (value, string) VALUES (1234, 'some')"; +// Initialize -if (!($s = oci_parse($c, $insert_sql))) { - die("oci_parse(insert) failed!\n"); -} +$stmtarray = array( + "drop table define4_tab", + "create table define4_tab (value number, string varchar(10))", + "insert into define4_tab (value, string) values (1234, 'some')", +); -if (!oci_execute($s)) { - die("oci_execute(insert) failed!\n"); +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } + } } -$stmt = oci_parse($c, "SELECT value, string FROM ".$table_name.""); +// Run test + +$stmt = oci_parse($c, "select value, string from define4_tab"); echo "Test 1\n"; // Only one of the two columns is defined @@ -42,7 +54,16 @@ var_dump(oci_free_statement($stmt)); var_dump($string); var_dump(oci_result($stmt, 'STRING')); -require dirname(__FILE__)."/drop_table.inc"; +// Cleanup + +$stmtarray = array( + "drop table define4_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} echo "Done\n"; @@ -51,15 +72,15 @@ echo "Done\n"; Test 1 bool(true) Test 2 -string(4) "1234" -string(4) "some" -string(4) "some" -string(4) "some" -string(4) "1234" -string(4) "some" +%unicode|string%(4) "1234" +%unicode|string%(4) "some" +%unicode|string%(4) "some" +%unicode|string%(4) "some" +%unicode|string%(4) "1234" +%unicode|string%(4) "some" Test 3 bool(true) -string(4) "some" +%unicode|string%(4) "some" Warning: oci_result(): %d is not a valid oci8 statement resource in %s on line %d bool(false) diff --git a/ext/oci8/tests/define5.phpt b/ext/oci8/tests/define5.phpt index c439b1d64..63541ce9d 100644 --- a/ext/oci8/tests/define5.phpt +++ b/ext/oci8/tests/define5.phpt @@ -5,19 +5,34 @@ oci_define_by_name() for statement re-execution --FILE-- <?php -require dirname(__FILE__)."/connect.inc"; -require dirname(__FILE__)."/create_table.inc"; +require(dirname(__FILE__)."/connect.inc"); -$insert_sql = "INSERT INTO ".$schema.$table_name." (id, string) VALUES (1, 'some')"; -$s = oci_parse($c, $insert_sql); -var_dump(oci_execute($s)); +// Initialize -$insert_sql = "INSERT INTO ".$schema.$table_name." (id, string) VALUES (2, 'thing')"; -$s = oci_parse($c, $insert_sql); -var_dump(oci_execute($s)); +$stmtarray = array( + "drop table define5_tab", + "create table define5_tab (id number, string varchar(10))", + "insert into define5_tab (id, string) values (1, 'some')", + "insert into define5_tab (id, string) values (2, 'thing')", +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } + } +} + +// Run test echo "Test 1 - must do define before execute\n"; -$stmt = oci_parse($c, "SELECT string FROM ".$table_name." where id = 1"); +$stmt = oci_parse($c, "select string from define5_tab where id = 1"); oci_execute($stmt); var_dump(oci_define_by_name($stmt, "STRING", $string)); while (oci_fetch($stmt)) { @@ -26,7 +41,7 @@ while (oci_fetch($stmt)) { } echo "Test 2 - normal define order\n"; -$stmt = oci_parse($c, "SELECT string FROM ".$table_name." where id = 1"); +$stmt = oci_parse($c, "select string from define5_tab where id = 1"); var_dump(oci_define_by_name($stmt, "STRING", $string)); oci_execute($stmt); @@ -35,30 +50,37 @@ while (oci_fetch($stmt)) { } echo "Test 3 - no new define done\n"; -$stmt = oci_parse($c, "SELECT string FROM ".$table_name." where id = 2"); +$stmt = oci_parse($c, "select string from define5_tab where id = 2"); oci_execute($stmt); while (oci_fetch($stmt)) { var_dump($string); // not updated with new value var_dump(oci_result($stmt, 'STRING')); } -require dirname(__FILE__)."/drop_table.inc"; +// Cleanup + +$stmtarray = array( + "drop table define5_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} echo "Done\n"; ?> ---EXPECT-- -bool(true) -bool(true) +--EXPECTF-- Test 1 - must do define before execute bool(true) NULL -string(4) "some" +%unicode|string%(4) "some" Test 2 - normal define order bool(true) -string(4) "some" +%unicode|string%(4) "some" Test 3 - no new define done -string(4) "some" -string(5) "thing" +%unicode|string%(4) "some" +%unicode|string%(5) "thing" Done diff --git a/ext/oci8/tests/define_old.phpt b/ext/oci8/tests/define_old.phpt index da52e619c..618f9d5f5 100644 --- a/ext/oci8/tests/define_old.phpt +++ b/ext/oci8/tests/define_old.phpt @@ -5,24 +5,36 @@ ocidefinebyname() --FILE-- <?php -require dirname(__FILE__)."/connect.inc"; -require dirname(__FILE__)."/create_table.inc"; - -$insert_sql = "INSERT INTO ".$schema.$table_name." (string) VALUES ('some')"; - -if (!($s = ociparse($c, $insert_sql))) { - die("oci_parse(insert) failed!\n"); +require(dirname(__FILE__)."/connect.inc"); + +// Initialize + +$stmtarray = array( + "drop table define_old_tab", + "create table define_old_tab (string varchar(10))", + "insert into define_old_tab (string) values ('some')", +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } + } } -if (!ociexecute($s)) { - die("oci_execute(insert) failed!\n"); -} +// Run test -$stmt = ociparse($c, "SELECT string FROM ".$table_name.""); +$stmt = ociparse($c, "select string from define_old_tab"); /* the define MUST be done BEFORE ociexecute! */ -$strong = ''; +$string = ''; ocidefinebyname($stmt, "STRING", $string, 20); ociexecute($stmt); @@ -31,11 +43,21 @@ while (ocifetch($stmt)) { var_dump($string); } -require dirname(__FILE__)."/drop_table.inc"; +// Cleanup + +$stmtarray = array( + "drop table define_old_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} + echo "Done\n"; ?> ---EXPECT-- -string(4) "some" +--EXPECTF-- +%unicode|string%(4) "some" Done diff --git a/ext/oci8/tests/driver_name.phpt b/ext/oci8/tests/driver_name.phpt new file mode 100644 index 000000000..187d7e186 --- /dev/null +++ b/ext/oci8/tests/driver_name.phpt @@ -0,0 +1,71 @@ +--TEST-- +Verify that the Driver Name attribute is set +--SKIPIF-- +<?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); + +require(dirname(__FILE__)."/connect.inc"); +if (strcasecmp($user, "system") && strcasecmp($user, "sys")) die("skip needs to be run as a DBA user"); +if ($test_drcp) die("skip as Output might vary with DRCP"); + +$sv = oci_server_version($c); +$sv = preg_match('/Release (11.2|12)/', $sv, $matches); + +if ($sv == 1) { + ob_start(); + phpinfo(INFO_MODULES); + $phpinfo = ob_get_clean(); + $iv = preg_match('/Oracle .*Version => (11.2|12)/', $phpinfo); + if ($iv != 1) { + die ("skip test expected to work only with Oracle 11g or greater version of client"); + } +} +else { + die ("skip test expected to work only with Oracle 11g or greater version of server"); +} + +?> +--FILE-- +<?php +require(dirname(__FILE__)."/connect.inc"); + +echo"**Test 1.1 - Default values for the attribute **************\n"; +get_attr($c); +oci_close($c); + +echo"\n***Test 1.2 - Get the values from different connections **************\n"; +// with oci_pconnect() +echo "Testing with oci_pconnect()\n"; +$pc1=oci_pconnect($user,$password,$dbase); +get_attr($pc1); +oci_close($pc1); + +echo "Testing with oci_new_connect()\n"; +$nc1=oci_new_connect($user,$password,$dbase); +get_attr($nc1); +oci_close($nc1); +echo "Done\n"; + +function get_attr($conn) +{ + $sel_stmt = "select client_driver + from v\$session_connect_info sci, v\$session s + where sci.client_driver is not null + and sci.sid = s.sid + and s.audsid = userenv('SESSIONID')"; + $s2 = oci_parse($conn,$sel_stmt); + oci_execute($s2,OCI_DEFAULT); + oci_fetch($s2); + echo "The value of DRIVER_NAME is ".oci_result($s2,1)."\n"; +} + +?> +--EXPECT-- +**Test 1.1 - Default values for the attribute ************** +The value of DRIVER_NAME is PHP OCI8 + +***Test 1.2 - Get the values from different connections ************** +Testing with oci_pconnect() +The value of DRIVER_NAME is PHP OCI8 +Testing with oci_new_connect() +The value of DRIVER_NAME is PHP OCI8 +Done diff --git a/ext/oci8/tests/drop_table.inc b/ext/oci8/tests/drop_table.inc index ffd99f5af..592a95a3d 100644 --- a/ext/oci8/tests/drop_table.inc +++ b/ext/oci8/tests/drop_table.inc @@ -1,12 +1,7 @@ <?php - - if ($c) { - $ora_sql = "DROP TABLE - ".$schema.$table_name." - "; - - $statement = OCIParse($c,$ora_sql); - OCIExecute($statement); - } - +if ($c) { + $ora_sql = "DROP TABLE ".$schema.$table_name; + $statement = oci_parse($c,$ora_sql); + oci_execute($statement); +} ?> diff --git a/ext/oci8/tests/drop_type.inc b/ext/oci8/tests/drop_type.inc index 047968ef2..98542a808 100644 --- a/ext/oci8/tests/drop_type.inc +++ b/ext/oci8/tests/drop_type.inc @@ -1,12 +1,7 @@ <?php - - if ($c) { - $ora_sql = "DROP TYPE - ".$type_name." - "; - - $statement = OCIParse($c,$ora_sql); - OCIExecute($statement); - } - +if ($c) { + $ora_sql = "DROP TYPE ".$type_name; + $statement = oci_parse($c,$ora_sql); + oci_execute($statement); +} ?> diff --git a/ext/oci8/tests/edition_1.phpt b/ext/oci8/tests/edition_1.phpt new file mode 100644 index 000000000..9a4b0f3b6 --- /dev/null +++ b/ext/oci8/tests/edition_1.phpt @@ -0,0 +1,156 @@ +--TEST-- +Basic test for setting Oracle 11gR2 "edition" attribute +--SKIPIF-- +<?php +if (!extension_loaded('oci8')) die("skip no oci8 extension"); +require(dirname(__FILE__)."/connect.inc"); +if (strcasecmp($user, "system") && strcasecmp($user, "sys")) + die("skip needs to be run as a DBA user"); +if ($test_drcp) + die("skip as Output might vary with DRCP"); + +$sv = oci_server_version($c); +$sv = preg_match('/Release (11\.2|12)/', $sv, $matches); +if ($sv == 1) { + ob_start(); + phpinfo(INFO_MODULES); + $phpinfo = ob_get_clean(); + $iv = preg_match('/Oracle .*Version => (11\.2|12)/', $phpinfo); + if ($iv != 1) { + die ("skip tests a feature that works only with Oracle 11gR2 or greater version of client"); + } +} +else { + die ("skip tests a feature that works only with Oracle 11gR2 or greater version of server"); +} + +?> +--FILE-- +<?php + +/* In 11.2, there can only be one child edition. So this test will + * fail to create the necessary editions if a child edition exists + * already + */ + +require(dirname(__FILE__)."/conn_attr.inc"); + +function select_fn($conn) { + $s = oci_parse($conn,"select * from view_ed"); + oci_execute($s); + while ($row = oci_fetch_row($s)) { + var_dump($row); + } +} +/* Create a editon MYEDITION + create a view view_ed in MYEDITION1. + create the same view 'view_ed' with a different definition in MYEDITION. + select from both the editions and verify the contents. */ + +set_edit_attr('MYEDITION'); +$conn = oci_connect('testuser','testuser',$dbase); +if ($conn === false) { + $m = oci_error(); + die("Error:" . $m['message']); +} + +$stmtarray = array( + "drop table edit_tab", + "create table edit_tab (name varchar2(10),age number,job varchar2(50), salary number)", + "insert into edit_tab values('mike',30,'Senior engineer',200)", + "insert into edit_tab values('juan',25,'engineer',100)", + "create or replace editioning view view_ed as select name,age,job from edit_tab", +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($conn, $stmt); + @oci_execute($s); +} + +// Check the current edition of the DB and the contents of view_ed. +get_edit_attr($conn); +select_fn($conn); + +// Create a different version of view_ed in MYEDITION1. +set_edit_attr('MYEDITION1'); +$conn2 = oci_new_connect('testuser','testuser',$dbase); +$stmt = "create or replace editioning view view_ed as select name,age,job,salary from edit_tab"; +$s = oci_parse($conn2, $stmt); +oci_execute($s); + +// Check the current edition of the DB and the contents of view_ed. +get_edit_attr($conn2); +select_fn($conn2); + +// Verify the contents in MYEDITION EDITION. +echo "version of view_ed in MYEDITION \n"; +get_edit_attr($conn); +select_fn($conn); + +clean_up($c); + +oci_close($conn); +oci_close($conn2); +echo "Done\n"; + +?> +--EXPECTF-- +The value of edition has been successfully set +The value of current EDITION is MYEDITION +array(3) { + [0]=> + %unicode|string%(%d) "mike" + [1]=> + %unicode|string%(%d) "30" + [2]=> + %unicode|string%(%d) "Senior engineer" +} +array(3) { + [0]=> + %unicode|string%(%d) "juan" + [1]=> + %unicode|string%(%d) "25" + [2]=> + %unicode|string%(%d) "engineer" +} + The value of edition has been successfully set +The value of current EDITION is MYEDITION1 +array(4) { + [0]=> + %unicode|string%(%d) "mike" + [1]=> + %unicode|string%(%d) "30" + [2]=> + %unicode|string%(%d) "Senior engineer" + [3]=> + %unicode|string%(%d) "200" +} +array(4) { + [0]=> + %unicode|string%(%d) "juan" + [1]=> + %unicode|string%(%d) "25" + [2]=> + %unicode|string%(%d) "engineer" + [3]=> + %unicode|string%(%d) "100" +} +version of view_ed in MYEDITION +The value of current EDITION is MYEDITION +array(3) { + [0]=> + %unicode|string%(%d) "mike" + [1]=> + %unicode|string%(%d) "30" + [2]=> + %unicode|string%(%d) "Senior engineer" +} +array(3) { + [0]=> + %unicode|string%(%d) "juan" + [1]=> + %unicode|string%(%d) "25" + [2]=> + %unicode|string%(%d) "engineer" +} +Done diff --git a/ext/oci8/tests/edition_2.phpt b/ext/oci8/tests/edition_2.phpt new file mode 100644 index 000000000..f7ab979bc --- /dev/null +++ b/ext/oci8/tests/edition_2.phpt @@ -0,0 +1,248 @@ +--TEST-- +Set and check Oracle 11gR2 "edition" attribute +--SKIPIF-- +<?php +if (!extension_loaded('oci8')) die("skip no oci8 extension"); +require(dirname(__FILE__)."/connect.inc"); +if (strcasecmp($user, "system") && strcasecmp($user, "sys")) + die("skip needs to be run as a DBA user"); +if ($test_drcp) + die("skip as Output might vary with DRCP"); + +$sv = oci_server_version($c); +$sv = preg_match('/Release (11\.2|12)/', $sv, $matches); +if ($sv == 1) { + ob_start(); + phpinfo(INFO_MODULES); + $phpinfo = ob_get_clean(); + $iv = preg_match('/Oracle .*Version => (11\.2|12)/', $phpinfo); + if ($iv != 1) { + die ("skip tests a feature that works only with Oracle 11gR2 or greater version of client"); + } +} +else { + die ("skip tests a feature that works only with Oracle 11gR2 or greater version of server"); +} + +?> +--FILE-- +<?php + +/* In 11.2, there can only be one child edition. So this test will + * fail to create the necessary editions if a child edition exists + * already + */ + +require(dirname(__FILE__)."/conn_attr.inc"); + +$user = 'testuser'; +$password = 'testuser'; + +echo"**Test 1.1 - Default value for the attribute **************\n"; +get_edit_attr($c); + +echo"\n\n**Test 1.2 - Set a value and get the same with different connections *********\n"; +set_edit_attr('MYEDITION'); + +// With oci_connect, oci_pconnect, oci_new_connect +$conn1 = get_conn(1); +get_edit_attr($conn1); + +//pconnect +$conn2 = get_conn(2); +get_edit_attr($conn2); + +//new_connect +$conn3 = get_conn(3); +get_edit_attr($conn3); + +oci_close($conn1); + +// With a oci_pconnect with a different charset. +$pc1 = oci_pconnect($user,$password,$dbase,"utf8"); +get_edit_attr($pc1); +oci_close($pc1); + + +echo"\n\n**Test 1.3 change the value and verify with existing conenctions.*********\n"; +set_edit_attr('MYEDITION1'); +get_edit_attr($conn2); +get_edit_attr($conn3); // Old value +oci_close($conn2); +oci_close($conn3); + +//open a new connection and get the edition value . This will have the updated value. +$c3 = get_conn(3); //oci_new_connect() +get_edit_attr($c3); + +$c4 = get_conn(2); //oci_pconnect() +get_edit_attr($c4); + +$c5 = get_conn(1); //oci_connect() +get_edit_attr($c5); + +oci_close($c3); +oci_close($c4); +oci_close($c5); + +echo "\n\n**Test 1.4 - with different type of values *********\n"; +$values_array = array(123,NULL,'NO EDITION','edition name which has more than thirty chars!!!edition name which has more than thirty chars!!!'); +foreach ($values_array as $val ) { + set_edit_attr($val); + $c1 = get_conn(1); //oci_connect() + if ($c1) { + get_edit_attr($c1); + oci_close($c1); + } +} + +echo "\n\n**Test 1.5 - Negative case with an invalid string value. *********\n"; +$c1 = get_conn(3); +$r = set_edit_attr($c1); + +echo"\n\n**Test 1.6 - Set Multiple times.*****\n"; +set_edit_attr('MYEDITION'); +set_edit_attr('MYEDITION1'); +$c1 = get_conn(1); +get_edit_attr($c1); +oci_close($c1); + +echo "\n\n**Test 1.7 - Test with ALTER SESSION statement to change the edition *******\n"; +// Set the edition value to MYEDITION. open a conn .get the value. +// execute the alter system set edition ='MYEDITION' .get the value . +// set it back to MYEDITION using oci_set_edition. and get the value. + +set_edit_attr('MYEDITION'); +$c1 = get_conn(3); +echo "get the value set to MYEDITION with oci_set_edition \n"; +get_edit_attr($c1); + +$alter_stmt = "alter session set edition = MYEDITION1"; +$s = oci_parse($c1,$alter_stmt); +oci_execute($s); +oci_commit($c1); +echo "Get the value set to MYEDITION1 with alter session\n"; +get_edit_attr($c1); + +echo " Get the value with a new connection \n"; +$c2 = get_conn(1); +get_edit_attr($c2); + +echo " Set the value back using oci-set_edition\n"; +set_edit_attr('MYEDITION'); +get_edit_attr($c2); + +echo " Get the value with a new conenction \n"; +$c3 = get_conn(1); +get_edit_attr($c3); + +oci_close($c1); +oci_close($c2); +oci_close($c3); + + +echo "\n\n**Test 1.8 - Test setting the attribute with scope ends*******\n"; +set_scope(); +get_scope(); + +clean_up($c); +echo "Done\n"; + + +function set_scope() { + $r = set_edit_attr('MYEDITION1'); +} + +function get_scope() { + $sc1 = oci_connect($GLOBALS['user'],$GLOBALS['password'],$GLOBALS['dbase']); + if ($sc1 === false) { + $m = oci_error(); + die("Error:" . $m['message']); + } + get_edit_attr($sc1); + oci_close($sc1); +} +?> +--EXPECTF-- +**Test 1.1 - Default value for the attribute ************** +The value of current EDITION is ORA$BASE + + +**Test 1.2 - Set a value and get the same with different connections ********* + The value of edition has been successfully set +Testing with oci_connect() +The value of current EDITION is MYEDITION +Testing with oci_pconnect() +The value of current EDITION is MYEDITION +Testing with oci_new_connect() +The value of current EDITION is MYEDITION +The value of current EDITION is MYEDITION + + +**Test 1.3 change the value and verify with existing conenctions.********* + The value of edition has been successfully set +The value of current EDITION is MYEDITION +The value of current EDITION is MYEDITION +Testing with oci_new_connect() +The value of current EDITION is MYEDITION1 +Testing with oci_pconnect() +The value of current EDITION is MYEDITION1 +Testing with oci_connect() +The value of current EDITION is MYEDITION1 + + +**Test 1.4 - with different type of values ********* + The value of edition has been successfully set +Testing with oci_connect() + +Warning: oci_connect(): ORA-38801: %s ORA_EDITION in %s on line %d + The value of edition has been successfully set +Testing with oci_connect() +The value of current EDITION is ORA$BASE + The value of edition has been successfully set +Testing with oci_connect() + +Warning: oci_connect(): ORA-38801: %s ORA_EDITION in %s on line %d + The value of edition has been successfully set +Testing with oci_connect() + +Warning: oci_connect(): ORA-38801: %s ORA_EDITION in %s on line %d + + +**Test 1.5 - Negative case with an invalid string value. ********* +Testing with oci_new_connect() + +Warning: oci_new_connect(): ORA-38801: %s ORA_EDITION in %s on line %d + The value of edition has been successfully set + + +**Test 1.6 - Set Multiple times.***** + The value of edition has been successfully set + The value of edition has been successfully set +Testing with oci_connect() +The value of current EDITION is MYEDITION1 + + +**Test 1.7 - Test with ALTER SESSION statement to change the edition ******* + The value of edition has been successfully set +Testing with oci_new_connect() +get the value set to MYEDITION with oci_set_edition +The value of current EDITION is MYEDITION +Get the value set to MYEDITION1 with alter session +The value of current EDITION is MYEDITION1 + Get the value with a new connection +Testing with oci_connect() +The value of current EDITION is MYEDITION + Set the value back using oci-set_edition + The value of edition has been successfully set +The value of current EDITION is MYEDITION + Get the value with a new conenction +Testing with oci_connect() +The value of current EDITION is MYEDITION + + +**Test 1.8 - Test setting the attribute with scope ends******* + The value of edition has been successfully set +The value of current EDITION is MYEDITION1 +Done + diff --git a/ext/oci8/tests/extauth_01.phpt b/ext/oci8/tests/extauth_01.phpt index e054a2216..30250ec24 100644 --- a/ext/oci8/tests/extauth_01.phpt +++ b/ext/oci8/tests/extauth_01.phpt @@ -139,12 +139,12 @@ bool(false) bool(false) Test 7 -Warning: oci_connect(): ORA-12154: TNS:could not resolve the connect identifier specified in %s on line %d +Warning: oci_connect(): ORA-12154: %s in %s on line %d array(4) { [%u|b%"code"]=> int(12154) [%u|b%"message"]=> - %unicode|string%(65) "ORA-12154: %s" + %unicode|string%(%d) "ORA-12154: %s" [%u|b%"offset"]=> int(0) [%u|b%"sqltext"]=> @@ -153,12 +153,12 @@ array(4) { bool(false) Test 8 -Warning: oci_connect(): ORA-12154: TNS:could not resolve the connect identifier specified in %s on line %d +Warning: oci_connect(): ORA-12154: %s in %s on line %d array(4) { [%u|b%"code"]=> int(12154) [%u|b%"message"]=> - %unicode|string%(65) "ORA-12154: %s" + %unicode|string%(%d) "ORA-12154: %s" [%u|b%"offset"]=> int(0) [%u|b%"sqltext"]=> diff --git a/ext/oci8/tests/extauth_02.phpt b/ext/oci8/tests/extauth_02.phpt index b27522961..d648eef08 100644 --- a/ext/oci8/tests/extauth_02.phpt +++ b/ext/oci8/tests/extauth_02.phpt @@ -139,12 +139,12 @@ bool(false) bool(false) Test 7 -Warning: oci_new_connect(): ORA-12154: TNS:could not resolve the connect identifier specified in %s on line %d +Warning: oci_new_connect(): ORA-12154: %s in %s on line %d array(4) { [%u|b%"code"]=> int(12154) [%u|b%"message"]=> - %unicode|string%(65) "ORA-12154: %s" + %unicode|string%(%d) "ORA-12154: %s" [%u|b%"offset"]=> int(0) [%u|b%"sqltext"]=> @@ -153,12 +153,12 @@ array(4) { bool(false) Test 8 -Warning: oci_new_connect(): ORA-12154: TNS:could not resolve the connect identifier specified in %s on line %d +Warning: oci_new_connect(): ORA-12154: %s in %s on line %d array(4) { [%u|b%"code"]=> int(12154) [%u|b%"message"]=> - %unicode|string%(65) "ORA-12154: %s" + %unicode|string%(%d) "ORA-12154: %s" [%u|b%"offset"]=> int(0) [%u|b%"sqltext"]=> diff --git a/ext/oci8/tests/extauth_03.phpt b/ext/oci8/tests/extauth_03.phpt index 50be0e724..021492f76 100644 --- a/ext/oci8/tests/extauth_03.phpt +++ b/ext/oci8/tests/extauth_03.phpt @@ -139,12 +139,12 @@ bool(false) bool(false) Test 7 -Warning: oci_pconnect(): ORA-12154: TNS:could not resolve the connect identifier specified in %s on line %d +Warning: oci_pconnect(): ORA-12154: %s in %s on line %d array(4) { [%u|b%"code"]=> int(12154) [%u|b%"message"]=> - %unicode|string%(65) "ORA-12154: %s" + %unicode|string%(%d) "ORA-12154: %s" [%u|b%"offset"]=> int(0) [%u|b%"sqltext"]=> @@ -153,12 +153,12 @@ array(4) { bool(false) Test 8 -Warning: oci_pconnect(): ORA-12154: TNS:could not resolve the connect identifier specified in %s on line %d +Warning: oci_pconnect(): ORA-12154: %s in %s on line %d array(4) { [%u|b%"code"]=> int(12154) [%u|b%"message"]=> - %unicode|string%(65) "ORA-12154: %s" + %unicode|string%(%d) "ORA-12154: %s" [%u|b%"offset"]=> int(0) [%u|b%"sqltext"]=> diff --git a/ext/oci8/tests/fetch.phpt b/ext/oci8/tests/fetch.phpt index 33cba657b..520632494 100644 --- a/ext/oci8/tests/fetch.phpt +++ b/ext/oci8/tests/fetch.phpt @@ -5,28 +5,39 @@ ocifetch() & ociresult() --FILE-- <?php -require dirname(__FILE__)."/connect.inc"; -require dirname(__FILE__).'/create_table.inc'; +require(dirname(__FILE__)."/connect.inc"); -$insert_sql = "INSERT INTO ".$schema.$table_name." (id, value) VALUES (1,1)"; +// Initialize -if (!($s = oci_parse($c, $insert_sql))) { - die("oci_parse(insert) failed!\n"); -} +$stmtarray = array( + "drop table fetch_tab", + "create table fetch_tab (id number, value number)", + "insert into fetch_tab (id, value) values (1,1)", + "insert into fetch_tab (id, value) values (1,1)", + "insert into fetch_tab (id, value) values (1,1)", +); -for ($i = 0; $i<3; $i++) { - if (!oci_execute($s)) { - die("oci_execute(insert) failed!\n"); +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } } } -if (!oci_commit($c)) { - die("oci_commit() failed!\n"); +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); } -$select_sql = "SELECT * FROM ".$schema.$table_name.""; +// Run Test -if (!($s = oci_parse($c, $select_sql))) { +if (!($s = oci_parse($c, "select * from fetch_tab"))) { die("oci_parse(select) failed!\n"); } @@ -35,22 +46,31 @@ if (!oci_execute($s)) { } while(ocifetch($s)) { - $i = 1; - while ($row = ociresult($s, $i)) { - $i++; + $row = ociresult($s, 1); + $row1 = ociresult($s, 2); var_dump($row); - } + var_dump($row1); +} + +// Cleanup + +$stmtarray = array( + "drop table fetch_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); } -require dirname(__FILE__).'/drop_table.inc'; echo "Done\n"; ?> ---EXPECT-- -string(1) "1" -string(1) "1" -string(1) "1" -string(1) "1" -string(1) "1" -string(1) "1" +--EXPECTF-- +%unicode|string%(1) "1" +%unicode|string%(1) "1" +%unicode|string%(1) "1" +%unicode|string%(1) "1" +%unicode|string%(1) "1" +%unicode|string%(1) "1" Done diff --git a/ext/oci8/tests/fetch_all.phpt b/ext/oci8/tests/fetch_all.phpt index 5d3738b89..a007bac83 100644 --- a/ext/oci8/tests/fetch_all.phpt +++ b/ext/oci8/tests/fetch_all.phpt @@ -5,28 +5,32 @@ oci_fetch_all() --FILE-- <?php -require dirname(__FILE__)."/connect.inc"; -require dirname(__FILE__).'/create_table.inc'; +require(dirname(__FILE__)."/connect.inc"); -$insert_sql = "INSERT INTO ".$schema."".$table_name." (id, value) VALUES (1,1)"; +// Initialize -if (!($s = oci_parse($c, $insert_sql))) { - die("oci_parse(insert) failed!\n"); -} +$stmtarray = array( + "drop table fetch_all_tab", + "create table fetch_all_tab (id number, value number)", + "insert into fetch_all_tab (id, value) values (1,1)", + "insert into fetch_all_tab (id, value) values (1,1)", + "insert into fetch_all_tab (id, value) values (1,1)" +); -for ($i = 0; $i<3; $i++) { - if (!oci_execute($s)) { - die("oci_execute(insert) failed!\n"); +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } } } -if (!oci_commit($c)) { - die("oci_commit() failed!\n"); -} - -$select_sql = "SELECT * FROM ".$schema."".$table_name.""; - -if (!($s = oci_parse($c, $select_sql))) { +if (!($s = oci_parse($c, "select * from fetch_all_tab"))) { die("oci_parse(select) failed!\n"); } @@ -45,105 +49,60 @@ if (!oci_execute($s)) { var_dump(ocifetchstatement($s, $all)); var_dump($all); -require dirname(__FILE__).'/drop_table.inc'; +// Cleanup + +$stmtarray = array( + "drop table fetch_all_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} echo "Done\n"; ?> ---EXPECT-- +--EXPECTF-- int(3) -array(5) { - ["ID"]=> +array(2) { + [%u|b%"ID"]=> array(3) { [0]=> - string(1) "1" + %unicode|string%(1) "1" [1]=> - string(1) "1" + %unicode|string%(1) "1" [2]=> - string(1) "1" + %unicode|string%(1) "1" } - ["VALUE"]=> + [%u|b%"VALUE"]=> array(3) { [0]=> - string(1) "1" + %unicode|string%(1) "1" [1]=> - string(1) "1" + %unicode|string%(1) "1" [2]=> - string(1) "1" - } - ["BLOB"]=> - array(3) { - [0]=> - NULL - [1]=> - NULL - [2]=> - NULL - } - ["CLOB"]=> - array(3) { - [0]=> - NULL - [1]=> - NULL - [2]=> - NULL - } - ["STRING"]=> - array(3) { - [0]=> - NULL - [1]=> - NULL - [2]=> - NULL + %unicode|string%(1) "1" } } int(3) -array(5) { - ["ID"]=> - array(3) { - [0]=> - string(1) "1" - [1]=> - string(1) "1" - [2]=> - string(1) "1" - } - ["VALUE"]=> - array(3) { - [0]=> - string(1) "1" - [1]=> - string(1) "1" - [2]=> - string(1) "1" - } - ["BLOB"]=> - array(3) { - [0]=> - NULL - [1]=> - NULL - [2]=> - NULL - } - ["CLOB"]=> +array(2) { + [%u|b%"ID"]=> array(3) { [0]=> - NULL + %unicode|string%(1) "1" [1]=> - NULL + %unicode|string%(1) "1" [2]=> - NULL + %unicode|string%(1) "1" } - ["STRING"]=> + [%u|b%"VALUE"]=> array(3) { [0]=> - NULL + %unicode|string%(1) "1" [1]=> - NULL + %unicode|string%(1) "1" [2]=> - NULL + %unicode|string%(1) "1" } } Done diff --git a/ext/oci8/tests/fetch_all3.phpt b/ext/oci8/tests/fetch_all3.phpt index 503e5dd88..42fe617dc 100644 --- a/ext/oci8/tests/fetch_all3.phpt +++ b/ext/oci8/tests/fetch_all3.phpt @@ -5,11 +5,34 @@ oci_fetch_all() - all combinations of flags --FILE-- <?php -require dirname(__FILE__)."/connect.inc"; -require dirname(__FILE__).'/create_table.inc'; +require(dirname(__FILE__)."/connect.inc"); -$insert_sql = "INSERT INTO ".$schema."".$table_name." (id, value) VALUES (:idbv,:vbv)"; +// Initialize +$stmtarray = array( + "drop table fetch_all3_tab", + "create table fetch_all3_tab (id number, value number)", +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } + } +} + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} + +$insert_sql = "insert into fetch_all3_tab (id, value) values (:idbv,:vbv)"; $s = oci_parse($c, $insert_sql); oci_bind_by_name($s, ":idbv", $idbv, SQLT_INT); oci_bind_by_name($s, ":vbv", $vbv, SQLT_INT); @@ -22,7 +45,9 @@ for ($i = 1; $i <= 4; $i++) { oci_commit($c); -$select_sql = "SELECT ID, VALUE FROM ".$schema."".$table_name." order by id"; +// Run Test + +$select_sql = "select id, value from fetch_all3_tab order by id"; $s = oci_parse($c, $select_sql); @@ -105,113 +130,123 @@ echo "OCI_NUM|OCI_ASSOC\n"; oci_execute($s); var_dump(oci_fetch_all($s, $all, 0, -1, OCI_NUM|OCI_ASSOC)); var_dump($all); -require dirname(__FILE__).'/drop_table.inc'; + +// Cleanup + +$stmtarray = array( + "drop table fetch_all3_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} echo "Done\n"; ?> ---EXPECT-- +--EXPECTF-- None int(4) array(2) { - ["ID"]=> + [%u|b%"ID"]=> array(4) { [0]=> - string(1) "1" + %unicode|string%(1) "1" [1]=> - string(1) "2" + %unicode|string%(1) "2" [2]=> - string(1) "3" + %unicode|string%(1) "3" [3]=> - string(1) "4" + %unicode|string%(1) "4" } - ["VALUE"]=> + [%u|b%"VALUE"]=> array(4) { [0]=> - string(2) "-1" + %unicode|string%(2) "-1" [1]=> - string(2) "-2" + %unicode|string%(2) "-2" [2]=> - string(2) "-3" + %unicode|string%(2) "-3" [3]=> - string(2) "-4" + %unicode|string%(2) "-4" } } OCI_ASSOC int(4) array(2) { - ["ID"]=> + [%u|b%"ID"]=> array(4) { [0]=> - string(1) "1" + %unicode|string%(1) "1" [1]=> - string(1) "2" + %unicode|string%(1) "2" [2]=> - string(1) "3" + %unicode|string%(1) "3" [3]=> - string(1) "4" + %unicode|string%(1) "4" } - ["VALUE"]=> + [%u|b%"VALUE"]=> array(4) { [0]=> - string(2) "-1" + %unicode|string%(2) "-1" [1]=> - string(2) "-2" + %unicode|string%(2) "-2" [2]=> - string(2) "-3" + %unicode|string%(2) "-3" [3]=> - string(2) "-4" + %unicode|string%(2) "-4" } } OCI_FETCHSTATEMENT_BY_COLUMN int(4) array(2) { - ["ID"]=> + [%u|b%"ID"]=> array(4) { [0]=> - string(1) "1" + %unicode|string%(1) "1" [1]=> - string(1) "2" + %unicode|string%(1) "2" [2]=> - string(1) "3" + %unicode|string%(1) "3" [3]=> - string(1) "4" + %unicode|string%(1) "4" } - ["VALUE"]=> + [%u|b%"VALUE"]=> array(4) { [0]=> - string(2) "-1" + %unicode|string%(2) "-1" [1]=> - string(2) "-2" + %unicode|string%(2) "-2" [2]=> - string(2) "-3" + %unicode|string%(2) "-3" [3]=> - string(2) "-4" + %unicode|string%(2) "-4" } } OCI_FETCHSTATEMENT_BY_COLUMN|OCI_ASSOC int(4) array(2) { - ["ID"]=> + [%u|b%"ID"]=> array(4) { [0]=> - string(1) "1" + %unicode|string%(1) "1" [1]=> - string(1) "2" + %unicode|string%(1) "2" [2]=> - string(1) "3" + %unicode|string%(1) "3" [3]=> - string(1) "4" + %unicode|string%(1) "4" } - ["VALUE"]=> + [%u|b%"VALUE"]=> array(4) { [0]=> - string(2) "-1" + %unicode|string%(2) "-1" [1]=> - string(2) "-2" + %unicode|string%(2) "-2" [2]=> - string(2) "-3" + %unicode|string%(2) "-3" [3]=> - string(2) "-4" + %unicode|string%(2) "-4" } } OCI_FETCHSTATEMENT_BY_COLUMN|OCI_NUM @@ -220,24 +255,24 @@ array(2) { [0]=> array(4) { [0]=> - string(1) "1" + %unicode|string%(1) "1" [1]=> - string(1) "2" + %unicode|string%(1) "2" [2]=> - string(1) "3" + %unicode|string%(1) "3" [3]=> - string(1) "4" + %unicode|string%(1) "4" } [1]=> array(4) { [0]=> - string(2) "-1" + %unicode|string%(2) "-1" [1]=> - string(2) "-2" + %unicode|string%(2) "-2" [2]=> - string(2) "-3" + %unicode|string%(2) "-3" [3]=> - string(2) "-4" + %unicode|string%(2) "-4" } } OCI_FETCHSTATEMENT_BY_COLUMN|OCI_NUM|OCI_ASSOC @@ -246,24 +281,24 @@ array(2) { [0]=> array(4) { [0]=> - string(1) "1" + %unicode|string%(1) "1" [1]=> - string(1) "2" + %unicode|string%(1) "2" [2]=> - string(1) "3" + %unicode|string%(1) "3" [3]=> - string(1) "4" + %unicode|string%(1) "4" } [1]=> array(4) { [0]=> - string(2) "-1" + %unicode|string%(2) "-1" [1]=> - string(2) "-2" + %unicode|string%(2) "-2" [2]=> - string(2) "-3" + %unicode|string%(2) "-3" [3]=> - string(2) "-4" + %unicode|string%(2) "-4" } } OCI_FETCHSTATEMENT_BY_ROW @@ -271,31 +306,31 @@ int(4) array(4) { [0]=> array(2) { - ["ID"]=> - string(1) "1" - ["VALUE"]=> - string(2) "-1" + [%u|b%"ID"]=> + %unicode|string%(1) "1" + [%u|b%"VALUE"]=> + %unicode|string%(2) "-1" } [1]=> array(2) { - ["ID"]=> - string(1) "2" - ["VALUE"]=> - string(2) "-2" + [%u|b%"ID"]=> + %unicode|string%(1) "2" + [%u|b%"VALUE"]=> + %unicode|string%(2) "-2" } [2]=> array(2) { - ["ID"]=> - string(1) "3" - ["VALUE"]=> - string(2) "-3" + [%u|b%"ID"]=> + %unicode|string%(1) "3" + [%u|b%"VALUE"]=> + %unicode|string%(2) "-3" } [3]=> array(2) { - ["ID"]=> - string(1) "4" - ["VALUE"]=> - string(2) "-4" + [%u|b%"ID"]=> + %unicode|string%(1) "4" + [%u|b%"VALUE"]=> + %unicode|string%(2) "-4" } } OCI_FETCHSTATEMENT_BY_ROW|OCI_ASSOC @@ -303,31 +338,31 @@ int(4) array(4) { [0]=> array(2) { - ["ID"]=> - string(1) "1" - ["VALUE"]=> - string(2) "-1" + [%u|b%"ID"]=> + %unicode|string%(1) "1" + [%u|b%"VALUE"]=> + %unicode|string%(2) "-1" } [1]=> array(2) { - ["ID"]=> - string(1) "2" - ["VALUE"]=> - string(2) "-2" + [%u|b%"ID"]=> + %unicode|string%(1) "2" + [%u|b%"VALUE"]=> + %unicode|string%(2) "-2" } [2]=> array(2) { - ["ID"]=> - string(1) "3" - ["VALUE"]=> - string(2) "-3" + [%u|b%"ID"]=> + %unicode|string%(1) "3" + [%u|b%"VALUE"]=> + %unicode|string%(2) "-3" } [3]=> array(2) { - ["ID"]=> - string(1) "4" - ["VALUE"]=> - string(2) "-4" + [%u|b%"ID"]=> + %unicode|string%(1) "4" + [%u|b%"VALUE"]=> + %unicode|string%(2) "-4" } } OCI_FETCHSTATEMENT_BY_ROW|OCI_FETCHSTATEMENT_BY_COLUMN @@ -335,31 +370,31 @@ int(4) array(4) { [0]=> array(2) { - ["ID"]=> - string(1) "1" - ["VALUE"]=> - string(2) "-1" + [%u|b%"ID"]=> + %unicode|string%(1) "1" + [%u|b%"VALUE"]=> + %unicode|string%(2) "-1" } [1]=> array(2) { - ["ID"]=> - string(1) "2" - ["VALUE"]=> - string(2) "-2" + [%u|b%"ID"]=> + %unicode|string%(1) "2" + [%u|b%"VALUE"]=> + %unicode|string%(2) "-2" } [2]=> array(2) { - ["ID"]=> - string(1) "3" - ["VALUE"]=> - string(2) "-3" + [%u|b%"ID"]=> + %unicode|string%(1) "3" + [%u|b%"VALUE"]=> + %unicode|string%(2) "-3" } [3]=> array(2) { - ["ID"]=> - string(1) "4" - ["VALUE"]=> - string(2) "-4" + [%u|b%"ID"]=> + %unicode|string%(1) "4" + [%u|b%"VALUE"]=> + %unicode|string%(2) "-4" } } OCI_FETCHSTATEMENT_BY_ROW|OCI_FETCHSTATEMENT_BY_COLUMN|OCI_ASSOC @@ -367,31 +402,31 @@ int(4) array(4) { [0]=> array(2) { - ["ID"]=> - string(1) "1" - ["VALUE"]=> - string(2) "-1" + [%u|b%"ID"]=> + %unicode|string%(1) "1" + [%u|b%"VALUE"]=> + %unicode|string%(2) "-1" } [1]=> array(2) { - ["ID"]=> - string(1) "2" - ["VALUE"]=> - string(2) "-2" + [%u|b%"ID"]=> + %unicode|string%(1) "2" + [%u|b%"VALUE"]=> + %unicode|string%(2) "-2" } [2]=> array(2) { - ["ID"]=> - string(1) "3" - ["VALUE"]=> - string(2) "-3" + [%u|b%"ID"]=> + %unicode|string%(1) "3" + [%u|b%"VALUE"]=> + %unicode|string%(2) "-3" } [3]=> array(2) { - ["ID"]=> - string(1) "4" - ["VALUE"]=> - string(2) "-4" + [%u|b%"ID"]=> + %unicode|string%(1) "4" + [%u|b%"VALUE"]=> + %unicode|string%(2) "-4" } } OCI_FETCHSTATEMENT_BY_ROW|OCI_FETCHSTATEMENT_BY_COLUMN|OCI_NUM @@ -400,30 +435,30 @@ array(4) { [0]=> array(2) { [0]=> - string(1) "1" + %unicode|string%(1) "1" [1]=> - string(2) "-1" + %unicode|string%(2) "-1" } [1]=> array(2) { [0]=> - string(1) "2" + %unicode|string%(1) "2" [1]=> - string(2) "-2" + %unicode|string%(2) "-2" } [2]=> array(2) { [0]=> - string(1) "3" + %unicode|string%(1) "3" [1]=> - string(2) "-3" + %unicode|string%(2) "-3" } [3]=> array(2) { [0]=> - string(1) "4" + %unicode|string%(1) "4" [1]=> - string(2) "-4" + %unicode|string%(2) "-4" } } OCI_FETCHSTATEMENT_BY_ROW|OCI_FETCHSTATEMENT_BY_COLUMN|OCI_NUM|OCI_ASSOC @@ -432,30 +467,30 @@ array(4) { [0]=> array(2) { [0]=> - string(1) "1" + %unicode|string%(1) "1" [1]=> - string(2) "-1" + %unicode|string%(2) "-1" } [1]=> array(2) { [0]=> - string(1) "2" + %unicode|string%(1) "2" [1]=> - string(2) "-2" + %unicode|string%(2) "-2" } [2]=> array(2) { [0]=> - string(1) "3" + %unicode|string%(1) "3" [1]=> - string(2) "-3" + %unicode|string%(2) "-3" } [3]=> array(2) { [0]=> - string(1) "4" + %unicode|string%(1) "4" [1]=> - string(2) "-4" + %unicode|string%(2) "-4" } } OCI_FETCHSTATEMENT_BY_ROW|OCI_NUM @@ -464,30 +499,30 @@ array(4) { [0]=> array(2) { [0]=> - string(1) "1" + %unicode|string%(1) "1" [1]=> - string(2) "-1" + %unicode|string%(2) "-1" } [1]=> array(2) { [0]=> - string(1) "2" + %unicode|string%(1) "2" [1]=> - string(2) "-2" + %unicode|string%(2) "-2" } [2]=> array(2) { [0]=> - string(1) "3" + %unicode|string%(1) "3" [1]=> - string(2) "-3" + %unicode|string%(2) "-3" } [3]=> array(2) { [0]=> - string(1) "4" + %unicode|string%(1) "4" [1]=> - string(2) "-4" + %unicode|string%(2) "-4" } } OCI_FETCHSTATEMENT_BY_ROW|OCI_NUM|OCI_ASSOC @@ -496,30 +531,30 @@ array(4) { [0]=> array(2) { [0]=> - string(1) "1" + %unicode|string%(1) "1" [1]=> - string(2) "-1" + %unicode|string%(2) "-1" } [1]=> array(2) { [0]=> - string(1) "2" + %unicode|string%(1) "2" [1]=> - string(2) "-2" + %unicode|string%(2) "-2" } [2]=> array(2) { [0]=> - string(1) "3" + %unicode|string%(1) "3" [1]=> - string(2) "-3" + %unicode|string%(2) "-3" } [3]=> array(2) { [0]=> - string(1) "4" + %unicode|string%(1) "4" [1]=> - string(2) "-4" + %unicode|string%(2) "-4" } } OCI_NUM @@ -528,24 +563,24 @@ array(2) { [0]=> array(4) { [0]=> - string(1) "1" + %unicode|string%(1) "1" [1]=> - string(1) "2" + %unicode|string%(1) "2" [2]=> - string(1) "3" + %unicode|string%(1) "3" [3]=> - string(1) "4" + %unicode|string%(1) "4" } [1]=> array(4) { [0]=> - string(2) "-1" + %unicode|string%(2) "-1" [1]=> - string(2) "-2" + %unicode|string%(2) "-2" [2]=> - string(2) "-3" + %unicode|string%(2) "-3" [3]=> - string(2) "-4" + %unicode|string%(2) "-4" } } OCI_NUM|OCI_ASSOC @@ -554,24 +589,24 @@ array(2) { [0]=> array(4) { [0]=> - string(1) "1" + %unicode|string%(1) "1" [1]=> - string(1) "2" + %unicode|string%(1) "2" [2]=> - string(1) "3" + %unicode|string%(1) "3" [3]=> - string(1) "4" + %unicode|string%(1) "4" } [1]=> array(4) { [0]=> - string(2) "-1" + %unicode|string%(2) "-1" [1]=> - string(2) "-2" + %unicode|string%(2) "-2" [2]=> - string(2) "-3" + %unicode|string%(2) "-3" [3]=> - string(2) "-4" + %unicode|string%(2) "-4" } } Done diff --git a/ext/oci8/tests/fetch_all4.phpt b/ext/oci8/tests/fetch_all4.phpt new file mode 100644 index 000000000..9b82262e3 --- /dev/null +++ b/ext/oci8/tests/fetch_all4.phpt @@ -0,0 +1,82 @@ +--TEST-- +Test oci_fetch_* array overwriting when query returns no rows +--SKIPIF-- +<?php if (!extension_loaded('oci8')) die ("skip no oci8 extension"); ?> +--FILE-- +<?php + +require(dirname(__FILE__).'/connect.inc'); + +// Initialization + +$stmtarray = array( + "drop table fetch_all4_tab", + "create table fetch_all4_tab (mycol1 number, mycol2 varchar2(20))", + "insert into fetch_all4_tab values (1, 'abc')" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + , 2289 // sequence does not exist + , 4080 // trigger does not exist + , 38802 // edition does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } + } +} + +// Run Test + +echo "Test 1\n"; + +$s = oci_parse($c, "select * from fetch_all4_tab where 1 = 0"); +oci_execute($s); +$res = array(1,2,3); // this array is replaced as a result of the query +$r = oci_fetch_all($s, $res); +var_dump($r); +var_dump($res); + +echo "Test 2\n"; + +$s = oci_parse($c, "select * from fetch_all4_tab where 1 = 0"); +oci_execute($s); +$row = array(1,2,3); // this array is replaced as a result of the query +$row = oci_fetch_array($s); +var_dump($row); + +// Clean up + +$stmtarray = array( + "drop table fetch_all4_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} + +oci_close($c); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +Test 1 +int(0) +array(2) { + [%u|b%"MYCOL1"]=> + array(0) { + } + [%u|b%"MYCOL2"]=> + array(0) { + } +} +Test 2 +bool(false) +===DONE=== diff --git a/ext/oci8/tests/fetch_all5.phpt b/ext/oci8/tests/fetch_all5.phpt new file mode 100644 index 000000000..bb9061a44 --- /dev/null +++ b/ext/oci8/tests/fetch_all5.phpt @@ -0,0 +1,127 @@ +--TEST-- +Test oci_fetch_all with 0 and -1 skip & maxrows +--SKIPIF-- +<?php if (!extension_loaded('oci8')) die ("skip no oci8 extension"); ?> +--FILE-- +<?php + +require(dirname(__FILE__).'/connect.inc'); + +// Initialization + +$stmtarray = array( + "drop table fetch_all5_tab", + "create table fetch_all5_tab (mycol1 number, mycol2 varchar2(20))", + "insert into fetch_all5_tab values (1, 'abc')", + "insert into fetch_all5_tab values (2, 'def')", + "insert into fetch_all5_tab values (3, 'ghi')" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + , 2289 // sequence does not exist + , 4080 // trigger does not exist + , 38802 // edition does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } + } +} + +// Run Test + +echo "Test 1\n"; + +$s = oci_parse($c, "select * from fetch_all5_tab order by 1"); +oci_execute($s); +$r = oci_fetch_all($s, $res, 0, -1); +var_dump($r); +var_dump($res); + +echo "Test 1\n"; + +$s = oci_parse($c, "select * from fetch_all5_tab order by 1"); +oci_execute($s); +$r = oci_fetch_all($s, $res, 0, 0); +var_dump($r); +var_dump($res); + +echo "Test 3\n"; + +$s = oci_parse($c, "select * from fetch_all5_tab order by 1"); +oci_execute($s); +$r = oci_fetch_all($s, $res, -1, 0); +var_dump($r); +var_dump($res); + +// Clean up + +$stmtarray = array( + "drop table fetch_all5_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} + +oci_close($c); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +Test 1 +int(3) +array(2) { + [%u|b%"MYCOL1"]=> + array(3) { + [0]=> + %unicode|string%(1) "1" + [1]=> + %unicode|string%(1) "2" + [2]=> + %unicode|string%(1) "3" + } + [%u|b%"MYCOL2"]=> + array(3) { + [0]=> + %unicode|string%(3) "abc" + [1]=> + %unicode|string%(3) "def" + [2]=> + %unicode|string%(3) "ghi" + } +} +Test 1 +int(3) +array(2) { + [%u|b%"MYCOL1"]=> + array(3) { + [0]=> + %unicode|string%(1) "1" + [1]=> + %unicode|string%(1) "2" + [2]=> + %unicode|string%(1) "3" + } + [%u|b%"MYCOL2"]=> + array(3) { + [0]=> + %unicode|string%(3) "abc" + [1]=> + %unicode|string%(3) "def" + [2]=> + %unicode|string%(3) "ghi" + } +} +Test 3 +int(0) +array(0) { +} +===DONE=== diff --git a/ext/oci8/tests/fetch_into.phpt b/ext/oci8/tests/fetch_into.phpt index 379f5fc14..17e06e1cf 100644 --- a/ext/oci8/tests/fetch_into.phpt +++ b/ext/oci8/tests/fetch_into.phpt @@ -5,78 +5,86 @@ ocifetchinto() --FILE-- <?php -require dirname(__FILE__)."/connect.inc"; -require dirname(__FILE__).'/create_table.inc'; +require(dirname(__FILE__)."/connect.inc"); -$insert_sql = "INSERT INTO ".$schema."".$table_name." (id, value) VALUES (1,1)"; +// Initialize -if (!($s = oci_parse($c, $insert_sql))) { - die("oci_parse(insert) failed!\n"); -} +$stmtarray = array( + "drop table fetch_into_tab", + "create table fetch_into_tab (id number, value number)", + "insert into fetch_into_tab (id, value) values (1,1)", + "insert into fetch_into_tab (id, value) values (1,1)", + "insert into fetch_into_tab (id, value) values (1,1)", +); -for ($i = 0; $i<3; $i++) { - if (!oci_execute($s)) { - die("oci_execute(insert) failed!\n"); +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } } } -if (!oci_commit($c)) { - die("oci_commit() failed!\n"); +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); } -$select_sql = "SELECT * FROM ".$schema."".$table_name.""; +// Run Test -if (!($s = oci_parse($c, $select_sql))) { +if (!($s = oci_parse($c, "select * from fetch_into_tab"))) { die("oci_parse(select) failed!\n"); } -/* oci_fetch_all */ +/* ocifetchinto */ if (!oci_execute($s)) { die("oci_execute(select) failed!\n"); } var_dump(ocifetchinto($s, $all)); var_dump($all); -/* oci_fetch_all */ +/* ocifetchinto */ if (!oci_execute($s)) { die("oci_execute(select) failed!\n"); } var_dump(ocifetchinto($s, $all, OCI_NUM+OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS)); var_dump($all); -require dirname(__FILE__).'/drop_table.inc'; +// Cleanup + +$stmtarray = array( + "drop table fetch_into_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} echo "Done\n"; ?> ---EXPECT-- -int(5) +--EXPECTF-- +int(2) array(2) { [0]=> - string(1) "1" + %unicode|string%(1) "1" [1]=> - string(1) "1" + %unicode|string%(1) "1" } -int(5) -array(10) { +int(2) +array(4) { [0]=> - string(1) "1" - ["ID"]=> - string(1) "1" + %unicode|string%(1) "1" + [%u|b%"ID"]=> + %unicode|string%(1) "1" [1]=> - string(1) "1" - ["VALUE"]=> - string(1) "1" - [2]=> - NULL - ["BLOB"]=> - NULL - [3]=> - NULL - ["CLOB"]=> - NULL - [4]=> - NULL - ["STRING"]=> - NULL + %unicode|string%(1) "1" + [%u|b%"VALUE"]=> + %unicode|string%(1) "1" } Done diff --git a/ext/oci8/tests/fetch_object.phpt b/ext/oci8/tests/fetch_object.phpt index 57b7fc03d..674a88ff2 100644 --- a/ext/oci8/tests/fetch_object.phpt +++ b/ext/oci8/tests/fetch_object.phpt @@ -5,78 +5,133 @@ oci_fetch_object() --FILE-- <?php -require dirname(__FILE__)."/connect.inc"; -require dirname(__FILE__).'/create_table.inc'; +require(dirname(__FILE__).'/connect.inc'); -$insert_sql = "INSERT INTO ".$schema."".$table_name." (id, value) VALUES (1,1)"; +// Initialization -if (!($s = oci_parse($c, $insert_sql))) { - die("oci_parse(insert) failed!\n"); -} +$stmtarray = array( + "drop table fetch_object_tab", + "create table fetch_object_tab (\"caseSensitive\" number, secondcol varchar2(20), anothercol char(15))", + "insert into fetch_object_tab values (123, '1st row col2 string', '1 more text')", + "insert into fetch_object_tab values (456, '2nd row col2 string', '2 more text')", + "insert into fetch_object_tab values (789, '3rd row col2 string', '3 more text')", +); -for ($i = 0; $i<3; $i++) { - if (!oci_execute($s)) { - die("oci_execute(insert) failed!\n"); +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + , 2289 // sequence does not exist + , 4080 // trigger does not exist + , 38802 // edition does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } } } -if (!oci_commit($c)) { - die("oci_commit() failed!\n"); -} +// Run Test -$select_sql = "SELECT * FROM ".$schema."".$table_name.""; +echo "Test 1\n"; -if (!($s = oci_parse($c, $select_sql))) { +if (!($s = oci_parse($c, 'select * from fetch_object_tab'))) { die("oci_parse(select) failed!\n"); } if (!oci_execute($s)) { die("oci_execute(select) failed!\n"); } + while ($row = oci_fetch_object($s)) { var_dump($row); } -require dirname(__FILE__).'/drop_table.inc'; +echo "Test 2\n"; + +if (!($s = oci_parse($c, 'select * from fetch_object_tab'))) { + die("oci_parse(select) failed!\n"); +} + +if (!oci_execute($s)) { + die("oci_execute(select) failed!\n"); +} -echo "Done\n"; +while ($row = oci_fetch_object($s)) { + echo $row->caseSensitive . "\n"; + echo $row->SECONDCOL . "\n"; + echo $row->ANOTHERCOL . "\n"; +} + +echo "Test 3\n"; + +if (!($s = oci_parse($c, 'select * from fetch_object_tab where rownum < 2 order by "caseSensitive"'))) { + die("oci_parse(select) failed!\n"); +} + +if (!oci_execute($s)) { + die("oci_execute(select) failed!\n"); +} + +$row = oci_fetch_object($s); +echo $row->caseSensitive . "\n"; +echo $row->CASESENSITIVE . "\n"; + +// Clean up + +$stmtarray = array( + "drop table fetch_object_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} ?> +===DONE=== +<?php exit(0); ?> --EXPECTF-- -object(stdClass)#%d (5) { - ["ID"]=> - string(1) "1" - ["VALUE"]=> - string(1) "1" - ["BLOB"]=> - NULL - ["CLOB"]=> - NULL - ["STRING"]=> - NULL +Test 1 +object(stdClass)#1 (3) { + [%u|b%"caseSensitive"]=> + %unicode|string%(3) "123" + [%u|b%"SECONDCOL"]=> + %unicode|string%(19) "1st row col2 string" + [%u|b%"ANOTHERCOL"]=> + %unicode|string%(15) "1 more text " } -object(stdClass)#%d (5) { - ["ID"]=> - string(1) "1" - ["VALUE"]=> - string(1) "1" - ["BLOB"]=> - NULL - ["CLOB"]=> - NULL - ["STRING"]=> - NULL +object(stdClass)#2 (3) { + [%u|b%"caseSensitive"]=> + %unicode|string%(3) "456" + [%u|b%"SECONDCOL"]=> + %unicode|string%(19) "2nd row col2 string" + [%u|b%"ANOTHERCOL"]=> + %unicode|string%(15) "2 more text " } -object(stdClass)#%d (5) { - ["ID"]=> - string(1) "1" - ["VALUE"]=> - string(1) "1" - ["BLOB"]=> - NULL - ["CLOB"]=> - NULL - ["STRING"]=> - NULL +object(stdClass)#1 (3) { + [%u|b%"caseSensitive"]=> + %unicode|string%(3) "789" + [%u|b%"SECONDCOL"]=> + %unicode|string%(19) "3rd row col2 string" + [%u|b%"ANOTHERCOL"]=> + %unicode|string%(15) "3 more text " } -Done +Test 2 +123 +1st row col2 string +1 more text +456 +2nd row col2 string +2 more text +789 +3rd row col2 string +3 more text +Test 3 +123 + +Notice: Undefined property: stdClass::$CASESENSITIVE in %sfetch_object.php on line %d + +===DONE=== diff --git a/ext/oci8/tests/fetch_object_2.phpt b/ext/oci8/tests/fetch_object_2.phpt new file mode 100644 index 000000000..342503d91 --- /dev/null +++ b/ext/oci8/tests/fetch_object_2.phpt @@ -0,0 +1,127 @@ +--TEST-- +oci_fetch_object() with CLOB and NULL +--SKIPIF-- +<?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); ?> +--FILE-- +<?php + +require(dirname(__FILE__).'/connect.inc'); + +// Initialization + +$stmtarray = array( + "drop table fetch_object_2_tab", + "create table fetch_object_2_tab (col1 number, col2 CLOB, col3 varchar2(15))", + "insert into fetch_object_2_tab values (123, '1st row col2 string', '1 more text')", + "insert into fetch_object_2_tab values (456, '2nd row col2 string', NULL)", + "insert into fetch_object_2_tab values (789, '3rd row col2 string', '3 more text')", +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + , 2289 // sequence does not exist + , 4080 // trigger does not exist + , 38802 // edition does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } + } +} + +// Run Test + +echo "Test 1\n"; + +if (!($s = oci_parse($c, 'select * from fetch_object_2_tab order by 1'))) { + die("oci_parse(select) failed!\n"); +} + +if (!oci_execute($s)) { + die("oci_execute(select) failed!\n"); +} + +while ($row = oci_fetch_object($s)) { + var_dump($row); +} + +echo "Test 2\n"; + +if (!($s = oci_parse($c, 'select * from fetch_object_2_tab order by 1'))) { + die("oci_parse(select) failed!\n"); +} + +if (!oci_execute($s)) { + die("oci_execute(select) failed!\n"); +} + +while ($row = oci_fetch_object($s)) { + echo $row->COL1 . "\n"; + echo $row->COL2->load(100) . "\n"; + echo $row->COL3 . "\n"; +} + +// Clean up + +$stmtarray = array( + "drop table fetch_object_2_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +Test 1 +object(stdClass)#%d (3) { + [%u|b%"COL1"]=> + %unicode|string%(3) "123" + [%u|b%"COL2"]=> + object(OCI-Lob)#%d (1) { + [%u|b%"descriptor"]=> + resource(15) of type (oci8 descriptor) + } + [%u|b%"COL3"]=> + %unicode|string%(11) "1 more text" +} +object(stdClass)#%d (3) { + [%u|b%"COL1"]=> + %unicode|string%(3) "456" + [%u|b%"COL2"]=> + object(OCI-Lob)#%d (1) { + [%u|b%"descriptor"]=> + resource(16) of type (oci8 descriptor) + } + [%u|b%"COL3"]=> + NULL +} +object(stdClass)#%d (3) { + [%u|b%"COL1"]=> + %unicode|string%(3) "789" + [%u|b%"COL2"]=> + object(OCI-Lob)#%d (1) { + [%u|b%"descriptor"]=> + resource(17) of type (oci8 descriptor) + } + [%u|b%"COL3"]=> + %unicode|string%(11) "3 more text" +} +Test 2 +123 +1st row col2 string +1 more text +456 +2nd row col2 string + +789 +3rd row col2 string +3 more text +===DONE=== diff --git a/ext/oci8/tests/fetch_row.phpt b/ext/oci8/tests/fetch_row.phpt index a637ecc6f..c6084d4fe 100644 --- a/ext/oci8/tests/fetch_row.phpt +++ b/ext/oci8/tests/fetch_row.phpt @@ -5,28 +5,39 @@ oci_fetch_row() --FILE-- <?php -require dirname(__FILE__)."/connect.inc"; -require dirname(__FILE__).'/create_table.inc'; +require(dirname(__FILE__)."/connect.inc"); -$insert_sql = "INSERT INTO ".$schema."".$table_name." (id, value) VALUES (1,1)"; +// Initialize -if (!($s = oci_parse($c, $insert_sql))) { - die("oci_parse(insert) failed!\n"); -} +$stmtarray = array( + "drop table fetch_row_tab", + "create table fetch_row_tab (id number, value number)", + "insert into fetch_row_tab (id, value) values (1,1)", + "insert into fetch_row_tab (id, value) values (1,1)", + "insert into fetch_row_tab (id, value) values (1,1)", +); -for ($i = 0; $i<3; $i++) { - if (!oci_execute($s)) { - die("oci_execute(insert) failed!\n"); +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } } } -if (!oci_commit($c)) { - die("oci_commit() failed!\n"); +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); } -$select_sql = "SELECT * FROM ".$schema."".$table_name.""; +// Run Test -if (!($s = oci_parse($c, $select_sql))) { +if (!($s = oci_parse($c, "select * from fetch_row_tab"))) { die("oci_parse(select) failed!\n"); } @@ -37,46 +48,37 @@ while ($row = oci_fetch_row($s)) { var_dump($row); } -require dirname(__FILE__).'/drop_table.inc'; +// Cleanup + +$stmtarray = array( + "drop table fetch_row_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} echo "Done\n"; ?> ---EXPECT-- -array(5) { +--EXPECTF-- +array(2) { [0]=> - string(1) "1" + %unicode|string%(1) "1" [1]=> - string(1) "1" - [2]=> - NULL - [3]=> - NULL - [4]=> - NULL + %unicode|string%(1) "1" } -array(5) { +array(2) { [0]=> - string(1) "1" + %unicode|string%(1) "1" [1]=> - string(1) "1" - [2]=> - NULL - [3]=> - NULL - [4]=> - NULL + %unicode|string%(1) "1" } -array(5) { +array(2) { [0]=> - string(1) "1" + %unicode|string%(1) "1" [1]=> - string(1) "1" - [2]=> - NULL - [3]=> - NULL - [4]=> - NULL + %unicode|string%(1) "1" } Done diff --git a/ext/oci8/tests/field_funcs1.phpt b/ext/oci8/tests/field_funcs1.phpt index b41e743e4..0b4ad76b3 100644 --- a/ext/oci8/tests/field_funcs1.phpt +++ b/ext/oci8/tests/field_funcs1.phpt @@ -5,28 +5,39 @@ oci_field_*() family --FILE-- <?php -require dirname(__FILE__)."/connect.inc"; -require dirname(__FILE__).'/create_table.inc'; - -$insert_sql = "INSERT INTO ".$schema."".$table_name." (id, value) VALUES (1,1)"; - -if (!($s = oci_parse($c, $insert_sql))) { - die("oci_parse(insert) failed!\n"); -} - -for ($i = 0; $i<3; $i++) { - if (!oci_execute($s)) { - die("oci_execute(insert) failed!\n"); +require(dirname(__FILE__)."/connect.inc"); + +// Initialize + +$stmtarray = array( + "drop table field_funcs1_tab", + "create table field_funcs1_tab (id number, value number)", + "insert into field_funcs1_tab (id, value) values (1,1)", + "insert into field_funcs1_tab (id, value) values (1,1)", + "insert into field_funcs1_tab (id, value) values (1,1)", +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } } } -if (!oci_commit($c)) { - die("oci_commit() failed!\n"); +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); } -$select_sql = "SELECT * FROM ".$schema."".$table_name.""; +// Run Test -if (!($s = oci_parse($c, $select_sql))) { +if (!($s = oci_parse($c, "select * from field_funcs1_tab"))) { die("oci_parse(select) failed!\n"); } @@ -71,23 +82,27 @@ var_dump(oci_field_size($s, array())); var_dump(oci_field_size($s)); -require dirname(__FILE__).'/drop_table.inc'; + +// Cleanup + +$stmtarray = array( + "drop table field_funcs1_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} echo "Done\n"; ?> --EXPECTF-- -array(5) { +array(2) { [0]=> - string(1) "1" + %unicode|string%(1) "1" [1]=> - string(1) "1" - [2]=> - NULL - [3]=> - NULL - [4]=> - NULL + %unicode|string%(1) "1" } Warning: oci_field_is_null(): Invalid column index "-1" in %s on line %d diff --git a/ext/oci8/tests/field_funcs2.phpt b/ext/oci8/tests/field_funcs2.phpt index 9b8d3e5a2..502d07913 100644 --- a/ext/oci8/tests/field_funcs2.phpt +++ b/ext/oci8/tests/field_funcs2.phpt @@ -5,10 +5,9 @@ Bug #41917 (invalid scale and precision) --FILE-- <?php -require dirname(__FILE__)."/connect.inc"; -require dirname(__FILE__).'/create_table.inc'; +require(dirname(__FILE__)."/connect.inc"); -$s = oci_parse($c, 'drop table b41917t'); +$s = oci_parse($c, 'drop table field_funcs2_tab'); @oci_execute($s); $t = array("C01" => "NUMBER", @@ -29,7 +28,7 @@ $t = array("C01" => "NUMBER", "C16" => "REAL", ); -$stmt = "create table b41917t (\n"; +$stmt = "create table field_funcs2_tab (\n"; foreach ($t as $colname => $type) { $stmt .= "$colname $type,\n"; } @@ -38,7 +37,7 @@ $stmt[strlen($stmt)-2] = ")"; $s = oci_parse($c, $stmt); oci_execute($s); -$s = oci_parse($c, "select * from b41917t"); +$s = oci_parse($c, "select * from field_funcs2_tab"); oci_execute($s); for ($i = 1; $i <= oci_num_fields($s); $i++) { @@ -67,4 +66,4 @@ C13 FLOAT: precision 126, scale -127 C14 FLOAT(9): precision 9, scale -127 C15 DOUBLE PRECISION: precision 126, scale -127 C16 REAL: precision 63, scale -127 -Done
\ No newline at end of file +Done diff --git a/ext/oci8/tests/lob_043.phpt b/ext/oci8/tests/lob_043.phpt new file mode 100644 index 000000000..5ae2d45eb --- /dev/null +++ b/ext/oci8/tests/lob_043.phpt @@ -0,0 +1,101 @@ +--TEST-- +Bug #49560 (LOB resource destructor and refcount test) +--SKIPIF-- +<?php if (!extension_loaded('oci8')) die ("skip no oci8 extension"); ?> +--FILE-- +<?php + +require(dirname(__FILE__).'/connect.inc'); + +// Initialization + +$stmtarray = array( + "drop table lob_043_tab", + "create table lob_043_tab(id number, c1 clob)", + "begin + for i in 1..50000 loop + insert into lob_043_tab (id, c1) values (i, i || ' abcdefghijklmnopq'); + end loop; + end;", +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + , 2289 // sequence does not exist + , 4080 // trigger does not exist + , 38802 // edition does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } + } +} + +// Run Test + +function f1($c) +{ + $s = oci_parse($c, 'select id, c1 from lob_043_tab order by id'); + oci_execute($s); + $r = array(); + while (($row = oci_fetch_array($s, OCI_RETURN_NULLS+OCI_ASSOC+OCI_RETURN_LOBS)) !== false) { + $r[] = $row['C1']; + } + echo "f1 ended\n"; + return $r; +} + +function f2($c) +{ + $s = oci_parse($c, 'select id, c1 from lob_043_tab order by id'); + oci_execute($s); + $r = array(); + while (($row = oci_fetch_array($s, OCI_RETURN_NULLS+OCI_ASSOC)) !== false) { + $r[] = $row['C1']; + } + echo "f2 ended\n"; + return $r; +} + +echo "Test 1\n"; +$r = f1($c); +/* + foreach ($r as $v) { + echo $v, "\n"; + } +*/ + +echo "Test 2\n"; +$r = f2($c); +/* + foreach ($r as $v) { + echo $v->load(), "\n"; + } +*/ + +// Clean up + +$stmtarray = array( + "drop table lob_043_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} + +oci_close($c); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +Test 1 +f1 ended +Test 2 +f2 ended +===DONE=== diff --git a/ext/oci8/tests/num.phpt b/ext/oci8/tests/num.phpt index 458e3774f..e9dc6a8ac 100644 --- a/ext/oci8/tests/num.phpt +++ b/ext/oci8/tests/num.phpt @@ -5,8 +5,34 @@ oci_num_*() family --FILE-- <?php -require dirname(__FILE__)."/connect.inc"; -require dirname(__FILE__).'/create_table.inc'; +require(dirname(__FILE__)."/connect.inc"); + +// Initialize + +$stmtarray = array( + "drop table num_tab", + "create table num_tab (id number, value number)", +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } + } +} + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} + +// Run Test echo "Test 1\n"; var_dump(ocirowcount()); @@ -14,13 +40,12 @@ var_dump(oci_num_rows()); var_dump(ocinumcols()); var_dump(oci_num_fields()); -$insert_sql = "INSERT INTO ".$schema.$table_name." (id, value) VALUES (1,1)"; - +echo "Test 2\n"; +$insert_sql = "insert into num_tab (id, value) values (1,1)"; if (!($s = oci_parse($c, $insert_sql))) { - die("oci_parse(insert) failed!\n"); + die("oci_parse(insert) failed!\n"); } -echo "Test 2\n"; var_dump(ocirowcount($s)); var_dump(oci_num_rows($s)); var_dump(ocinumcols($s)); @@ -49,7 +74,7 @@ var_dump(ocinumcols($s)); var_dump(oci_num_fields($s)); // All rows -$select_sql = "SELECT * FROM ".$schema.$table_name.""; +$select_sql = "select * from num_tab"; if (!($s = oci_parse($c, $select_sql))) { die("oci_parse(select) failed!\n"); @@ -83,7 +108,7 @@ var_dump(ocinumcols($s)); var_dump(oci_num_fields($s)); // One row -$select_sql = "SELECT id, value FROM ".$schema.$table_name." WHERE ROWNUM < 2"; +$select_sql = "SELECT id, value FROM num_tab WHERE ROWNUM < 2"; if (!($s = oci_parse($c, $select_sql))) { die("oci_parse(select) failed!\n"); @@ -104,7 +129,7 @@ var_dump(ocinumcols($s)); var_dump(oci_num_fields($s)); // No rows -$select_sql = "SELECT id FROM ".$schema.$table_name." WHERE 1=0"; +$select_sql = "select id from num_tab where 1=0"; if (!($s = oci_parse($c, $select_sql))) { die("oci_parse(select) failed!\n"); @@ -124,7 +149,7 @@ var_dump(oci_num_rows($s)); var_dump(ocinumcols($s)); var_dump(oci_num_fields($s)); -$delete_sql = "DELETE FROM ".$schema.$table_name.""; +$delete_sql = "delete from num_tab"; if (!($s = oci_parse($c, $delete_sql))) { die("oci_parse(delete) failed!\n"); @@ -149,7 +174,17 @@ var_dump(oci_num_rows($s)); var_dump(ocinumcols($s)); var_dump(oci_num_fields($s)); -require dirname(__FILE__).'/drop_table.inc'; + +// Cleanup + +$stmtarray = array( + "drop table num_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} echo "Done\n"; @@ -191,13 +226,13 @@ int(0) Test 5b int(0) int(0) -int(5) -int(5) +int(2) +int(2) Test 5c int(3) int(3) -int(5) -int(5) +int(2) +int(2) Test 6 int(1) int(1) diff --git a/ext/oci8/tests/oci8safemode.phpt b/ext/oci8/tests/oci8safemode.phpt index 112e544c8..1c62f36d3 100644 --- a/ext/oci8/tests/oci8safemode.phpt +++ b/ext/oci8/tests/oci8safemode.phpt @@ -15,7 +15,7 @@ $r = oci_password_change($c, "hr", "hrpwd", "hrpwd"); echo "Done\n"; ?> --EXPECTF-- -PHP Warning: Directive 'safe_mode' is deprecated in PHP 5.3 and greater in Unknown on line 0 +%sarning:%sDirective 'safe_mode' is deprecated in PHP 5.3 and greater in Unknown on line 0 Warning: oci_connect(): Privileged connect is disabled in Safe Mode in %s on line %d diff --git a/ext/oci8/tests/password_new.phpt b/ext/oci8/tests/password_new.phpt index e8642abca..ba6baa964 100644 --- a/ext/oci8/tests/password_new.phpt +++ b/ext/oci8/tests/password_new.phpt @@ -3,21 +3,21 @@ oci_password_change() --SKIPIF-- <?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); -require dirname(__FILE__)."/connect.inc"; +require(dirname(__FILE__)."/connect.inc"); if (empty($dbase)) die ("skip requires database connection string be set"); if ($test_drcp) die("skip password change not supported in DRCP Mode"); -// This test is known to fail with Oracle 10g client libraries -// connecting to Oracle Database 11.1.0.6 (Oracle bug 6277160) +// This test is known to fail with Oracle 10.2.0.4 client libraries +// connecting to Oracle Database 11 (Oracle bug 6277160, fixed 10.2.0.5) $sv = oci_server_version($c); -$sv = preg_match('/11.1/', $sv, $matches); +$sv = preg_match('/Release (11|12)\./', $sv, $matches); if ($sv === 1) { ob_start(); phpinfo(INFO_MODULES); $phpinfo = ob_get_clean(); $iv = preg_match('/Oracle .*Version => 10/', $phpinfo); if ($iv === 1) { - die ("skip test known to fail using Oracle 10gR2 client libs connecting to Oracle 11.1 (6277160)"); + die ("skip test known to fail using Oracle 10.2.0.4 client libs connecting to Oracle 11 (6277160)"); } } ?> diff --git a/ext/oci8/tests/password_old.phpt b/ext/oci8/tests/password_old.phpt index 157bdebca..abcaeb1e5 100644 --- a/ext/oci8/tests/password_old.phpt +++ b/ext/oci8/tests/password_old.phpt @@ -3,21 +3,21 @@ ocipasswordchange() --SKIPIF-- <?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); -require dirname(__FILE__)."/connect.inc"; +require(dirname(__FILE__)."/connect.inc"); if (empty($dbase)) die ("skip requires database connection string be set"); if ($test_drcp) die("skip password change not supported in DRCP Mode"); -// This test is known to fail with Oracle 10g client libraries -// connecting to Oracle Database 11.1.0.6 (Oracle bug 6277160) +// This test is known to fail with Oracle 10.2.0.4 client libraries +// connecting to Oracle Database 11 (Oracle bug 6277160, fixed 10.2.0.5) $sv = oci_server_version($c); -$sv = preg_match('/11.1/', $sv, $matches); +$sv = preg_match('/Release (11|12)\./', $sv, $matches); if ($sv === 1) { ob_start(); phpinfo(INFO_MODULES); $phpinfo = ob_get_clean(); $iv = preg_match('/Oracle .*Version => 10/', $phpinfo); if ($iv === 1) { - die ("skip test known to fail using Oracle 10gR2 client libs connecting to Oracle 11.1 (6277160)"); + die ("skip test known to fail using Oracle 10.2.0.4 client libs connecting to Oracle 11 (6277160)"); } } ?> diff --git a/ext/oci8/tests/prefetch.phpt b/ext/oci8/tests/prefetch.phpt index fa4b8fdc6..26762601d 100644 --- a/ext/oci8/tests/prefetch.phpt +++ b/ext/oci8/tests/prefetch.phpt @@ -5,26 +5,39 @@ oci_set_prefetch() --FILE-- <?php -require dirname(__FILE__)."/connect.inc"; -require dirname(__FILE__).'/create_table.inc'; +require(dirname(__FILE__)."/connect.inc"); -$insert_sql = "INSERT INTO ".$schema.$table_name." (id, value) VALUES (1,1)"; +// Initialize -if (!($s = oci_parse($c, $insert_sql))) { - die("oci_parse(insert) failed!\n"); -} +$stmtarray = array( + "drop table prefetch_tab", + "create table prefetch_tab (id number, value number)", + "insert into prefetch_tab (id, value) values (1,1)", + "insert into prefetch_tab (id, value) values (1,1)", + "insert into prefetch_tab (id, value) values (1,1)", +); -for ($i = 0; $i<3; $i++) { - if (!oci_execute($s)) { - die("oci_execute(insert) failed!\n"); +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } } } -if (!oci_commit($c)) { - die("oci_commit() failed!\n"); +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); } -$select_sql = "SELECT * FROM ".$schema.$table_name.""; +// Run Test + +$select_sql = "select * from prefetch_tab"; if (!($s = oci_parse($c, $select_sql))) { die("oci_parse(select) failed!\n"); @@ -37,11 +50,19 @@ if (!oci_execute($s)) { } var_dump(oci_fetch($s)); - var_dump(oci_num_rows($s)); -require dirname(__FILE__).'/drop_table.inc'; - +// Cleanup + +$stmtarray = array( + "drop table prefetch_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} + echo "Done\n"; ?> --EXPECT-- diff --git a/ext/oci8/tests/prefetch_old.phpt b/ext/oci8/tests/prefetch_old.phpt index cb9cb390e..c2ac8fe84 100644 --- a/ext/oci8/tests/prefetch_old.phpt +++ b/ext/oci8/tests/prefetch_old.phpt @@ -5,26 +5,41 @@ ocisetprefetch() --FILE-- <?php -require dirname(__FILE__)."/connect.inc"; -require dirname(__FILE__).'/create_table.inc'; +require(dirname(__FILE__)."/connect.inc"); -$insert_sql = "INSERT INTO ".$schema.$table_name." (id, value) VALUES (1,1)"; +$stmtarray = array( + "drop table prefetch_old_tab", + "create table prefetch_old_tab (id number, value number)", + "insert into prefetch_old_tab (id, value) values (1,1)", + "insert into prefetch_old_tab (id, value) values (1,1)", + "insert into prefetch_old_tab (id, value) values (1,1)", +); -if (!($s = ociparse($c, $insert_sql))) { - die("ociparse(insert) failed!\n"); +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } + } } -for ($i = 0; $i<3; $i++) { - if (!ociexecute($s)) { - die("ociexecute(insert) failed!\n"); - } +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); } +// Run Test + if (!ocicommit($c)) { die("ocicommit() failed!\n"); } -$select_sql = "SELECT * FROM ".$schema.$table_name.""; +$select_sql = "select * from prefetch_old_tab"; if (!($s = ociparse($c, $select_sql))) { die("ociparse(select) failed!\n"); @@ -37,10 +52,19 @@ if (!ociexecute($s)) { } var_dump(ocifetch($s)); - var_dump(ocirowcount($s)); -require dirname(__FILE__).'/drop_table.inc'; + +// Cleanup + +$stmtarray = array( + "drop table prefetch_old_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} echo "Done\n"; ?> diff --git a/ext/oci8/tests/refcur_prefetch_1.phpt b/ext/oci8/tests/refcur_prefetch_1.phpt new file mode 100644 index 000000000..c603fdd5b --- /dev/null +++ b/ext/oci8/tests/refcur_prefetch_1.phpt @@ -0,0 +1,256 @@ +--TEST-- +Prefetch with REF cursor. Test different values for prefetch with oci_set_prefetch(). +--SKIPIF-- +<?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); +if (!extension_loaded('oci8')) die("skip no oci8 extension"); +require(dirname(__FILE__)."/connect.inc"); +ob_start(); +phpinfo(INFO_MODULES); +$phpinfo = ob_get_clean(); +$iv = preg_match('/Oracle .*Version => (11\.2|12\.)/', $phpinfo); +if ($iv == 1) { + $sv = oci_server_version($c); + $sv = preg_match('/Release 1[012]\./', $sv, $matches); + if ($sv != 1) { + die ("skip expected output only valid when using Oracle 10g or greater server"); + } +} +else { + die ("skip expected output only valid when using Oracle 11.2 or greater client"); +} +?> +--FILE-- +<?php +require(dirname(__FILE__)."/connect.inc"); + +// Creates the necessary package and tables. +$stmtarray = array( + "DROP TABLE refcurtest", + "CREATE TABLE refcurtest (c1 NUMBER, c2 VARCHAR(20))", + "CREATE or REPLACE PACKAGE refcurpkg is + type refcursortype is ref cursor; + procedure open_ref_cur(cur1 out refcursortype); + procedure fetch_ref_cur(cur1 in refcursortype, c1 out number,c2 out varchar2); + end refcurpkg;", + "CREATE or REPLACE PACKAGE body refcurpkg is + procedure open_ref_cur(cur1 out refcursortype) is + begin + open cur1 for select * from refcurtest order by c1; + end open_ref_cur; + procedure fetch_ref_cur(cur1 in refcursortype, c1 out number, + c2 out varchar2) is + begin + fetch cur1 into c1,c2; + end fetch_ref_cur; + end refcurpkg;" + ); + +foreach($stmtarray as $stmt) { + $s = oci_parse($c,$stmt); + $r = @oci_execute($s); + if (!$r) { + $msg = oci_error($s); + if ($msg['code'] != 942) { + echo $msg['message'],"\n"; + } + } +} + +// Insert 500 rows into the table. +$insert_sql = "INSERT INTO refcurtest (c1, c2) VALUES (:c1,:c2)"; +if (!($s = oci_parse($c, $insert_sql))) { + die("oci_parse(insert) failed!\n"); +} + +for ($i = 0; $i<=500; $i++) { + $val2 = 'test'.$i; + oci_bind_by_name($s,':c1',$i); + oci_bind_by_name($s,':c2',$val2); + if (!oci_execute($s)) { + die("oci_execute(insert) failed!\n"); + } +} + +// Various values for prefetch +$pref = array(0,1,501,499,250,12345,-12345,-1); +foreach($pref as $value) { + echo"-----------------------------------------------\n"; + echo "Test with Prefetch value set to $value \n"; + echo"-----------------------------------------------\n"; + $cur1 = oci_new_cursor($c); + fetch_frm_php($c,$cur1,$value); + fetch_frm_plsql($c,$cur1); +} + + +// This function sets the prefetch count to the given $value and fetches one row . + +function fetch_frm_php($c,$cur1,$value) { + $sql1 = "begin refcurpkg.open_ref_cur(:cur1); end;"; + $s1 = oci_parse($c,$sql1); + if (!oci_bind_by_name($s1,":cur1",$cur1,-1,SQLT_RSET)) { + die("oci_bind_by_name(sql1) failed!\n"); + } + oci_execute($s1); + oci_set_prefetch($cur1,$value); + oci_execute($cur1); + echo "Fetch Row from PHP\n"; + var_dump(oci_fetch_row($cur1)); +} + +// This function calls the fetch_ref_cur procedure to get the values from the REF cur. + +function fetch_frm_plsql($c,$cur1) { + $sql2 = "begin refcurpkg.fetch_ref_cur(:curs1,:c1,:c2); end;"; + $s2 = oci_parse($c,$sql2); + if (!oci_bind_by_name($s2,":curs1",$cur1,-1,SQLT_RSET)) { + die("oci_bind_by_name(sql2) failed!\n"); + } + if (!oci_bind_by_name($s2,":c1",$c1,SQLT_INT)) { + die("oci_bind_by_name(sql2) failed!\n"); + } + if (!oci_bind_by_name($s2,":c2",$c2,SQLT_AFC)) { + die("oci_bind_by_name(sql2) failed!\n"); + } + oci_execute($s2); + echo "Fetch Row from PL/SQL\n"; + var_dump($c1); + var_dump($c2); +} + +// Clean up here + +$stmtarray = array( + "drop package refcurpkg", + "drop table refcurtest" +); + +foreach($stmtarray as $stmt) { + $s = oci_parse($c,$stmt); + $r = @oci_execute($s); + if (!$r) { + $msg = oci_error($s); + echo $msg['message'],"\n"; + } +} +oci_close($c); +echo "Done\n"; +?> +--EXPECTF-- +----------------------------------------------- +Test with Prefetch value set to 0 +----------------------------------------------- +Fetch Row from PHP +array(2) { + [0]=> + %unicode|string%(%d) "0" + [1]=> + %unicode|string%(%d) "test0" +} +Fetch Row from PL/SQL +%unicode|string%(%d) "1" +%unicode|string%(%d) "test1" +----------------------------------------------- +Test with Prefetch value set to 1 +----------------------------------------------- +Fetch Row from PHP +array(2) { + [0]=> + %unicode|string%(%d) "0" + [1]=> + %unicode|string%(%d) "test0" +} +Fetch Row from PL/SQL +%unicode|string%(%d) "2" +%unicode|string%(%d) "test2" +----------------------------------------------- +Test with Prefetch value set to 501 +----------------------------------------------- +Fetch Row from PHP +array(2) { + [0]=> + %unicode|string%(%d) "0" + [1]=> + %unicode|string%(%d) "test0" +} + +Warning: oci_execute(): ORA-01002: %s +ORA-06512: at "SYSTEM.REFCURPKG", line %d +ORA-06512: at line %d in %s on line %d +Fetch Row from PL/SQL +NULL +NULL +----------------------------------------------- +Test with Prefetch value set to 499 +----------------------------------------------- +Fetch Row from PHP +array(2) { + [0]=> + %unicode|string%(%d) "0" + [1]=> + %unicode|string%(%d) "test0" +} +Fetch Row from PL/SQL +%unicode|string%(%d) "500" +%unicode|string%(%d) "test500" +----------------------------------------------- +Test with Prefetch value set to 250 +----------------------------------------------- +Fetch Row from PHP +array(2) { + [0]=> + %unicode|string%(%d) "0" + [1]=> + %unicode|string%(%d) "test0" +} +Fetch Row from PL/SQL +%unicode|string%(%d) "251" +%unicode|string%(%d) "test251" +----------------------------------------------- +Test with Prefetch value set to 12345 +----------------------------------------------- +Fetch Row from PHP +array(2) { + [0]=> + %unicode|string%(%d) "0" + [1]=> + %unicode|string%(%d) "test0" +} + +Warning: oci_execute(): ORA-01002: %s +ORA-06512: at "SYSTEM.REFCURPKG", line %d +ORA-06512: at line %d in %s on line %d +Fetch Row from PL/SQL +NULL +NULL +----------------------------------------------- +Test with Prefetch value set to -12345 +----------------------------------------------- + +Warning: oci_set_prefetch(): Number of rows to be prefetched has to be greater than or equal to 0 in %s on line %d +Fetch Row from PHP +array(2) { + [0]=> + %unicode|string%(%d) "0" + [1]=> + %unicode|string%(%d) "test0" +} +Fetch Row from PL/SQL +%unicode|string%(%d) "101" +%unicode|string%(%d) "test101" +----------------------------------------------- +Test with Prefetch value set to -1 +----------------------------------------------- + +Warning: oci_set_prefetch(): Number of rows to be prefetched has to be greater than or equal to 0 in %s on line %d +Fetch Row from PHP +array(2) { + [0]=> + %unicode|string%(%d) "0" + [1]=> + %unicode|string%(%d) "test0" +} +Fetch Row from PL/SQL +%unicode|string%(%d) "101" +%unicode|string%(%d) "test101" +Done diff --git a/ext/oci8/tests/refcur_prefetch_2.phpt b/ext/oci8/tests/refcur_prefetch_2.phpt new file mode 100644 index 000000000..751ffa78f --- /dev/null +++ b/ext/oci8/tests/refcur_prefetch_2.phpt @@ -0,0 +1,317 @@ +--TEST-- +Prefetch with REF cursor. Test No 2 +--SKIPIF-- +<?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); +if (!extension_loaded('oci8')) die("skip no oci8 extension"); +require(dirname(__FILE__)."/connect.inc"); +ob_start(); +phpinfo(INFO_MODULES); +$phpinfo = ob_get_clean(); +$iv = preg_match('/Oracle .*Version => (11\.2|12\.)/', $phpinfo); +if ($iv == 1) { + $sv = oci_server_version($c); + $sv = preg_match('/Release 1[012]\./', $sv, $matches); + if ($sv != 1) { + die ("skip expected output only valid when using Oracle 10g or greater server"); + } +} +else { + die ("skip expected output only valid when using Oracle 11.1 or greater client"); +} +?> +--FILE-- +<?php +require dirname(__FILE__)."/connect.inc"; + +// Creates the necessary package and tables. +$stmtarray = array( + "DROP TABLE refcurtest", + "CREATE TABLE refcurtest (c1 NUMBER, c2 VARCHAR(20))", + "CREATE or REPLACE PACKAGE refcurpkg is + type refcursortype is ref cursor; + procedure open_ref_cur(cur1 out refcursortype); + procedure fetch_ref_cur(cur1 in refcursortype, c1 out number,c2 out varchar2); + end refcurpkg;", + "CREATE or REPLACE PACKAGE body refcurpkg is + procedure open_ref_cur(cur1 out refcursortype) is + begin + open cur1 for select * from refcurtest order by c1; + end open_ref_cur; + procedure fetch_ref_cur(cur1 in refcursortype, c1 out number, + c2 out varchar2) is + begin + fetch cur1 into c1,c2; + end fetch_ref_cur; + end refcurpkg;" + ); + +foreach($stmtarray as $stmt) { + $s = oci_parse($c,$stmt); + $r = @oci_execute($s); + if (!$r) { + $msg = oci_error($s); + if ($msg['code'] != 942) { + echo $msg['message'],"\n"; + } + } +} + +// Insert 500 rows into the table. +$insert_sql = "INSERT INTO refcurtest (c1, c2) VALUES (:c1,:c2)"; +if (!($s = oci_parse($c, $insert_sql))) { + die("oci_parse(insert) failed!\n"); +} + +for ($i = 0; $i <= 500; $i++) { + $val2 = 'test'.$i; + oci_bind_by_name($s,':c1',$i); + oci_bind_by_name($s,':c2',$val2); + if (!oci_execute($s)) { + die("oci_execute(insert) failed!\n"); + } +} + +// Steps to Fetch from PHP . For every sub-test,the cursor is bound and then executed. + +$sql1 = "begin refcurpkg.open_ref_cur(:cur1); end;"; +$s1 = oci_parse($c,$sql1); +$cur1 = oci_new_cursor($c); +if (!oci_bind_by_name($s1,":cur1",$cur1,-1,SQLT_RSET)) { + die("oci_bind_by_name(sql1) failed!\n"); +} + + +// Steps to Fetch from PL/SQL . For every sub-test,the cursor is bound and then executed. + +$sql2 = "begin refcurpkg.fetch_ref_cur(:curs1,:c1,:c2); end;"; +$s2 = oci_parse($c,$sql2); +if (!oci_bind_by_name($s2,":curs1",$cur1,-1,SQLT_RSET)) { + die("oci_bind_by_name(sql2) failed!\n"); +} +if (!oci_bind_by_name($s2,":c1",$c1,SQLT_INT)) { + die("oci_bind_by_name(sql2) failed!\n"); +} +if (!oci_bind_by_name($s2,":c2",$c2,SQLT_AFC)) { + die("oci_bind_by_name(sql2) failed!\n"); +} + + +echo "------Test 1- Check Roundtrips with prefetch 0 and 5 -----------\n"; +oci_execute($s1); +oci_execute($cur1); +$initial_rt = print_roundtrips($c); +oci_set_prefetch($cur1,0); +for ($i = 0;$i<5;$i++) { + var_dump(oci_fetch_row($cur1)); +} + +$cnt = (print_roundtrips($c) - $initial_rt); +echo "Number of roundtrips made with prefetch count 0 for 5 rows is $cnt\n"; + +$initial_rt = print_roundtrips($c); +oci_set_prefetch($cur1,5); +for ($i = 0;$i<5;$i++) { + var_dump(oci_fetch_row($cur1)); +} + +$cnt = (print_roundtrips($c) - $initial_rt ); +echo "Number of roundtrips made with prefetch count 5 for 5 rows is $cnt\n"; + +echo "------Test 2 - Set Prefetch before PL/SQL fetch ----------\n"; +// Fetch from PHP +$cur1 = oci_new_cursor($c); +if (!oci_bind_by_name($s1,":cur1",$cur1,-1,SQLT_RSET)) { + die("oci_bind_by_name(sql1) failed!\n"); +} + +echo "Fetch Row from PHP\n"; +oci_execute($s1); +oci_execute($cur1); +var_dump(oci_fetch_row($cur1)); +oci_set_prefetch($cur1,5); + +// Fetch from PL/SQL +if (!oci_bind_by_name($s2,":curs1",$cur1,-1,SQLT_RSET)) { + die("oci_bind_by_name(sql2) failed!\n"); +} +oci_execute($s2); +echo "Fetch Row from PL/SQL\n"; +var_dump($c1); +var_dump($c2); + +echo "------Test 3 - Set Prefetch after PL/SQL fetch ----------\n"; +$cur1 = oci_new_cursor($c); +// Fetch from PL/SQL +if (!oci_bind_by_name($s2,":curs1",$cur1,-1,SQLT_RSET)) { + die("oci_bind_by_name(sql2) failed!\n"); +} +oci_execute($s2); +echo "Fetch Row from PL/SQL\n"; +var_dump($c1); +var_dump($c2); + +// Fetch from PHP +echo "Fetch Row from PHP\n"; +if (!oci_bind_by_name($s1,":cur1",$cur1,-1,SQLT_RSET)) { + die("oci_bind_by_name(sql1) failed!\n"); +} +oci_set_prefetch($cur1,5); +oci_execute($s1); +oci_execute($cur1); +var_dump(oci_fetch_row($cur1)); + +echo "------Test 4- Overwrite prefetch-----------\n"; +// Fetch from PHP +$cur1 = oci_new_cursor($c); +if (!oci_bind_by_name($s1,":cur1",$cur1,-1,SQLT_RSET)) { + die("oci_bind_by_name(sql1) failed!\n"); +} +echo "Fetch Row from PHP\n"; +oci_execute($s1); +oci_execute($cur1); +var_dump(oci_fetch_row($cur1)); +oci_set_prefetch($cur1,5); +oci_set_prefetch($cur1,0); +oci_set_prefetch($cur1,100); + +// Fetch from PL/SQL +if (!oci_bind_by_name($s2,":curs1",$cur1,-1,SQLT_RSET)) { + die("oci_bind_by_name(sql2) failed!\n"); +} +oci_execute($s2); +echo "Fetch Row from PL/SQL\n"; +var_dump($c1); +var_dump($c2); + + +function print_roundtrips($c) { + $sql_stmt = "select value from v\$mystat a,v\$statname c where + a.statistic#=c.statistic# and c.name='SQL*Net roundtrips to/from client'"; + $s = oci_parse($c,$sql_stmt); + oci_define_by_name($s,"VALUE",$value); + oci_execute($s); + oci_fetch($s); + return $value; +} + +// Clean up here + +$stmtarray = array( + "drop package refcurpkg", + "drop table refcurtest" +); + +foreach($stmtarray as $stmt) { + $s = oci_parse($c,$stmt); + $r = @oci_execute($s); + if (!$r) { + $msg = oci_error($s); + echo $msg['message'],"\n"; + } +} + +oci_close($c); +echo "Done\n"; +?> +--EXPECTF-- +------Test 1- Check Roundtrips with prefetch 0 and 5 ----------- +array(2) { + [0]=> + %unicode|string%(%d) "0" + [1]=> + %unicode|string%(%d) "test0" +} +array(2) { + [0]=> + %unicode|string%(%d) "1" + [1]=> + %unicode|string%(%d) "test1" +} +array(2) { + [0]=> + %unicode|string%(%d) "2" + [1]=> + %unicode|string%(%d) "test2" +} +array(2) { + [0]=> + %unicode|string%(%d) "3" + [1]=> + %unicode|string%(%d) "test3" +} +array(2) { + [0]=> + %unicode|string%(%d) "4" + [1]=> + %unicode|string%(%d) "test4" +} +Number of roundtrips made with prefetch count 0 for 5 rows is 6 +array(2) { + [0]=> + %unicode|string%(%d) "5" + [1]=> + %unicode|string%(%d) "test5" +} +array(2) { + [0]=> + %unicode|string%(%d) "6" + [1]=> + %unicode|string%(%d) "test6" +} +array(2) { + [0]=> + %unicode|string%(%d) "7" + [1]=> + %unicode|string%(%d) "test7" +} +array(2) { + [0]=> + %unicode|string%(%d) "8" + [1]=> + %unicode|string%(%d) "test8" +} +array(2) { + [0]=> + %unicode|string%(%d) "9" + [1]=> + %unicode|string%(%d) "test9" +} +Number of roundtrips made with prefetch count 5 for 5 rows is 2 +------Test 2 - Set Prefetch before PL/SQL fetch ---------- +Fetch Row from PHP +array(2) { + [0]=> + %unicode|string%(%d) "0" + [1]=> + %unicode|string%(%d) "test0" +} +Fetch Row from PL/SQL +%unicode|string%(%d) "101" +%unicode|string%(%d) "test101" +------Test 3 - Set Prefetch after PL/SQL fetch ---------- + +Warning: oci_execute(): ORA-01001: %s +ORA-06512: at "SYSTEM.REFCURPKG", line %d +ORA-06512: at line %d in %s on line %d +Fetch Row from PL/SQL +%unicode|string%(%d) "101" +%unicode|string%(%d) "test101" +Fetch Row from PHP +array(2) { + [0]=> + %unicode|string%(%d) "0" + [1]=> + %unicode|string%(%d) "test0" +} +------Test 4- Overwrite prefetch----------- +Fetch Row from PHP +array(2) { + [0]=> + %unicode|string%(%d) "0" + [1]=> + %unicode|string%(%d) "test0" +} +Fetch Row from PL/SQL +%unicode|string%(%d) "101" +%unicode|string%(%d) "test101" +Done diff --git a/ext/oci8/tests/refcur_prefetch_3.phpt b/ext/oci8/tests/refcur_prefetch_3.phpt new file mode 100644 index 000000000..0666a96e9 --- /dev/null +++ b/ext/oci8/tests/refcur_prefetch_3.phpt @@ -0,0 +1,161 @@ +--TEST-- +Prefetch with Nested cursors with INI setting. +--INI-- +oci8.default_prefetch=5 +--SKIPIF-- +<?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); +if (!extension_loaded('oci8')) die("skip no oci8 extension"); +require(dirname(__FILE__)."/connect.inc"); +ob_start(); +phpinfo(INFO_MODULES); +$phpinfo = ob_get_clean(); +$iv = preg_match('/Oracle .*Version => (11\.2|12\.)/', $phpinfo); +if ($iv == 1) { + $sv = oci_server_version($c); + $sv = preg_match('/Release (11\.2|12\.)/', $sv, $matches); + if ($sv != 1) { + die ("skip expected output only valid when using Oracle 11.2 or greater server"); + } +} +else { + die ("skip expected output only valid when using Oracle 11.2 or greater client"); +} + +?> +--FILE-- +<?php +require dirname(__FILE__)."/connect.inc"; + +//Create tables here +$stmtarray = array( + "drop table nescurtest", + "create table nescurtest(c1 varchar2(10))" +); + +foreach($stmtarray as $stmt) { + $s = oci_parse($c,$stmt); + $r = @oci_execute($s); + if (!$r) { + $msg = oci_error($s); + if ($msg['code'] !=942) { + echo $msg['message'],"\n"; + } + } +} +// Insert 500 rows into the table. +$insert_sql = "INSERT INTO nescurtest (c1) VALUES (:c1)"; +if (!($s = oci_parse($c, $insert_sql))) { + die("oci_parse(insert) failed!\n"); +} + +for ($i = 0; $i<=500; $i++) { + $val2 = 'test'.$i; + oci_bind_by_name($s,':c1',$val2); + if (!oci_execute($s)) { + die("oci_execute(insert) failed!\n"); + } +} + +echo"-----------------------------------------------\n"; +echo "Test with Nested Cursors\n"; +echo"-----------------------------------------------\n"; +$cur1 = oci_new_cursor($c); +$sqlstmt = "select cursor(select * from nescurtest) curs1 from dual"; +$s = oci_parse($c,$sqlstmt); +oci_execute($s); +$data = oci_fetch_array($s); +oci_execute($data['CURS1']); + +// Calculate round-trips +$initial_rt = print_roundtrips($c); +for ($i = 0;$i<10;$i++) { + echo "Fetch Row using Nested cursor Query\n"; + var_dump(oci_fetch_row($data['CURS1'])); +} + +$cnt = (print_roundtrips($c) - $initial_rt); +echo "Number of roundtrips made with prefetch count 5 for 10 rows is $cnt\n"; + +function print_roundtrips($c) { + $sql_stmt = "select value from v\$mystat a,v\$statname c where + a.statistic#=c.statistic# and c.name='SQL*Net roundtrips to/from client'"; + $s = oci_parse($c,$sql_stmt); + oci_define_by_name($s,"VALUE",$value); + oci_execute($s); + oci_fetch($s); + return $value; +} + +// Clean up here + +$stmtarray = array( + "drop table nescurtest" +); + +foreach($stmtarray as $stmt) { + $s = oci_parse($c,$stmt); + $r = @oci_execute($s); + if (!$r) { + $msg = oci_error($s); + echo $msg['message'],"\n"; + } +} +oci_close($c); +echo "Done\n"; +?> +--EXPECTF-- +----------------------------------------------- +Test with Nested Cursors +----------------------------------------------- +Fetch Row using Nested cursor Query +array(1) { + [0]=> + %unicode|string%(%d) "test0" +} +Fetch Row using Nested cursor Query +array(1) { + [0]=> + %unicode|string%(%d) "test1" +} +Fetch Row using Nested cursor Query +array(1) { + [0]=> + %unicode|string%(%d) "test2" +} +Fetch Row using Nested cursor Query +array(1) { + [0]=> + %unicode|string%(%d) "test3" +} +Fetch Row using Nested cursor Query +array(1) { + [0]=> + %unicode|string%(%d) "test4" +} +Fetch Row using Nested cursor Query +array(1) { + [0]=> + %unicode|string%(%d) "test5" +} +Fetch Row using Nested cursor Query +array(1) { + [0]=> + %unicode|string%(%d) "test6" +} +Fetch Row using Nested cursor Query +array(1) { + [0]=> + %unicode|string%(%d) "test7" +} +Fetch Row using Nested cursor Query +array(1) { + [0]=> + %unicode|string%(%d) "test8" +} +Fetch Row using Nested cursor Query +array(1) { + [0]=> + %unicode|string%(%d) "test9" +} +Number of roundtrips made with prefetch count 5 for 10 rows is 3 +Done diff --git a/ext/oci8/tests/reflection1.phpt b/ext/oci8/tests/reflection1.phpt index 62ee02b84..5f2e73d80 100644 --- a/ext/oci8/tests/reflection1.phpt +++ b/ext/oci8/tests/reflection1.phpt @@ -121,6 +121,11 @@ reflection::export(new reflectionfunction('ocicollassignelem')); reflection::export(new reflectionfunction('ocicollsize')); reflection::export(new reflectionfunction('ocicollmax')); reflection::export(new reflectionfunction('ocicolltrim')); +reflection::export(new reflectionfunction('oci_set_edition')); +reflection::export(new reflectionfunction('oci_set_module_name')); +reflection::export(new reflectionfunction('oci_set_action')); +reflection::export(new reflectionfunction('oci_set_client_info')); +reflection::export(new reflectionfunction('oci_set_client_identifier')); ?> ===DONE=== @@ -1049,4 +1054,43 @@ Function [ <internal%s> function ocicolltrim ] { } } +Function [ <internal%s> function oci_set_edition ] { + + - Parameters [1] { + Parameter #0 [ <required> $edition_name ] + } +} + +Function [ <internal%s> function oci_set_module_name ] { + + - Parameters [2] { + Parameter #0 [ <required> $connection_resource ] + Parameter #1 [ <required> $module_name ] + } +} + +Function [ <internal%s> function oci_set_action ] { + + - Parameters [2] { + Parameter #0 [ <required> $connection_resource ] + Parameter #1 [ <required> $action ] + } +} + +Function [ <internal%s> function oci_set_client_info ] { + + - Parameters [2] { + Parameter #0 [ <required> $connection_resource ] + Parameter #1 [ <required> $client_information ] + } +} + +Function [ <internal%s> function oci_set_client_identifier ] { + + - Parameters [2] { + Parameter #0 [ <required> $connection_resource ] + Parameter #1 [ <required> $client_identifier ] + } +} + ===DONE=== diff --git a/ext/oci8/tests/xmltype_02.phpt b/ext/oci8/tests/xmltype_02.phpt new file mode 100644 index 000000000..9b6fa8ad3 --- /dev/null +++ b/ext/oci8/tests/xmltype_02.phpt @@ -0,0 +1,197 @@ +--TEST-- +Basic XMLType test #2 +--SKIPIF-- +<?php if (!extension_loaded('oci8')) die ("skip no oci8 extension"); ?> +--FILE-- +<?php + +require(dirname(__FILE__).'/connect.inc'); + +// Initialization + +$stmtarray = array( + "drop table xmltype_02_tab", + "create table xmltype_02_tab (warehouse_id number, warehouse_spec xmltype)", +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + $r = @oci_execute($s); + if (!$r) { + $m = oci_error($s); + if (!in_array($m['code'], array( // ignore expected errors + 942 // table or view does not exist + , 2289 // sequence does not exist + , 4080 // trigger does not exist + ))) { + echo $stmt . PHP_EOL . $m['message'] . PHP_EOL; + } + } +} + +// Run Test + + +$id = 1; + +// Delete any current entry +$s = oci_parse($c, "delete from xmltype_02_tab where warehouse_id = :id"); +oci_bind_by_name($s, ':id', $id); +oci_execute($s); + +// XML data to be inserted +$xml =<<<EOF +<?xml version="1.0"?> +<Warehouse> +<WarehouseId>1</WarehouseId> +<WarehouseName>Southlake, Texas</WarehouseName> +<Building>Owned</Building> +<Area>25000</Area> +<Docks>2</Docks> +<DockType>Rear load</DockType> +<WaterAccess>true</WaterAccess> +<RailAccess>N</RailAccess> +<Parking>Street</Parking> +<VClearance>10</VClearance> +</Warehouse> +EOF; + +echo "Test 1 Insert new XML data using a temporary CLOB\n"; +$s = oci_parse($c, + "insert into xmltype_02_tab (warehouse_id, warehouse_spec) + values (:id, XMLType(:clob))"); +oci_bind_by_name($s, ':id', $id); +$lob = oci_new_descriptor($c, OCI_D_LOB); +oci_bind_by_name($s, ':clob', $lob, -1, OCI_B_CLOB); +$lob->writeTemporary($xml); +oci_execute($s); +$lob->close(); + +// Query the row back +$s = oci_parse($c, 'select xmltype.getclobval(warehouse_spec) + from xmltype_02_tab where warehouse_id = :id'); +$r = oci_bind_by_name($s, ':id', $id); +oci_execute($s); +$row = oci_fetch_array($s, OCI_NUM); + +var_dump($row); + +echo "Test 2 Manipulate the data using SimpleXML\n"; + +$sx = simplexml_load_string((binary)$row[0]->load()); +$row[0]->free(); +var_dump($sx); + +$sx->Docks -= 1; // change the data + +var_dump($sx); + +echo "Test 3: Update changes using a temporary CLOB\n"; + +$s = oci_parse($c, 'update xmltype_02_tab + set warehouse_spec = XMLType(:clob) + where warehouse_id = :id'); +oci_bind_by_name($s, ':id', $id); +$lob = oci_new_descriptor($c, OCI_D_LOB); +oci_bind_by_name($s, ':clob', $lob, -1, OCI_B_CLOB); +$lob->writeTemporary($sx->asXml()); +oci_execute($s); +$lob->close(); + +// Query the changed row back and print it +$s = oci_parse($c, 'select xmltype.getclobval(warehouse_spec) + from xmltype_02_tab where warehouse_id = :id'); +$r = oci_bind_by_name($s, ':id', $id); +oci_execute($s); +$row = oci_fetch_array($s, OCI_NUM); +var_dump($row[0]->load()); +$row[0]->free(); + +// Clean up + +//require(dirname(__FILE__).'/drop_table.inc'); + +$stmtarray = array( + "drop table xmltype_02_tab" +); + +foreach ($stmtarray as $stmt) { + $s = oci_parse($c, $stmt); + oci_execute($s); +} + +oci_close($c); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +Test 1 Insert new XML data using a temporary CLOB +array(1) { + [0]=> + object(OCI-Lob)#%d (1) { + [%u|b%"descriptor"]=> + resource(%d) of type (oci8 descriptor) + } +} +Test 2 Manipulate the data using SimpleXML +object(SimpleXMLElement)#%d (10) { + [%u|b%"WarehouseId"]=> + %unicode|string%(1) "1" + [%u|b%"WarehouseName"]=> + %unicode|string%(16) "Southlake, Texas" + [%u|b%"Building"]=> + %unicode|string%(5) "Owned" + [%u|b%"Area"]=> + %unicode|string%(5) "25000" + [%u|b%"Docks"]=> + %unicode|string%(1) "2" + [%u|b%"DockType"]=> + %unicode|string%(9) "Rear load" + [%u|b%"WaterAccess"]=> + %unicode|string%(4) "true" + [%u|b%"RailAccess"]=> + %unicode|string%(1) "N" + [%u|b%"Parking"]=> + %unicode|string%(6) "Street" + [%u|b%"VClearance"]=> + %unicode|string%(2) "10" +} +object(SimpleXMLElement)#%d (10) { + [%u|b%"WarehouseId"]=> + %unicode|string%(1) "1" + [%u|b%"WarehouseName"]=> + %unicode|string%(16) "Southlake, Texas" + [%u|b%"Building"]=> + %unicode|string%(5) "Owned" + [%u|b%"Area"]=> + %unicode|string%(5) "25000" + [%u|b%"Docks"]=> + %unicode|string%(1) "1" + [%u|b%"DockType"]=> + %unicode|string%(9) "Rear load" + [%u|b%"WaterAccess"]=> + %unicode|string%(4) "true" + [%u|b%"RailAccess"]=> + %unicode|string%(1) "N" + [%u|b%"Parking"]=> + %unicode|string%(6) "Street" + [%u|b%"VClearance"]=> + %unicode|string%(2) "10" +} +Test 3: Update changes using a temporary CLOB +%unicode|string%(331) "<?xml version="1.0"?> +<Warehouse> +<WarehouseId>1</WarehouseId> +<WarehouseName>Southlake, Texas</WarehouseName> +<Building>Owned</Building> +<Area>25000</Area> +<Docks>1</Docks> +<DockType>Rear load</DockType> +<WaterAccess>true</WaterAccess> +<RailAccess>N</RailAccess> +<Parking>Street</Parking> +<VClearance>10</VClearance> +</Warehouse> +" +===DONE===
\ No newline at end of file |
