com php-src: Don't repeat yourself: ext/sqlite3/sqlite3.c
| From: | Christoph Michael Becker | Date: | Thu, 15 Aug 2019 11:10:53 +0000 |
| Subject: | com php-src: Don't repeat yourself: ext/sqlite3/sqlite3.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-107933@lists.php.net to get a copy of this message | ||
Commit: e3ebdb6be2adac499e5d801bda10294710f46d3d
Author: Christoph M. Becker <cmbecker69@gmx.de> Thu, 15 Aug 2019 13:09:52 +0200
Parents: 107c1e0c1bc1cc2acdd904ffaff563ae4d021ef7
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=e3ebdb6be2adac499e5d801bda10294710f46d3d
Log:
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.
Changed paths:
M ext/sqlite3/sqlite3.c
Diff:
diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c
index 9f68a34..b968246 100644
--- a/ext/sqlite3/sqlite3.c
+++ b/ext/sqlite3/sqlite3.c
@@ -1735,9 +1735,8 @@ static int register_bound_parameter_to_sqlite(struct php_sqlite3_bound_param
*pa
}
/* }}} */
-/* {{{ proto bool SQLite3Stmt::bindParam(int parameter_number, mixed parameter [, int type])
- Bind Parameter to a stmt variable. */
-PHP_METHOD(sqlite3stmt, bindParam)
+/* {{{ Common implementation of ::bindParam() and ::bindValue */
+static void sqlite3stmt_bind(INTERNAL_FUNCTION_PARAMETERS)
{
php_sqlite3_stmt *stmt_obj;
zval *object = ZEND_THIS;
@@ -1774,42 +1773,19 @@ PHP_METHOD(sqlite3stmt, bindParam)
}
/* }}} */
+/* {{{ proto bool SQLite3Stmt::bindParam(int parameter_number, mixed parameter [, int type])
+ Bind Parameter to a stmt variable.. */
+PHP_METHOD(sqlite3stmt, bindParam)
+{
+ sqlite3stmt_bind(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
/* {{{ proto bool SQLite3Stmt::bindValue(int parameter_number, mixed parameter [, int type])
Bind Value of a parameter to a stmt variable. */
PHP_METHOD(sqlite3stmt, bindValue)
{
- php_sqlite3_stmt *stmt_obj;
- zval *object = ZEND_THIS;
- struct php_sqlite3_bound_param param = {0};
- zval *parameter;
- stmt_obj = Z_SQLITE3_STMT_P(object);
-
- param.param_number = -1;
- param.type = SQLITE3_TEXT;
-
- if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "lz|l",
¶m.param_number, ¶meter, ¶m.type) == FAILURE) {
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz|l", ¶m.name, ¶meter,
¶m.type) == FAILURE) {
- return;
- }
- }
-
- SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3);
- SQLITE3_CHECK_INITIALIZED_STMT(stmt_obj->stmt, SQLite3Stmt);
-
- ZVAL_COPY(¶m.parameter, parameter);
-
- if (ZEND_NUM_ARGS() < 3) {
- PHP_SQLITE3_SET_TYPE(parameter, param);
- }
-
- if (!register_bound_parameter_to_sqlite(¶m, stmt_obj)) {
- if (!Z_ISUNDEF(param.parameter)) {
- zval_ptr_dtor(&(param.parameter));
- ZVAL_UNDEF(¶m.parameter);
- }
- RETURN_FALSE;
- }
- RETURN_TRUE;
+ sqlite3stmt_bind(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
/* }}} */