Skip to content

Commit 43349ea

Browse files
committed
Added sqlite.assoc_case ini entry with 0 as the default value.
0 - Make no changes to the keys in the associative array 1 - Change the keys to uppercase 2 - Change the keys to lowercase
1 parent 04c5e2f commit 43349ea

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

ext/sqlite/php_sqlite.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ PHP_FUNCTION(sqlite_error_string);
6969
PHP_FUNCTION(sqlite_create_aggregate);
7070
PHP_FUNCTION(sqlite_create_function);
7171

72+
ZEND_BEGIN_MODULE_GLOBALS(sqlite)
73+
int assoc_case;
74+
ZEND_END_MODULE_GLOBALS(sqlite)
75+
7276
#ifdef ZTS
7377
#define SQLITE_G(v) TSRMG(sqlite_globals_id, zend_sqlite_globals *, v)
7478
#else

ext/sqlite/sqlite.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,39 @@
3737

3838
#include <sqlite.h>
3939

40+
ZEND_DECLARE_MODULE_GLOBALS(sqlite)
41+
4042
extern int sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out);
4143
extern int sqlite_decode_binary(const unsigned char *in, unsigned char *out);
4244

4345
static unsigned char arg3_force_ref[] = {3, BYREF_NONE, BYREF_NONE, BYREF_FORCE };
4446

4547
static int le_sqlite_db, le_sqlite_result, le_sqlite_pdb;
4648

49+
static inline void php_sqlite_strtoupper(char *s)
50+
{
51+
while (*s!='\0') {
52+
*s = toupper(*s);
53+
s++;
54+
}
55+
}
56+
57+
static inline void php_sqlite_strtolower(char *s)
58+
{
59+
while (*s!='\0') {
60+
*s = tolower(*s);
61+
s++;
62+
}
63+
}
64+
65+
/* {{{ PHP_INI
66+
*/
67+
PHP_INI_BEGIN()
68+
STD_PHP_INI_ENTRY_EX("sqlite.assoc_case", "0", PHP_INI_ALL, OnUpdateInt, assoc_case, zend_sqlite_globals, sqlite_globals, display_link_numbers)
69+
PHP_INI_END()
70+
/* }}} */
71+
72+
4773
#define DB_FROM_ZVAL(db, zv) ZEND_FETCH_RESOURCE2(db, struct php_sqlite_db *, zv, -1, "sqlite database", le_sqlite_db, le_sqlite_pdb)
4874

4975
struct php_sqlite_result {
@@ -535,6 +561,7 @@ static int php_sqlite_authorizer(void *autharg, int access_type, const char *arg
535561

536562
PHP_MINIT_FUNCTION(sqlite)
537563
{
564+
REGISTER_INI_ENTRIES();
538565
le_sqlite_db = zend_register_list_destructors_ex(php_sqlite_db_dtor, NULL, "sqlite database", module_number);
539566
le_sqlite_pdb = zend_register_list_destructors_ex(NULL, php_sqlite_db_dtor, "sqlite database (persistent)", module_number);
540567
le_sqlite_result = zend_register_list_destructors_ex(php_sqlite_result_dtor, NULL, "sqlite result", module_number);
@@ -581,6 +608,8 @@ PHP_MINFO_FUNCTION(sqlite)
581608
php_info_print_table_row(2, "SQLite Library", sqlite_libversion());
582609
php_info_print_table_row(2, "SQLite Encoding", sqlite_libencoding());
583610
php_info_print_table_end();
611+
612+
DISPLAY_INI_ENTRIES();
584613
}
585614

586615
static struct php_sqlite_db *php_sqlite_open(char *filename, int mode, char *persistent_id, zval *return_value, zval *errmsg)
@@ -1007,6 +1036,12 @@ PHP_FUNCTION(sqlite_fetch_array)
10071036
}
10081037
}
10091038
if (mode & PHPSQLITE_ASSOC) {
1039+
/* Lets see if we need to change case of the assoc key */
1040+
if (SQLITE_G(assoc_case) == 1) {
1041+
php_sqlite_strtoupper((char*)colnames[j]);
1042+
} else if (SQLITE_G(assoc_case) == 2) {
1043+
php_sqlite_strtolower((char*)colnames[j]);
1044+
}
10101045
if (decoded == NULL) {
10111046
add_assoc_null(return_value, (char*)colnames[j]);
10121047
} else {
@@ -1386,3 +1421,12 @@ PHP_FUNCTION(sqlite_create_function)
13861421
}
13871422
}
13881423
/* }}} */
1424+
1425+
/*
1426+
* Local variables:
1427+
* tab-width: 4
1428+
* c-basic-offset: 4
1429+
* End:
1430+
* vim600: sw=4 ts=4 fdm=marker
1431+
* vim<600: sw=4 ts=4
1432+
*/

0 commit comments

Comments
 (0)