mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 19:11:39 -06:00
Fix inserting into tables with multiple primary key columns
See issue #1834.
This commit is contained in:
@@ -112,7 +112,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
AddRecordDialog::AddRecordDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier& tableName, QWidget* parent, const QString &pseudo_pk)
|
||||
AddRecordDialog::AddRecordDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier& tableName, QWidget* parent, const std::vector<std::string>& pseudo_pk)
|
||||
: QDialog(parent),
|
||||
ui(new Ui::AddRecordDialog),
|
||||
pdb(db),
|
||||
@@ -184,7 +184,8 @@ void AddRecordDialog::populateFields()
|
||||
QStringList pk;
|
||||
|
||||
// Initialize fields, fks and pk differently depending on whether it's a table or a view.
|
||||
if (pseudo_pk.isNull())
|
||||
const sqlb::ObjectPtr obj = pdb.getObjectByName(curTable);
|
||||
if (obj->type() == sqlb::Object::Table)
|
||||
{
|
||||
sqlb::TablePtr m_table = pdb.getObjectByName<sqlb::Table>(curTable);
|
||||
fields = m_table->fields;
|
||||
@@ -195,7 +196,8 @@ void AddRecordDialog::populateFields()
|
||||
sqlb::ViewPtr m_view = pdb.getObjectByName<sqlb::View>(curTable);
|
||||
fields = m_view->fields;
|
||||
fks.fill(sqlb::ConstraintPtr(nullptr), fields.size());
|
||||
pk = QStringList(pseudo_pk);
|
||||
for(const auto& col : pseudo_pk)
|
||||
pk << QString::fromStdString(col);
|
||||
}
|
||||
|
||||
for(uint i = 0; i < fields.size(); i++)
|
||||
|
||||
@@ -19,7 +19,7 @@ class AddRecordDialog : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AddRecordDialog(DBBrowserDB& pdb, const sqlb::ObjectIdentifier& tableName, QWidget* parent = nullptr, const QString& pseudo_pk = QString());
|
||||
explicit AddRecordDialog(DBBrowserDB& pdb, const sqlb::ObjectIdentifier& tableName, QWidget* parent = nullptr, const std::vector<std::string>& pseudo_pk = {});
|
||||
~AddRecordDialog() override;
|
||||
|
||||
protected:
|
||||
@@ -46,7 +46,7 @@ private:
|
||||
Ui::AddRecordDialog* ui;
|
||||
DBBrowserDB& pdb;
|
||||
sqlb::ObjectIdentifier curTable;
|
||||
QString pseudo_pk;
|
||||
std::vector<std::string> pseudo_pk;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -967,7 +967,7 @@ void MainWindow::addRecord()
|
||||
|
||||
void MainWindow::insertValues()
|
||||
{
|
||||
QString pseudo_pk = m_browseTableModel->hasPseudoPk() ? QString::fromStdString(m_browseTableModel->pseudoPk().front()) : QString();
|
||||
std::vector<std::string> pseudo_pk = m_browseTableModel->hasPseudoPk() ? m_browseTableModel->pseudoPk() : std::vector<std::string>();
|
||||
AddRecordDialog dialog(db, currentlyBrowsedTableName(), this, pseudo_pk);
|
||||
if (dialog.exec())
|
||||
populateTable();
|
||||
|
||||
Reference in New Issue
Block a user