mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2025-09-23 08:39:07 +03:00
Parameter "nobind" has been added to variable
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
include(../common.pri)
|
||||
DEFINES+=HAVE_REPORT_DESIGNER
|
||||
|
||||
contains(CONFIG,dialogdesigner){
|
||||
|
@@ -77,10 +77,8 @@ bool QueryHolder::runQuery(IDataSource::DatasourceMode mode)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_prepared){
|
||||
extractParams();
|
||||
if (!m_prepared) return false;
|
||||
}
|
||||
extractParams();
|
||||
if (!m_prepared) return false;
|
||||
|
||||
query.prepare(m_preparedSQL);
|
||||
fillParams(&query);
|
||||
@@ -152,35 +150,13 @@ void QueryHolder::fillParams(QSqlQuery *query)
|
||||
|
||||
void QueryHolder::extractParams()
|
||||
{
|
||||
m_preparedSQL = replaceVariables(m_queryText);
|
||||
m_preparedSQL = dataManager()->replaceVariables(m_queryText, m_aliasesToParam);
|
||||
m_prepared = true;
|
||||
}
|
||||
|
||||
QString QueryHolder::replaceVariables(QString query)
|
||||
{
|
||||
QRegExp rx(Const::VARIABLE_RX);
|
||||
int curentAliasIndex = 0;
|
||||
if (query.contains(rx)){
|
||||
int pos = -1;
|
||||
while ((pos=rx.indexIn(query))!=-1){
|
||||
|
||||
QString variable=rx.cap(0);
|
||||
variable.remove("$V{");
|
||||
variable.remove("}");
|
||||
|
||||
if (m_aliasesToParam.contains(variable)){
|
||||
curentAliasIndex++;
|
||||
m_aliasesToParam.insert(variable+"_alias"+QString::number(curentAliasIndex),variable);
|
||||
variable += "_alias"+QString::number(curentAliasIndex);
|
||||
} else {
|
||||
m_aliasesToParam.insert(variable,variable);
|
||||
}
|
||||
|
||||
query.replace(pos,rx.cap(0).length(),":"+variable);
|
||||
|
||||
}
|
||||
}
|
||||
return query;
|
||||
return dataManager()->replaceVariables(query, m_aliasesToParam);
|
||||
}
|
||||
|
||||
QString QueryHolder::queryText()
|
||||
@@ -450,32 +426,7 @@ QString SubQueryHolder::extractField(QString source)
|
||||
|
||||
QString SubQueryHolder::replaceFields(QString query)
|
||||
{
|
||||
QRegExp rx(Const::FIELD_RX);
|
||||
int curentAliasIndex=0;
|
||||
if (query.contains(rx)){
|
||||
int pos;
|
||||
while ((pos=rx.indexIn(query))!=-1){
|
||||
QString field=rx.cap(0);
|
||||
field.remove("$D{");
|
||||
field.remove("}");
|
||||
|
||||
if (!m_aliasesToParam.contains(field)){
|
||||
if (field.contains("."))
|
||||
m_aliasesToParam.insert(field,field);
|
||||
else
|
||||
m_aliasesToParam.insert(field,m_masterDatasource+"."+field);
|
||||
} else {
|
||||
curentAliasIndex++;
|
||||
if (field.contains("."))
|
||||
m_aliasesToParam.insert(field+"_alias"+QString::number(curentAliasIndex),field);
|
||||
else
|
||||
m_aliasesToParam.insert(field+"_alias"+QString::number(curentAliasIndex),m_masterDatasource+"."+field);
|
||||
field+="_alias"+QString::number(curentAliasIndex);
|
||||
}
|
||||
query.replace(pos,rx.cap(0).length(),":"+extractField(field));
|
||||
}
|
||||
}
|
||||
return query;
|
||||
return dataManager()->replaceFields(query, m_aliasesToParam);
|
||||
}
|
||||
|
||||
SubQueryDesc::SubQueryDesc(QString queryName, QString queryText, QString connection, QString masterDatasourceName)
|
||||
|
@@ -450,17 +450,32 @@ QString DataSourceManager::replaceVariables(QString query, QMap<QString,QString>
|
||||
QString var=rx.cap(0);
|
||||
var.remove("$V{");
|
||||
var.remove("}");
|
||||
|
||||
if (aliasesToParam.contains(var)){
|
||||
curentAliasIndex++;
|
||||
aliasesToParam.insert(var+"_v_alias"+QString::number(curentAliasIndex),var);
|
||||
var += "_v_alias"+QString::number(curentAliasIndex);
|
||||
if (!rx.cap(1).isEmpty()){
|
||||
if (aliasesToParam.contains(var)){
|
||||
curentAliasIndex++;
|
||||
aliasesToParam.insert(var+"_v_alias"+QString::number(curentAliasIndex),var);
|
||||
var += "_v_alias"+QString::number(curentAliasIndex);
|
||||
} else {
|
||||
aliasesToParam.insert(var,var);
|
||||
}
|
||||
query.replace(pos,rx.cap(0).length(),":"+var);
|
||||
} else {
|
||||
aliasesToParam.insert(var,var);
|
||||
QString varName = rx.cap(2).trimmed();
|
||||
QString varParam = rx.cap(3).trimmed();
|
||||
if (!varName.isEmpty()){
|
||||
if (!varParam.isEmpty() && varParam.compare("nobind") == 0 ){
|
||||
query.replace(pos,rx.cap(0).length(), variable(varName).toString());
|
||||
} else {
|
||||
query.replace(pos,rx.cap(0).length(),
|
||||
QString(tr("Uknown parametr \"%1\" for variable \"%2\" found!")
|
||||
.arg(varName)
|
||||
.arg(varParam))
|
||||
);
|
||||
}
|
||||
} else {
|
||||
query.replace(pos,rx.cap(0).length(),QString(tr("Variable \"%1\" not found!").arg(var)));
|
||||
}
|
||||
}
|
||||
|
||||
query.replace(pos,rx.cap(0).length(),":"+var);
|
||||
|
||||
}
|
||||
}
|
||||
return query;
|
||||
@@ -1291,13 +1306,11 @@ void DataSourceManager::invalidateQueriesContainsVariable(const QString& variabl
|
||||
|
||||
void DataSourceManager::slotVariableHasBeenAdded(const QString& variableName)
|
||||
{
|
||||
//qDebug()<< "variable has been added"<< variableName;
|
||||
invalidateQueriesContainsVariable(variableName);
|
||||
}
|
||||
|
||||
void DataSourceManager::slotVariableHasBeenChanged(const QString& variableName)
|
||||
{
|
||||
//qDebug()<< "variable has been changed"<< variableName;
|
||||
invalidateQueriesContainsVariable(variableName);
|
||||
}
|
||||
|
||||
|
@@ -82,8 +82,8 @@ namespace Const{
|
||||
const qreal BAND_NAME_TEXT_OPACITY = 0.6;
|
||||
const qreal SELECTION_OPACITY = 0.3;
|
||||
const QString FIELD_RX = "\\$D\\s*\\{\\s*([^{}]*)\\s*\\}";
|
||||
const QString VARIABLE_RX = "\\$V\\s*\\{\\s*([^{}]*)\\s*\\}";
|
||||
const QString NAMED_VARIABLE_RX = "\\$V\\s*\\{\\s*(%1)\\s*\\}";
|
||||
const QString VARIABLE_RX = "\\$V\\s*\\{\\s*(?:([^\\{\\},]*)|(?:([^\\{\\}]*)\\s*,\\s*([^\\{\\}]*)))\\s*\\}";
|
||||
const QString NAMED_VARIABLE_RX = "\\$V\\s*\\{\\s*(?:(%1)|(?:(%1)\\s*,\\s*([^\\{\\}]*)))\\s*\\}";
|
||||
const QString SCRIPT_RX = "\\$S\\s*\\{(.*)\\}";
|
||||
const QString GROUP_FUNCTION_PARAM_RX = "\\(\\s*((?:(?:\\\")|(?:))(?:(?:\\$(?:(?:D\\{\\s*\\w*..*\\})|(?:V\\{\\s*\\w*\\s*\\})|(?:S\\{.+\\})))|(?:\\w*))(?:(?:\\\")|(?:)))(?:(?:\\s*,\\s*(?:\\\"(\\w*)\\\"))|(?:))(?:(?:\\s*,\\s*(?:(\\w*)))|(?:))\\)";
|
||||
const int DATASOURCE_INDEX = 3;
|
||||
@@ -94,6 +94,7 @@ namespace Const{
|
||||
const QString GROUP_FUNCTION_NAME_RX = "%1\\s*\\((.*[^\\)])\\)";
|
||||
const int SCENE_MARGIN = 50;
|
||||
const QString FUNCTION_MANAGER_NAME = "LimeReport";
|
||||
const QString DATAFUNCTIONS_MANAGER_NAME = "DatasourceFunctions";
|
||||
const QString EOW("~!@#$%^&*()+{}|:\"<>?,/;'[]\\-=");
|
||||
const int DEFAULT_TAB_INDENTION = 4;
|
||||
|
||||
|
Reference in New Issue
Block a user