Skip to content

Fixed DOUBLE EXECUTION OF QUERIES when executing first SQLite3Result-… #8415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

HochMartinez
Copy link

…>fetcharray()

Steps to fix the bug:

  1. Disabled sqlite3_reset(stmt_obj->stmt) in SQLite3::query() and SQLite3Stmt::execute().
    sqlite3_reset(stmt_obj->stmt) forces a new execution of the query on the first execution of SQLite3Result::fetcharray().

  2. Added 'int last_error' to struct '_php_sqlite3_result_object'.
    last_error is used to store the returned value of the step command executed in SQLite3::query() and SQLite3Stmt::execute(), in order to pass this step return code to SQLite3Result::fetcharray().

  3. SQLite3Result::fetcharray() reads last_error, process it and only steps if it is equal to SQLITE_ROW.

…>fetcharray()

Steps to fix the bug:

1. Disabled sqlite3_reset(stmt_obj->stmt) in SQLite3::query() and SQLite3Stmt::execute().
sqlite3_reset(stmt_obj->stmt) forces a new execution of the query on the first execution of SQLite3Result::fetcharray().

2. Added 'int last_error' to struct '_php_sqlite3_result_object'.
last_error is used to store the returned value of the step command executed in SQLite3::query() and SQLite3Stmt::execute(), in order to pass this step return code to SQLite3Result::fetcharray().

3. SQLite3Result::fetcharray() reads last_error, process it and only steps if it is equal to SQLITE_ROW.
…DOUBLE QUERY EXECUTION on first SQLite3Result->fetchArray()

Store the last step error code from Sqlite3::query(), SQlite3Stmt::execute() in  _php_sqlite3_result_object, to passe it to SQLite3Result::fetchArray().
Also stores last step error from SQLite3Result::fetchArray() to pass it to next SQLite3Result::fetchArray().
@cmb69
Copy link
Member

cmb69 commented Apr 21, 2022

Please do not submit new pull requests if you just want to add commits to an existing PR.

Anyhow, this solution looks a bit like my previous attempt at fixing this (PR #5204), and like I commented there, this would break SQLite3::lastErrorCode() and ::lastErrorMsg(), and likely has more issues.

@cmb69 cmb69 closed this Apr 21, 2022
@HochMartinez
Copy link
Author

Hi Christoph,

Ok, I reviewed my code and wrote a small correction that, as far as I know, does not break SQLite3::lastErrorCode() and ::lastErrorMsg(). It does not change or affect the error processing logic of the code.

I guess that this last patch fixes this bug for good. It's working fine in my PHP build.

As I commented, I'm new to Github. In order to have this code reviewed and merged, I only have to commit it to HochMartinez:patch-2? No pull requests?...

@cmb69
Copy link
Member

cmb69 commented Apr 21, 2022

In order to have this code reviewed and merged, I only have to commit it to HochMartinez:patch-2? No pull requests?...

Yes, that would work.

…esult->fetchArray()

This fix prevents avoids the double execution of a query when calling SQLite3Result->fetchArray().
This second fix does not alter or affect the error logic of SQLite3Result->fetchArray().
Correction to a comment.
@HochMartinez
Copy link
Author

Hi Christoph,

I just pushed the new fix here:

HochMartinez:patch-2

It affects two files, Sqlite3.c and php_sqlite3_structs.h.

As I commented, the patch does not affect the error logic. It's a very simple fix, so all should work fine.

Thanks and greetings from Barcelona... :-)

@cmb69
Copy link
Member

cmb69 commented Apr 22, 2022

Thanks for the update! There are still failing tests; please check that.

@HochMartinez
Copy link
Author

Hi Christoph,

I can't see the relationship of the errors with the changes I made. I append the errors.

You have a lot more experience. Maybe you could check what happens.

As we commented the patch I submitted is very simple and, as far as I know, does not affect the error handling logic.

Greetings!

...............................................................................

========DIFF========
001+ B1::f()
001- Fatal error: Call to protected method B1::f() from scope B2 in %s on line %d
========DONE========
XFAIL Inconsistencies when accessing protected members [Zend/tests/access_modifiers_008.phpt] XFAIL REASON: Discussion: http://marc.info/?l=php-internals&m=120221184420957&w=2

========DIFF========
001+ bool(true)
001- bool(false)
002-
003- Fatal error: Call to protected method B1::f() from scope B2 in %s on line %d
========DONE========
XFAIL Inconsistencies when accessing protected members - 2 [Zend/tests/access_modifiers_009.phpt] XFAIL REASON: Discussion: http://marc.info/?l=php-internals&m=120221184420957&w=2

========DIFF========

Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d
bool(false)
016+
017+ Warning: unlink(): open_basedir restriction in effect. File(/home/runner/work/php-src/php-src/tests/security/test/ok/symlink.txt) is not within the allowed path(s): (.) in /home/runner/work/php-src/php-src/tests/security/open_basedir_linkinfo.php on line 26
018+ bool(false)
016- bool(true)
*** Finished testing open_basedir configuration [linkinfo] ***

@cmb69
Copy link
Member

cmb69 commented Apr 26, 2022

I'm referring to the 4 failing sqlite3 tests. These are likely caused by your changes.

@ramsey ramsey added this to the PHP 8.2 milestone May 22, 2022
@ramsey
Copy link
Member

ramsey commented May 22, 2022

@HochMartinez Have you been able to investigate the 4 failing sqlite3 tests that @cmb69 referenced?

@HochMartinez
Copy link
Author

HochMartinez commented May 22, 2022 via email

@ramsey
Copy link
Member

ramsey commented May 22, 2022

I’d love to get this patch into 8.2 so that it can help others. I hope you can find the time to add tests so we can merge this ahead of the first alpha release. Thanks!

@github-actions
Copy link

There has not been any recent activity in this PR. It will automatically be closed in 7 days if no further action is taken.

@github-actions github-actions bot added the Stale label Jul 22, 2022
@github-actions github-actions bot closed this Jul 30, 2022
@iluuu1994 iluuu1994 modified the milestones: PHP 8.2, PHP 8.1 Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants