mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Improvements for the "Unlock view editing" feature
Provide a combo box for selecting the field from the list of fields in the view. Uncheck the menu option when the user cancels the action. Escape the primary key in the UPDATE statements since it is not always rowid (views, without rowid tables) and consequently the name might needed it.
This commit is contained in:
@@ -2923,19 +2923,30 @@ void MainWindow::unlockViewEditing(bool unlock, QString pk)
|
||||
enableEditing(true);
|
||||
return;
|
||||
}
|
||||
sqlb::ViewPtr obj = db.getObjectByName(currentTable).dynamicCast<sqlb::View>();
|
||||
|
||||
// If the view gets unlocked for editing and we don't have a 'primary key' for this view yet, then ask for one
|
||||
if(unlock && pk.isEmpty())
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
bool ok;
|
||||
|
||||
// Ask for a PK
|
||||
pk = QInputDialog::getText(this, qApp->applicationName(), tr("Please enter a pseudo-primary key in order to enable editing on this view. "
|
||||
"This should be the name of a unique column in the view."));
|
||||
pk = QInputDialog::getItem(this,
|
||||
qApp->applicationName(),
|
||||
tr("Please enter a pseudo-primary key in order to enable editing on this view. "
|
||||
"This should be the name of a unique column in the view."),
|
||||
obj->fieldNames(),
|
||||
0,
|
||||
false,
|
||||
&ok);
|
||||
|
||||
// Cancelled?
|
||||
if(pk.isEmpty())
|
||||
if(!ok || pk.isEmpty()) {
|
||||
ui->actionUnlockViewEditing->setChecked(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Do some basic testing of the input and if the input appears to be good, go on
|
||||
if(db.executeSQL(QString("SELECT %1 FROM %2 LIMIT 1;").arg(sqlb::escapeIdentifier(pk)).arg(currentTable.toString()), false, true))
|
||||
|
||||
@@ -1144,7 +1144,7 @@ bool DBBrowserDB::updateRecord(const sqlb::ObjectIdentifier& table, const QStrin
|
||||
QString sql = QString("UPDATE %1 SET %2=? WHERE %3='%4';")
|
||||
.arg(table.toString())
|
||||
.arg(sqlb::escapeIdentifier(column))
|
||||
.arg(pk)
|
||||
.arg(sqlb::escapeIdentifier(pk))
|
||||
.arg(QString(rowid).replace("'", "''"));
|
||||
|
||||
logSQL(sql, kLogMsg_App);
|
||||
|
||||
Reference in New Issue
Block a user