Skip to content

Commit 058c034

Browse files
committed
ext/sqlite3: adding busy() call.
checks if the prepared statement had been fetched but did not complete yet. close GH-18843
1 parent 71a2544 commit 058c034

File tree

6 files changed

+57
-1
lines changed

6 files changed

+57
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ PHP NEWS
240240
. Fix overall theorical overflows on zend_string buffer allocations.
241241
(David Carlier/nielsdos)
242242

243+
- Sqlite:
244+
. Added Sqlite3Stmt::busy to check if a statement is still being executed.
245+
(David Carlier)
246+
243247
- Standard:
244248
. Fixed crypt() tests on musl when using --with-external-libcrypt
245249
(Michael Orlitzky).

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,10 @@ PHP 8.5 UPGRADE NOTES
393393
. ReflectionConstant::getAttributes() was introduced.
394394
RFC: https://wiki.php.net/rfc/attributes-on-constants
395395

396+
- Sqlite:
397+
. Sqlite3Stmt::busy to check if a statement had been fetched
398+
but not completely.
399+
396400
- Standard:
397401
. Added array_first() and array_last().
398402
RFC: https://wiki.php.net/rfc/array_first_last

ext/sqlite3/sqlite3.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,23 @@ PHP_METHOD(SQLite3Stmt, readOnly)
14791479
}
14801480
/* }}} */
14811481

1482+
PHP_METHOD(SQLite3Stmt, busy)
1483+
{
1484+
php_sqlite3_stmt *stmt_obj;
1485+
zval *object = ZEND_THIS;
1486+
stmt_obj = Z_SQLITE3_STMT_P(object);
1487+
1488+
ZEND_PARSE_PARAMETERS_NONE();
1489+
1490+
SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3);
1491+
SQLITE3_CHECK_INITIALIZED_STMT(stmt_obj->stmt, SQLite3Stmt);
1492+
1493+
if (sqlite3_stmt_busy(stmt_obj->stmt)) {
1494+
RETURN_TRUE;
1495+
}
1496+
RETURN_FALSE;
1497+
}
1498+
14821499
/* bind parameters to a statement before execution */
14831500
static int php_sqlite3_bind_params(php_sqlite3_stmt *stmt_obj) /* {{{ */
14841501
{

ext/sqlite3/sqlite3.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ public function readOnly(): bool {}
272272

273273
/** @tentative-return-type */
274274
public function reset(): bool {}
275+
276+
public function busy(): bool {}
275277
}
276278

277279
/** @not-serializable */

ext/sqlite3/sqlite3_arginfo.h

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
SQLite3_stmt::busy
3+
--EXTENSIONS--
4+
sqlite3
5+
--SKIPIF--
6+
<?php
7+
$version = SQLite3::version();
8+
if ($version['versionNumber'] < 3007004) die("skip");
9+
?>
10+
--FILE--
11+
<?php
12+
13+
require_once(__DIR__ . '/new_db.inc');
14+
$db->exec('CREATE TABLE test_busy (a string);');
15+
$db->exec('INSERT INTO test_busy VALUES ("interleaved"), ("statements")');
16+
$st = $db->prepare('SELECT a FROM test_busy');
17+
var_dump($st->busy());
18+
$r = $st->execute();
19+
$r->fetchArray();
20+
var_dump($st->busy());
21+
?>
22+
--EXPECT--
23+
bool(false)
24+
bool(true)

0 commit comments

Comments
 (0)