From: Marcus Boerger Date: Sat, 14 Jun 2003 18:16:47 +0000 (+0000) Subject: - Update license X-Git-Tag: RELEASE_1_0_2~254 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f2b387c6147375501ad6de814bede9357fa4cf8;p=php - Update license - Don't buffer in non buffered mode --- diff --git a/ext/sqlite/php_sqlite.h b/ext/sqlite/php_sqlite.h index ec14e69390..37538ba30f 100644 --- a/ext/sqlite/php_sqlite.h +++ b/ext/sqlite/php_sqlite.h @@ -1,23 +1,23 @@ /* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Wez Furlong | - | Tal Peer | - | Marcus Boerger | - +----------------------------------------------------------------------+ - - $Id$ + +----------------------------------------------------------------------+ + | PHP Version 4 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2003 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.0 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_0.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Wez Furlong | + | Tal Peer | + | Marcus Boerger | + +----------------------------------------------------------------------+ + + $Id$ */ #ifndef PHP_SQLITE_H diff --git a/ext/sqlite/sqlite.c b/ext/sqlite/sqlite.c index f104167b92..f9ac9b31dc 100644 --- a/ext/sqlite/sqlite.c +++ b/ext/sqlite/sqlite.c @@ -1,23 +1,23 @@ /* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Wez Furlong | - | Tal Peer | - | Marcus Boerger | - +----------------------------------------------------------------------+ - - $Id$ + +----------------------------------------------------------------------+ + | PHP Version 4 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2003 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.0 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_0.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Wez Furlong | + | Tal Peer | + | Marcus Boerger | + +----------------------------------------------------------------------+ + + $Id$ */ #ifdef HAVE_CONFIG_H @@ -770,7 +770,7 @@ PHP_FUNCTION(sqlite_popen) return; } - php_error_docref(NULL TSRMLS_CC, E_WARNING, "some other type of persistent resource is using this hash key!?"); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Some other type of persistent resource is using this hash key!?"); RETURN_FALSE; } @@ -1078,10 +1078,9 @@ static void php_sqlite_fetch_array(struct php_sqlite_result *res, int mode, zend if (rowdata[j] == NULL) { ZVAL_NULL(decoded); } else if (decode_binary && rowdata[j][0] == '\x01') { - int l = strlen(rowdata[j]); - Z_STRVAL_P(decoded) = emalloc(l); - Z_STRLEN_P(decoded) = l = sqlite_decode_binary(rowdata[j]+1, Z_STRVAL_P(decoded)); - Z_STRVAL_P(decoded)[l] = '\0'; + Z_STRVAL_P(decoded) = emalloc(strlen(rowdata[j])); + Z_STRLEN_P(decoded) = sqlite_decode_binary(rowdata[j]+1, Z_STRVAL_P(decoded)); + Z_STRVAL_P(decoded)[Z_STRLEN_P(decoded)] = '\0'; Z_TYPE_P(decoded) = IS_STRING; if (!buffered) { efree((char*)rowdata[j]); @@ -1095,10 +1094,12 @@ static void php_sqlite_fetch_array(struct php_sqlite_result *res, int mode, zend } if (mode & PHPSQLITE_NUM) { - add_index_zval(return_value, j, decoded); if (mode & PHPSQLITE_ASSOC) { + add_index_zval(return_value, j, decoded); ZVAL_ADDREF(decoded); add_assoc_zval(return_value, (char*)colnames[j], decoded); + } else { + add_next_index_zval(return_value, decoded); } } else { add_assoc_zval(return_value, (char*)colnames[j], decoded); @@ -1300,11 +1301,25 @@ PHP_FUNCTION(sqlite_fetch_string) } if (decode_binary && rowdata[0] != NULL && rowdata[0][0] == '\x01') { - decoded = do_alloca(strlen(rowdata[0])); + decoded = emalloc(strlen(rowdata[0])); decoded_len = sqlite_decode_binary(rowdata[0]+1, decoded); + if (!res->buffered) { + efree((char*)rowdata[0]); + rowdata[0] = NULL; + } } else { - decoded = (char*)rowdata[0]; - decoded_len = decoded ? strlen(decoded) : 0; + if (rowdata[0]) { + decoded_len = strlen((char*)rowdata[0]); + if (res->buffered) { + decoded = estrndup((char*)rowdata[0], decoded_len); + } else { + decoded = (char*)rowdata[0]; + rowdata[0] = NULL; + } + } else { + decoded_len = 0; + decoded = NULL; + } } if (!res->buffered) { @@ -1317,7 +1332,7 @@ PHP_FUNCTION(sqlite_fetch_string) if (decoded == NULL) { RETURN_NULL(); } else { - RETURN_STRINGL(decoded, decoded_len, 1); + RETURN_STRINGL(decoded, decoded_len, 0); } } /* }}} */ diff --git a/ext/sqlite/tests/sqlite_016.phpt b/ext/sqlite/tests/sqlite_016.phpt new file mode 100755 index 0000000000..69ecc1202a --- /dev/null +++ b/ext/sqlite/tests/sqlite_016.phpt @@ -0,0 +1,42 @@ +--TEST-- +sqlite: fetch string +--INI-- +sqlite.assoc_case=0 +--SKIPIF-- + +--FILE-- + 'one', 1 => 'two'), + array (0 => 'three', 1 => 'four') + ); + +sqlite_query("CREATE TABLE strings(a VARCHAR, b VARCHAR)", $db); + +foreach ($data as $str) { + sqlite_query("INSERT INTO strings VALUES('${str[0]}','${str[1]}')", $db); +} + +echo "====BUFFERED====\n"; +$r = sqlite_query("SELECT a, b from strings", $db); +while (sqlite_has_more($r)) { + var_dump(sqlite_fetch_string($r, SQLITE_NUM)); +} +echo "====UNBUFFERED====\n"; +$r = sqlite_unbuffered_query("SELECT a, b from strings", $db); +while (sqlite_has_more($r)) { + var_dump(sqlite_fetch_string($r, SQLITE_NUM)); +} +echo "DONE!\n"; +?> +--EXPECT-- +====BUFFERED==== +string(3) "one" +string(5) "three" +====UNBUFFERED==== +string(3) "one" +string(5) "three" +DONE!