helly Thu Aug 28 19:19:53 2003 EDT Added files: /php-src/ext/sqlite/tests sqlite_024.phpt sqlite_oo_024.phpt
Modified files: /php-src/ext/sqlite php_sqlite.h sqlite.c Log: Add sqlite_fetch_object()
Index: php-src/ext/sqlite/php_sqlite.h diff -u php-src/ext/sqlite/php_sqlite.h:1.25 php-src/ext/sqlite/php_sqlite.h:1.26 --- php-src/ext/sqlite/php_sqlite.h:1.25 Sun Jul 13 05:38:33 2003 +++ php-src/ext/sqlite/php_sqlite.h Thu Aug 28 19:19:51 2003 @@ -17,7 +17,7 @@ | Marcus Boerger <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ - $Id: php_sqlite.h,v 1.25 2003/07/13 09:38:33 wez Exp $ + $Id: php_sqlite.h,v 1.26 2003/08/28 23:19:51 helly Exp $ */ #ifndef PHP_SQLITE_H @@ -51,6 +51,7 @@ PHP_FUNCTION(sqlite_single_query); PHP_FUNCTION(sqlite_fetch_array); +PHP_FUNCTION(sqlite_fetch_object); PHP_FUNCTION(sqlite_fetch_single); PHP_FUNCTION(sqlite_fetch_all); PHP_FUNCTION(sqlite_current); Index: php-src/ext/sqlite/sqlite.c diff -u php-src/ext/sqlite/sqlite.c:1.84 php-src/ext/sqlite/sqlite.c:1.85 --- php-src/ext/sqlite/sqlite.c:1.84 Mon Aug 25 16:55:14 2003 +++ php-src/ext/sqlite/sqlite.c Thu Aug 28 19:19:51 2003 @@ -17,7 +17,7 @@ | Marcus Boerger <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ - $Id: sqlite.c,v 1.84 2003/08/25 20:55:14 helly Exp $ + $Id: sqlite.c,v 1.85 2003/08/28 23:19:51 helly Exp $ */ #ifdef HAVE_CONFIG_H @@ -161,6 +161,7 @@ PHP_FE(sqlite_array_query, NULL) PHP_FE(sqlite_single_query, NULL) PHP_FE(sqlite_fetch_array, NULL) + PHP_FE(sqlite_fetch_object, NULL) PHP_FE(sqlite_fetch_single, NULL) PHP_FALIAS(sqlite_fetch_string, sqlite_fetch_single, NULL) PHP_FE(sqlite_fetch_all, NULL) @@ -214,6 +215,7 @@ function_entry sqlite_funcs_query[] = { PHP_ME_MAPPING(fetch_array, sqlite_fetch_array, NULL) + PHP_ME_MAPPING(fetch_object, sqlite_fetch_object, NULL) PHP_ME_MAPPING(fetch_single, sqlite_fetch_single, NULL) PHP_ME_MAPPING(fetch_all, sqlite_fetch_all, NULL) PHP_ME_MAPPING(column, sqlite_column, NULL) @@ -236,6 +238,7 @@ function_entry sqlite_funcs_ub_query[] = { PHP_ME_MAPPING(fetch_array, sqlite_fetch_array, NULL) + PHP_ME_MAPPING(fetch_object, sqlite_fetch_object, NULL) PHP_ME_MAPPING(fetch_single, sqlite_fetch_single, NULL) PHP_ME_MAPPING(fetch_all, sqlite_fetch_all, NULL) PHP_ME_MAPPING(column, sqlite_column, NULL) @@ -938,7 +941,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.84 2003/08/25 20:55:14 helly Exp $"); + php_info_print_table_row(2, "PECL Module version", PHP_SQLITE_MODULE_VERSION " $Id: sqlite.c,v 1.85 2003/08/28 23:19:51 helly 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(); @@ -1159,7 +1162,7 @@ php_set_error_handling(EH_THROW, sqlite_ce_exception TSRMLS_CC); if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lz/", &filename, &filename_len, &mode, &errmsg)) { - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); + php_std_error_handling(); RETURN_NULL(); } if (errmsg) { @@ -1167,18 +1170,18 @@ } if (PG(safe_mode) && (!php_checkuid(filename, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); + php_std_error_handling(); RETURN_NULL(); } if (php_check_open_basedir(filename TSRMLS_CC)) { - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); + php_std_error_handling(); RETURN_NULL(); } php_sqlite_open(filename, mode, NULL, return_value, errmsg, return_value TSRMLS_CC); - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); + php_std_error_handling(); } /* }}} */ @@ -1657,6 +1660,84 @@ } php_sqlite_fetch_array(res, mode, decode_binary, 1, return_value TSRMLS_CC); +} +/* }}} */ + +/* {{{ proto object sqlite_fetch_object(resource result [, string class_name [, bool decode_binary]]) + Fetches the next row from a result set as an object. */ +PHP_FUNCTION(sqlite_fetch_object) +{ + zval *zres; + zend_bool decode_binary = 1; + struct php_sqlite_result *res; + zval *object = getThis(); + char *class_name; + int class_name_len; + zend_class_entry *ce; + zval dataset; + zend_fcall_info fci; + zend_fcall_info_cache fcc; + zval *retval_ptr; + + php_set_error_handling(object ? EH_THROW : EH_NORMAL, sqlite_ce_exception TSRMLS_CC); + if (object) { + if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sb", &class_name, &class_name_len, &decode_binary)) { + php_std_error_handling(); + return; + } + RES_FROM_OBJECT(res, object); + if (!ZEND_NUM_ARGS()) { + ce = zend_standard_class_def; + } else { + ce = zend_fetch_class(class_name, class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC); + } + } else { + if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|sb", &zres, &class_name, &class_name_len, &decode_binary)) { + php_std_error_handling(); + return; + } + ZEND_FETCH_RESOURCE(res, struct php_sqlite_result *, &zres, -1, "sqlite result", le_sqlite_result); + if (ZEND_NUM_ARGS() < 2) { + ce = zend_standard_class_def; + } else { + ce = zend_fetch_class(class_name, class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC); + } + } + + if (!ce) { + zend_throw_exception_ex(sqlite_ce_exception, 0 TSRMLS_CC, "Could not find class '%s'", class_name); + php_std_error_handling(); + return; + } + + php_sqlite_fetch_array(res, PHPSQLITE_ASSOC, decode_binary, 1, &dataset TSRMLS_CC); + + object_and_properties_init(return_value, ce, Z_ARRVAL(dataset)); + + php_std_error_handling(); /* before calling the ctor */ + + if (ce->constructor) { + fci.size = sizeof(fci); + fci.function_table = &ce->function_table; + fci.function_name = NULL; + fci.symbol_table = NULL; + fci.object_pp = &return_value; + fci.retval_ptr_ptr = &retval_ptr; + fci.param_count = 0; + fci.params = NULL; + fci.no_separation = 1; + + fcc.initialized = 1; + fcc.function_handler = ce->constructor; + fcc.calling_scope = EG(scope); + fcc.object_pp = &return_value; + + if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) { + zend_throw_exception_ex(sqlite_ce_exception, 0 TSRMLS_CC, "Could not execute %s::%s()", class_name, ce->constructor->common.function_name); + } else { + zval_ptr_dtor(&retval_ptr); + } + } } /* }}} */ Index: php-src/ext/sqlite/tests/sqlite_024.phpt +++ php-src/ext/sqlite/tests/sqlite_024.phpt --TEST-- sqlite: sqlite_fetch_object --INI-- sqlite.assoc_case=0 --SKIPIF-- <?php # vim:ft=php if (!extension_loaded("sqlite")) print "skip"; ?> --FILE-- <?php include "blankdb.inc"; class class24 { function __construct() { echo __METHOD__ . "\n"; } } $data = array( "one", "two", "three" ); sqlite_query($db, "CREATE TABLE strings(a)"); foreach ($data as $str) { sqlite_query($db, "INSERT INTO strings VALUES('$str')"); } echo "====stdclass====\n"; $res = sqlite_query($db, "SELECT a FROM strings", SQLITE_ASSOC); while (sqlite_has_more($res)) { var_dump(sqlite_fetch_object($res, 'class24')); } echo "====class24!====\n"; $res = sqlite_query($db, "SELECT a FROM strings", SQLITE_ASSOC); while (sqlite_has_more($res)) { var_dump(sqlite_fetch_object($res)); } echo "====DONE!====\n"; ?> --EXPECTF-- ====stdclass==== class24::__construct object(class24)#%d (1) { ["a"]=> string(3) "one" } class24::__construct object(class24)#%d (1) { ["a"]=> string(3) "two" } class24::__construct object(class24)#%d (1) { ["a"]=> string(5) "three" } ====class24!==== object(stdClass)#%d (1) { ["a"]=> string(3) "one" } object(stdClass)#%d (1) { ["a"]=> string(3) "two" } object(stdClass)#%d (1) { ["a"]=> string(5) "three" } ====DONE!==== Index: php-src/ext/sqlite/tests/sqlite_oo_024.phpt +++ php-src/ext/sqlite/tests/sqlite_oo_024.phpt --TEST-- sqlite-oo: sqlite::fetch_object --INI-- sqlite.assoc_case=0 --SKIPIF-- <?php # vim:ft=php if (!extension_loaded("sqlite")) print "skip"; ?> --FILE-- <?php include "blankdb_oo.inc"; class class24 { function __construct() { echo __METHOD__ . "\n"; } } $data = array( "one", "two", "three" ); $db->query("CREATE TABLE strings(a)"); foreach ($data as $str) { $db->query("INSERT INTO strings VALUES('$str')"); } echo "====stdclass====\n"; $res = $db->query("SELECT a FROM strings", SQLITE_ASSOC); while ($res->has_more()) { var_dump($res->fetch_object('class24')); } echo "====class24!====\n"; $res = $db->query("SELECT a FROM strings", SQLITE_ASSOC); while ($res->has_more()) { var_dump($res->fetch_object()); } echo "====DONE!====\n"; ?> --EXPECTF-- ====stdclass==== class24::__construct object(class24)#%d (1) { ["a"]=> string(3) "one" } class24::__construct object(class24)#%d (1) { ["a"]=> string(3) "two" } class24::__construct object(class24)#%d (1) { ["a"]=> string(5) "three" } ====class24!==== object(stdClass)#%d (1) { ["a"]=> string(3) "one" } object(stdClass)#%d (1) { ["a"]=> string(3) "two" } object(stdClass)#%d (1) { ["a"]=> string(5) "three" } ====DONE!====
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php