cvs: php-src /ext/oci8 oci8.c /ext/oci8/tests connect_with_charset_001.phpt
| From: | Antony Dovgal | Date: | Thu, 10 Aug 2006 12:15:24 +0000 |
| Subject: | cvs: php-src /ext/oci8 oci8.c /ext/oci8/tests connect_with_charset_001.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-39887@lists.php.net to get a copy of this message | ||
tony2001 Thu Aug 10 12:15:24 2006 UTC
Added files:
/php-src/ext/oci8/tests connect_with_charset_001.phpt
Modified files:
/php-src/ext/oci8 oci8.c
Log:
improve connection character set detection:
* output a warning if invalid character set was passed to the function
* use NLS_LANG by default
http://cvs.php.net/viewvc.cgi/php-src/ext/oci8/oci8.c?r1=1.312&r2=1.313&diff_format=u
Index: php-src/ext/oci8/oci8.c
diff -u php-src/ext/oci8/oci8.c:1.312 php-src/ext/oci8/oci8.c:1.313
--- php-src/ext/oci8/oci8.c:1.312 Wed Aug 9 10:16:20 2006
+++ php-src/ext/oci8/oci8.c Thu Aug 10 12:15:24 2006
@@ -26,7 +26,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: oci8.c,v 1.312 2006/08/09 10:16:20 tony2001 Exp $ */
+/* $Id: oci8.c,v 1.313 2006/08/10 12:15:24 tony2001 Exp $ */
/* TODO
*
* file://localhost/www/docs/oci10/ociaahan.htm#423823 - implement lob_empty() with
OCI_ATTR_LOBEMPTY
@@ -668,7 +668,7 @@
php_info_print_table_start();
php_info_print_table_row(2, "OCI8 Support", "enabled");
php_info_print_table_row(2, "Version", "1.2.1");
- php_info_print_table_row(2, "Revision", "$Revision: 1.312 $");
+ php_info_print_table_row(2, "Revision", "$Revision: 1.313 $");
sprintf(buf, "%ld", OCI_G(num_persistent));
php_info_print_table_row(2, "Active Persistent Connections", buf);
@@ -981,6 +981,7 @@
time_t timestamp;
#if HAVE_OCI_ENV_NLS_CREATE
ub2 charsetid = 0;
+ ub2 charsetid_nls_lang = 0;
#endif
switch (session_mode) {
@@ -1014,15 +1015,31 @@
}
smart_str_appendl_ex(&hashed_details, "__", sizeof("__") - 1, 0);
+ /* Initialize global handles if the weren't initialized before */
+ if (OCI_G(env) == NULL) {
+ php_oci_init_global_handles(TSRMLS_C);
+ }
+
#if HAVE_OCI_ENV_NLS_CREATE
if (charset && *charset) {
- smart_str_appends_ex(&hashed_details, charset, 0);
+ charsetid = PHP_OCI_CALL(OCINlsCharSetNameToId, (OCI_G(env), charset));
+ if (!charsetid) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid character set name: %s",
charset);
+ } else {
+ smart_str_append_unsigned_ex(&hashed_details, charsetid, 0);
+ }
}
- else {
+
+ /* use NLS_LANG if no or invalid charset specified */
+ if (!charsetid) {
size_t rsize = 0;
+ sword result;
- PHP_OCI_CALL(OCINlsEnvironmentVariableGet, (&charsetid, 2, OCI_NLS_CHARSET_ID, 0,
&rsize));
- smart_str_append_unsigned_ex(&hashed_details, charsetid, 0);
+ result = PHP_OCI_CALL(OCINlsEnvironmentVariableGet, (&charsetid_nls_lang, 0,
OCI_NLS_CHARSET_ID, 0, &rsize))
+ if (result != OCI_SUCCESS) {
+ charsetid_nls_lang = 0;
+ }
+ smart_str_append_unsigned_ex(&hashed_details, charsetid_nls_lang, 0);
}
#else
if (charset && *charset) {
@@ -1038,12 +1055,6 @@
/* make it lowercase */
php_strtolower(hashed_details.c, hashed_details.len);
- /* Initialize global handles if the weren't initialized before */
-
- if (OCI_G(env) == NULL) {
- php_oci_init_global_handles(TSRMLS_C);
- }
-
if (!exclusive && !new_password) {
zend_bool found = 0;
@@ -1173,16 +1184,14 @@
#if HAVE_OCI_ENV_NLS_CREATE
#define PHP_OCI_INIT_FUNC_NAME "OCIEnvNlsCreate"
- if (charset && *charset) {
- charsetid = PHP_OCI_CALL(OCINlsCharSetNameToId, (OCI_G(env), charset));
- connection->charset = charsetid;
- }
- else if (charsetid) {
+ if (charsetid) {
connection->charset = charsetid;
+ } else {
+ connection->charset = charsetid_nls_lang;
}
/* create an environment using the character set id, Oracle 9i+ ONLY */
- OCI_G(errcode) = PHP_OCI_CALL(OCIEnvNlsCreate, (&(connection->env), PHP_OCI_INIT_MODE, 0,
NULL, NULL, NULL, 0, NULL, charsetid, charsetid));
+ OCI_G(errcode) = PHP_OCI_CALL(OCIEnvNlsCreate, (&(connection->env), PHP_OCI_INIT_MODE, 0,
NULL, NULL, NULL, 0, NULL, connection->charset, connection->charset));
#elif HAVE_OCI_ENV_CREATE
#define PHP_OCI_INIT_FUNC_NAME "OCIEnvCreate"
http://cvs.php.net/viewvc.cgi/php-src/ext/oci8/tests/connect_with_charset_001.phpt?view=markup&rev=1.1
Index: php-src/ext/oci8/tests/connect_with_charset_001.phpt
+++ php-src/ext/oci8/tests/connect_with_charset_001.phpt
--TEST--
oci_connect() with invalid character set
--SKIPIF--
<?php if (!extension_loaded("oci8")) print "skip"; ?>
--FILE--
<?php
require dirname(__FILE__)."/connect.inc";
var_dump($c1 = oci_connect($user, $password, $dbase));
var_dump($c2 = oci_connect($user, $password, $dbase, ""));
var_dump($c3 = oci_connect($user, $password, $dbase, "blah"));
var_dump($c4 = oci_connect($user, $password, $dbase, "obviously wrong"));
var_dump($c3 == $c4);
var_dump($c5 = oci_connect($user, $password, $dbase, "US7ASCII"));
var_dump($c6 = oci_connect($user, $password, $dbase, "UTF8"));
var_dump($c5 == $c6);
echo "Done\n";
?>
--EXPECTF--
resource(%d) of type (oci8 connection)
resource(%d) of type (oci8 connection)
Warning: oci_connect(): Invalid character set name: blah in %s on line %d
resource(%d) of type (oci8 connection)
Warning: oci_connect(): Invalid character set name: obviously wrong in %s on line %d
resource(%d) of type (oci8 connection)
bool(true)
resource(%d) of type (oci8 connection)
resource(%d) of type (oci8 connection)
bool(false)
Done