mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2024-12-25 13:04:38 +03:00
QueryHolder fixed
This commit is contained in:
commit
d47b84235e
@ -62,7 +62,7 @@ RCC_DIR = $${ARCH_DIR}/$${BUILD_TYPE}/rcc
|
|||||||
|
|
||||||
LIMEREPORT_VERSION_MAJOR = 1
|
LIMEREPORT_VERSION_MAJOR = 1
|
||||||
LIMEREPORT_VERSION_MINOR = 4
|
LIMEREPORT_VERSION_MINOR = 4
|
||||||
LIMEREPORT_VERSION_RELEASE = 49
|
LIMEREPORT_VERSION_RELEASE = 51
|
||||||
|
|
||||||
LIMEREPORT_VERSION = '\\"$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}\\"'
|
LIMEREPORT_VERSION = '\\"$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}\\"'
|
||||||
DEFINES += LIMEREPORT_VERSION_STR=\"$${LIMEREPORT_VERSION}\"
|
DEFINES += LIMEREPORT_VERSION_STR=\"$${LIMEREPORT_VERSION}\"
|
||||||
|
@ -57,21 +57,21 @@ IDataSource * ModelHolder::dataSource(IDataSource::DatasourceMode mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QueryHolder::QueryHolder(QString queryText, QString connectionName, DataSourceManager *dataManager)
|
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)
|
m_mode(IDataSource::RENDER_MODE), m_dataManager(dataManager), m_prepared(true)
|
||||||
{
|
{
|
||||||
extractParams();
|
extractParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryHolder::~QueryHolder()
|
QueryHolder::~QueryHolder(){}
|
||||||
{
|
|
||||||
if (m_query) delete m_query;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QueryHolder::runQuery(IDataSource::DatasourceMode mode)
|
bool QueryHolder::runQuery(IDataSource::DatasourceMode mode)
|
||||||
{
|
{
|
||||||
m_mode = mode;
|
m_mode = mode;
|
||||||
|
|
||||||
QSqlDatabase db = QSqlDatabase::database(m_connectionName);
|
QSqlDatabase db = QSqlDatabase::database(m_connectionName);
|
||||||
|
QSqlQuery* query = new QSqlQuery(db);
|
||||||
|
|
||||||
if (!db.isValid()) {
|
if (!db.isValid()) {
|
||||||
setLastError(QObject::tr("Invalid connection! %1").arg(m_connectionName));
|
setLastError(QObject::tr("Invalid connection! %1").arg(m_connectionName));
|
||||||
return false;
|
return false;
|
||||||
@ -82,16 +82,13 @@ bool QueryHolder::runQuery(IDataSource::DatasourceMode mode)
|
|||||||
if (!m_prepared) return false;
|
if (!m_prepared) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_query){
|
query->prepare(m_preparedSQL);
|
||||||
m_query = new QSqlQuery(db);
|
|
||||||
m_query->prepare(m_preparedSQL);
|
|
||||||
}
|
|
||||||
|
|
||||||
fillParams(m_query);
|
fillParams(query);
|
||||||
m_query->exec();
|
query->exec();
|
||||||
|
|
||||||
QSqlQueryModel *model = new QSqlQueryModel;
|
QSqlQueryModel *model = new QSqlQueryModel;
|
||||||
model->setQuery(*m_query);
|
model->setQuery(*query);
|
||||||
|
|
||||||
while (model->canFetchMore())
|
while (model->canFetchMore())
|
||||||
model->fetchMore();
|
model->fetchMore();
|
||||||
@ -102,7 +99,7 @@ bool QueryHolder::runQuery(IDataSource::DatasourceMode mode)
|
|||||||
setLastError(model->lastError().text());
|
setLastError(model->lastError().text());
|
||||||
delete model;
|
delete model;
|
||||||
return false;
|
return false;
|
||||||
} else setLastError("");
|
} else { setLastError("");}
|
||||||
|
|
||||||
setDatasource(IDataSource::Ptr(new ModelToDataSource(model,true)));
|
setDatasource(IDataSource::Ptr(new ModelToDataSource(model,true)));
|
||||||
return true;
|
return true;
|
||||||
@ -122,7 +119,6 @@ void QueryHolder::invalidate(IDataSource::DatasourceMode mode, bool dbWillBeClos
|
|||||||
QSqlDatabase db = QSqlDatabase::database(m_connectionName);
|
QSqlDatabase db = QSqlDatabase::database(m_connectionName);
|
||||||
if (!db.isValid() || dbWillBeClosed){
|
if (!db.isValid() || dbWillBeClosed){
|
||||||
setLastError(QObject::tr("Invalid connection! %1").arg(m_connectionName));
|
setLastError(QObject::tr("Invalid connection! %1").arg(m_connectionName));
|
||||||
delete m_query;
|
|
||||||
m_dataSource.clear();
|
m_dataSource.clear();
|
||||||
} else {
|
} else {
|
||||||
runQuery(mode);
|
runQuery(mode);
|
||||||
@ -197,10 +193,6 @@ void QueryHolder::setQueryText(QString queryText)
|
|||||||
{
|
{
|
||||||
m_queryText=queryText;
|
m_queryText=queryText;
|
||||||
m_prepared = false;
|
m_prepared = false;
|
||||||
if (m_query) {
|
|
||||||
delete m_query;
|
|
||||||
m_query = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IDataSource* QueryHolder::dataSource(IDataSource::DatasourceMode mode)
|
IDataSource* QueryHolder::dataSource(IDataSource::DatasourceMode mode)
|
||||||
|
@ -199,7 +199,7 @@ public:
|
|||||||
bool isRemovable() const { return true; }
|
bool isRemovable() const { return true; }
|
||||||
bool isPrepared() const {return m_prepared;}
|
bool isPrepared() const {return m_prepared;}
|
||||||
QString lastError() const { return m_lastError; }
|
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 invalidate(IDataSource::DatasourceMode mode, bool dbWillBeClosed = false);
|
||||||
void update();
|
void update();
|
||||||
void clearErrors(){setLastError("");}
|
void clearErrors(){setLastError("");}
|
||||||
@ -211,7 +211,6 @@ protected:
|
|||||||
virtual void extractParams();
|
virtual void extractParams();
|
||||||
QString replaceVariables(QString query);
|
QString replaceVariables(QString query);
|
||||||
QMap<QString,QString> m_aliasesToParam;
|
QMap<QString,QString> m_aliasesToParam;
|
||||||
QSqlQuery* m_query;
|
|
||||||
QString m_preparedSQL;
|
QString m_preparedSQL;
|
||||||
private:
|
private:
|
||||||
QString m_queryText;
|
QString m_queryText;
|
||||||
|
@ -933,7 +933,7 @@ void DataSourceManager::disconnectConnection(const QString& connectionName)
|
|||||||
if (isQuery(datasourceName) || isSubQuery(datasourceName)){
|
if (isQuery(datasourceName) || isSubQuery(datasourceName)){
|
||||||
QueryHolder* qh = dynamic_cast<QueryHolder*>(dataSourceHolder(datasourceName));
|
QueryHolder* qh = dynamic_cast<QueryHolder*>(dataSourceHolder(datasourceName));
|
||||||
if (qh && qh->connectionName().compare(connectionName,Qt::CaseInsensitive)==0){
|
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"));
|
qh->setLastError(tr("invalid connection"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user