diff --git a/libs/db/connection.cpp b/libs/db/connection.cpp --- a/libs/db/connection.cpp +++ b/libs/db/connection.cpp @@ -1248,6 +1248,8 @@ number = 0; QList subqueries_for_lookup_data; // subqueries will be added to FROM section QString kexidb_subquery_prefix("__kexidb_subquery_"); + QuerySchemaParameterValueListIterator paramValuesIt(driver, params); + QuerySchemaParameterValueListIterator *paramValuesItPtr = params.isEmpty() ? 0 : ¶mValuesIt; foreach(Field *f, *querySchema.fields()) { if (querySchema.isColumnVisible(number)) { if (!sql.isEmpty()) @@ -1261,7 +1263,7 @@ sql += QLatin1Char('*'); } else { if (f->isExpression()) { - sql += f->expression()->toString(driver); + sql += f->expression()->toString(driver, paramValuesItPtr); } else { if (!f->table()) //sanity check return QString(); @@ -1492,8 +1494,6 @@ } //EXPLICITLY SPECIFIED WHERE EXPRESSION if (querySchema.whereExpression()) { - QuerySchemaParameterValueListIterator paramValuesIt(driver, params); - QuerySchemaParameterValueListIterator *paramValuesItPtr = params.isEmpty() ? 0 : ¶mValuesIt; if (wasWhere) { //TODO: () are not always needed s_where = '(' + s_where + ") AND (" + querySchema.whereExpression()->toString(driver, paramValuesItPtr) + ')'; diff --git a/libs/db/parser/parser_p.cpp b/libs/db/parser/parser_p.cpp --- a/libs/db/parser/parser_p.cpp +++ b/libs/db/parser/parser_p.cpp @@ -362,7 +362,8 @@ || c == KexiDBExpr_Logical || c == KexiDBExpr_Relational || c == KexiDBExpr_Function - || c == KexiDBExpr_Aggregation; + || c == KexiDBExpr_Aggregation + || c == KexiDBExpr_QueryParameter; if (c == KexiDBExpr_Variable) { //just a variable, do nothing, addColumn() will handle this diff --git a/libs/db/queryschema.cpp b/libs/db/queryschema.cpp --- a/libs/db/queryschema.cpp +++ b/libs/db/queryschema.cpp @@ -1508,10 +1508,18 @@ QuerySchemaParameterList QuerySchema::parameters() { - if (!whereExpression()) - return QuerySchemaParameterList(); QuerySchemaParameterList params; - whereExpression()->getQueryParameters(params); + const QueryColumnInfo::Vector fieldsExpanded(this->fieldsExpanded()); + for (int i=0; i < fieldsExpanded.count(); ++i) { + const QueryColumnInfo *ci = fieldsExpanded[i]; + if (ci->field->expression()) { + ci->field->expression()->getQueryParameters(params); + } + } + BaseExpr *where = whereExpression(); + if (where) { + where->getQueryParameters(params); + } return params; }