Skip to content

Commit

Permalink
QueryHolder fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
fralx committed Oct 27, 2017
2 parents 00bc175 + 7cb5569 commit d47b842
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
2 changes: 1 addition & 1 deletion common.pri
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ RCC_DIR = $${ARCH_DIR}/$${BUILD_TYPE}/rcc

LIMEREPORT_VERSION_MAJOR = 1
LIMEREPORT_VERSION_MINOR = 4
LIMEREPORT_VERSION_RELEASE = 49
LIMEREPORT_VERSION_RELEASE = 51

LIMEREPORT_VERSION = '\\"$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}\\"'
DEFINES += LIMEREPORT_VERSION_STR=\"$${LIMEREPORT_VERSION}\"
Expand Down
28 changes: 10 additions & 18 deletions limereport/lrdatadesignintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ IDataSource * ModelHolder::dataSource(IDataSource::DatasourceMode mode)
}

QueryHolder::QueryHolder(QString queryText, QString connectionName, DataSourceManager *dataManager)
: m_query(0), m_queryText(queryText), m_connectionName(connectionName),
: m_queryText(queryText), m_connectionName(connectionName),
m_mode(IDataSource::RENDER_MODE), m_dataManager(dataManager), m_prepared(true)
{
extractParams();
}

QueryHolder::~QueryHolder()
{
if (m_query) delete m_query;
}
QueryHolder::~QueryHolder(){}

bool QueryHolder::runQuery(IDataSource::DatasourceMode mode)
{
m_mode = mode;

QSqlDatabase db = QSqlDatabase::database(m_connectionName);
QSqlQuery* query = new QSqlQuery(db);

if (!db.isValid()) {
setLastError(QObject::tr("Invalid connection! %1").arg(m_connectionName));
return false;
Expand All @@ -82,16 +82,13 @@ bool QueryHolder::runQuery(IDataSource::DatasourceMode mode)
if (!m_prepared) return false;
}

if (!m_query){
m_query = new QSqlQuery(db);
m_query->prepare(m_preparedSQL);
}
query->prepare(m_preparedSQL);

fillParams(m_query);
m_query->exec();
fillParams(query);
query->exec();

QSqlQueryModel *model = new QSqlQueryModel;
model->setQuery(*m_query);
model->setQuery(*query);

while (model->canFetchMore())
model->fetchMore();
Expand All @@ -102,7 +99,7 @@ bool QueryHolder::runQuery(IDataSource::DatasourceMode mode)
setLastError(model->lastError().text());
delete model;
return false;
} else setLastError("");
} else { setLastError("");}

setDatasource(IDataSource::Ptr(new ModelToDataSource(model,true)));
return true;
Expand All @@ -122,7 +119,6 @@ void QueryHolder::invalidate(IDataSource::DatasourceMode mode, bool dbWillBeClos
QSqlDatabase db = QSqlDatabase::database(m_connectionName);
if (!db.isValid() || dbWillBeClosed){
setLastError(QObject::tr("Invalid connection! %1").arg(m_connectionName));
delete m_query;
m_dataSource.clear();
} else {
runQuery(mode);
Expand Down Expand Up @@ -197,10 +193,6 @@ void QueryHolder::setQueryText(QString queryText)
{
m_queryText=queryText;
m_prepared = false;
if (m_query) {
delete m_query;
m_query = 0;
}
}

IDataSource* QueryHolder::dataSource(IDataSource::DatasourceMode mode)
Expand Down
3 changes: 1 addition & 2 deletions limereport/lrdatadesignintf.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class QueryHolder:public IDataSourceHolder{
bool isRemovable() const { return true; }
bool isPrepared() const {return m_prepared;}
QString lastError() const { return m_lastError; }
void setLastError(QString value){m_lastError=value; if (m_query) {delete m_query; m_query=0;}}
void setLastError(QString value){m_lastError=value;}
void invalidate(IDataSource::DatasourceMode mode, bool dbWillBeClosed = false);
void update();
void clearErrors(){setLastError("");}
Expand All @@ -211,7 +211,6 @@ class QueryHolder:public IDataSourceHolder{
virtual void extractParams();
QString replaceVariables(QString query);
QMap<QString,QString> m_aliasesToParam;
QSqlQuery* m_query;
QString m_preparedSQL;
private:
QString m_queryText;
Expand Down
2 changes: 1 addition & 1 deletion limereport/lrdatasourcemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ void DataSourceManager::disconnectConnection(const QString& connectionName)
if (isQuery(datasourceName) || isSubQuery(datasourceName)){
QueryHolder* qh = dynamic_cast<QueryHolder*>(dataSourceHolder(datasourceName));
if (qh && qh->connectionName().compare(connectionName,Qt::CaseInsensitive)==0){
qh->invalidate(designTime()?IDataSource::DESIGN_MODE:IDataSource::RENDER_MODE, true);
qh->invalidate(designTime()?IDataSource::DESIGN_MODE:IDataSource::RENDER_MODE);
qh->setLastError(tr("invalid connection"));
}
}
Expand Down

0 comments on commit d47b842

Please sign in to comment.