summaryrefslogtreecommitdiff
path: root/ext/dbx
diff options
context:
space:
mode:
authorMarc Boeren <mboeren@php.net>2002-10-28 09:41:15 +0000
committerMarc Boeren <mboeren@php.net>2002-10-28 09:41:15 +0000
commit1d1febb79b6b6aab154f10351a6aa8dec3a0790c (patch)
treeda25b2371b5aa5b4d5addd63cae0b9e899aa0481 /ext/dbx
parentfe34195288af2a9c15513269661c0e37c13db3d0 (diff)
downloadphp-git-1d1febb79b6b6aab154f10351a6aa8dec3a0790c.tar.gz
Added ini-entry and dbx_query flags to control the returned
column names (unchanged, lowercase, uppercase).
Diffstat (limited to 'ext/dbx')
-rw-r--r--ext/dbx/dbx.c58
-rw-r--r--ext/dbx/dbx.h25
-rw-r--r--ext/dbx/dbx_oci8.c2
-rw-r--r--ext/dbx/tests/002.phpt3
-rw-r--r--ext/dbx/tests/005.phpt11
5 files changed, 78 insertions, 21 deletions
diff --git a/ext/dbx/dbx.c b/ext/dbx/dbx.c
index c4d195d957..1d04d91b1b 100644
--- a/ext/dbx/dbx.c
+++ b/ext/dbx/dbx.c
@@ -30,6 +30,7 @@
#include "php_ini.h"
#include "php_dbx.h"
#include "ext/standard/info.h"
+#include "ext/standard/php_string.h"
/* defines for supported databases */
#define DBX_UNKNOWN 0
@@ -168,8 +169,14 @@ zend_module_entry dbx_module_entry = {
ZEND_GET_MODULE(dbx)
#endif
+ZEND_INI_BEGIN()
+ ZEND_INI_ENTRY("dbx.colnames_case", "unchanged", ZEND_INI_SYSTEM, NULL)
+ZEND_INI_END()
+
ZEND_MINIT_FUNCTION(dbx)
{
+ REGISTER_INI_ENTRIES();
+
REGISTER_LONG_CONSTANT("DBX_MYSQL", DBX_MYSQL, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DBX_ODBC", DBX_ODBC, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DBX_PGSQL", DBX_PGSQL, CONST_CS | CONST_PERSISTENT);
@@ -184,6 +191,10 @@ ZEND_MINIT_FUNCTION(dbx)
REGISTER_LONG_CONSTANT("DBX_RESULT_INDEX", DBX_RESULT_INDEX, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DBX_RESULT_ASSOC", DBX_RESULT_ASSOC, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("DBX_COLNAMES_UNCHANGED", DBX_COLNAMES_UNCHANGED, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("DBX_COLNAMES_UPPERCASE", DBX_COLNAMES_UPPERCASE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("DBX_COLNAMES_LOWERCASE", DBX_COLNAMES_LOWERCASE, CONST_CS | CONST_PERSISTENT);
+
REGISTER_LONG_CONSTANT("DBX_CMP_NATIVE", DBX_CMP_NATIVE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DBX_CMP_TEXT", DBX_CMP_TEXT, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DBX_CMP_NUMBER", DBX_CMP_NUMBER, CONST_CS | CONST_PERSISTENT);
@@ -195,6 +206,7 @@ ZEND_MINIT_FUNCTION(dbx)
ZEND_MSHUTDOWN_FUNCTION(dbx)
{
+ UNREGISTER_INI_ENTRIES();
return SUCCESS;
}
@@ -215,6 +227,7 @@ ZEND_MINFO_FUNCTION(dbx)
php_info_print_table_row(2, "dbx version", "1.0.0");
php_info_print_table_row(2, "supported databases", "MySQL\nODBC\nPostgreSQL\nMicrosoft SQL Server\nFrontBase\nOracle 8 (oci8)\nSybase-CT");
php_info_print_table_end();
+ DISPLAY_INI_ENTRIES();
}
/*
@@ -353,10 +366,20 @@ ZEND_FUNCTION(dbx_query)
long col_index;
long row_count;
zval *info;
- long info_flags;
+ long query_flags;
+ long result_flags;
zval *data;
zval **row_ptr;
zval **inforow_ptr;
+ /* default values for colname-case */
+ char * colnames_case = INI_STR("dbx.colnames_case");
+ long colcase = DBX_COLNAMES_UNCHANGED;
+ if (!strcmp(colnames_case, "uppercase")) {
+ colcase = DBX_COLNAMES_UPPERCASE;
+ }
+ if (!strcmp(colnames_case, "lowercase")) {
+ colcase = DBX_COLNAMES_LOWERCASE;
+ }
if (ZEND_NUM_ARGS()<min_number_of_arguments || ZEND_NUM_ARGS()>number_of_arguments || zend_get_parameters_array_ex(ZEND_NUM_ARGS(), arguments) == FAILURE) {
WRONG_PARAM_COUNT;
@@ -366,14 +389,26 @@ ZEND_FUNCTION(dbx_query)
RETURN_LONG(0);
}
/* default values */
- info_flags = DBX_RESULT_INFO | DBX_RESULT_INDEX | DBX_RESULT_ASSOC;
+ result_flags = DBX_RESULT_INFO | DBX_RESULT_INDEX | DBX_RESULT_ASSOC;
/* parameter overrides */
if (ZEND_NUM_ARGS()>2) {
convert_to_long_ex(arguments[2]);
- info_flags = Z_LVAL_PP(arguments[2]);
+ query_flags = Z_LVAL_PP(arguments[2]);
/* fieldnames are needed for association! */
- if (info_flags & DBX_RESULT_ASSOC) {
- info_flags |= DBX_RESULT_INFO;
+ result_flags = (query_flags & DBX_RESULT_INFO) | (query_flags & DBX_RESULT_INDEX) | (query_flags & DBX_RESULT_ASSOC);
+ if (result_flags & DBX_RESULT_ASSOC) {
+ result_flags |= DBX_RESULT_INFO;
+ }
+ if (!result_flags) result_flags = DBX_RESULT_INFO | DBX_RESULT_INDEX | DBX_RESULT_ASSOC;
+ /* override ini-setting for colcase */
+ if (query_flags & DBX_COLNAMES_UNCHANGED) {
+ colcase = DBX_COLNAMES_UNCHANGED;
+ }
+ if (query_flags & DBX_COLNAMES_UPPERCASE) {
+ colcase = DBX_COLNAMES_UPPERCASE;
+ }
+ if (query_flags & DBX_COLNAMES_LOWERCASE) {
+ colcase = DBX_COLNAMES_LOWERCASE;
}
}
MAKE_STD_ZVAL(rv_result_handle);
@@ -398,7 +433,7 @@ ZEND_FUNCTION(dbx_query)
/* add result_handle property to return_value */
zend_hash_update(Z_OBJPROP_P(return_value), "handle", 7, (void *)&(rv_result_handle), sizeof(zval *), NULL);
/* init info property as array and add to return_value as a property */
- if (info_flags & DBX_RESULT_INFO) {
+ if (result_flags & DBX_RESULT_INFO) {
MAKE_STD_ZVAL(info);
if (array_init(info) != SUCCESS) {
zend_error(E_ERROR, "dbx_query: unable to create info-array for results...");
@@ -426,7 +461,7 @@ ZEND_FUNCTION(dbx_query)
}
zend_hash_update(Z_OBJPROP_P(return_value), "cols", 5, (void *)&(rv_column_count), sizeof(zval *), NULL);
/* fill the info array with columnnames and types (indexed and assoc) */
- if (info_flags & DBX_RESULT_INFO) {
+ if (result_flags & DBX_RESULT_INFO) {
zval *info_row_name;
zval *info_row_type;
MAKE_STD_ZVAL(info_row_name);
@@ -450,6 +485,13 @@ ZEND_FUNCTION(dbx_query)
MAKE_STD_ZVAL(rv_column_name);
ZVAL_LONG(rv_column_name, 0);
result = switch_dbx_getcolumnname(&rv_column_name, &rv_result_handle, col_index, INTERNAL_FUNCTION_PARAM_PASSTHRU, dbx_module);
+ /* modify case if requested */
+ if (colcase==DBX_COLNAMES_UPPERCASE) {
+ php_strtoupper(Z_STRVAL_P(rv_column_name), Z_STRLEN_P(rv_column_name));
+ }
+ if (colcase==DBX_COLNAMES_LOWERCASE) {
+ php_strtolower(Z_STRVAL_P(rv_column_name), Z_STRLEN_P(rv_column_name));
+ }
if (result) {
zend_hash_index_update(Z_ARRVAL_P(info_row_name), col_index, (void *)&(rv_column_name), sizeof(zval *), NULL);
} else {
@@ -479,7 +521,7 @@ ZEND_FUNCTION(dbx_query)
if (result) {
zend_hash_index_update(Z_ARRVAL_P(data), row_count, (void *)&(rv_row), sizeof(zval *), (void **) &row_ptr);
/* associate results with fieldnames */
- if (info_flags & DBX_RESULT_ASSOC) {
+ if (result_flags & DBX_RESULT_ASSOC) {
zval **columnname_ptr, **actual_ptr;
for (col_index=0; col_index<Z_LVAL_P(rv_column_count); ++col_index) {
zend_hash_index_find(Z_ARRVAL_PP(inforow_ptr), col_index, (void **) &columnname_ptr);
diff --git a/ext/dbx/dbx.h b/ext/dbx/dbx.h
index 8bfb9fe73a..338061855a 100644
--- a/ext/dbx/dbx.h
+++ b/ext/dbx/dbx.h
@@ -31,17 +31,20 @@
#include "php.h"
-#define DBX_PERSISTENT (1<<0)
-
-#define DBX_RESULT_INFO (1<<0)
-#define DBX_RESULT_INDEX (1<<1)
-#define DBX_RESULT_ASSOC (1<<2)
-
-#define DBX_CMP_NATIVE (1<<0)
-#define DBX_CMP_TEXT (1<<1)
-#define DBX_CMP_NUMBER (1<<2)
-#define DBX_CMP_ASC (1<<3)
-#define DBX_CMP_DESC (1<<4)
+#define DBX_PERSISTENT (1<<0)
+
+#define DBX_RESULT_INFO (1<<0)
+#define DBX_RESULT_INDEX (1<<1)
+#define DBX_RESULT_ASSOC (1<<2)
+#define DBX_COLNAMES_UNCHANGED (1<<3)
+#define DBX_COLNAMES_UPPERCASE (1<<4)
+#define DBX_COLNAMES_LOWERCASE (1<<5)
+
+#define DBX_CMP_NATIVE (1<<0)
+#define DBX_CMP_TEXT (1<<1)
+#define DBX_CMP_NUMBER (1<<2)
+#define DBX_CMP_ASC (1<<3)
+#define DBX_CMP_DESC (1<<4)
#define MOVE_RETURNED_TO_RV(rv, returned_zval) { **rv = *returned_zval; zval_copy_ctor(*rv); zval_ptr_dtor(&returned_zval); }
diff --git a/ext/dbx/dbx_oci8.c b/ext/dbx/dbx_oci8.c
index 95216487f7..efdfbea472 100644
--- a/ext/dbx/dbx_oci8.c
+++ b/ext/dbx/dbx_oci8.c
@@ -24,7 +24,6 @@
#include "dbx.h"
#include "dbx_oci8.h"
-#include "ext/standard/php_string.h" /* for auto-change column names to lowercase*/
#define OCI_ASSOC 1<<0
#define OCI_NUM 1<<1
@@ -179,7 +178,6 @@ int dbx_oci8_getcolumnname(zval **rv, zval **result_handle, long column_index, I
return 0;
}
FREE_ZVAL(zval_column_index);
- php_strtolower(Z_STRVAL_P(returned_zval), Z_STRLEN_P(returned_zval));
MOVE_RETURNED_TO_RV(rv, returned_zval);
return 1;
}
diff --git a/ext/dbx/tests/002.phpt b/ext/dbx/tests/002.phpt
index 391a3fa688..cf51901cb9 100644
--- a/ext/dbx/tests/002.phpt
+++ b/ext/dbx/tests/002.phpt
@@ -15,6 +15,9 @@ if (DBX_PERSISTENT=="DBX_PERSISTENT") print('!DBX_PERSISTENT');
if (DBX_RESULT_INFO=="DBX_RESULT_INFO") print('!DBX_RESULT_INFO');
if (DBX_RESULT_INDEX=="DBX_RESULT_INDEX") print('!DBX_RESULT_INDEX');
if (DBX_RESULT_ASSOC=="DBX_RESULT_ASSOC") print('!DBX_RESULT_ASSOC');
+if (DBX_COLNAMES_UNCHANGED=="DBX_COLNAMES_UNCHANGED") print('!DBX_COLNAMES_UNCHANGED');
+if (DBX_COLNAMES_UPPERCASE=="DBX_COLNAMES_UPPERCASE") print('!DBX_COLNAMES_UPPERCASE');
+if (DBX_COLNAMES_LOWERCASE=="DBX_COLNAMES_LOWERCASE") print('!DBX_COLNAMES_LOWERCASE');
if (DBX_CMP_NATIVE=="DBX_CMP_NATIVE") print('!DBX_CMP_NATIVE');
if (DBX_CMP_TEXT=="DBX_CMP_TEXT") print('!DBX_CMP_TEXT');
if (DBX_CMP_NUMBER=="DBX_CMP_NUMBER") print('!DBX_CMP_NUMBER');
diff --git a/ext/dbx/tests/005.phpt b/ext/dbx/tests/005.phpt
index beb7fb7931..a26224a928 100644
--- a/ext/dbx/tests/005.phpt
+++ b/ext/dbx/tests/005.phpt
@@ -56,6 +56,15 @@ else {
}
}
}
+ // colnames_case flags
+ if ($dro=dbx_query($dlo, $sql_statement, DBX_COLNAMES_LOWERCASE)) {
+ print('column name lowercased: ');
+ print($dro->info["name"][0].".".$dro->data[0]['id'].".".$dro->data[0]['description']."\n");
+ }
+ if ($dro=dbx_query($dlo, $sql_statement, DBX_COLNAMES_UPPERCASE)) {
+ print('column name uppercased: ');
+ print($dro->info["name"][0].".".$dro->data[0]['ID'].".".$dro->data[0]['DESCRIPTION']."\n");
+ }
// generate errors
if (!@dbx_query(0, $sql_statement)) {
@@ -87,6 +96,8 @@ insert-query: dbx_query works ok
update-query: dbx_query works ok
999999.temporary_record.11
delete-query: dbx_query works ok
+column name lowercased: id.1.root
+column name uppercased: ID.1.root
wrong dbx_link_object: query failure works ok
wrong sql-statement: query failure works ok
too many parameters: query failure works ok