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 <QStandardPaths>
|
||||
#include <QStringBuilder>
|
||||
#include <ranges>
|
||||
#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)
|
||||
{
|
||||
|
|
@ -174,6 +194,7 @@ INSERT INTO connection_parameter (connection_uuid, pname, pvalue)
|
|||
|
||||
QByteArray b64; // needs to stay in scope until query is executed
|
||||
SQLiteTransaction tx(db);
|
||||
|
||||
SQLitePreparedStatement stmt = db.Prepare(q_insert_or_replace_into_connection);
|
||||
stmt.Bind(1, cc.uuid().toString());
|
||||
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)
|
||||
VALUES(?1, ?2, ?3))__");
|
||||
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.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()];
|
||||
for (int i = 0; i < count; ++i) {
|
||||
QUuid uuid = grp->connections().at(row + i)->uuid();
|
||||
auto stmt = m_db.Prepare(
|
||||
"DELETE FROM connection "
|
||||
" WHERE uuid=?0");
|
||||
stmt.Bind(0, uuid.toString());
|
||||
stmt.Step();
|
||||
RemoveConnection(m_db, uuid);
|
||||
}
|
||||
beginRemoveRows(parent, row, row + count - 1);
|
||||
SCOPE_EXIT { endRemoveRows(); };
|
||||
|
|
@ -420,7 +442,7 @@ void ConnectionTreeModel::save(const QString &group_name, const ConnectionConfig
|
|||
grp->update(conn_idx, cc);
|
||||
// send change event
|
||||
auto node = grp->connections().at(conn_idx);
|
||||
dataChanged(
|
||||
emit dataChanged(
|
||||
createIndex(conn_idx, 0, node.get()),
|
||||
createIndex(conn_idx, ColCount-1, node.get()));
|
||||
saveToDb(*node);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue