diff options
| author | 2025-01-16 01:58:22 -0500 | |
|---|---|---|
| committer | 2025-01-16 01:58:22 -0500 | |
| commit | a5ae79be08125b31bb6b8d9703090a98c6fd2e30 (patch) | |
| tree | 569ee612c9de85b2bb423efa485688ef1d43852e /SQLiteStudio3/coreSQLiteStudio/plugins | |
| parent | 21966b4f924b0a1933d9662e75ff253bd154fdb7 (diff) | |
| parent | 81a21e6ce040e7740de86340c8ea4dba30e69bc3 (diff) | |
Update upstream source from tag 'upstream/3.4.13+dfsg'
Update to upstream version '3.4.13+dfsg'
with Debian dir bf81ee0219cb8e4562a4751df17d75814772d2d6
Diffstat (limited to 'SQLiteStudio3/coreSQLiteStudio/plugins')
| -rw-r--r-- | SQLiteStudio3/coreSQLiteStudio/plugins/scriptingsql.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/SQLiteStudio3/coreSQLiteStudio/plugins/scriptingsql.cpp b/SQLiteStudio3/coreSQLiteStudio/plugins/scriptingsql.cpp index 7edd7e7..47aabfc 100644 --- a/SQLiteStudio3/coreSQLiteStudio/plugins/scriptingsql.cpp +++ b/SQLiteStudio3/coreSQLiteStudio/plugins/scriptingsql.cpp @@ -3,6 +3,7 @@ #include "db/db.h" #include "db/sqlquery.h" #include "services/dbmanager.h" +#include "common/utils_sql.h" ScriptingSql::ScriptingSql() { @@ -58,7 +59,9 @@ QVariant ScriptingSql::evaluate(ScriptingPlugin::Context* context, const QString QString sql = code; if (ctx->variables.size() > 0) { - for (const QString& key : ctx->variables.keys()) + QList<QString> keys = ctx->variables.keys(); + std::sort(keys.begin(), keys.end(), std::greater<QString>()); + for (const QString& key : keys) { QString value = "'" + ctx->variables[key].toString() + "'"; sql.replace(":" + key, value).replace("@" + key, value).replace("$" + key, value); @@ -151,15 +154,26 @@ void ScriptingSql::deinit() void ScriptingSql::replaceNamedArgs(QString& sql, const ScriptingPlugin::FunctionInfo& funcInfo, const QList<QVariant>& args) { + // First build map of argName to its value in order in which arguments were passed to the function int i = 0; - for (const QString& key : funcInfo.getArguments()) + QStringList argNames = funcInfo.getArguments(); + QHash<QString, QString> argMap; + for (const QString& argName : argNames) { if (i >= args.size()) break; - QString value = "'" + args[i++].toString() + "'"; - sql.replace(":" + key, value) - .replace("@" + key, value) - .replace("$" + key, value); + argMap[argName] = valueToSqlLiteral(args[i++]); + } + + // Then sort arguments in alphabetically descending order, to prevent replacing shorter names first + // and proceed with argument substitutions + std::sort(argNames.begin(), argNames.end(), std::greater<QString>()); + for (const QString& argName : argNames) + { + QString value = argMap[argName]; + sql.replace(":" + argName, value) + .replace("@" + argName, value) + .replace("$" + argName, value); } } |
