cvs: php-src /ext/sqlite config.m4 config.w32 sqlite.c /ext/sqlite/tests sqlite_oo_032.phpt

From: Date: Tue, 15 Feb 2005 21:09:42 +0000
Subject: cvs: php-src /ext/sqlite config.m4 config.w32 sqlite.c /ext/sqlite/tests sqlite_oo_032.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-30434@lists.php.net to get a copy of this message
helly Tue Feb 15 16:09:42 2005 EDT Added files: /php-src/ext/sqlite/tests sqlite_oo_032.phpt Modified files: /php-src/ext/sqlite config.m4 config.w32 sqlite.c Log: - SQLite depends on SPL if it is present - Add SQLiteResult::count() - SQLiteResult implements Countable if present http://cvs.php.net/diff.php/php-src/ext/sqlite/config.m4?r1=1.30&r2=1.31&ty=u Index: php-src/ext/sqlite/config.m4 diff -u php-src/ext/sqlite/config.m4:1.30 php-src/ext/sqlite/config.m4:1.31 --- php-src/ext/sqlite/config.m4:1.30 Sat Feb 12 22:15:11 2005 +++ php-src/ext/sqlite/config.m4 Tue Feb 15 16:09:42 2005 @@ -1,4 +1,4 @@ -dnl $Id: config.m4,v 1.30 2005/02/13 03:15:11 wez Exp $ +dnl $Id: config.m4,v 1.31 2005/02/15 21:09:42 helly Exp $ dnl config.m4 for extension sqlite dnl vim:et:ts=2:sw=2 @@ -70,6 +70,7 @@ libsqlite/src/where.c libsqlite/src/trigger.c" PHP_NEW_EXTENSION(sqlite, sqlite.c sess_sqlite.c $sources, $ext_shared,,$PHP_SQLITE_CFLAGS) + PHP_ADD_EXTENSION_DEP(sqlite, spl) PHP_ADD_BUILD_DIR($ext_builddir/libsqlite) PHP_ADD_BUILD_DIR($ext_builddir/libsqlite/src) AC_CHECK_SIZEOF(char *,4) http://cvs.php.net/diff.php/php-src/ext/sqlite/config.w32?r1=1.5&r2=1.6&ty=u Index: php-src/ext/sqlite/config.w32 diff -u php-src/ext/sqlite/config.w32:1.5 php-src/ext/sqlite/config.w32:1.6 --- php-src/ext/sqlite/config.w32:1.5 Tue May 25 09:01:05 2004 +++ php-src/ext/sqlite/config.w32 Tue Feb 15 16:09:42 2005 @@ -1,4 +1,4 @@ -// $Id: config.w32,v 1.5 2004/05/25 13:01:05 wez Exp $ +// $Id: config.w32,v 1.6 2005/02/15 21:09:42 helly Exp $ // vim:ft=javascript ARG_WITH("sqlite", "SQLite support", "yes"); @@ -27,6 +27,5 @@ if (!PHP_SQLITE_SHARED) { ADD_DEF_FILE(configure_module_dirname + "\\php_sqlite.def"); } + ADD_EXTENSION_DEP('sqlite', 'spl') } - - http://cvs.php.net/diff.php/php-src/ext/sqlite/sqlite.c?r1=1.156&r2=1.157&ty=u Index: php-src/ext/sqlite/sqlite.c diff -u php-src/ext/sqlite/sqlite.c:1.156 php-src/ext/sqlite/sqlite.c:1.157 --- php-src/ext/sqlite/sqlite.c:1.156 Tue Jan 25 14:08:38 2005 +++ php-src/ext/sqlite/sqlite.c Tue Feb 15 16:09:42 2005 @@ -17,7 +17,7 @@ | Marcus Boerger <helly@php.net> | +----------------------------------------------------------------------+ - $Id: sqlite.c,v 1.156 2005/01/25 19:08:38 helly Exp $ + $Id: sqlite.c,v 1.157 2005/02/15 21:09:42 helly Exp $ */ #ifdef HAVE_CONFIG_H @@ -46,6 +46,7 @@ #ifdef HAVE_SPL extern PHPAPI zend_class_entry *spl_ce_RuntimeException; +extern PHPAPI zend_class_entry *spl_ce_Countable; #endif #ifndef safe_emalloc @@ -65,6 +66,8 @@ #define php_sqlite_encode_binary(in, n, out) sqlite_encode_binary((const unsigned char *)in, n, (unsigned char *)out) #define php_sqlite_decode_binary(in, out) sqlite_decode_binary((const unsigned char *)in, (unsigned char *)out) +static int sqlite_count_elements(zval *object, long *count TSRMLS_DC); + static int le_sqlite_db, le_sqlite_result, le_sqlite_pdb; static inline void php_sqlite_strtoupper(char *s) @@ -90,7 +93,6 @@ PHP_INI_END() /* }}} */ - #define DB_FROM_ZVAL(db, zv) ZEND_FETCH_RESOURCE2(db, struct php_sqlite_db *, zv, -1, "sqlite database", le_sqlite_db, le_sqlite_pdb) #define DB_FROM_OBJECT(db, object) \ @@ -113,10 +115,6 @@ } \ } -#define SQLITE_THROW(message) \ - PG(suppress_errors) = 0; \ - EG(exception) = zend_throw_exception(sqlite_ce_exception, message, 0 TSRMLS_CC); - #define PHP_SQLITE_EMPTY_QUERY \ if (!sql_len) { \ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot execute empty query."); \ @@ -234,6 +232,8 @@ PHP_ME_MAPPING(next, sqlite_next, NULL) PHP_ME_MAPPING(valid, sqlite_valid, NULL) PHP_ME_MAPPING(rewind, sqlite_rewind, NULL) + /* countable */ + PHP_ME_MAPPING(count, sqlite_num_rows, NULL) /* additional */ PHP_ME_MAPPING(prev, sqlite_prev, NULL) PHP_ME_MAPPING(hasPrev, sqlite_has_prev, NULL) @@ -1009,11 +1009,16 @@ #endif sqlite_object_handlers_query.get_class_entry = sqlite_get_ce_query; sqlite_object_handlers_ub_query.get_class_entry = sqlite_get_ce_ub_query; + sqlite_object_handlers_ub_query.count_elements = sqlite_count_elements; sqlite_ce_ub_query->get_iterator = sqlite_get_iterator; sqlite_ce_ub_query->iterator_funcs.funcs = &sqlite_ub_query_iterator_funcs; +#ifdef HAVE_SPL + 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); +#endif sqlite_ce_query->get_iterator = sqlite_get_iterator; sqlite_ce_query->iterator_funcs.funcs = &sqlite_query_iterator_funcs; @@ -1081,7 +1086,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.156 2005/01/25 19:08:38 helly Exp $"); + php_info_print_table_row(2, "PECL Module version", PHP_SQLITE_MODULE_VERSION " $Id: sqlite.c,v 1.157 2005/02/15 21:09:42 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(); @@ -2398,6 +2403,19 @@ } /* }}} */ +static int sqlite_count_elements(zval *object, long *count TSRMLS_DC) /* {{{ */ +{ + sqlite_object *obj = (sqlite_object*) zend_object_store_get_object(object TSRMLS_CC); + + if (obj->u.res->buffered) { + * count = obj->u.res->nrows; + return SUCCESS; + } else { + zend_throw_exception(sqlite_ce_exception, "Row count is not available for unbuffered queries", 0 TSRMLS_CC); + return FAILURE; + } +} /* }}} */ + /* {{{ proto int sqlite_num_rows(resource result) Returns the number of rows in a buffered result set. */ PHP_FUNCTION(sqlite_num_rows) http://cvs.php.net/co.php/php-src/ext/sqlite/tests/sqlite_oo_032.phpt?r=1.1&p=1 Index: php-src/ext/sqlite/tests/sqlite_oo_032.phpt +++ php-src/ext/sqlite/tests/sqlite_oo_032.phpt --TEST-- sqlite-oo: and SPL Countable --SKIPIF-- <?php # vim:ft=php if (!extension_loaded("sqlite")) print "skip"; if (!extension_loaded("spl")) print "skip SPL is not present"; ?> --FILE-- <?php include "blankdb_oo.inc"; $db->query("CREATE TABLE menu(id_l int PRIMARY KEY, id_r int UNIQUE, key VARCHAR(10))"); $db->query("INSERT INTO menu VALUES( 1, 12, 'A')"); $db->query("INSERT INTO menu VALUES( 2, 9, 'B')"); $db->query("INSERT INTO menu VALUES(10, 11, 'F')"); $db->query("INSERT INTO menu VALUES( 3, 6, 'C')"); $db->query("INSERT INTO menu VALUES( 7, 8, 'E')"); $db->query("INSERT INTO menu VALUES( 4, 5, 'D')"); $res = $db->query("SELECT * from menu"); var_dump($res->count()); var_dump(count($res)); ?> ===DONE=== --EXPECT-- int(6) int(6) ===DONE===

« previous php.cvs (#30434) next »