~ubuntu-branches/ubuntu/hardy/php5/hardy-updates

« back to all changes in this revision

Viewing changes to ext/dbx/dbx.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-10-09 03:14:32 UTC
  • Revision ID: james.westby@ubuntu.com-20051009031432-kspik3lobxstafv9
Tags: upstream-5.0.5
ImportĀ upstreamĀ versionĀ 5.0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   +----------------------------------------------------------------------+
 
3
   | PHP Version 5                                                        |
 
4
   +----------------------------------------------------------------------+
 
5
   | Copyright (c) 1997-2004 The PHP Group                                |
 
6
   +----------------------------------------------------------------------+
 
7
   | dbx module version 1.0                                               |
 
8
   +----------------------------------------------------------------------+
 
9
   | Copyright (c) 2001-2003 Guidance Rotterdam BV                        |
 
10
   +----------------------------------------------------------------------+
 
11
   | This source file is subject to version 3.0 of the PHP license,       |
 
12
   | that is bundled with this package in the file LICENSE, and is        |
 
13
   | available through the world-wide-web at the following url:           |
 
14
   | http://www.php.net/license/3_0.txt.                                  |
 
15
   | If you did not receive a copy of the PHP license and are unable to   |
 
16
   | obtain it through the world-wide-web, please send a note to          |
 
17
   | license@php.net so we can mail you a copy immediately.               |
 
18
   +----------------------------------------------------------------------+
 
19
   | Author : Marc Boeren         <marc@guidance.nl>                      |
 
20
   +----------------------------------------------------------------------+
 
21
*/
 
22
 
 
23
/* $Id: dbx.c,v 1.57 2004/01/08 08:15:09 andi Exp $ */
 
24
 
 
25
#ifdef HAVE_CONFIG_H
 
26
#include "config.h"
 
27
#endif
 
28
 
 
29
#include "php.h"
 
30
#include "php_ini.h"
 
31
#include "php_dbx.h"
 
32
#include "ext/standard/info.h"
 
33
 
 
34
/* defines for supported databases */
 
35
#define DBX_UNKNOWN 0
 
36
#define DBX_MYSQL 1
 
37
#define DBX_ODBC 2
 
38
#define DBX_PGSQL 3
 
39
#define DBX_MSSQL 4
 
40
#define DBX_FBSQL 5
 
41
#define DBX_OCI8 6
 
42
#define DBX_SYBASECT 7
 
43
#define DBX_SQLITE 8
 
44
/* includes for supported databases */
 
45
#include "dbx.h"
 
46
#include "dbx_mysql.h"
 
47
#include "dbx_odbc.h"
 
48
#include "dbx_pgsql.h"
 
49
#include "dbx_mssql.h"
 
50
#include "dbx_fbsql.h"
 
51
#include "dbx_oci8.h"
 
52
#include "dbx_sybasect.h"
 
53
#include "dbx_sqlite.h"
 
54
 
 
55
/* support routines */
 
56
int module_exists(char *module_name)
 
57
{
 
58
        zend_module_entry *zme;
 
59
        int r;
 
60
        r = zend_hash_find(&module_registry, module_name, strlen(module_name)+1, (void **) &zme);
 
61
        return r==0?1:0;
 
62
}
 
63
 
 
64
int module_identifier_exists(long module_identifier)
 
65
{
 
66
        switch (module_identifier) {
 
67
                case DBX_MYSQL: return module_exists("mysql");
 
68
                case DBX_ODBC: return module_exists("odbc");
 
69
                case DBX_PGSQL: return module_exists("pgsql");
 
70
                case DBX_MSSQL: return module_exists("mssql");
 
71
                case DBX_FBSQL: return module_exists("fbsql");
 
72
                case DBX_OCI8: return module_exists("oci8");
 
73
                case DBX_SYBASECT: return module_exists("sybase_ct");
 
74
                case DBX_SQLITE: return module_exists("sqlite");
 
75
        }
 
76
        return 0;
 
77
}
 
78
 
 
79
int get_module_identifier(char *module_name)
 
80
{
 
81
        if (!strcmp("mysql", module_name)) return DBX_MYSQL;
 
82
        if (!strcmp("odbc", module_name)) return DBX_ODBC;
 
83
        if (!strcmp("pgsql", module_name)) return DBX_PGSQL;
 
84
        if (!strcmp("mssql", module_name)) return DBX_MSSQL;
 
85
        if (!strcmp("fbsql", module_name)) return DBX_FBSQL;
 
86
        if (!strcmp("oci8", module_name)) return DBX_OCI8;
 
87
        if (!strcmp("sybase_ct", module_name)) return DBX_SYBASECT;
 
88
        if (!strcmp("sqlite", module_name)) return DBX_SQLITE;
 
89
        return DBX_UNKNOWN;
 
90
}
 
91
 
 
92
int split_dbx_handle_object(zval **dbx_object, zval ***pdbx_handle, zval ***pdbx_module, zval ***pdbx_database TSRMLS_DC)
 
93
{
 
94
        convert_to_object_ex(dbx_object);
 
95
        if (zend_hash_find(Z_OBJPROP_PP(dbx_object), "handle", 7, (void **) pdbx_handle)==FAILURE
 
96
        || zend_hash_find(Z_OBJPROP_PP(dbx_object), "module", 7, (void **) pdbx_module)==FAILURE
 
97
        || zend_hash_find(Z_OBJPROP_PP(dbx_object), "database", 9, (void **) pdbx_database)==FAILURE) {
 
98
                return 0;
 
99
        }
 
100
        return 1;
 
101
}
 
102
 
 
103
int split_dbx_result_object(zval **dbx_result, zval ***pdbx_link, zval ***pdbx_handle, zval ***pdbx_flags, zval ***pdbx_info, zval ***pdbx_cols , zval ***pdbx_rows TSRMLS_DC)
 
104
{
 
105
        convert_to_object_ex(dbx_result);
 
106
        if (zend_hash_find(Z_OBJPROP_PP(dbx_result), "link", 5, (void **) pdbx_link)==FAILURE
 
107
        || zend_hash_find(Z_OBJPROP_PP(dbx_result), "handle", 7, (void **) pdbx_handle)==FAILURE
 
108
        || zend_hash_find(Z_OBJPROP_PP(dbx_result), "flags", 6, (void **) pdbx_flags)==FAILURE
 
109
        || zend_hash_find(Z_OBJPROP_PP(dbx_result), "info", 5, (void **) pdbx_info)==FAILURE
 
110
        || zend_hash_find(Z_OBJPROP_PP(dbx_result), "cols", 5, (void **) pdbx_cols)==FAILURE
 
111
        || zend_hash_find(Z_OBJPROP_PP(dbx_result), "rows", 5, (void **) pdbx_rows)==FAILURE) {
 
112
                return 0;
 
113
        }
 
114
        return 1;
 
115
}
 
116
 
 
117
/* from dbx.h, to be used in support-files (dbx_mysql.c etc...) */
 
118
void dbx_call_any_function(INTERNAL_FUNCTION_PARAMETERS, char *function_name, zval **returnvalue, int number_of_arguments, zval ***params)
 
119
{
 
120
        zval *zval_function_name;
 
121
 
 
122
        MAKE_STD_ZVAL(zval_function_name);
 
123
        ZVAL_STRING(zval_function_name, function_name, 1);
 
124
        if (call_user_function_ex(EG(function_table), NULL, zval_function_name, returnvalue, number_of_arguments, params, 0, NULL TSRMLS_CC) == FAILURE) {
 
125
                php_error_docref(NULL TSRMLS_CC, E_ERROR, "function '%s' not found", Z_STRVAL_P(zval_function_name));
 
126
        }
 
127
        zval_dtor(zval_function_name); /* to free stringvalue memory */
 
128
        FREE_ZVAL(zval_function_name);
 
129
}
 
130
 
 
131
/* switch_dbx functions declarations
 
132
 * each must be supported in the dbx_module files as dbx_module_function,
 
133
 *   e.g. switch_dbx_connect expects a dbx_mysql_connect in de dbx_mysql files
 
134
 *   all params except the dbx_module param are passed on
 
135
 * each must return the expected zval *'s in the rv parameter, which are passed on unmodified
 
136
 * do NOT use the return_value parameter from INTERNAL_FUNCTION_PARAMETERS
 
137
 * you can additionally return 0 or 1 for failure or success which will also be returned by the switches
 
138
 */
 
139
int switch_dbx_connect(zval **rv, zval **host, zval **db, zval **username, zval **password, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module);
 
140
        /* returns connection handle as resource on success or 0 as long on failure */
 
141
int switch_dbx_pconnect(zval **rv, zval **host, zval **db, zval **username, zval **password, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module);
 
142
        /* returns persistent connection handle as resource on success or 0 as long on failure */
 
143
int switch_dbx_close(zval **rv, zval **dbx_handle, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module);
 
144
        /* returns 1 as long on success or 0 as long on failure */
 
145
int switch_dbx_query(zval **rv, zval **dbx_handle, zval **db_name, zval **sql_statement, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module);
 
146
        /* returns 1 as long or result identifier as resource on success or 0 as long on failure */
 
147
int switch_dbx_getcolumncount(zval **rv, zval **result_handle, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module);
 
148
        /* returns column-count as long on success or 0 as long on failure */
 
149
int switch_dbx_getcolumnname(zval **rv, zval **result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module);
 
150
        /* returns column-name as string on success or 0 as long on failure */
 
151
int switch_dbx_getcolumntype(zval **rv, zval **result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module);
 
152
        /* returns column-type as string on success or 0 as long on failure */
 
153
int switch_dbx_getrow(zval **rv, zval **result_handle, long row_number, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module);
 
154
        /* returns array[0..columncount-1] as strings on success or 0 as long on failure */
 
155
int switch_dbx_error(zval **rv, zval **dbx_handle, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module);
 
156
        /* returns string */
 
157
int switch_dbx_esc(zval **rv, zval **dbx_handle, zval **string, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module);
 
158
        /* returns escaped string */
 
159
 
 
160
/* Every user visible function must have an entry in dbx_functions[].
 
161
*/
 
162
function_entry dbx_functions[] = {
 
163
        ZEND_FE(dbx_connect,    NULL)
 
164
        ZEND_FE(dbx_close,              NULL)
 
165
        ZEND_FE(dbx_query,              NULL)
 
166
        ZEND_FE(dbx_fetch_row,  NULL)
 
167
        ZEND_FE(dbx_error,              NULL)
 
168
        ZEND_FE(dbx_escape_string,      NULL)
 
169
 
 
170
        ZEND_FE(dbx_sort,               NULL)
 
171
        ZEND_FE(dbx_compare,    NULL)
 
172
 
 
173
        {NULL, NULL, NULL} /* Must be the last line in dbx_functions[] */
 
174
};
 
175
 
 
176
zend_module_entry dbx_module_entry = {
 
177
        STANDARD_MODULE_HEADER,
 
178
        "dbx",
 
179
        dbx_functions,
 
180
        ZEND_MINIT(dbx),
 
181
        ZEND_MSHUTDOWN(dbx),
 
182
        NULL, /*ZEND_RINIT(dbx),         Replace with NULL if there's nothing to do at request start */
 
183
        NULL, /*ZEND_RSHUTDOWN(dbx),     Replace with NULL if there's nothing to do at request end */
 
184
        ZEND_MINFO(dbx),
 
185
        NO_VERSION_YET,
 
186
        STANDARD_MODULE_PROPERTIES
 
187
};
 
188
 
 
189
#ifdef COMPILE_DL_DBX
 
190
ZEND_GET_MODULE(dbx)
 
191
#endif
 
192
 
 
193
ZEND_INI_BEGIN()
 
194
        ZEND_INI_ENTRY("dbx.colnames_case", "unchanged", ZEND_INI_SYSTEM, NULL)
 
195
ZEND_INI_END()
 
196
 
 
197
ZEND_MINIT_FUNCTION(dbx)
 
198
{
 
199
        REGISTER_INI_ENTRIES();
 
200
 
 
201
        REGISTER_LONG_CONSTANT("DBX_MYSQL", DBX_MYSQL, CONST_CS | CONST_PERSISTENT);
 
202
        REGISTER_LONG_CONSTANT("DBX_ODBC", DBX_ODBC, CONST_CS | CONST_PERSISTENT);
 
203
        REGISTER_LONG_CONSTANT("DBX_PGSQL", DBX_PGSQL, CONST_CS | CONST_PERSISTENT);
 
204
        REGISTER_LONG_CONSTANT("DBX_MSSQL", DBX_MSSQL, CONST_CS | CONST_PERSISTENT);
 
205
        REGISTER_LONG_CONSTANT("DBX_FBSQL", DBX_FBSQL, CONST_CS | CONST_PERSISTENT);
 
206
        REGISTER_LONG_CONSTANT("DBX_OCI8", DBX_OCI8, CONST_CS | CONST_PERSISTENT);
 
207
        REGISTER_LONG_CONSTANT("DBX_SYBASECT", DBX_SYBASECT, CONST_CS | CONST_PERSISTENT);
 
208
        REGISTER_LONG_CONSTANT("DBX_SQLITE", DBX_SQLITE, CONST_CS | CONST_PERSISTENT);
 
209
 
 
210
        REGISTER_LONG_CONSTANT("DBX_PERSISTENT", DBX_PERSISTENT, CONST_CS | CONST_PERSISTENT);
 
211
 
 
212
        REGISTER_LONG_CONSTANT("DBX_RESULT_INFO", DBX_RESULT_INFO, CONST_CS | CONST_PERSISTENT);
 
213
        REGISTER_LONG_CONSTANT("DBX_RESULT_INDEX", DBX_RESULT_INDEX, CONST_CS | CONST_PERSISTENT);
 
214
        REGISTER_LONG_CONSTANT("DBX_RESULT_ASSOC", DBX_RESULT_ASSOC, CONST_CS | CONST_PERSISTENT);
 
215
        REGISTER_LONG_CONSTANT("DBX_RESULT_UNBUFFERED", DBX_RESULT_UNBUFFERED, CONST_CS | CONST_PERSISTENT);
 
216
 
 
217
        REGISTER_LONG_CONSTANT("DBX_COLNAMES_UNCHANGED", DBX_COLNAMES_UNCHANGED, CONST_CS | CONST_PERSISTENT);
 
218
        REGISTER_LONG_CONSTANT("DBX_COLNAMES_UPPERCASE", DBX_COLNAMES_UPPERCASE, CONST_CS | CONST_PERSISTENT);
 
219
        REGISTER_LONG_CONSTANT("DBX_COLNAMES_LOWERCASE", DBX_COLNAMES_LOWERCASE, CONST_CS | CONST_PERSISTENT);
 
220
 
 
221
        REGISTER_LONG_CONSTANT("DBX_CMP_NATIVE", DBX_CMP_NATIVE, CONST_CS | CONST_PERSISTENT);
 
222
        REGISTER_LONG_CONSTANT("DBX_CMP_TEXT", DBX_CMP_TEXT, CONST_CS | CONST_PERSISTENT);
 
223
        REGISTER_LONG_CONSTANT("DBX_CMP_NUMBER", DBX_CMP_NUMBER, CONST_CS | CONST_PERSISTENT);
 
224
        REGISTER_LONG_CONSTANT("DBX_CMP_ASC", DBX_CMP_ASC, CONST_CS | CONST_PERSISTENT);
 
225
        REGISTER_LONG_CONSTANT("DBX_CMP_DESC", DBX_CMP_DESC, CONST_CS | CONST_PERSISTENT);
 
226
 
 
227
        return SUCCESS;
 
228
}
 
229
 
 
230
ZEND_MSHUTDOWN_FUNCTION(dbx)
 
231
{
 
232
        UNREGISTER_INI_ENTRIES();
 
233
        return SUCCESS;
 
234
}
 
235
 
 
236
/* Remove if there's nothing to do at request start */
 
237
/*ZEND_RINIT_FUNCTION(dbx)
 
238
{       return SUCCESS;
 
239
}*/
 
240
 
 
241
/* Remove if there's nothing to do at request end */
 
242
/*ZEND_RSHUTDOWN_FUNCTION(dbx)
 
243
{       return SUCCESS;
 
244
}*/
 
245
 
 
246
ZEND_MINFO_FUNCTION(dbx)
 
247
{
 
248
        php_info_print_table_start();
 
249
        php_info_print_table_row(2, "dbx support", "enabled");
 
250
        php_info_print_table_row(2, "dbx version", "1.1.0");
 
251
        php_info_print_table_row(2, "supported databases", "MySQL\nODBC\nPostgreSQL\nMicrosoft SQL Server\nFrontBase\nOracle 8 (oci8)\nSybase-CT\nSQLite");
 
252
        php_info_print_table_end();
 
253
        DISPLAY_INI_ENTRIES();
 
254
}
 
255
 
 
256
/*
 
257
 
 
258
        actual implementation of the dbx functions
 
259
 
 
260
*/
 
261
 
 
262
/* {{{ proto dbx_link_object dbx_connect(string module_name, string host, string db, string username, string password [, bool persistent])
 
263
   Returns a dbx_link_object on success and returns 0 on failure */
 
264
ZEND_FUNCTION(dbx_connect)
 
265
{
 
266
        int number_of_arguments=5;
 
267
        zval **arguments[6];
 
268
 
 
269
        int result;
 
270
        long module_identifier;
 
271
        zval *dbx_module;
 
272
        zval *db_name;
 
273
        zval *rv_dbx_handle;
 
274
        int persistent=0;
 
275
 
 
276
        if ( !(ZEND_NUM_ARGS()==number_of_arguments+1 || ZEND_NUM_ARGS()==number_of_arguments) || zend_get_parameters_array_ex(ZEND_NUM_ARGS(), arguments) == FAILURE) {
 
277
                WRONG_PARAM_COUNT;
 
278
        }
 
279
        if (ZEND_NUM_ARGS()==number_of_arguments+1) {
 
280
                convert_to_long_ex(arguments[5]);
 
281
                if (Z_LVAL_PP(arguments[5])!=0) persistent=1;
 
282
        }
 
283
 
 
284
        if (Z_TYPE_PP(arguments[0]) == IS_LONG) {
 
285
                if (!module_identifier_exists(Z_LVAL_PP(arguments[0]))) {
 
286
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "dbx: module '%ld' not loaded or not supported.", Z_LVAL_PP(arguments[0]));
 
287
                        return;
 
288
                }
 
289
                module_identifier = Z_LVAL_PP(arguments[0]);
 
290
        } else {
 
291
                convert_to_string_ex(arguments[0]);
 
292
                if (!module_exists(Z_STRVAL_PP(arguments[0]))) {
 
293
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "dbx: module '%s' not loaded.", Z_STRVAL_PP(arguments[0]));
 
294
                        return;
 
295
                }
 
296
                module_identifier=get_module_identifier(Z_STRVAL_PP(arguments[0]));
 
297
                if (!module_identifier) {
 
298
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "dbx: unsupported module '%s'.", Z_STRVAL_PP(arguments[0]));
 
299
                        return;
 
300
                }
 
301
        }
 
302
 
 
303
        MAKE_STD_ZVAL(dbx_module); 
 
304
        ZVAL_LONG(dbx_module, module_identifier);
 
305
        MAKE_STD_ZVAL(rv_dbx_handle); 
 
306
        ZVAL_LONG(rv_dbx_handle, 0);
 
307
        convert_to_string_ex(arguments[1]);
 
308
        convert_to_string_ex(arguments[2]);
 
309
        convert_to_string_ex(arguments[3]);
 
310
        convert_to_string_ex(arguments[4]);
 
311
        MAKE_STD_ZVAL(db_name); 
 
312
        ZVAL_STRING(db_name, Z_STRVAL_PP(arguments[2]), 1);
 
313
        if (persistent) {
 
314
                result = switch_dbx_pconnect(&rv_dbx_handle, arguments[1], arguments[2], arguments[3], arguments[4], INTERNAL_FUNCTION_PARAM_PASSTHRU, &dbx_module);
 
315
        } else {
 
316
                result = switch_dbx_connect(&rv_dbx_handle, arguments[1], arguments[2], arguments[3], arguments[4], INTERNAL_FUNCTION_PARAM_PASSTHRU, &dbx_module);
 
317
        }
 
318
        if (!result) {
 
319
                FREE_ZVAL(dbx_module);
 
320
                zval_dtor(db_name); /* to free stringvalue memory */
 
321
                FREE_ZVAL(db_name);
 
322
                FREE_ZVAL(rv_dbx_handle);
 
323
                RETURN_LONG(0);
 
324
        }
 
325
 
 
326
        object_init(return_value);
 
327
 
 
328
        zend_hash_update(Z_OBJPROP_P(return_value), "handle", 7, (void *)&(rv_dbx_handle), sizeof(zval *), NULL);
 
329
        zend_hash_update(Z_OBJPROP_P(return_value), "module", 7, (void *)&(dbx_module), sizeof(zval *), NULL);
 
330
        zend_hash_update(Z_OBJPROP_P(return_value), "database", 9, (void *)&(db_name), sizeof(zval *), NULL);
 
331
}
 
332
/* }}} */
 
333
 
 
334
/* {{{ proto int dbx_close(dbx_link_object dbx_link)
 
335
   Returns success or failure 
 
336
*/
 
337
ZEND_FUNCTION(dbx_close)
 
338
{
 
339
        int number_of_arguments=1;
 
340
        zval **arguments[1];
 
341
 
 
342
        int result;
 
343
        zval **dbx_handle;
 
344
        zval **dbx_module;
 
345
        zval **dbx_database;
 
346
        zval *rv_success;
 
347
 
 
348
        if (ZEND_NUM_ARGS() !=number_of_arguments || zend_get_parameters_array_ex(number_of_arguments, arguments) == FAILURE) {
 
349
                WRONG_PARAM_COUNT;
 
350
        }
 
351
        if (!split_dbx_handle_object(arguments[0], &dbx_handle, &dbx_module, &dbx_database TSRMLS_CC)) {
 
352
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "not a valid dbx_handle-object...");
 
353
                RETURN_LONG(0);
 
354
        }
 
355
 
 
356
        MAKE_STD_ZVAL(rv_success); 
 
357
        ZVAL_LONG(rv_success, 0);
 
358
 
 
359
        result = switch_dbx_close(&rv_success, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU, dbx_module);
 
360
 
 
361
        result = (result && Z_LVAL_P(rv_success))?1:0;
 
362
        FREE_ZVAL(rv_success);
 
363
 
 
364
        RETURN_LONG(result?1:0);
 
365
}
 
366
/* }}} */
 
367
 
 
368
/* {{{ proto dbx_result_object dbx_query(dbx_link_object dbx_link, string sql_statement [, int flags])
 
369
   Returns a dbx_link_object on success and returns 0 on failure */
 
370
ZEND_FUNCTION(dbx_query)
 
371
{
 
372
        int min_number_of_arguments=2;
 
373
        int number_of_arguments=3;
 
374
        zval **arguments[3];
 
375
 
 
376
        int result;
 
377
        zval **dbx_handle;
 
378
        zval **dbx_module;
 
379
        zval **dbx_database;
 
380
        zval *rv_result_handle;
 
381
        zval *rv_column_count;
 
382
        long col_index;
 
383
        long row_count;
 
384
        zval *info;
 
385
        long query_flags;
 
386
        long result_flags;
 
387
        zval *data;
 
388
        zval **row_ptr;
 
389
        zval **inforow_ptr;
 
390
        /* default values for colname-case */
 
391
        char * colnames_case = INI_STR("dbx.colnames_case");
 
392
        long colcase = DBX_COLNAMES_UNCHANGED;
 
393
        if (!strcmp(colnames_case, "uppercase")) {
 
394
                colcase = DBX_COLNAMES_UPPERCASE;
 
395
        }
 
396
        if (!strcmp(colnames_case, "lowercase")) {
 
397
                colcase = DBX_COLNAMES_LOWERCASE;
 
398
        }
 
399
 
 
400
        if (ZEND_NUM_ARGS()<min_number_of_arguments || ZEND_NUM_ARGS()>number_of_arguments || zend_get_parameters_array_ex(ZEND_NUM_ARGS(), arguments) == FAILURE) {
 
401
                WRONG_PARAM_COUNT;
 
402
        }
 
403
        if (!split_dbx_handle_object(arguments[0], &dbx_handle, &dbx_module, &dbx_database TSRMLS_CC)) {
 
404
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "not a valid dbx_handle-object...");
 
405
                RETURN_LONG(0);
 
406
        }
 
407
        /* default values */
 
408
        result_flags = DBX_RESULT_INFO | DBX_RESULT_INDEX | DBX_RESULT_ASSOC;
 
409
        /* parameter overrides */
 
410
        if (ZEND_NUM_ARGS()>2) {
 
411
                convert_to_long_ex(arguments[2]);
 
412
                query_flags = Z_LVAL_PP(arguments[2]);
 
413
                /* fieldnames are needed for association! */
 
414
                result_flags = (query_flags & DBX_RESULT_INFO) | (query_flags & DBX_RESULT_INDEX) | (query_flags & DBX_RESULT_ASSOC) | (query_flags & DBX_RESULT_UNBUFFERED);
 
415
                if (result_flags & DBX_RESULT_ASSOC) {
 
416
                        result_flags |= DBX_RESULT_INFO;
 
417
                }
 
418
                if (!result_flags) result_flags = DBX_RESULT_INFO | DBX_RESULT_INDEX | DBX_RESULT_ASSOC;
 
419
                if (result_flags == DBX_RESULT_UNBUFFERED) result_flags |= DBX_RESULT_INFO | DBX_RESULT_INDEX | DBX_RESULT_ASSOC;
 
420
                /* override ini-setting for colcase */
 
421
                if (query_flags & DBX_COLNAMES_UNCHANGED) {
 
422
                        colcase = DBX_COLNAMES_UNCHANGED;
 
423
                }
 
424
                if (query_flags & DBX_COLNAMES_UPPERCASE) {
 
425
                        colcase = DBX_COLNAMES_UPPERCASE;
 
426
                }
 
427
                if (query_flags & DBX_COLNAMES_LOWERCASE) {
 
428
                        colcase = DBX_COLNAMES_LOWERCASE;
 
429
                }
 
430
        }
 
431
        MAKE_STD_ZVAL(rv_result_handle); 
 
432
        ZVAL_LONG(rv_result_handle, 0);
 
433
        convert_to_string_ex(arguments[1]);
 
434
        result = switch_dbx_query(&rv_result_handle, dbx_handle, dbx_database, arguments[1], INTERNAL_FUNCTION_PARAM_PASSTHRU, dbx_module);
 
435
        /* boolean return value means either failure for any query or success for queries that don't return anything  */
 
436
        if (!result || (rv_result_handle && Z_TYPE_P(rv_result_handle)==IS_BOOL)) {
 
437
                result = (result && Z_LVAL_P(rv_result_handle))?1:0;
 
438
                FREE_ZVAL(rv_result_handle);
 
439
                RETURN_LONG(result?1:0);
 
440
        }
 
441
        /* if you get here, the query succeeded and returned results, so we'll return them
 
442
         * rv_result_handle holds a resource
 
443
         */
 
444
        /* init return_value as object (of rows) */
 
445
        object_init(return_value);
 
446
 
 
447
        zend_hash_update(Z_OBJPROP_P(return_value), "link", 5, (void *)(arguments[0]), sizeof(zval *), NULL);
 
448
         /* need extra refcount here otherwise the link object is destroyed when the 
 
449
          * query resultobject is destroyed (or not assigned!)
 
450
          */
 
451
        zval_add_ref(arguments[0]);
 
452
        /* add result_handle property to return_value */
 
453
        zend_hash_update(Z_OBJPROP_P(return_value), "handle", 7, (void *)&(rv_result_handle), sizeof(zval *), NULL);
 
454
        /* add flags property to return_value */
 
455
        add_property_long(return_value, "flags", result_flags | colcase);
 
456
        /* init info property as array and add to return_value as a property */
 
457
        if (result_flags & DBX_RESULT_INFO) {
 
458
                MAKE_STD_ZVAL(info); 
 
459
                array_init(info);
 
460
                zend_hash_update(Z_OBJPROP_P(return_value), "info", 5, (void *)&(info), sizeof(zval *), NULL);
 
461
        }
 
462
        /* init data property as array and add to return_value as a property */
 
463
        if (!(result_flags & DBX_RESULT_UNBUFFERED)) {
 
464
                MAKE_STD_ZVAL(data); 
 
465
                array_init(data);
 
466
                zend_hash_update(Z_OBJPROP_P(return_value), "data", 5, (void *)&(data), sizeof(zval *), NULL);
 
467
        }
 
468
        /* get columncount and add to returnvalue as property */
 
469
        MAKE_STD_ZVAL(rv_column_count); 
 
470
        ZVAL_LONG(rv_column_count, 0);
 
471
        result = switch_dbx_getcolumncount(&rv_column_count, &rv_result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU, dbx_module);
 
472
        if (!result) { 
 
473
                php_error_docref(NULL TSRMLS_CC, E_ERROR, "get column_count failed...");
 
474
                FREE_ZVAL(rv_column_count);
 
475
                RETURN_LONG(0); 
 
476
        }
 
477
        zend_hash_update(Z_OBJPROP_P(return_value), "cols", 5, (void *)&(rv_column_count), sizeof(zval *), NULL);
 
478
        /* fill the info array with columnnames and types (indexed and assoc) */
 
479
        if (result_flags & DBX_RESULT_INFO) {
 
480
                zval *info_row_name;
 
481
                zval *info_row_type;
 
482
                MAKE_STD_ZVAL(info_row_name);
 
483
                MAKE_STD_ZVAL(info_row_type);
 
484
                array_init(info_row_name);
 
485
                array_init(info_row_type);
 
486
                for (col_index=0; col_index<Z_LVAL_P(rv_column_count); ++col_index) {
 
487
                        zval *rv_column_name;
 
488
                        zval *rv_column_type;
 
489
                        /* get name */
 
490
                        MAKE_STD_ZVAL(rv_column_name);
 
491
                        ZVAL_LONG(rv_column_name, 0);
 
492
                        result = switch_dbx_getcolumnname(&rv_column_name, &rv_result_handle, col_index, INTERNAL_FUNCTION_PARAM_PASSTHRU, dbx_module);
 
493
                        /* modify case if requested */
 
494
                        if (colcase==DBX_COLNAMES_UPPERCASE) {
 
495
                                php_strtoupper(Z_STRVAL_P(rv_column_name), Z_STRLEN_P(rv_column_name));
 
496
                                }
 
497
                        if (colcase==DBX_COLNAMES_LOWERCASE) {
 
498
                                php_strtolower(Z_STRVAL_P(rv_column_name), Z_STRLEN_P(rv_column_name));
 
499
                                }
 
500
                        if (result) { 
 
501
                                zend_hash_index_update(Z_ARRVAL_P(info_row_name), col_index, (void *)&(rv_column_name), sizeof(zval *), NULL);
 
502
                        } else {
 
503
                                FREE_ZVAL(rv_column_name);
 
504
                        }
 
505
                        /* get type */
 
506
                        MAKE_STD_ZVAL(rv_column_type);
 
507
                        ZVAL_LONG(rv_column_type, 0);
 
508
                        result = switch_dbx_getcolumntype(&rv_column_type, &rv_result_handle, col_index, INTERNAL_FUNCTION_PARAM_PASSTHRU, dbx_module);
 
509
                        if (result) { 
 
510
                                zend_hash_index_update(Z_ARRVAL_P(info_row_type), col_index, (void *)&(rv_column_type), sizeof(zval *), NULL);
 
511
                        } else {
 
512
                                FREE_ZVAL(rv_column_type);
 
513
                        }
 
514
                }
 
515
                zend_hash_update(Z_ARRVAL_P(info), "name", 5, (void *) &info_row_name, sizeof(zval *), (void **) &inforow_ptr);
 
516
                zend_hash_update(Z_ARRVAL_P(info), "type", 5, (void *) &info_row_type, sizeof(zval *), NULL);
 
517
        }
 
518
        /* fill each row array with fieldvalues (indexed (and assoc)) */
 
519
        if (!(result_flags & DBX_RESULT_UNBUFFERED)) {
 
520
                row_count=0;
 
521
                result=1;
 
522
                while (result) {
 
523
                        zval *rv_row;
 
524
                        MAKE_STD_ZVAL(rv_row);
 
525
                        ZVAL_LONG(rv_row, 0);
 
526
                        result = switch_dbx_getrow(&rv_row, &rv_result_handle, row_count, INTERNAL_FUNCTION_PARAM_PASSTHRU, dbx_module);
 
527
                        if (result) {
 
528
                                zend_hash_index_update(Z_ARRVAL_P(data), row_count, (void *)&(rv_row), sizeof(zval *), (void **) &row_ptr);
 
529
                                /* associate results with fieldnames */
 
530
                                if (result_flags & DBX_RESULT_ASSOC) {
 
531
                                        zval **columnname_ptr, **actual_ptr;
 
532
                                        for (col_index=0; col_index<Z_LVAL_P(rv_column_count); ++col_index) {
 
533
                                                zend_hash_index_find(Z_ARRVAL_PP(inforow_ptr), col_index, (void **) &columnname_ptr);
 
534
                                                zend_hash_index_find(Z_ARRVAL_PP(row_ptr), col_index, (void **) &actual_ptr);
 
535
                                                (*actual_ptr)->refcount+=1;
 
536
                                                (*actual_ptr)->is_ref=1;
 
537
                                                zend_hash_update(Z_ARRVAL_PP(row_ptr), Z_STRVAL_PP(columnname_ptr), Z_STRLEN_PP(columnname_ptr) + 1, actual_ptr, sizeof(zval *), NULL);
 
538
                                        }
 
539
                                }
 
540
                                ++row_count;
 
541
                        } else {
 
542
                                FREE_ZVAL(rv_row);
 
543
                        }
 
544
                }
 
545
                /* add row_count property */
 
546
                add_property_long(return_value, "rows", row_count);
 
547
        }
 
548
        else {
 
549
                add_property_long(return_value, "rows", 0);
 
550
        }
 
551
}
 
552
/* }}} */
 
553
 
 
554
/* {{{ proto dbx_row dbx_fetch_row(dbx_query_object dbx_q)
 
555
   Returns a row (index and assoc based on query) on success and returns 0 on failure or no more rows */
 
556
ZEND_FUNCTION(dbx_fetch_row)
 
557
{
 
558
        int number_of_arguments=1;
 
559
        zval **arguments[1];
 
560
 
 
561
        zval **dbx_result_link;
 
562
        zval **dbx_result_handle;
 
563
        zval **dbx_result_flags;
 
564
        zval **dbx_result_info;
 
565
        zval **dbx_result_cols;
 
566
        zval **dbx_result_rows;
 
567
 
 
568
        zval **dbx_handle;
 
569
        zval **dbx_module;
 
570
        zval **dbx_database;
 
571
 
 
572
        int result;
 
573
        long col_index;
 
574
        long col_count;
 
575
        long row_count;
 
576
        long result_flags;
 
577
        zval **inforow_ptr;
 
578
 
 
579
        if (ZEND_NUM_ARGS()!=number_of_arguments || zend_get_parameters_array_ex(ZEND_NUM_ARGS(), arguments) == FAILURE) {
 
580
                WRONG_PARAM_COUNT;
 
581
        }
 
582
        if (!split_dbx_result_object(arguments[0], &dbx_result_link, &dbx_result_handle, &dbx_result_flags, &dbx_result_info, &dbx_result_cols, &dbx_result_rows TSRMLS_CC)) {
 
583
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "not a valid dbx_result-object...");
 
584
                RETURN_LONG(0);
 
585
        }
 
586
        if (!split_dbx_handle_object(dbx_result_link, &dbx_handle, &dbx_module, &dbx_database TSRMLS_CC)) {
 
587
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "not a valid dbx_handle-object...");
 
588
                RETURN_LONG(0);
 
589
        }
 
590
 
 
591
        /* default values */
 
592
        result_flags = Z_LVAL_PP(dbx_result_flags);
 
593
        col_count = Z_LVAL_PP(dbx_result_cols);
 
594
        row_count = Z_LVAL_PP(dbx_result_rows);
 
595
 
 
596
        /* find fieldnames (for assoc) */
 
597
        if (result_flags & DBX_RESULT_ASSOC) {
 
598
                zend_hash_find(Z_ARRVAL_PP(dbx_result_info), "name", 5, (void **) &inforow_ptr);
 
599
        }
 
600
 
 
601
        result = switch_dbx_getrow(&return_value, dbx_result_handle, row_count, INTERNAL_FUNCTION_PARAM_PASSTHRU, dbx_module);
 
602
        if (result) {
 
603
                /* associate results with fieldnames */
 
604
                if (result_flags & DBX_RESULT_ASSOC) {
 
605
                        zval **columnname_ptr, **actual_ptr;
 
606
                        for (col_index=0; col_index<col_count; ++col_index) {
 
607
                                zend_hash_index_find(Z_ARRVAL_PP(inforow_ptr), col_index, (void **) &columnname_ptr);
 
608
                                zend_hash_index_find(Z_ARRVAL_P(return_value), col_index, (void **) &actual_ptr);
 
609
                                (*actual_ptr)->refcount+=1;
 
610
                                (*actual_ptr)->is_ref=1;
 
611
                                zend_hash_update(Z_ARRVAL_P(return_value), Z_STRVAL_PP(columnname_ptr), Z_STRLEN_PP(columnname_ptr) + 1, actual_ptr, sizeof(zval *), NULL);
 
612
                        }
 
613
                }
 
614
        ++row_count;
 
615
        add_property_long(*arguments[0], "rows", row_count);
 
616
        }
 
617
}
 
618
/* }}} */
 
619
 
 
620
 
 
621
/* {{{ proto string dbx_error(dbx_link_object dbx_link)
 
622
   Returns success or failure 
 
623
*/
 
624
ZEND_FUNCTION(dbx_error)
 
625
{
 
626
        int number_of_arguments=1;
 
627
        zval **arguments[1];
 
628
 
 
629
        int result;
 
630
        zval **dbx_handle;
 
631
        zval **dbx_module;
 
632
        zval **dbx_database;
 
633
        zval *rv_errormsg;
 
634
 
 
635
        if (ZEND_NUM_ARGS() !=number_of_arguments || zend_get_parameters_array_ex(number_of_arguments, arguments) == FAILURE) {
 
636
                WRONG_PARAM_COUNT;
 
637
        }
 
638
        if (!split_dbx_handle_object(arguments[0], &dbx_handle, &dbx_module, &dbx_database TSRMLS_CC)) {
 
639
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "not a valid dbx_handle-object...");
 
640
                RETURN_LONG(0);
 
641
        }
 
642
 
 
643
        MAKE_STD_ZVAL(rv_errormsg); 
 
644
        ZVAL_LONG(rv_errormsg, 0);
 
645
        result = switch_dbx_error(&rv_errormsg, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU, dbx_module);
 
646
        if (!result) {
 
647
                FREE_ZVAL(rv_errormsg);
 
648
                RETURN_STRING("", 1); 
 
649
        }
 
650
        MOVE_RETURNED_TO_RV(&return_value, rv_errormsg);
 
651
}
 
652
/* }}} */
 
653
 
 
654
/* {{{ proto string dbx_escape_string(dbx_link_object dbx_link, string sz)
 
655
   Returns escaped string or NULL on error
 
656
*/
 
657
ZEND_FUNCTION(dbx_escape_string)
 
658
{
 
659
        int number_of_arguments=2;
 
660
        zval **arguments[2];
 
661
 
 
662
        int result;
 
663
        zval **dbx_handle;
 
664
        zval **dbx_module;
 
665
        zval **dbx_database;
 
666
        zval *rv;
 
667
 
 
668
        if (ZEND_NUM_ARGS() !=number_of_arguments || zend_get_parameters_array_ex(number_of_arguments, arguments) == FAILURE) {
 
669
                WRONG_PARAM_COUNT;
 
670
        }
 
671
        if (!split_dbx_handle_object(arguments[0], &dbx_handle, &dbx_module, &dbx_database TSRMLS_CC)) {
 
672
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "not a valid dbx_handle-object...");
 
673
                RETURN_NULL();
 
674
        }
 
675
        convert_to_string_ex(arguments[1]);
 
676
 
 
677
        MAKE_STD_ZVAL(rv); 
 
678
        ZVAL_LONG(rv, 0);
 
679
        result = switch_dbx_esc(&rv, dbx_handle, arguments[1], INTERNAL_FUNCTION_PARAM_PASSTHRU, dbx_module);
 
680
        if (!result) { /* this will probably never happen */
 
681
                FREE_ZVAL(rv);
 
682
                RETURN_NULL();
 
683
        }
 
684
        MOVE_RETURNED_TO_RV(&return_value, rv);
 
685
}
 
686
/* }}} */
 
687
 
 
688
/*
 
689
 *      dbx functions that are database independent... like sorting result_objects!
 
690
 */
 
691
 
 
692
/* {{{ proto int dbx_compare(array row_x, array row_y, string columnname [, int flags])
 
693
   Returns row_y[columnname] - row_x[columnname], converted to -1, 0 or 1 */
 
694
ZEND_FUNCTION(dbx_compare)
 
695
{
 
696
        int min_number_of_arguments=3;
 
697
        int max_number_of_arguments=4;
 
698
        int number_of_arguments=-1;
 
699
        long comparison_direction=DBX_CMP_ASC;
 
700
        long comparison_type=DBX_CMP_NATIVE;
 
701
        double dtemp;
 
702
        long ltemp;
 
703
        zval **arguments[4];
 
704
        zval **zv_a;
 
705
        zval **zv_b;
 
706
        int result=0;
 
707
        number_of_arguments=ZEND_NUM_ARGS();
 
708
        if (number_of_arguments<min_number_of_arguments || number_of_arguments>max_number_of_arguments || zend_get_parameters_array_ex(number_of_arguments, arguments) == FAILURE) {
 
709
                WRONG_PARAM_COUNT;
 
710
        }
 
711
 
 
712
        if (Z_TYPE_PP(arguments[0]) != IS_ARRAY
 
713
        || Z_TYPE_PP(arguments[1]) != IS_ARRAY) {
 
714
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Wrong argument type for compare");
 
715
                RETURN_LONG(0);
 
716
        }
 
717
        convert_to_string_ex(arguments[2]); /* field name */
 
718
        comparison_type = DBX_CMP_NATIVE;
 
719
        comparison_direction = DBX_CMP_ASC;
 
720
        if (number_of_arguments>3) {
 
721
                convert_to_long_ex(arguments[3]); /* comparison type and direction*/
 
722
                /* direction */
 
723
                if (Z_LVAL_PP(arguments[3]) & DBX_CMP_DESC) {
 
724
                        comparison_direction=DBX_CMP_DESC;
 
725
                }
 
726
                if (Z_LVAL_PP(arguments[3]) & DBX_CMP_ASC) {
 
727
                        comparison_direction=DBX_CMP_ASC;
 
728
                }
 
729
                /* type */
 
730
                if (Z_LVAL_PP(arguments[3]) & DBX_CMP_NUMBER) {
 
731
                        comparison_type=DBX_CMP_NUMBER;
 
732
                }
 
733
                if (Z_LVAL_PP(arguments[3]) & DBX_CMP_TEXT) {
 
734
                        comparison_type=DBX_CMP_TEXT;
 
735
                }
 
736
                if (Z_LVAL_PP(arguments[3]) & DBX_CMP_NATIVE) {
 
737
                        comparison_type=DBX_CMP_NATIVE;
 
738
                }
 
739
        }
 
740
 
 
741
        if (zend_hash_find(Z_ARRVAL_PP(arguments[0]), Z_STRVAL_PP(arguments[2]), Z_STRLEN_PP(arguments[2])+1, (void **) &zv_a)==FAILURE
 
742
        || zend_hash_find(Z_ARRVAL_PP(arguments[1]), Z_STRVAL_PP(arguments[2]), Z_STRLEN_PP(arguments[2])+1, (void **) &zv_b)==FAILURE)  {
 
743
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Field '%s' not available in result-object", Z_STRVAL_PP(arguments[2]));
 
744
                RETURN_LONG(0);
 
745
        }
 
746
 
 
747
        switch (comparison_type) {
 
748
                case DBX_CMP_TEXT:
 
749
                        convert_to_string_ex(zv_a);
 
750
                        convert_to_string_ex(zv_b);
 
751
                        break;
 
752
                case DBX_CMP_NUMBER:
 
753
                        convert_to_double_ex(zv_a);
 
754
                        convert_to_double_ex(zv_b);
 
755
                        break;
 
756
        }
 
757
        switch (Z_TYPE_PP(zv_a)) {
 
758
                case IS_NULL:
 
759
                        result=0;
 
760
                        break;
 
761
                case IS_BOOL:
 
762
                case IS_LONG:
 
763
                case IS_CONSTANT:
 
764
                        ltemp = Z_LVAL_PP(zv_a) - Z_LVAL_PP(zv_b);
 
765
                        result = (ltemp==0?0: (ltemp>0?1:-1));
 
766
                        break;
 
767
                case IS_DOUBLE:
 
768
                        dtemp = (Z_DVAL_PP(zv_a) - Z_DVAL_PP(zv_b));
 
769
                        result = (dtemp==0?0: (dtemp>0?1:-1));
 
770
                        break;
 
771
                case IS_STRING:
 
772
                        ltemp = strcmp(Z_STRVAL_PP(zv_a), Z_STRVAL_PP(zv_b));
 
773
                        result = (ltemp==0?0: (ltemp>0?1:-1));
 
774
                        break;
 
775
                default: result=0;
 
776
        }
 
777
 
 
778
        if (comparison_direction==DBX_CMP_DESC) RETURN_LONG(-result);
 
779
        RETURN_LONG(result);
 
780
}
 
781
/* }}} */
 
782
 
 
783
/* {{{ proto int dbx_sort(object dbx_result, string compare_function_name)
 
784
   Returns 0 on failure, 1 on success */
 
785
ZEND_FUNCTION(dbx_sort)
 
786
{
 
787
        int number_of_arguments=2;
 
788
        zval **arguments[2];
 
789
        zval **zval_data;
 
790
        zval *returned_zval;
 
791
        if (ZEND_NUM_ARGS() !=number_of_arguments || zend_get_parameters_array_ex(number_of_arguments, arguments) == FAILURE) {
 
792
                WRONG_PARAM_COUNT;
 
793
        }
 
794
 
 
795
        if (Z_TYPE_PP(arguments[0]) != IS_OBJECT
 
796
        || Z_TYPE_PP(arguments[1]) != IS_STRING) {
 
797
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Wrong argument type for sort");
 
798
                RETURN_LONG(0);
 
799
        }
 
800
 
 
801
        if (zend_hash_find(Z_OBJPROP_PP(arguments[0]), "data", 5, (void **) &zval_data)==FAILURE
 
802
        || Z_TYPE_PP(zval_data) != IS_ARRAY) {
 
803
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Wrong argument type for sort");
 
804
                RETURN_LONG(0);
 
805
        }
 
806
 
 
807
        arguments[0] = zval_data;
 
808
        dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "usort", &returned_zval, number_of_arguments, arguments);
 
809
        zval_ptr_dtor(&returned_zval);
 
810
        
 
811
        RETURN_LONG(1);
 
812
}
 
813
/* }}} */
 
814
 
 
815
/***********************************/
 
816
 
 
817
/*
 
818
 * switch_dbx functions
 
819
 */
 
820
int switch_dbx_connect(zval **rv, zval **host, zval **db, zval **username, zval **password, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module)
 
821
{
 
822
        /* returns connection handle as resource on success or 0 as long on failure */
 
823
        switch (Z_LVAL_PP(dbx_module)) {
 
824
                case DBX_MYSQL: return dbx_mysql_connect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
825
                case DBX_ODBC:  return dbx_odbc_connect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
826
                case DBX_PGSQL: return dbx_pgsql_connect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
827
                case DBX_MSSQL: return dbx_mssql_connect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
828
                case DBX_FBSQL: return dbx_fbsql_connect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
829
                case DBX_OCI8:  return dbx_oci8_connect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
830
                case DBX_SYBASECT: return dbx_sybasect_connect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
831
                case DBX_SQLITE: return dbx_sqlite_connect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
832
        }
 
833
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "not supported in this module");
 
834
        return 0;
 
835
}
 
836
 
 
837
int switch_dbx_pconnect(zval **rv, zval **host, zval **db, zval **username, zval **password, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module)
 
838
{
 
839
        /* returns persistent connection handle as resource on success or 0 as long on failure */
 
840
        switch (Z_LVAL_PP(dbx_module)) {
 
841
                case DBX_MYSQL: return dbx_mysql_pconnect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
842
                case DBX_ODBC:  return dbx_odbc_pconnect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
843
                case DBX_PGSQL: return dbx_pgsql_pconnect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
844
                case DBX_MSSQL: return dbx_mssql_pconnect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
845
                case DBX_FBSQL: return dbx_fbsql_pconnect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
846
                case DBX_OCI8:  return dbx_oci8_pconnect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
847
                case DBX_SYBASECT: return dbx_sybasect_pconnect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
848
                case DBX_SQLITE: return dbx_sqlite_pconnect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
849
        }
 
850
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "not supported in this module");
 
851
        return 0;
 
852
}
 
853
 
 
854
int switch_dbx_close(zval **rv, zval **dbx_handle, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module)
 
855
{
 
856
        /* returns 1 as long on success or 0 as long on failure */
 
857
        switch (Z_LVAL_PP(dbx_module)) {
 
858
                case DBX_MYSQL: return dbx_mysql_close(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
859
                case DBX_ODBC:  return dbx_odbc_close(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
860
                case DBX_PGSQL: return dbx_pgsql_close(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
861
                case DBX_MSSQL: return dbx_mssql_close(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
862
                case DBX_FBSQL: return dbx_fbsql_close(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
863
                case DBX_OCI8:  return dbx_oci8_close(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
864
                case DBX_SYBASECT: return dbx_sybasect_close(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
865
                case DBX_SQLITE: return dbx_sqlite_close(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
866
        }
 
867
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "not supported in this module");
 
868
        return 0;
 
869
}
 
870
 
 
871
int switch_dbx_query(zval **rv, zval **dbx_handle, zval **db_name, zval **sql_statement, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module)
 
872
{
 
873
        /* returns 1 as long or result identifier as resource on success or 0 as long on failure */
 
874
        switch (Z_LVAL_PP(dbx_module)) {
 
875
                case DBX_MYSQL: return dbx_mysql_query(rv, dbx_handle, db_name, sql_statement, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
876
                case DBX_ODBC:  return dbx_odbc_query(rv, dbx_handle, db_name, sql_statement, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
877
                case DBX_PGSQL: return dbx_pgsql_query(rv, dbx_handle, db_name, sql_statement, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
878
                case DBX_MSSQL: return dbx_mssql_query(rv, dbx_handle, db_name, sql_statement, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
879
                case DBX_FBSQL: return dbx_fbsql_query(rv, dbx_handle, db_name, sql_statement, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
880
                case DBX_OCI8:  return dbx_oci8_query(rv, dbx_handle, db_name, sql_statement, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
881
                case DBX_SYBASECT: return dbx_sybasect_query(rv, dbx_handle, db_name, sql_statement, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
882
                case DBX_SQLITE: return dbx_sqlite_query(rv, dbx_handle, db_name, sql_statement, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
883
        }
 
884
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "not supported in this module");
 
885
        return 0;
 
886
}
 
887
 
 
888
int switch_dbx_getcolumncount(zval **rv, zval **result_handle, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module)
 
889
{
 
890
        /* returns column-count as long on success or 0 as long on failure */
 
891
        switch (Z_LVAL_PP(dbx_module)) {
 
892
                case DBX_MYSQL: return dbx_mysql_getcolumncount(rv, result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
893
                case DBX_ODBC:  return dbx_odbc_getcolumncount(rv, result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
894
                case DBX_PGSQL: return dbx_pgsql_getcolumncount(rv, result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
895
                case DBX_MSSQL: return dbx_mssql_getcolumncount(rv, result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
896
                case DBX_FBSQL: return dbx_fbsql_getcolumncount(rv, result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
897
                case DBX_OCI8:  return dbx_oci8_getcolumncount(rv, result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
898
                case DBX_SYBASECT: return dbx_sybasect_getcolumncount(rv, result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
899
                case DBX_SQLITE: return dbx_sqlite_getcolumncount(rv, result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
900
        }
 
901
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "not supported in this module");
 
902
        return 0;
 
903
}
 
904
 
 
905
int switch_dbx_getcolumnname(zval **rv, zval **result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module)
 
906
{
 
907
        /* returns column-name as string on success or 0 as long on failure */
 
908
        switch (Z_LVAL_PP(dbx_module)) {
 
909
                case DBX_MYSQL: return dbx_mysql_getcolumnname(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
910
                case DBX_ODBC:  return dbx_odbc_getcolumnname(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
911
                case DBX_PGSQL: return dbx_pgsql_getcolumnname(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
912
                case DBX_MSSQL: return dbx_mssql_getcolumnname(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
913
                case DBX_FBSQL: return dbx_fbsql_getcolumnname(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
914
                case DBX_OCI8:  return dbx_oci8_getcolumnname(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
915
                case DBX_SYBASECT: return dbx_sybasect_getcolumnname(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
916
                case DBX_SQLITE: return dbx_sqlite_getcolumnname(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
917
        }
 
918
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "not supported in this module");
 
919
        return 0;
 
920
}
 
921
 
 
922
int switch_dbx_getcolumntype(zval **rv, zval **result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module)
 
923
{
 
924
        /* returns column-type as string on success or 0 as long on failure */
 
925
        switch (Z_LVAL_PP(dbx_module)) {
 
926
                case DBX_MYSQL: return dbx_mysql_getcolumntype(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
927
                case DBX_ODBC:  return dbx_odbc_getcolumntype(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
928
                case DBX_PGSQL: return dbx_pgsql_getcolumntype(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
929
                case DBX_MSSQL: return dbx_mssql_getcolumntype(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
930
                case DBX_FBSQL: return dbx_fbsql_getcolumntype(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
931
                case DBX_OCI8:  return dbx_oci8_getcolumntype(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
932
                case DBX_SYBASECT: return dbx_sybasect_getcolumntype(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
933
                case DBX_SQLITE: return dbx_sqlite_getcolumntype(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
934
        }
 
935
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "not supported in this module");
 
936
        return 0;
 
937
}
 
938
 
 
939
int switch_dbx_getrow(zval **rv, zval **result_handle, long row_number, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module)
 
940
{
 
941
        /* returns array[0..columncount-1] as strings on success or 0 as long on failure */
 
942
        switch (Z_LVAL_PP(dbx_module)) {
 
943
                case DBX_MYSQL: return dbx_mysql_getrow(rv, result_handle, row_number, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
944
                case DBX_ODBC:  return dbx_odbc_getrow(rv, result_handle, row_number, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
945
                case DBX_PGSQL: return dbx_pgsql_getrow(rv, result_handle, row_number, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
946
                case DBX_MSSQL: return dbx_mssql_getrow(rv, result_handle, row_number, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
947
                case DBX_FBSQL: return dbx_fbsql_getrow(rv, result_handle, row_number, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
948
                case DBX_OCI8:  return dbx_oci8_getrow(rv, result_handle, row_number, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
949
                case DBX_SYBASECT: return dbx_sybasect_getrow(rv, result_handle, row_number, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
950
                case DBX_SQLITE: return dbx_sqlite_getrow(rv, result_handle, row_number, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
951
        }
 
952
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "not supported in this module");
 
953
        return 0;
 
954
}
 
955
 
 
956
int switch_dbx_error(zval **rv, zval **dbx_handle, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module)
 
957
{
 
958
        /* returns string */
 
959
        switch (Z_LVAL_PP(dbx_module)) {
 
960
                case DBX_MYSQL: return dbx_mysql_error(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
961
                case DBX_ODBC:  return dbx_odbc_error(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
962
                case DBX_PGSQL: return dbx_pgsql_error(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
963
                case DBX_MSSQL: return dbx_mssql_error(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
964
                case DBX_FBSQL: return dbx_fbsql_error(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
965
                /* case DBX_OCI8:  return dbx_oci8_error(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU); */
 
966
                case DBX_SYBASECT: return dbx_sybasect_error(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
967
                case DBX_SQLITE: return dbx_sqlite_error(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
968
        }
 
969
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "not supported in this module");
 
970
        return 0;
 
971
}
 
972
 
 
973
int switch_dbx_esc(zval **rv, zval **dbx_handle, zval **string, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module)
 
974
{
 
975
        /* returns escaped string */
 
976
        switch (Z_LVAL_PP(dbx_module)) {
 
977
                case DBX_MYSQL: return dbx_mysql_esc(rv, dbx_handle, string, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
978
                case DBX_ODBC:  return dbx_odbc_esc(rv, dbx_handle, string, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
979
                case DBX_PGSQL: return dbx_pgsql_esc(rv, dbx_handle, string, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
980
                case DBX_MSSQL: return dbx_mssql_esc(rv, dbx_handle, string, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
981
                case DBX_FBSQL: return dbx_fbsql_esc(rv, dbx_handle, string, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
982
                case DBX_OCI8:  return dbx_oci8_esc(rv, dbx_handle, string, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
983
                case DBX_SYBASECT: return dbx_sybasect_esc(rv, dbx_handle, string, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
984
                case DBX_SQLITE: return dbx_sqlite_esc(rv, dbx_handle, string, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
985
        }
 
986
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "not supported in this module");
 
987
        return 0;
 
988
}
 
989
 
 
990
/*
 
991
 * Local variables:
 
992
 * tab-width: 4
 
993
 * c-basic-offset: 4
 
994
 * End:
 
995
 */