[PHP-CVS] cvs: php-src(PHP_5_3) /ext/pdo_sqlite sqlite_statement.c
iliaa Wed May 20 15:05:36 2009 UTC Modified files: (Branch: PHP_5_3) /php-src/ext/pdo_sqlite sqlite_statement.c Log: MFB: Re-introduce the Matteo's patch and combine default & text handling since they appear to be the same irregardless on notes inside sqlite3.h http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_sqlite/sqlite_statement.c?r1=1.18.2.4.2.3.2.9&r2=1.18.2.4.2.3.2.10&diff_format=u Index: php-src/ext/pdo_sqlite/sqlite_statement.c diff -u php-src/ext/pdo_sqlite/sqlite_statement.c:1.18.2.4.2.3.2.9 php-src/ext/pdo_sqlite/sqlite_statement.c:1.18.2.4.2.3.2.10 --- php-src/ext/pdo_sqlite/sqlite_statement.c:1.18.2.4.2.3.2.9 Tue May 19 19:15:18 2009 +++ php-src/ext/pdo_sqlite/sqlite_statement.c Wed May 20 15:05:36 2009 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: sqlite_statement.c,v 1.18.2.4.2.3.2.9 2009/05/19 19:15:18 iliaa Exp $ */ +/* $Id: sqlite_statement.c,v 1.18.2.4.2.3.2.10 2009/05/20 15:05:36 iliaa Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -262,16 +262,6 @@ *len = sqlite3_column_bytes(S->stmt, colno); return 1; - case SQLITE3_TEXT: - *ptr = (char*)sqlite3_column_text(S->stmt, colno); - *len = sqlite3_column_bytes(S->stmt, colno); -#if SQLITE_VERSION_NUMBER < 3004000 - if (*len) { - /* sqlite3.h says "the NUL terminator is included in the byte count for TEXT values" */ - (*len)--; - } -#endif - return 1; default: *ptr = (char*)sqlite3_column_text(S->stmt, colno); *len = sqlite3_column_bytes(S->stmt, colno); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php-src(PHP_5_3) /ext/pdo_sqlite sqlite_statement.c
Ilia Alshanetsky ha scritto: > iliaa Tue May 19 19:15:18 2009 UTC > > Modified files: (Branch: PHP_5_3) > /php-src/ext/pdo_sqlite sqlite_statement.c > Log: > The \0 removal is only needed prior to 3.4.0 I hate to do this (and as a php-src newbie I'm a bit afraid to), but once again this is simply wrong. The commit breaks compatibility with sqlite < 3.4.0. You are trying to fix something that has never been broken. The sqlite3.h comment was wrong and the missing parens were leading you to think that the issue existed and was being worked around in PHP. Otherwise PDO_SQLITE would have been returning strings with trailing '\0' since Feb 2005 to June 2007, which is quite unlikely. See: http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_sqlite/sqlite_statement.c?r1=1.12&r2=1.13&view=patch http://www.sqlite.org/changes.html#version_3_4_0 I've verified the compatibility break by compiling PHP 5.3 with a cvs checkout of sqlite 3.3.8 (-D 2007-01-01). Here's the result of one of the many failing tests: TEST 6/14 [ext/pdo_sqlite/tests/bug46139.phpt] DIFF 002+ 'fo' 002- 'foo' 004+ 'fo' 004- 'foo' 006+ 'fo' 006- 'foo' DONE I hope this is enough proof to back up my theory and for you to revert your latest changes. Cheers -- Matteo Beccati OpenX - http://www.openx.org -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src(PHP_5_3) /ext/pdo_sqlite sqlite_statement.c
iliaa Tue May 19 19:15:18 2009 UTC Modified files: (Branch: PHP_5_3) /php-src/ext/pdo_sqlite sqlite_statement.c Log: The \0 removal is only needed prior to 3.4.0 http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_sqlite/sqlite_statement.c?r1=1.18.2.4.2.3.2.8&r2=1.18.2.4.2.3.2.9&diff_format=u Index: php-src/ext/pdo_sqlite/sqlite_statement.c diff -u php-src/ext/pdo_sqlite/sqlite_statement.c:1.18.2.4.2.3.2.8 php-src/ext/pdo_sqlite/sqlite_statement.c:1.18.2.4.2.3.2.9 --- php-src/ext/pdo_sqlite/sqlite_statement.c:1.18.2.4.2.3.2.8 Tue May 19 16:14:13 2009 +++ php-src/ext/pdo_sqlite/sqlite_statement.c Tue May 19 19:15:18 2009 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: sqlite_statement.c,v 1.18.2.4.2.3.2.8 2009/05/19 16:14:13 iliaa Exp $ */ +/* $Id: sqlite_statement.c,v 1.18.2.4.2.3.2.9 2009/05/19 19:15:18 iliaa Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -265,12 +265,13 @@ case SQLITE3_TEXT: *ptr = (char*)sqlite3_column_text(S->stmt, colno); *len = sqlite3_column_bytes(S->stmt, colno); +#if SQLITE_VERSION_NUMBER < 3004000 if (*len) { /* sqlite3.h says "the NUL terminator is included in the byte count for TEXT values" */ - *len--; /* do not remove this, even though it generates a warning */ + (*len)--; } +#endif return 1; - default: *ptr = (char*)sqlite3_column_text(S->stmt, colno); *len = sqlite3_column_bytes(S->stmt, colno); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php-src(PHP_5_3) /ext/pdo_sqlite sqlite_statement.c
it looks like in recent version of sqlite3 the behavior had changed some what. I am going to check which version of sqlite3 had followed the old behavior and put the code into the appropriate define block. Ilia Alshanetsky On 19-May-09, at 1:33 PM, Matteo Beccati wrote: Ilia Alshanetsky ha scritto: *len is a pointer to an integer, that is being decremented to reduce the overall length of the string to "remove" the NUL terminator. If you remove the operation you'll end up with 2 NULs at the end of the string. As I said, I coulndn't find any reference to the fact that "the NUL terminator is included in the byte count for TEXT values" in sqlite3.h. I don't want to argue about this, but here's a small test case that hopefully proves that the code you added back is just useless, as it doesn't do what you'd expect by reading the comment. $ cat len.c; gcc -Wall len.c; ./a.out #include #include void decrease_len(int *len) { *len--; } int main(int argc, char **argv) { int len = 10; decrease_len(&len); assert(len == 9); return 0; } len.c: In function ‘decrease_len’: len.c:6: warning: value computed is not used a.out: len.c:14: main: Assertion `len == 9' failed. Aborted Cheers -- Matteo Beccati OpenX - http://www.openx.org -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php-src(PHP_5_3) /ext/pdo_sqlite sqlite_statement.c
The code should be (*len)--; then the result is as desired, I'll adjust. Ilia Alshanetsky On 19-May-09, at 1:33 PM, Matteo Beccati wrote: Ilia Alshanetsky ha scritto: *len is a pointer to an integer, that is being decremented to reduce the overall length of the string to "remove" the NUL terminator. If you remove the operation you'll end up with 2 NULs at the end of the string. As I said, I coulndn't find any reference to the fact that "the NUL terminator is included in the byte count for TEXT values" in sqlite3.h. I don't want to argue about this, but here's a small test case that hopefully proves that the code you added back is just useless, as it doesn't do what you'd expect by reading the comment. $ cat len.c; gcc -Wall len.c; ./a.out #include #include void decrease_len(int *len) { *len--; } int main(int argc, char **argv) { int len = 10; decrease_len(&len); assert(len == 9); return 0; } len.c: In function ‘decrease_len’: len.c:6: warning: value computed is not used a.out: len.c:14: main: Assertion `len == 9' failed. Aborted Cheers -- Matteo Beccati OpenX - http://www.openx.org -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php-src(PHP_5_3) /ext/pdo_sqlite sqlite_statement.c
Ilia Alshanetsky ha scritto: > *len is a pointer to an integer, that is being decremented to reduce the > overall length of the string to "remove" the NUL terminator. If you > remove the operation you'll end up with 2 NULs at the end of the string. As I said, I coulndn't find any reference to the fact that "the NUL terminator is included in the byte count for TEXT values" in sqlite3.h. I don't want to argue about this, but here's a small test case that hopefully proves that the code you added back is just useless, as it doesn't do what you'd expect by reading the comment. $ cat len.c; gcc -Wall len.c; ./a.out #include #include void decrease_len(int *len) { *len--; } int main(int argc, char **argv) { int len = 10; decrease_len(&len); assert(len == 9); return 0; } len.c: In function ‘decrease_len’: len.c:6: warning: value computed is not used a.out: len.c:14: main: Assertion `len == 9' failed. Aborted Cheers -- Matteo Beccati OpenX - http://www.openx.org -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php-src(PHP_5_3) /ext/pdo_sqlite sqlite_statement.c
*len is a pointer to an integer, that is being decremented to reduce the overall length of the string to "remove" the NUL terminator. If you remove the operation you'll end up with 2 NULs at the end of the string. Ilia Alshanetsky On 19-May-09, at 12:58 PM, Matteo Beccati wrote: Hi Ilia, + if (*len) { +/* sqlite3.h says "the NUL terminator is included in the byte count for TEXT values" */ +*len--; /* do not remove this, even though it generates a warning */ + } Would you mind explaining me why the fix was faulty? Cheers -- Matteo Beccati OpenX - http://www.openx.org -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php-src(PHP_5_3) /ext/pdo_sqlite sqlite_statement.c
Hi Ilia, > + if (*len) { > + /* sqlite3.h says "the NUL terminator is > included in the byte count for TEXT values" */ > + *len--; /* do not remove this, even though it > generates a warning */ > + } Would you mind explaining me why the fix was faulty? Cheers -- Matteo Beccati OpenX - http://www.openx.org -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src(PHP_5_3) /ext/pdo_sqlite sqlite_statement.c
iliaa Tue May 19 16:14:13 2009 UTC Modified files: (Branch: PHP_5_3) /php-src/ext/pdo_sqlite sqlite_statement.c Log: Revert faulty warning fix http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_sqlite/sqlite_statement.c?r1=1.18.2.4.2.3.2.7&r2=1.18.2.4.2.3.2.8&diff_format=u Index: php-src/ext/pdo_sqlite/sqlite_statement.c diff -u php-src/ext/pdo_sqlite/sqlite_statement.c:1.18.2.4.2.3.2.7 php-src/ext/pdo_sqlite/sqlite_statement.c:1.18.2.4.2.3.2.8 --- php-src/ext/pdo_sqlite/sqlite_statement.c:1.18.2.4.2.3.2.7 Thu May 7 23:29:54 2009 +++ php-src/ext/pdo_sqlite/sqlite_statement.c Tue May 19 16:14:13 2009 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: sqlite_statement.c,v 1.18.2.4.2.3.2.7 2009/05/07 23:29:54 mbeccati Exp $ */ +/* $Id: sqlite_statement.c,v 1.18.2.4.2.3.2.8 2009/05/19 16:14:13 iliaa Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -265,6 +265,10 @@ case SQLITE3_TEXT: *ptr = (char*)sqlite3_column_text(S->stmt, colno); *len = sqlite3_column_bytes(S->stmt, colno); + if (*len) { + /* sqlite3.h says "the NUL terminator is included in the byte count for TEXT values" */ + *len--; /* do not remove this, even though it generates a warning */ + } return 1; default: -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src(PHP_5_3) /ext/pdo_sqlite sqlite_statement.c
indeyetsWed Apr 1 14:35:24 2009 UTC Modified files: (Branch: PHP_5_3) /php-src/ext/pdo_sqlite sqlite_statement.c Log: MFH: reverted previous patch, using explicit cast instead http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_sqlite/sqlite_statement.c?r1=1.18.2.4.2.3.2.5&r2=1.18.2.4.2.3.2.6&diff_format=u Index: php-src/ext/pdo_sqlite/sqlite_statement.c diff -u php-src/ext/pdo_sqlite/sqlite_statement.c:1.18.2.4.2.3.2.5 php-src/ext/pdo_sqlite/sqlite_statement.c:1.18.2.4.2.3.2.6 --- php-src/ext/pdo_sqlite/sqlite_statement.c:1.18.2.4.2.3.2.5 Wed Apr 1 11:32:14 2009 +++ php-src/ext/pdo_sqlite/sqlite_statement.c Wed Apr 1 14:35:24 2009 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: sqlite_statement.c,v 1.18.2.4.2.3.2.5 2009/04/01 11:32:14 indeyets Exp $ */ +/* $Id: sqlite_statement.c,v 1.18.2.4.2.3.2.6 2009/04/01 14:35:24 indeyets Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -282,9 +282,7 @@ static int pdo_sqlite_stmt_col_meta(pdo_stmt_t *stmt, long colno, zval *return_value TSRMLS_DC) { pdo_sqlite_stmt *S = (pdo_sqlite_stmt*)stmt->driver_data; - const char *_str; - size_t _str_len; - char *str; + const char *str; zval *flags; if (!S->stmt) { @@ -320,21 +318,15 @@ break; } - _str = sqlite3_column_decltype(S->stmt, colno); - _str_len = strlen(_str); - if (_str) { - str = emalloc(_str_len); - strcpy(str, _str); - add_assoc_string(return_value, "sqlite:decl_type", str, 1); + str = sqlite3_column_decltype(S->stmt, colno); + if (str) { + add_assoc_string(return_value, "sqlite:decl_type", (char *)str, 1); } #ifdef SQLITE_ENABLE_COLUMN_METADATA - _str = sqlite3_column_table_name(S->stmt, colno); - _str_len = strlen(_str); - if (_str) { - str = emalloc(_str_len); - strcpy(str, _str); - add_assoc_string(return_value, "table", str, 1); + str = sqlite3_column_table_name(S->stmt, colno); + if (str) { + add_assoc_string(return_value, "table", (char *)str, 1); } #endif -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src(PHP_5_3) /ext/pdo_sqlite sqlite_statement.c
indeyetsWed Apr 1 11:32:14 2009 UTC Modified files: (Branch: PHP_5_3) /php-src/ext/pdo_sqlite sqlite_statement.c Log: MFH: const pointer was used in non-const context http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_sqlite/sqlite_statement.c?r1=1.18.2.4.2.3.2.4&r2=1.18.2.4.2.3.2.5&diff_format=u Index: php-src/ext/pdo_sqlite/sqlite_statement.c diff -u php-src/ext/pdo_sqlite/sqlite_statement.c:1.18.2.4.2.3.2.4 php-src/ext/pdo_sqlite/sqlite_statement.c:1.18.2.4.2.3.2.5 --- php-src/ext/pdo_sqlite/sqlite_statement.c:1.18.2.4.2.3.2.4 Tue Jan 13 02:50:54 2009 +++ php-src/ext/pdo_sqlite/sqlite_statement.c Wed Apr 1 11:32:14 2009 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: sqlite_statement.c,v 1.18.2.4.2.3.2.4 2009/01/13 02:50:54 scottmac Exp $ */ +/* $Id: sqlite_statement.c,v 1.18.2.4.2.3.2.5 2009/04/01 11:32:14 indeyets Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -282,6 +282,8 @@ static int pdo_sqlite_stmt_col_meta(pdo_stmt_t *stmt, long colno, zval *return_value TSRMLS_DC) { pdo_sqlite_stmt *S = (pdo_sqlite_stmt*)stmt->driver_data; + const char *_str; + size_t _str_len; char *str; zval *flags; @@ -318,14 +320,20 @@ break; } - str = (char*)sqlite3_column_decltype(S->stmt, colno); - if (str) { + _str = sqlite3_column_decltype(S->stmt, colno); + _str_len = strlen(_str); + if (_str) { + str = emalloc(_str_len); + strcpy(str, _str); add_assoc_string(return_value, "sqlite:decl_type", str, 1); } #ifdef SQLITE_ENABLE_COLUMN_METADATA - str = sqlite3_column_table_name(S->stmt, colno); - if (str) { + _str = sqlite3_column_table_name(S->stmt, colno); + _str_len = strlen(_str); + if (_str) { + str = emalloc(_str_len); + strcpy(str, _str); add_assoc_string(return_value, "table", str, 1); } #endif -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src(PHP_5_3) /ext/pdo_sqlite sqlite_statement.c
scottmacFri Mar 7 16:58:55 2008 UTC Modified files: (Branch: PHP_5_3) /php-src/ext/pdo_sqlite sqlite_statement.c Log: Fixed bug #41135 (When binding as binary data use sqlite3_bind_blob() to stop errors with null bytes.) Fixed bug #42443 (Bind integers and booleans as integers rather than strings.) http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_sqlite/sqlite_statement.c?r1=1.18.2.4.2.3.2.1&r2=1.18.2.4.2.3.2.2&diff_format=u Index: php-src/ext/pdo_sqlite/sqlite_statement.c diff -u php-src/ext/pdo_sqlite/sqlite_statement.c:1.18.2.4.2.3.2.1 php-src/ext/pdo_sqlite/sqlite_statement.c:1.18.2.4.2.3.2.2 --- php-src/ext/pdo_sqlite/sqlite_statement.c:1.18.2.4.2.3.2.1 Mon Dec 31 07:17:12 2007 +++ php-src/ext/pdo_sqlite/sqlite_statement.c Fri Mar 7 16:58:55 2008 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: sqlite_statement.c,v 1.18.2.4.2.3.2.1 2007/12/31 07:17:12 sebastian Exp $ */ +/* $Id: sqlite_statement.c,v 1.18.2.4.2.3.2.2 2008/03/07 16:58:55 scottmac Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -104,6 +104,21 @@ pdo_sqlite_error_stmt(stmt); return 0; + case PDO_PARAM_INT: + case PDO_PARAM_BOOL: + if (Z_TYPE_P(param->parameter) == IS_NULL) { + if (sqlite3_bind_null(S->stmt, param->paramno + 1) == SQLITE_OK) { + return 1; + } + } else { + convert_to_long(param->parameter); + if (SQLITE_OK == sqlite3_bind_int(S->stmt, param->paramno + 1, Z_LVAL_P(param->parameter))) { + return 1; + } + } + pdo_sqlite_error_stmt(stmt); + return 0; + case PDO_PARAM_LOB: if (Z_TYPE_P(param->parameter) == IS_RESOURCE) { php_stream *stm; @@ -117,9 +132,25 @@ pdo_raise_impl_error(stmt->dbh, stmt, "HY105", "Expected a stream resource" TSRMLS_CC); return 0; } + } else if (Z_TYPE_P(param->parameter) == IS_NULL) { + if (sqlite3_bind_null(S->stmt, param->paramno + 1) == SQLITE_OK) { + return 1; + } + pdo_sqlite_error_stmt(stmt); + return 0; + } else { + convert_to_string(param->parameter); } - /* fall through */ - + + if (SQLITE_OK == sqlite3_bind_blob(S->stmt, param->paramno + 1, + Z_STRVAL_P(param->parameter), + Z_STRLEN_P(param->parameter), + SQLITE_STATIC)) { + return 1; + } + pdo_sqlite_error_stmt(stmt); + return 0; + case PDO_PARAM_STR: default: if (Z_TYPE_P(param->parameter) == IS_NULL) { -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php