0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 00:33:02 +03:00

QueryHolder fixed

This commit is contained in:
Arin Alexander 2017-10-27 22:58:10 +03:00
commit 23641333da
4 changed files with 13 additions and 22 deletions

View File

@ -70,7 +70,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}\\\"

View File

@ -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)

View File

@ -200,7 +200,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("");}
@ -212,7 +212,6 @@ protected:
virtual void extractParams();
QString replaceVariables(QString query);
QMap<QString,QString> m_aliasesToParam;
QSqlQuery* m_query;
QString m_preparedSQL;
private:
QString m_queryText;

View File

@ -935,7 +935,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"));
}
}