Skip to content

Commit 9a77fec

Browse files
committed
Add an optional array parameter to SQLite3Stmt::execute() method, like in PDOStatement
1 parent 1ea8c82 commit 9a77fec

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

ext/sqlite3/sqlite3.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1762,18 +1762,60 @@ PHP_METHOD(SQLite3Stmt, execute)
17621762
php_sqlite3_stmt *stmt_obj;
17631763
php_sqlite3_result *result;
17641764
zval *object = ZEND_THIS;
1765+
zval *input_params = NULL;
17651766
int return_code = 0;
17661767
int bind_rc = 0;
17671768

17681769
stmt_obj = Z_SQLITE3_STMT_P(object);
17691770

1770-
ZEND_PARSE_PARAMETERS_NONE();
1771+
ZEND_PARSE_PARAMETERS_START(0, 1)
1772+
Z_PARAM_OPTIONAL
1773+
Z_PARAM_ARRAY_OR_NULL(input_params)
1774+
ZEND_PARSE_PARAMETERS_END();
17711775

17721776
SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3);
17731777

17741778
/* Always reset statement before execution, see bug #77051 */
17751779
sqlite3_reset(stmt_obj->stmt);
17761780

1781+
if (input_params) {
1782+
sqlite3_stmt
1783+
struct php_sqlite3_bound_param param = {0};
1784+
zval *parameter;
1785+
zval *tmp;
1786+
zend_string *key = NULL;
1787+
zend_ulong num_index;
1788+
1789+
if (stmt_obj->bound_params) {
1790+
zend_hash_destroy(stmt_obj->bound_params);
1791+
FREE_HASHTABLE(stmt_obj->bound_params);
1792+
stmt_obj->bound_params = NULL;
1793+
}
1794+
1795+
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(input_params), num_index, key, tmp) {
1796+
memset(&param, 0, sizeof(param));
1797+
1798+
param.param_number = -1;
1799+
param.type = SQLITE3_TEXT;
1800+
ZVAL_COPY(&param.parameter, tmp);
1801+
1802+
if (key) {
1803+
param.name = key;
1804+
} else {
1805+
/* for easier use, we are zero-based here */
1806+
param.param_number = num_index + 1;
1807+
}
1808+
1809+
if (!register_bound_parameter_to_sqlite(&param, stmt_obj)) {
1810+
if (!Z_ISUNDEF(param.parameter)) {
1811+
zval_ptr_dtor(&(param.parameter));
1812+
ZVAL_UNDEF(&param.parameter);
1813+
}
1814+
RETURN_FALSE;
1815+
}
1816+
} ZEND_HASH_FOREACH_END();
1817+
}
1818+
17771819
/* Bind parameters to the statement */
17781820
bind_rc = php_sqlite3_bind_params(stmt_obj);
17791821

ext/sqlite3/sqlite3.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ public function clear(): bool {}
363363
public function close(): bool {}
364364

365365
/** @tentative-return-type */
366-
public function execute(): SQLite3Result|false {}
366+
public function execute(?array $params = null): SQLite3Result|false {}
367367

368368
/** @tentative-return-type */
369369
public function getSQL(bool $expand = false): string|false {}

ext/sqlite3/sqlite3_arginfo.h

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)