Fix verwijderen connectie
This commit is contained in:
parent
fdf049a2a3
commit
2e516c9284
1 changed files with 29 additions and 7 deletions
|
|
@ -13,6 +13,7 @@
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
|
#include <ranges>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -164,6 +165,25 @@ INSERT INTO connection_parameter (connection_uuid, pname, pvalue)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void RemoveConnection(SQLiteConnection &db, QUuid uuid)
|
||||||
|
{
|
||||||
|
SQLiteTransaction tx(db);
|
||||||
|
|
||||||
|
auto stmt = db.Prepare(
|
||||||
|
"DELETE FROM connection_parameter "
|
||||||
|
" WHERE connection_uuid=?1");
|
||||||
|
stmt.Bind(1, uuid.toString());
|
||||||
|
stmt.Step();
|
||||||
|
|
||||||
|
stmt = db.Prepare(
|
||||||
|
"DELETE FROM connection "
|
||||||
|
" WHERE uuid=?1");
|
||||||
|
stmt.Bind(1, uuid.toString());
|
||||||
|
stmt.Step();
|
||||||
|
|
||||||
|
tx.Commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SaveConnectionConfig(SQLiteConnection &db, const ConnectionConfig &cc, int conngroup_id)
|
void SaveConnectionConfig(SQLiteConnection &db, const ConnectionConfig &cc, int conngroup_id)
|
||||||
{
|
{
|
||||||
|
|
@ -174,6 +194,7 @@ INSERT INTO connection_parameter (connection_uuid, pname, pvalue)
|
||||||
|
|
||||||
QByteArray b64; // needs to stay in scope until query is executed
|
QByteArray b64; // needs to stay in scope until query is executed
|
||||||
SQLiteTransaction tx(db);
|
SQLiteTransaction tx(db);
|
||||||
|
|
||||||
SQLitePreparedStatement stmt = db.Prepare(q_insert_or_replace_into_connection);
|
SQLitePreparedStatement stmt = db.Prepare(q_insert_or_replace_into_connection);
|
||||||
stmt.Bind(1, cc.uuid().toString());
|
stmt.Bind(1, cc.uuid().toString());
|
||||||
stmt.Bind(2, cc.name());
|
stmt.Bind(2, cc.name());
|
||||||
|
|
@ -195,7 +216,12 @@ INSERT INTO connection_parameter (connection_uuid, pname, pvalue)
|
||||||
R"__(INSERT INTO connection_parameter (connection_uuid, pname, pvalue)
|
R"__(INSERT INTO connection_parameter (connection_uuid, pname, pvalue)
|
||||||
VALUES(?1, ?2, ?3))__");
|
VALUES(?1, ?2, ?3))__");
|
||||||
const std::unordered_map<QString, QString>& params = cc.getParameters();
|
const std::unordered_map<QString, QString>& params = cc.getParameters();
|
||||||
for (auto && p : params)
|
for (auto && p : params | std::views::filter(
|
||||||
|
[] (auto ¶m)
|
||||||
|
{
|
||||||
|
// do not save unencrypted password
|
||||||
|
return param.first != "password";
|
||||||
|
}))
|
||||||
{
|
{
|
||||||
stmt.Reset();
|
stmt.Reset();
|
||||||
stmt.Bind(1, cc.uuid().toString());
|
stmt.Bind(1, cc.uuid().toString());
|
||||||
|
|
@ -396,11 +422,7 @@ bool ConnectionTreeModel::removeRows(int row, int count, const QModelIndex &pare
|
||||||
auto grp = m_groups[parent.row()];
|
auto grp = m_groups[parent.row()];
|
||||||
for (int i = 0; i < count; ++i) {
|
for (int i = 0; i < count; ++i) {
|
||||||
QUuid uuid = grp->connections().at(row + i)->uuid();
|
QUuid uuid = grp->connections().at(row + i)->uuid();
|
||||||
auto stmt = m_db.Prepare(
|
RemoveConnection(m_db, uuid);
|
||||||
"DELETE FROM connection "
|
|
||||||
" WHERE uuid=?0");
|
|
||||||
stmt.Bind(0, uuid.toString());
|
|
||||||
stmt.Step();
|
|
||||||
}
|
}
|
||||||
beginRemoveRows(parent, row, row + count - 1);
|
beginRemoveRows(parent, row, row + count - 1);
|
||||||
SCOPE_EXIT { endRemoveRows(); };
|
SCOPE_EXIT { endRemoveRows(); };
|
||||||
|
|
@ -420,7 +442,7 @@ void ConnectionTreeModel::save(const QString &group_name, const ConnectionConfig
|
||||||
grp->update(conn_idx, cc);
|
grp->update(conn_idx, cc);
|
||||||
// send change event
|
// send change event
|
||||||
auto node = grp->connections().at(conn_idx);
|
auto node = grp->connections().at(conn_idx);
|
||||||
dataChanged(
|
emit dataChanged(
|
||||||
createIndex(conn_idx, 0, node.get()),
|
createIndex(conn_idx, 0, node.get()),
|
||||||
createIndex(conn_idx, ColCount-1, node.get()));
|
createIndex(conn_idx, ColCount-1, node.get()));
|
||||||
saveToDb(*node);
|
saveToDb(*node);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue