From a5b034d4a9c44f9bc1e83b01de82530f8fc63013 Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Sat, 4 Apr 2015 14:41:04 -0400 Subject: Imported Upstream version 3.0.4 --- SQLiteStudio3/coreSQLiteStudio/db/abstractdb3.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'SQLiteStudio3/coreSQLiteStudio/db/abstractdb3.h') diff --git a/SQLiteStudio3/coreSQLiteStudio/db/abstractdb3.h b/SQLiteStudio3/coreSQLiteStudio/db/abstractdb3.h index 7a84ec2..9cb58aa 100644 --- a/SQLiteStudio3/coreSQLiteStudio/db/abstractdb3.h +++ b/SQLiteStudio3/coreSQLiteStudio/db/abstractdb3.h @@ -868,7 +868,8 @@ bool AbstractDb3::Query::execInternal(const QList& args) if (res != T::OK) return false; - for (int paramIdx = 1; paramIdx <= queryWithParams.second; paramIdx++) + + for (int paramIdx = 1, argCount = args.size(); paramIdx <= queryWithParams.second && paramIdx <= argCount; paramIdx++) { res = bindParam(paramIdx, args[paramIdx-1]); if (res != T::OK) @@ -906,16 +907,25 @@ bool AbstractDb3::Query::execInternal(const QHash& args) if (res != T::OK) return false; - int paramIdx = 1; - foreach (const QString& paramName, queryWithParams.second) + int paramIdx = -1; + for (const QString& paramName : queryWithParams.second) { if (!args.contains(paramName)) { + qWarning() << "Could not bind parameter" << paramName << "because it was not found in passed arguments."; + setError(SqlErrorCode::OTHER_EXECUTION_ERROR, "Error while preparing statement: could not bind parameter " + paramName); + return false; + } + + paramIdx = T::bind_parameter_index(stmt, paramName.toUtf8().constData()); + if (paramIdx <= 0) + { + qWarning() << "Could not bind parameter" << paramName << "because it was not found in prepared statement."; setError(SqlErrorCode::OTHER_EXECUTION_ERROR, "Error while preparing statement: could not bind parameter " + paramName); return false; } - res = bindParam(paramIdx++, args[paramName]); + res = bindParam(paramIdx, args[paramName]); if (res != T::OK) { db->extractLastError(); -- cgit v1.2.3