summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2016-02-19 21:40:53 +0100
committerHaru <haru@dotalux.com>2016-03-20 18:32:07 +0100
commit127093b5327de343f4ae3f7c8752c465eea911c8 (patch)
treeaad51f53ba9bb8b99aa55a902ab1353a1937b403 /src/common
parentf4fced20c769ccee7f808531221dda481f7bbcca (diff)
downloadhercules-127093b5327de343f4ae3f7c8752c465eea911c8.tar.gz
hercules-127093b5327de343f4ae3f7c8752c465eea911c8.tar.bz2
hercules-127093b5327de343f4ae3f7c8752c465eea911c8.tar.xz
hercules-127093b5327de343f4ae3f7c8752c465eea911c8.zip
Changed buffer argument of SQL->StmtBindParam() to const
Parameters are supposed to be read-only Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/common')
-rw-r--r--src/common/sql.c19
-rw-r--r--src/common/sql.h2
2 files changed, 15 insertions, 6 deletions
diff --git a/src/common/sql.c b/src/common/sql.c
index 1dcf5d374..65960d8ea 100644
--- a/src/common/sql.c
+++ b/src/common/sql.c
@@ -629,7 +629,7 @@ size_t SqlStmt_NumParams(struct SqlStmt *self)
}
/// Binds a parameter to a buffer.
-int SqlStmt_BindParam(struct SqlStmt *self, size_t idx, enum SqlDataType buffer_type, void *buffer, size_t buffer_len)
+int SqlStmt_BindParam(struct SqlStmt *self, size_t idx, enum SqlDataType buffer_type, const void *buffer, size_t buffer_len)
{
if( self == NULL )
return SQL_ERROR;
@@ -650,10 +650,19 @@ int SqlStmt_BindParam(struct SqlStmt *self, size_t idx, enum SqlDataType buffer_
self->params[i].buffer_type = MYSQL_TYPE_NULL;
self->bind_params = true;
}
- if( idx < self->max_params )
- return Sql_P_BindSqlDataType(self->params+idx, buffer_type, buffer, buffer_len, NULL, NULL);
- else
- return SQL_SUCCESS;// out of range - ignore
+ if (idx >= self->max_params)
+ return SQL_SUCCESS; // out of range - ignore
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-qual"
+ /*
+ * MySQL uses the same struct with a non-const buffer for both
+ * parameters (input) and columns (output).
+ * As such, we get to close our eyes and pretend we didn't see we're
+ * dropping a const qualifier here.
+ */
+ return Sql_P_BindSqlDataType(self->params+idx, buffer_type, (void *)buffer, buffer_len, NULL, NULL);
+#pragma GCC diagnostic pop
}
/// Executes the prepared statement.
diff --git a/src/common/sql.h b/src/common/sql.h
index 3619895b1..07be829fc 100644
--- a/src/common/sql.h
+++ b/src/common/sql.h
@@ -209,7 +209,7 @@ struct sql_interface {
/// All parameters should have bindings.
///
/// @return SQL_SUCCESS or SQL_ERROR
- int (*StmtBindParam)(struct SqlStmt *self, size_t idx, enum SqlDataType buffer_type, void *buffer, size_t buffer_len);
+ int (*StmtBindParam)(struct SqlStmt *self, size_t idx, enum SqlDataType buffer_type, const void *buffer, size_t buffer_len);
/// Executes the prepared statement.
/// Any previous result is freed and all column bindings are removed.