mirror of
https://github.com/fralx/LimeReport.git
synced 2024-12-25 00:54:39 +03:00
LimeReport will not delete external connections
This commit is contained in:
parent
8659818a30
commit
8fb3fb5aba
@ -350,12 +350,14 @@ void ModelToDataSource::slotModelDestroed()
|
|||||||
|
|
||||||
ConnectionDesc::ConnectionDesc(QSqlDatabase db, QObject *parent)
|
ConnectionDesc::ConnectionDesc(QSqlDatabase db, QObject *parent)
|
||||||
: QObject(parent), m_connectionName(db.connectionName()), m_connectionHost(db.hostName()), m_connectionDriver(db.driverName()),
|
: QObject(parent), m_connectionName(db.connectionName()), m_connectionHost(db.hostName()), m_connectionDriver(db.driverName()),
|
||||||
m_databaseName(db.databaseName()), m_user(db.userName()), m_password(db.password()), m_autoconnect(false)
|
m_databaseName(db.databaseName()), m_user(db.userName()), m_password(db.password()), m_autoconnect(false),
|
||||||
|
m_internal(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
ConnectionDesc::ConnectionDesc(QObject *parent)
|
ConnectionDesc::ConnectionDesc(QObject *parent)
|
||||||
:QObject(parent),m_connectionName(""),m_connectionHost(""),m_connectionDriver(""),
|
:QObject(parent),m_connectionName(""),m_connectionHost(""),m_connectionDriver(""),
|
||||||
m_databaseName(""), m_user(""), m_password(""), m_autoconnect(false)
|
m_databaseName(""), m_user(""), m_password(""), m_autoconnect(false),
|
||||||
|
m_internal(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
ConnectionDesc::Ptr ConnectionDesc::create(QSqlDatabase db, QObject *parent)
|
ConnectionDesc::Ptr ConnectionDesc::create(QSqlDatabase db, QObject *parent)
|
||||||
|
@ -130,6 +130,8 @@ public:
|
|||||||
void setAutoconnect(bool value){m_autoconnect=value;}
|
void setAutoconnect(bool value){m_autoconnect=value;}
|
||||||
bool autoconnect(){return m_autoconnect;}
|
bool autoconnect(){return m_autoconnect;}
|
||||||
bool isEqual(const QSqlDatabase& db);
|
bool isEqual(const QSqlDatabase& db);
|
||||||
|
bool isInternal(){ return m_internal; }
|
||||||
|
void setInternal(bool value) {m_internal = value;}
|
||||||
signals:
|
signals:
|
||||||
void nameChanged(const QString& oldName,const QString& newName);
|
void nameChanged(const QString& oldName,const QString& newName);
|
||||||
private:
|
private:
|
||||||
@ -140,6 +142,7 @@ private:
|
|||||||
QString m_user;
|
QString m_user;
|
||||||
QString m_password;
|
QString m_password;
|
||||||
bool m_autoconnect;
|
bool m_autoconnect;
|
||||||
|
bool m_internal;
|
||||||
};
|
};
|
||||||
|
|
||||||
class IConnectionController{
|
class IConnectionController{
|
||||||
|
@ -620,13 +620,15 @@ void DataSourceManager::removeDatasource(const QString &name)
|
|||||||
emit datasourcesChanged();
|
emit datasourcesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataSourceManager::removeConnection(const QString &name)
|
void DataSourceManager::removeConnection(const QString &connectionName)
|
||||||
{
|
{
|
||||||
for(int i=0;i<m_connections.count();++i){
|
for(int i=0;i<m_connections.count();++i){
|
||||||
if (m_connections.at(i)->name()==name){
|
if (m_connections.at(i)->name()==connectionName){
|
||||||
QSqlDatabase db = QSqlDatabase::database(name);
|
if (m_connections.at(i)->isInternal()){
|
||||||
|
QSqlDatabase db = QSqlDatabase::database(connectionName);
|
||||||
db.close();
|
db.close();
|
||||||
QSqlDatabase::removeDatabase(name);
|
QSqlDatabase::removeDatabase(connectionName);
|
||||||
|
}
|
||||||
delete m_connections.at(i);
|
delete m_connections.at(i);
|
||||||
m_connections.removeAt(i);
|
m_connections.removeAt(i);
|
||||||
}
|
}
|
||||||
@ -654,9 +656,11 @@ void DataSourceManager::addConnectionDesc(ConnectionDesc * connection)
|
|||||||
bool DataSourceManager::checkConnectionDesc(ConnectionDesc *connection)
|
bool DataSourceManager::checkConnectionDesc(ConnectionDesc *connection)
|
||||||
{
|
{
|
||||||
if (connectConnection(connection)){
|
if (connectConnection(connection)){
|
||||||
|
if (connection->isInternal())
|
||||||
QSqlDatabase::removeDatabase(connection->name());
|
QSqlDatabase::removeDatabase(connection->name());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (connection->isInternal())
|
||||||
QSqlDatabase::removeDatabase(connection->name());
|
QSqlDatabase::removeDatabase(connection->name());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -721,6 +725,7 @@ bool DataSourceManager::initAndOpenDB(QSqlDatabase& db, ConnectionDesc& connecti
|
|||||||
}
|
}
|
||||||
|
|
||||||
connected=db.open();
|
connected=db.open();
|
||||||
|
connectionDesc.setInternal(true);
|
||||||
if (!connected) setLastError(db.lastError().text());
|
if (!connected) setLastError(db.lastError().text());
|
||||||
return connected;
|
return connected;
|
||||||
}
|
}
|
||||||
@ -760,18 +765,18 @@ bool DataSourceManager::connectConnection(ConnectionDesc *connectionDesc)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
QSqlDatabase db = QSqlDatabase::database(connectionDesc->name());
|
QSqlDatabase db = QSqlDatabase::database(connectionDesc->name());
|
||||||
if (!connectionDesc->isEqual(db)){
|
if (!connectionDesc->isEqual(db) && connectionDesc->isInternal()){
|
||||||
db.close();
|
db.close();
|
||||||
connected = initAndOpenDB(db, *connectionDesc);
|
connected = initAndOpenDB(db, *connectionDesc);
|
||||||
} else {
|
} else {
|
||||||
//connected = db.isOpen();
|
|
||||||
connected = checkConnection(db);
|
connected = checkConnection(db);
|
||||||
if (!connected)
|
if (!connected && connectionDesc->isInternal())
|
||||||
connected = initAndOpenDB(db, *connectionDesc);
|
connected = initAndOpenDB(db, *connectionDesc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!connected) {
|
if (!connected) {
|
||||||
|
if (connectionDesc->isInternal())
|
||||||
QSqlDatabase::removeDatabase(connectionDesc->name());
|
QSqlDatabase::removeDatabase(connectionDesc->name());
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
@ -884,11 +889,13 @@ void DataSourceManager::disconnectConnection(const QString& connectionName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
|
||||||
|
ConnectionDesc* connectionDesc = connectionByName(connectionName);
|
||||||
|
if (connectionDesc->isInternal()){
|
||||||
QSqlDatabase db = QSqlDatabase::database(connectionName);
|
QSqlDatabase db = QSqlDatabase::database(connectionName);
|
||||||
if (db.isOpen()) db.close();
|
if (db.isOpen()) db.close();
|
||||||
}
|
|
||||||
if (QSqlDatabase::contains(connectionName)) QSqlDatabase::removeDatabase(connectionName);
|
if (QSqlDatabase::contains(connectionName)) QSqlDatabase::removeDatabase(connectionName);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1185,6 +1192,7 @@ void DataSourceManager::clear(ClearMethod method)
|
|||||||
|
|
||||||
QList<ConnectionDesc*>::iterator cit = m_connections.begin();
|
QList<ConnectionDesc*>::iterator cit = m_connections.begin();
|
||||||
while( cit != m_connections.end() ){
|
while( cit != m_connections.end() ){
|
||||||
|
if ( (*cit)->isInternal() )
|
||||||
QSqlDatabase::removeDatabase( (*cit)->name() );
|
QSqlDatabase::removeDatabase( (*cit)->name() );
|
||||||
delete (*cit);
|
delete (*cit);
|
||||||
cit = m_connections.erase(cit);
|
cit = m_connections.erase(cit);
|
||||||
|
@ -131,7 +131,7 @@ public:
|
|||||||
QString queryText(const QString& dataSourceName);
|
QString queryText(const QString& dataSourceName);
|
||||||
QString connectionName(const QString& dataSourceName);
|
QString connectionName(const QString& dataSourceName);
|
||||||
void removeDatasource(const QString& name);
|
void removeDatasource(const QString& name);
|
||||||
void removeConnection(const QString& name);
|
void removeConnection(const QString& connectionName);
|
||||||
bool isQuery(const QString& dataSourceName);
|
bool isQuery(const QString& dataSourceName);
|
||||||
bool containsDatasource(const QString& dataSourceName);
|
bool containsDatasource(const QString& dataSourceName);
|
||||||
bool isSubQuery(const QString& dataSourceName);
|
bool isSubQuery(const QString& dataSourceName);
|
||||||
|
Loading…
Reference in New Issue
Block a user