http://cvs.php.net/diff.php/php-src/ext/sqlite/sqlite.c?r1=1.166.2.7&r2=1.166.2.8&ty=u
Index: php-src/ext/sqlite/sqlite.c
diff -u php-src/ext/sqlite/sqlite.c:1.166.2.7
php-src/ext/sqlite/sqlite.c:1.166.2.8
--- php-src/ext/sqlite/sqlite.c:1.166.2.7 Fri Nov 25 11:01:41 2005
+++ php-src/ext/sqlite/sqlite.c Mon Dec 5 15:40:54 2005
@@ -17,7 +17,7 @@
| Marcus Boerger <[EMAIL PROTECTED]> |
+----------------------------------------------------------------------+
- $Id: sqlite.c,v 1.166.2.7 2005/11/25 16:01:41 sniper Exp $
+ $Id: sqlite.c,v 1.166.2.8 2005/12/05 20:40:54 bfrance Exp $
*/
#ifdef HAVE_CONFIG_H
@@ -29,7 +29,9 @@
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
+#if HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION)
#include "ext/session/php_session.h"
+#endif
#include "php_sqlite.h"
#if HAVE_TIME_H
@@ -346,11 +348,11 @@
{
if (rsrc->ptr) {
struct php_sqlite_db *db = (struct php_sqlite_db*)rsrc->ptr;
-
+
sqlite_close(db->db);
zend_hash_destroy(&db->callbacks);
-
+
pefree(db, db->is_persistent);
rsrc->ptr = NULL;
@@ -413,7 +415,7 @@
/* don't leave pending commits hanging around */
sqlite_exec(db->db, "ROLLBACK", NULL, NULL, NULL);
-
+
return 0;
}
@@ -438,7 +440,7 @@
sqlite_set_result_error(func, "not enough parameters", -1);
return;
}
-
+
ZVAL_STRING(&funcname, (char*)argv[0], 1);
if (!zend_make_callable(&funcname, &callable TSRMLS_CC)) {
@@ -449,10 +451,10 @@
zval_dtor(&funcname);
return;
}
-
+
if (argc > 1) {
zargs = (zval ***)safe_emalloc((argc - 1), sizeof(zval **), 0);
-
+
for (i = 0; i < argc-1; i++) {
zargs[i] = emalloc(sizeof(zval *));
MAKE_STD_ZVAL(*zargs[i]);
@@ -529,7 +531,7 @@
if (argc > 0) {
zargs = (zval ***)safe_emalloc(argc, sizeof(zval **), 0);
-
+
for (i = 0; i < argc; i++) {
zargs[i] = emalloc(sizeof(zval *));
MAKE_STD_ZVAL(*zargs[i]);
@@ -608,10 +610,10 @@
if (argc < 1) {
return;
}
-
+
zargc = argc + 1;
zargs = (zval ***)safe_emalloc(zargc, sizeof(zval **), 0);
-
+
/* first arg is always the context zval */
context_p = (zval **)sqlite_aggregate_context(func, sizeof(*context_p));
@@ -673,9 +675,9 @@
sqlite_set_result_error(func, "this function has not been
correctly defined for this request", -1);
return;
}
-
+
context_p = (zval **)sqlite_aggregate_context(func, sizeof(*context_p));
-
+
res = call_user_function_ex(EG(function_table),
NULL,
funcs->fini,
@@ -837,7 +839,7 @@
static zend_object_value sqlite_object_new_db(zend_class_entry *class_type
TSRMLS_DC)
{
zend_object_value retval;
-
+
sqlite_object_new(class_type, &sqlite_object_handlers_db, &retval
TSRMLS_CC);
return retval;
}
@@ -845,7 +847,7 @@
static zend_object_value sqlite_object_new_query(zend_class_entry *class_type
TSRMLS_DC)
{
zend_object_value retval;
-
+
sqlite_object_new(class_type, &sqlite_object_handlers_query, &retval
TSRMLS_CC);
return retval;
}
@@ -853,7 +855,7 @@
static zend_object_value sqlite_object_new_ub_query(zend_class_entry
*class_type TSRMLS_DC)
{
zend_object_value retval;
-
+
sqlite_object_new(class_type, &sqlite_object_handlers_ub_query, &retval
TSRMLS_CC);
return retval;
}
@@ -861,7 +863,7 @@
static zend_object_value sqlite_object_new_exception(zend_class_entry
*class_type TSRMLS_DC)
{
zend_object_value retval;
-
+
sqlite_object_new(class_type, &sqlite_object_handlers_exception,
&retval TSRMLS_CC);
return retval;
}
@@ -947,7 +949,7 @@
MAKE_STD_ZVAL(**data);
php_sqlite_fetch_array(res, res->mode, 1, 0, **data TSRMLS_CC);
}
-
+
}
int sqlite_iterator_get_current_key(zend_object_iterator *iter, char
**str_key, uint *str_key_len, ulong *int_key TSRMLS_DC)
@@ -976,7 +978,7 @@
/* php_error_docref(NULL TSRMLS_CC, E_WARNING, "no more rows
available"); */
return;
}
-
+
res->curr_row++;
}
}
@@ -1029,7 +1031,7 @@
REGISTER_SQLITE_CLASS(Exception, exception, spl_ce_RuntimeException);
#else
REGISTER_SQLITE_CLASS(Exception, exception,
zend_exception_get_default());
-#endif
+#endif
sqlite_ce_db->ce_flags &= ~ZEND_ACC_FINAL_CLASS;
sqlite_ce_db->constructor->common.fn_flags |= ZEND_ACC_FINAL;
@@ -1044,7 +1046,7 @@
#if defined(HAVE_SPL) && ((PHP_MAJOR_VERSION > 5) || (PHP_MAJOR_VERSION == 5 &&
PHP_MINOR_VERSION >= 1))
zend_class_implements(sqlite_ce_query TSRMLS_CC, 2, zend_ce_iterator,
spl_ce_Countable);
#else
- zend_class_implements(sqlite_ce_query TSRMLS_CC, 1, zend_ce_iterator);
+ zend_class_implements(sqlite_ce_query TSRMLS_CC, 1, zend_ce_iterator);
#endif
sqlite_ce_query->get_iterator = sqlite_get_iterator;
sqlite_ce_query->iterator_funcs.funcs = &sqlite_query_iterator_funcs;
@@ -1056,7 +1058,7 @@
#if HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION)
php_session_register_module(ps_sqlite_ptr);
#endif
-
+
le_sqlite_db =
zend_register_list_destructors_ex(php_sqlite_db_dtor, NULL, "sqlite database",
module_number);
le_sqlite_pdb = zend_register_list_destructors_ex(NULL,
php_sqlite_db_dtor, "sqlite database (persistent)", module_number);
le_sqlite_result =
zend_register_list_destructors_ex(php_sqlite_result_dtor, NULL, "sqlite
result", module_number);
@@ -1064,7 +1066,7 @@
REGISTER_LONG_CONSTANT("SQLITE_BOTH", PHPSQLITE_BOTH,
CONST_CS|CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SQLITE_NUM", PHPSQLITE_NUM,
CONST_CS|CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SQLITE_ASSOC", PHPSQLITE_ASSOC,
CONST_CS|CONST_PERSISTENT);
-
+
REGISTER_LONG_CONSTANT("SQLITE_OK",
SQLITE_OK, CONST_CS|CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SQLITE_ERROR",
SQLITE_ERROR, CONST_CS|CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SQLITE_INTERNAL",
SQLITE_INTERNAL, CONST_CS|CONST_PERSISTENT);
@@ -1098,7 +1100,7 @@
#ifdef PHP_SQLITE2_HAVE_PDO
if (FAILURE == php_pdo_register_driver(&pdo_sqlite2_driver)) {
- return FAILURE;
+ return FAILURE;
}
#endif
@@ -1125,7 +1127,7 @@
{
php_info_print_table_start();
php_info_print_table_header(2, "SQLite support", "enabled");
- php_info_print_table_row(2, "PECL Module version",
PHP_SQLITE_MODULE_VERSION " $Id: sqlite.c,v 1.166.2.7 2005/11/25 16:01:41 sniper Exp
$");
+ php_info_print_table_row(2, "PECL Module version",
PHP_SQLITE_MODULE_VERSION " $Id: sqlite.c,v 1.166.2.8 2005/12/05 20:40:54 bfrance
Exp $");
php_info_print_table_row(2, "SQLite Library", sqlite_libversion());
php_info_print_table_row(2, "SQLite Encoding", sqlite_libencoding());
php_info_print_table_end();
@@ -1166,7 +1168,7 @@
db->db = sdb;
zend_hash_init(&db->callbacks, 0, NULL, php_sqlite_callback_dtor,
db->is_persistent);
-
+
/* register the PHP functions */
sqlite_create_function(sdb, "php", -1,
php_sqlite_generic_function_callback, 0);
@@ -1180,7 +1182,7 @@
if (PG(safe_mode) || (PG(open_basedir) && *PG(open_basedir))) {
sqlite_set_authorizer(sdb, php_sqlite_authorizer, NULL);
}
-
+
db->rsrc_id = ZEND_REGISTER_RESOURCE(object ? NULL :
return_value, db, persistent_id ? le_sqlite_pdb : le_sqlite_db);
if (object) {
/* if object is not an object then we're called from the
factory() function */
@@ -1203,7 +1205,7 @@
php_error_docref(NULL TSRMLS_CC, E_WARNING,
"Failed to register persistent resource");
}
}
-
+
return db;
}
@@ -1217,7 +1219,7 @@
zval *errmsg = NULL;
struct php_sqlite_db *db = NULL;
list_entry *le;
-
+
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lz/",
&filename, &filename_len, &mode, &errmsg)) {
return;
@@ -1230,7 +1232,7 @@
if (strncmp(filename, ":memory:", sizeof(":memory:") - 1)) {
/* resolve the fully-qualified path name to use as the hash key
*/
fullpath = expand_filepath(filename, NULL TSRMLS_CC);
-
+
if (PG(safe_mode) && (!php_checkuid(fullpath, NULL,
CHECKUID_CHECK_FILE_AND_DIR))) {
RETURN_FALSE;
}
@@ -1243,12 +1245,12 @@
}
hashkeylen = spprintf(&hashkey, 0, "sqlite_pdb_%s:%ld", fullpath, mode);
-
+
/* do we have an existing persistent connection ? */
if (SUCCESS == zend_hash_find(&EG(persistent_list), hashkey, hashkeylen+1,
(void*)&le)) {
if (Z_TYPE_P(le) == le_sqlite_pdb) {
db = (struct php_sqlite_db*)le->ptr;
-
+
if (db->rsrc_id == FAILURE) {
/* give it a valid resource id for this request
*/
db->rsrc_id =
ZEND_REGISTER_RESOURCE(return_value, db, le_sqlite_pdb);
@@ -1306,7 +1308,7 @@
if (strncmp(filename, ":memory:", sizeof(":memory:") - 1)) {
/* resolve the fully-qualified path name to use as the hash key
*/
fullpath = expand_filepath(filename, NULL TSRMLS_CC);
-
+
if (PG(safe_mode) && (!php_checkuid(fullpath, NULL,
CHECKUID_CHECK_FILE_AND_DIR))) {
php_std_error_handling();
efree(fullpath);
@@ -1361,13 +1363,13 @@
if (strncmp(filename, ":memory:", sizeof(":memory:") - 1)) {
/* resolve the fully-qualified path name to use as the hash key
*/
fullpath = expand_filepath(filename, NULL TSRMLS_CC);
-
+
if (PG(safe_mode) && (!php_checkuid(fullpath, NULL,
CHECKUID_CHECK_FILE_AND_DIR))) {
efree(fullpath);
php_std_error_handling();
RETURN_NULL();
}
-
+
if (php_check_open_basedir(fullpath TSRMLS_CC)) {
efree(fullpath);
php_std_error_handling();
@@ -1556,7 +1558,7 @@
memcpy(*prres, &res, sizeof(**prres));
(*prres)->db = db;
zend_list_addref(db->rsrc_id);
-
+
/* now the result set is ready for stepping: get first row */
if (php_sqlite_fetch((*prres) TSRMLS_CC) != SQLITE_OK) {
@@ -1565,10 +1567,10 @@
if (return_value) {
RETURN_FALSE;
} else {
- return;
+ return;
}
}
-
+
(*prres)->curr_row = 0;
if (object) {
@@ -1607,7 +1609,7 @@
DB_FROM_OBJECT(db, object);
} else {
if (FAILURE ==
zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
- ZEND_NUM_ARGS() TSRMLS_CC, "sr|lz/",
&sql, &sql_len, &zdb, &mode, &errmsg) &&
+ ZEND_NUM_ARGS() TSRMLS_CC, "sr|lz/",
&sql, &sql_len, &zdb, &mode, &errmsg) &&
FAILURE == zend_parse_parameters(ZEND_NUM_ARGS()
TSRMLS_CC, "rs|lz/", &zdb, &sql, &sql_len, &mode, &errmsg)) {
return;
}
@@ -1661,7 +1663,7 @@
DB_FROM_OBJECT(db, object);
} else {
if (FAILURE ==
zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
- ZEND_NUM_ARGS() TSRMLS_CC, "sr|l", &tbl, &tbl_len, &zdb,
&result_type) &&
+ ZEND_NUM_ARGS() TSRMLS_CC, "sr|l", &tbl, &tbl_len, &zdb,
&result_type) &&
FAILURE == zend_parse_parameters(ZEND_NUM_ARGS()
TSRMLS_CC, "rs|l", &zdb, &tbl, &tbl_len, &result_type)) {
return;
}
@@ -1732,7 +1734,7 @@
DB_FROM_OBJECT(db, object);
} else {
if (FAILURE ==
zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
- ZEND_NUM_ARGS() TSRMLS_CC, "sr|lz/",
&sql, &sql_len, &zdb, &mode, &errmsg) &&
+ ZEND_NUM_ARGS() TSRMLS_CC, "sr|lz/",
&sql, &sql_len, &zdb, &mode, &errmsg) &&
FAILURE == zend_parse_parameters(ZEND_NUM_ARGS()
TSRMLS_CC, "rs|lz/", &zdb, &sql, &sql_len, &mode, &errmsg)) {
return;
}
@@ -1783,7 +1785,7 @@
DB_FROM_OBJECT(db, object);
} else {
if(FAILURE ==
zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
- ZEND_NUM_ARGS() TSRMLS_CC, "sr", &sql, &sql_len, &zdb)
&&
+ ZEND_NUM_ARGS() TSRMLS_CC, "sr", &sql, &sql_len, &zdb)
&&
FAILURE == zend_parse_parameters(ZEND_NUM_ARGS()
TSRMLS_CC, "rs|z/", &zdb, &sql, &sql_len, &errmsg)) {
return;
}
@@ -1924,12 +1926,12 @@
if (!res->buffered) {
efree((char*)rowdata[j]);
rowdata[j] = NULL;
- }
+ }
} else {
RETVAL_STRING((char*)rowdata[j], res->buffered);
if (!res->buffered) {
rowdata[j] = NULL;
- }
+ }
}
}
/* }}} */
@@ -2027,7 +2029,7 @@
zval dataset;
zend_fcall_info fci;
zend_fcall_info_cache fcc;
- zval *retval_ptr;
+ zval *retval_ptr;
zval *ctor_params = NULL;
php_set_error_handling(object ? EH_THROW : EH_NORMAL,
sqlite_ce_exception TSRMLS_CC);
@@ -2095,7 +2097,7 @@
} else {
/* Two problems why we throw exceptions here:
PHP is typeless
* and hence passing one argument that's not an
array could be
- * by mistake and the other way round is
possible, too. The
+ * by mistake and the other way round is
possible, too. The
* single value is an array. Also we'd have to
make that one
* argument passed by reference.
*/
@@ -2150,7 +2152,7 @@
DB_FROM_OBJECT(db, object);
} else {
if (FAILURE ==
zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
- ZEND_NUM_ARGS() TSRMLS_CC, "sr|lb", &sql,
&sql_len, &zdb, &mode, &decode_binary) &&
+ ZEND_NUM_ARGS() TSRMLS_CC, "sr|lb", &sql,
&sql_len, &zdb, &mode, &decode_binary) &&
FAILURE == zend_parse_parameters(ZEND_NUM_ARGS()
TSRMLS_CC, "rs|lb", &zdb, &sql, &sql_len, &mode, &decode_binary)) {
return;
}
@@ -2169,15 +2171,15 @@
}
return;
}
-
+
rres = (struct php_sqlite_result *)emalloc(sizeof(*rres));
sqlite_query(NULL, db, sql, sql_len, (int)mode, 0, NULL, &rres, NULL
TSRMLS_CC);
- if (db->last_err_code != SQLITE_OK) {
- if (rres) {
- efree(rres);
- }
- RETURN_FALSE;
- }
+ if (db->last_err_code != SQLITE_OK) {
+ if (rres) {
+ efree(rres);
+ }
+ RETURN_FALSE;
+ }
array_init(return_value);
@@ -2196,13 +2198,13 @@
const char **rowdata;
char *decoded;
int decoded_len;
-
+
/* check range of the row */
if (res->curr_row >= res->nrows) {
/* no more */
RETURN_FALSE;
}
-
+
if (res->buffered) {
rowdata = (const char**)&res->table[res->curr_row *
res->ncolumns];
} else {
@@ -2266,7 +2268,7 @@
RES_FROM_OBJECT(db, object);
} else {
if (FAILURE ==
zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
- ZEND_NUM_ARGS() TSRMLS_CC, "sr|bb", &sql,
&sql_len, &zdb, &srow, &decode_binary) &&
+ ZEND_NUM_ARGS() TSRMLS_CC, "sr|bb", &sql,
&sql_len, &zdb, &srow, &decode_binary) &&
FAILURE == zend_parse_parameters(ZEND_NUM_ARGS()
TSRMLS_CC, "rs|bb", &zdb, &sql, &sql_len, &srow, &decode_binary)) {
return;
}
@@ -2568,7 +2570,7 @@
RETURN_FALSE;
}
- RETURN_BOOL(res->curr_row);
+ RETURN_BOOL(res->curr_row);
}
/* }}} */
@@ -2651,7 +2653,7 @@
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot seek an
unbuffered result set");
RETURN_FALSE;
}
-
+
if (row < 0 || row >= res->nrows) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "row %ld out of
range", row);
RETURN_FALSE;
@@ -2686,7 +2688,7 @@
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot rewind an
unbuffered result set");
RETURN_FALSE;
}
-
+
if (!res->nrows) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "no rows received");
RETURN_FALSE;
@@ -2807,12 +2809,12 @@
if (stringlen && (string[0] == '\x01' || memchr(string, '\0',
stringlen) != NULL)) {
/* binary string */
int enclen;
-
+
ret = safe_emalloc(1 + stringlen / 254, 257, 3);
ret[0] = '\x01';
enclen = php_sqlite_encode_binary(string, stringlen, ret+1);
RETVAL_STRINGL(ret, enclen+1, 0);
-
+
} else if (stringlen) {
ret = sqlite_mprintf("%q", string);
if (ret) {
@@ -2859,7 +2861,7 @@
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
&code)) {
return;
}
-
+
msg = sqlite_error_string(code);
if (msg) {
@@ -2927,7 +2929,7 @@
}
alloc_funcs->is_valid = 1;
*funcs = alloc_funcs;
-
+
return ret;
}
@@ -2963,7 +2965,7 @@
return;
}
efree(callable);
-
+
if (!zend_is_callable(zfinal, 0, &callable)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "finalize
function `%s' is not callable", callable);
efree(callable);
@@ -2971,13 +2973,13 @@
}
efree(callable);
-
+
if (prep_callback_struct(db, 1, funcname, zstep, zfinal, &funcs) ==
DO_REG) {
sqlite_create_aggregate(db->db, funcname, num_args,
php_sqlite_agg_step_function_callback,
php_sqlite_agg_fini_function_callback, funcs);
}
-
+
}
/* }}} */
@@ -2993,7 +2995,7 @@
struct php_sqlite_agg_functions *funcs;
char *callable = NULL;
long num_args = -1;
-
+
zval *object = getThis();
if (object) {
@@ -3014,7 +3016,7 @@
return;
}
efree(callable);
-
+
if (prep_callback_struct(db, 0, funcname, zcall, NULL, &funcs) ==
DO_REG) {
sqlite_create_function(db->db, funcname, num_args,
php_sqlite_function_callback, funcs);
}
@@ -3039,7 +3041,7 @@
/* binary string */
int enclen;
char *ret;
-
+
ret = safe_emalloc(1 + datalen / 254, 257, 3);
ret[0] = '\x01';
enclen = php_sqlite_encode_binary(data, datalen, ret+1);
@@ -3068,7 +3070,7 @@
/* encoded string */
int enclen;
char *ret;
-
+
ret = emalloc(datalen);
enclen = php_sqlite_decode_binary(data+1, ret);
ret[enclen] = '\0';