Skip to content

Commit e3ebdb6

Browse files
committed
Don't repeat yourself
SQLite3::bindParam() and SQLite3::bindValue() have identical implementation (the only thing that differs is the second parameter's passing mode), so we unify the implementation.
1 parent 107c1e0 commit e3ebdb6

File tree

1 file changed

+11
-35
lines changed

1 file changed

+11
-35
lines changed

ext/sqlite3/sqlite3.c

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,9 +1735,8 @@ static int register_bound_parameter_to_sqlite(struct php_sqlite3_bound_param *pa
17351735
}
17361736
/* }}} */
17371737

1738-
/* {{{ proto bool SQLite3Stmt::bindParam(int parameter_number, mixed parameter [, int type])
1739-
Bind Parameter to a stmt variable. */
1740-
PHP_METHOD(sqlite3stmt, bindParam)
1738+
/* {{{ Common implementation of ::bindParam() and ::bindValue */
1739+
static void sqlite3stmt_bind(INTERNAL_FUNCTION_PARAMETERS)
17411740
{
17421741
php_sqlite3_stmt *stmt_obj;
17431742
zval *object = ZEND_THIS;
@@ -1774,42 +1773,19 @@ PHP_METHOD(sqlite3stmt, bindParam)
17741773
}
17751774
/* }}} */
17761775

1776+
/* {{{ proto bool SQLite3Stmt::bindParam(int parameter_number, mixed parameter [, int type])
1777+
Bind Parameter to a stmt variable. */
1778+
PHP_METHOD(sqlite3stmt, bindParam)
1779+
{
1780+
sqlite3stmt_bind(INTERNAL_FUNCTION_PARAM_PASSTHRU);
1781+
}
1782+
/* }}} */
1783+
17771784
/* {{{ proto bool SQLite3Stmt::bindValue(int parameter_number, mixed parameter [, int type])
17781785
Bind Value of a parameter to a stmt variable. */
17791786
PHP_METHOD(sqlite3stmt, bindValue)
17801787
{
1781-
php_sqlite3_stmt *stmt_obj;
1782-
zval *object = ZEND_THIS;
1783-
struct php_sqlite3_bound_param param = {0};
1784-
zval *parameter;
1785-
stmt_obj = Z_SQLITE3_STMT_P(object);
1786-
1787-
param.param_number = -1;
1788-
param.type = SQLITE3_TEXT;
1789-
1790-
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "lz|l", &param.param_number, &parameter, &param.type) == FAILURE) {
1791-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz|l", &param.name, &parameter, &param.type) == FAILURE) {
1792-
return;
1793-
}
1794-
}
1795-
1796-
SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3);
1797-
SQLITE3_CHECK_INITIALIZED_STMT(stmt_obj->stmt, SQLite3Stmt);
1798-
1799-
ZVAL_COPY(&param.parameter, parameter);
1800-
1801-
if (ZEND_NUM_ARGS() < 3) {
1802-
PHP_SQLITE3_SET_TYPE(parameter, param);
1803-
}
1804-
1805-
if (!register_bound_parameter_to_sqlite(&param, stmt_obj)) {
1806-
if (!Z_ISUNDEF(param.parameter)) {
1807-
zval_ptr_dtor(&(param.parameter));
1808-
ZVAL_UNDEF(&param.parameter);
1809-
}
1810-
RETURN_FALSE;
1811-
}
1812-
RETURN_TRUE;
1788+
sqlite3stmt_bind(INTERNAL_FUNCTION_PARAM_PASSTHRU);
18131789
}
18141790
/* }}} */
18151791

0 commit comments

Comments
 (0)