diff --git a/common.pri b/common.pri index db77728..7d1aadf 100644 --- a/common.pri +++ b/common.pri @@ -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}\" diff --git a/limereport/lrdatadesignintf.cpp b/limereport/lrdatadesignintf.cpp index d33eda8..78f8ab2 100644 --- a/limereport/lrdatadesignintf.cpp +++ b/limereport/lrdatadesignintf.cpp @@ -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; @@ -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(); @@ -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; @@ -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); @@ -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) diff --git a/limereport/lrdatadesignintf.h b/limereport/lrdatadesignintf.h index 9910049..cafe60d 100644 --- a/limereport/lrdatadesignintf.h +++ b/limereport/lrdatadesignintf.h @@ -199,7 +199,7 @@ public: 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("");} @@ -211,7 +211,6 @@ protected: virtual void extractParams(); QString replaceVariables(QString query); QMap m_aliasesToParam; - QSqlQuery* m_query; QString m_preparedSQL; private: QString m_queryText; diff --git a/limereport/lrdatasourcemanager.cpp b/limereport/lrdatasourcemanager.cpp index 272c60b..436f35a 100644 --- a/limereport/lrdatasourcemanager.cpp +++ b/limereport/lrdatasourcemanager.cpp @@ -933,7 +933,7 @@ void DataSourceManager::disconnectConnection(const QString& connectionName) if (isQuery(datasourceName) || isSubQuery(datasourceName)){ QueryHolder* qh = dynamic_cast(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")); } }