Skip to content

Avoid query rerun. Closes: #13587 #13588

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/sqlite3/php_sqlite3_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ struct _php_sqlite3_result_object {
zend_string **column_names;

int is_prepared_statement;
int complete;
zend_object zo;
};

Expand Down
35 changes: 29 additions & 6 deletions ext/sqlite3/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,11 @@ PHP_METHOD(SQLite3, query)
return_code = sqlite3_step(result->stmt_obj->stmt);

switch (return_code) {
case SQLITE_ROW: /* Valid Row */
case SQLITE_DONE: /* Valid but no results */
{
result->complete = 1;
}
case SQLITE_ROW: /* Valid Row */
{
php_sqlite3_free_list *free_item;
free_item = emalloc(sizeof(php_sqlite3_free_list));
Expand All @@ -610,6 +613,7 @@ PHP_METHOD(SQLite3, query)
break;
}
default:
result->complete = 1;
if (!EG(exception)) {
php_sqlite3_error(db_obj, sqlite3_errcode(db_obj->db), "Unable to execute statement: %s", sqlite3_errmsg(db_obj->db));
}
Expand Down Expand Up @@ -700,6 +704,9 @@ PHP_METHOD(SQLite3, querySingle)
return_code = sqlite3_step(stmt);

switch (return_code) {
php_sqlite3_result *result_obj;
zval *object = ZEND_THIS;
result_obj = Z_SQLITE3_RESULT_P(object);
case SQLITE_ROW: /* Valid Row */
{
if (!entire_row) {
Expand All @@ -717,6 +724,8 @@ PHP_METHOD(SQLite3, querySingle)
}
case SQLITE_DONE: /* Valid but no results */
{
result_obj->complete = 1;

if (!entire_row) {
RETVAL_NULL();
} else {
Expand All @@ -725,6 +734,7 @@ PHP_METHOD(SQLite3, querySingle)
break;
}
default:
result_obj->complete = 1;
if (!EG(exception)) {
php_sqlite3_error(db_obj, sqlite3_errcode(db_obj->db), "Unable to execute statement: %s", sqlite3_errmsg(db_obj->db));
}
Expand Down Expand Up @@ -1798,14 +1808,16 @@ PHP_METHOD(SQLite3Stmt, execute)

return_code = sqlite3_step(stmt_obj->stmt);

sqlite3_reset(stmt_obj->stmt);
object_init_ex(return_value, php_sqlite3_result_entry);
result = Z_SQLITE3_RESULT_P(return_value);
switch (return_code) {
case SQLITE_ROW: /* Valid Row */
case SQLITE_DONE: /* Valid but no results */
{
result->complete = 1;
}
case SQLITE_ROW: /* Valid Row */
{
sqlite3_reset(stmt_obj->stmt);
object_init_ex(return_value, php_sqlite3_result_entry);
result = Z_SQLITE3_RESULT_P(return_value);

result->is_prepared_statement = 1;
result->db_obj = stmt_obj->db_obj;
result->stmt_obj = stmt_obj;
Expand All @@ -1816,9 +1828,11 @@ PHP_METHOD(SQLite3Stmt, execute)
break;
}
case SQLITE_ERROR:
result_obj->complete = 1;
sqlite3_reset(stmt_obj->stmt);
ZEND_FALLTHROUGH;
default:
result_obj->complete = 1;
if (!EG(exception)) {
php_sqlite3_error(stmt_obj->db_obj, sqlite3_errcode(sqlite3_db_handle(stmt_obj->stmt)), "Unable to execute statement: %s", sqlite3_errmsg(sqlite3_db_handle(stmt_obj->stmt)));
}
Expand Down Expand Up @@ -1886,6 +1900,10 @@ PHP_METHOD(SQLite3Result, numColumns)

SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result)

if (result_obj->complete) {
RETURN_FALSE;
}

RETURN_LONG(sqlite3_column_count(result_obj->stmt_obj->stmt));
}
/* }}} */
Expand Down Expand Up @@ -1953,6 +1971,10 @@ PHP_METHOD(SQLite3Result, fetchArray)

SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result)

if (result_obj->complete==1) {
return;
}

ret = sqlite3_step(result_obj->stmt_obj->stmt);
switch (ret) {
case SQLITE_ROW:
Expand Down Expand Up @@ -2006,6 +2028,7 @@ PHP_METHOD(SQLite3Result, fetchArray)
break;

default:
result_obj->complete = 1;
php_sqlite3_error(result_obj->db_obj, sqlite3_errcode(sqlite3_db_handle(result_obj->stmt_obj->stmt)), "Unable to execute statement: %s", sqlite3_errmsg(sqlite3_db_handle(result_obj->stmt_obj->stmt)));
}
}
Expand Down