diff options
| author | 2015-04-04 14:41:04 -0400 | |
|---|---|---|
| committer | 2015-04-04 14:41:04 -0400 | |
| commit | a5b034d4a9c44f9bc1e83b01de82530f8fc63013 (patch) | |
| tree | 7a358206c4aff9c33df1752c92eafec97cee2244 /SQLiteStudio3/coreSQLiteStudio/db/abstractdb3.h | |
| parent | 306d6d3ca9c9ad774d19135681a7f9805f77035f (diff) | |
Imported Upstream version 3.0.4upstream/3.0.4
Diffstat (limited to 'SQLiteStudio3/coreSQLiteStudio/db/abstractdb3.h')
| -rw-r--r-- | SQLiteStudio3/coreSQLiteStudio/db/abstractdb3.h | 18 |
1 files changed, 14 insertions, 4 deletions
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<T>::Query::execInternal(const QList<QVariant>& 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<T>::Query::execInternal(const QHash<QString, QVariant>& 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(); |
