Skip to content

Commit 61b76a7

Browse files
committed
Better error message on bindValue count missmatch
1 parent 197662f commit 61b76a7

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/connection.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ GameDataDBAsyncResult* Connection::pushAsyncQuery(game_state& gs, mariadb::conne
8585
[queryString, boundValues, result = gd_res->data, &gs](mariadb::connection_ref con) -> bool {
8686
try {
8787
auto statement = con->create_statement(queryString);
88+
89+
if (statement->get_bind_count() != boundValues.size()) {
90+
invoker_lock l;
91+
throwQueryError(gs, con, 2,
92+
r_string("Invalid number of bind values. Expected "sv)+std::to_string(statement->get_bind_count())+" got "sv+std::to_string(boundValues.size())
93+
, queryString);
94+
return false;
95+
}
8896
uint32_t idx = 0;
8997
for (auto& it : boundValues) {
9098

@@ -211,6 +219,14 @@ game_value Connection::cmd_execute(game_state& gs, game_value_parameter con, gam
211219
try {
212220
auto statement = session->create_statement(query->getQueryString());
213221

222+
if (statement->get_bind_count() != query->boundValues.size()) {
223+
invoker_lock l;
224+
throwQueryError(gs, session, 2,
225+
r_string("Invalid number of bind values. Expected "sv) + std::to_string(statement->get_bind_count()) + " got "sv + std::to_string(query->boundValues.size())
226+
, query->getQueryString());
227+
return {};
228+
}
229+
214230
uint32_t idx = 0;
215231
for (auto& it : query->boundValues) {
216232

0 commit comments

Comments
 (0)