iliaa           Tue Dec  9 20:02:21 2003 EDT

  Added files:                 
    /php-src/ext/sqlite/tests   sqlite_025.phpt 

  Modified files:              
    /php-src/ext/sqlite sqlite.c 
  Log:
  Fixed a crash in SQLite when fetching data using sqlite_fetch_object() in 
  a loop.
  
  
  
Index: php-src/ext/sqlite/sqlite.c
diff -u php-src/ext/sqlite/sqlite.c:1.101 php-src/ext/sqlite/sqlite.c:1.102
--- php-src/ext/sqlite/sqlite.c:1.101   Sat Oct 25 19:17:15 2003
+++ php-src/ext/sqlite/sqlite.c Tue Dec  9 20:02:19 2003
@@ -17,7 +17,7 @@
    |          Marcus Boerger <[EMAIL PROTECTED]>                              |
    +----------------------------------------------------------------------+
 
-   $Id: sqlite.c,v 1.101 2003/10/25 23:17:15 helly Exp $ 
+   $Id: sqlite.c,v 1.102 2003/12/10 01:02:19 iliaa Exp $ 
 */
 
 #ifdef HAVE_CONFIG_H
@@ -1072,7 +1072,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.101 2003/10/25 23:17:15 helly Exp $");
+       php_info_print_table_row(2, "PECL Module version", PHP_SQLITE_MODULE_VERSION " 
$Id: sqlite.c,v 1.102 2003/12/10 01:02:19 iliaa 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();
@@ -1845,7 +1845,11 @@
                return;
        }
 
-       php_sqlite_fetch_array(res, PHPSQLITE_ASSOC, decode_binary, 1, &dataset 
TSRMLS_CC);
+       if (res->curr_row < res->nrows) {
+               php_sqlite_fetch_array(res, PHPSQLITE_ASSOC, decode_binary, 1, 
&dataset TSRMLS_CC);
+       } else {
+               RETURN_FALSE;
+       }
 
        object_and_properties_init(return_value, ce, NULL);
        zend_merge_properties(return_value, Z_ARRVAL(dataset), 1 TSRMLS_CC);

Index: php-src/ext/sqlite/tests/sqlite_025.phpt
+++ php-src/ext/sqlite/tests/sqlite_025.phpt
--TEST--
sqlite: sqlite_fetch_object in a loop
--INI--
sqlite.assoc_case=0
--SKIPIF--
<?php # vim:ft=php
if (!extension_loaded("sqlite")) print "skip"; ?>
--FILE--
<?php 
include "blankdb.inc";

sqlite_query($db, "CREATE TABLE strings(a)");

foreach (array("one", "two", "three") as $str) {
        sqlite_query($db, "INSERT INTO strings VALUES('$str')");
}

$res = sqlite_query("SELECT * FROM strings", $db);

while (($obj = sqlite_fetch_object($res))) {
        var_dump($obj);
}

sqlite_close($db);
?>
--EXPECTF--
object(stdClass)#1 (1) {
  ["a"]=>
  string(3) "one"
}
object(stdClass)#2 (1) {
  ["a"]=>
  string(3) "two"
}
object(stdClass)#1 (1) {
  ["a"]=>
  string(5) "three"
}

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to