diff --git a/UPGRADING b/UPGRADING index 26c87d7aeb795..c0302b40a02a5 100644 --- a/UPGRADING +++ b/UPGRADING @@ -390,6 +390,10 @@ PHP 8.5 UPGRADE NOTES . ReflectionConstant::getAttributes() was introduced. RFC: https://wiki.php.net/rfc/attributes-on-constants +- Sqlite: + . Sqlite3Stmt::busy to check if a statement had been fetched + but not completely. + - Standard: . Added array_first() and array_last(). RFC: https://wiki.php.net/rfc/array_first_last diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index 1396e693d9955..3b0811ccd7d2c 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -1479,6 +1479,23 @@ PHP_METHOD(SQLite3Stmt, readOnly) } /* }}} */ +PHP_METHOD(SQLite3Stmt, busy) +{ + php_sqlite3_stmt *stmt_obj; + zval *object = ZEND_THIS; + stmt_obj = Z_SQLITE3_STMT_P(object); + + ZEND_PARSE_PARAMETERS_NONE(); + + SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3); + SQLITE3_CHECK_INITIALIZED_STMT(stmt_obj->stmt, SQLite3Stmt); + + if (sqlite3_stmt_busy(stmt_obj->stmt)) { + RETURN_TRUE; + } + RETURN_FALSE; +} + /* bind parameters to a statement before execution */ static int php_sqlite3_bind_params(php_sqlite3_stmt *stmt_obj) /* {{{ */ { diff --git a/ext/sqlite3/sqlite3.stub.php b/ext/sqlite3/sqlite3.stub.php index 3545da36acfcd..8a3d90470767a 100644 --- a/ext/sqlite3/sqlite3.stub.php +++ b/ext/sqlite3/sqlite3.stub.php @@ -272,6 +272,8 @@ public function readOnly(): bool {} /** @tentative-return-type */ public function reset(): bool {} + + public function busy(): bool {} } /** @not-serializable */ diff --git a/ext/sqlite3/sqlite3_arginfo.h b/ext/sqlite3/sqlite3_arginfo.h index 654e25edead6c..f83188841b43f 100644 --- a/ext/sqlite3/sqlite3_arginfo.h +++ b/ext/sqlite3/sqlite3_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: edf910997672a2b8d8b5c25e8a7a4ff1c135e7b1 */ + * Stub hash: 28132e0e4df61f19dc4b23a7c9f79be6b3e40a8e */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3___construct, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) @@ -144,6 +144,9 @@ ZEND_END_ARG_INFO() #define arginfo_class_SQLite3Stmt_reset arginfo_class_SQLite3_close +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_SQLite3Stmt_busy, 0, 0, _IS_BOOL, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3Result___construct, 0, 0, 0) ZEND_END_ARG_INFO() @@ -202,6 +205,7 @@ ZEND_METHOD(SQLite3Stmt, getSQL); ZEND_METHOD(SQLite3Stmt, paramCount); ZEND_METHOD(SQLite3Stmt, readOnly); ZEND_METHOD(SQLite3Stmt, reset); +ZEND_METHOD(SQLite3Stmt, busy); ZEND_METHOD(SQLite3Result, __construct); ZEND_METHOD(SQLite3Result, numColumns); ZEND_METHOD(SQLite3Result, columnName); @@ -253,6 +257,7 @@ static const zend_function_entry class_SQLite3Stmt_methods[] = { ZEND_ME(SQLite3Stmt, paramCount, arginfo_class_SQLite3Stmt_paramCount, ZEND_ACC_PUBLIC) ZEND_ME(SQLite3Stmt, readOnly, arginfo_class_SQLite3Stmt_readOnly, ZEND_ACC_PUBLIC) ZEND_ME(SQLite3Stmt, reset, arginfo_class_SQLite3Stmt_reset, ZEND_ACC_PUBLIC) + ZEND_ME(SQLite3Stmt, busy, arginfo_class_SQLite3Stmt_busy, ZEND_ACC_PUBLIC) ZEND_FE_END }; diff --git a/ext/sqlite3/tests/sqlite3_stmt_busy.phpt b/ext/sqlite3/tests/sqlite3_stmt_busy.phpt new file mode 100644 index 0000000000000..8110d374afe68 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_stmt_busy.phpt @@ -0,0 +1,24 @@ +--TEST-- +SQLite3_stmt::busy +--EXTENSIONS-- +sqlite3 +--SKIPIF-- + +--FILE-- +exec('CREATE TABLE test_busy (a string);'); +$db->exec('INSERT INTO test_busy VALUES ("interleaved"), ("statements")'); +$st = $db->prepare('SELECT a FROM test_busy'); +var_dump($st->busy()); +$r = $st->execute(); +$r->fetchArray(); +var_dump($st->busy()); +?> +--EXPECT-- +bool(false) +bool(true)