Problems with WITHOUT ROWID tables with PK of string type (#1559)

* Problems with WITHOUT ROWID tables with PK of string type

This fixes two related problems:
- When the PK is updated the hidden column 0 must be updated too,
  otherwise any further editing of the same row before a table refresh is
  broken.
- When a new record is inserted and the PK has string type we cannot
  simply make a pseudo auto-increment and insert that value as rowid
  because that added key would be impossible to update because our
  UPDATE clause will try to update a column with a string and it contains
  an integer. In this case it's better to let the user enter the PK value,
  so the new Add Record dialog is directly invoked.

See issue #1332 and (tangentially) #1049. The first should be fixed now.
The later not, but at least there is now a workaround: removing the
AUTOINCREMENT option and use the WITHOUT ROWID one.

* Problems with WITHOUT ROWID tables with PK of string type (alternative 2)

Update after review:

- cached_row is not modified after unlock();

- Alternative solution to initial key value insertion:
  When a new record is inserted and the PK has string type we still make a
  pseudo auto-increment and insert that value as a string literal. In this
  way we can later update that row. When we inserted it as integer an
  actual integer will be inserted by SQLite, and our UPDATE clause, which
  always uses string in the WHERE condition, won't match the row (SQLite
  does not convert to integer when the column is of type string in this
  context).

See issue #1332.
This commit is contained in:
Manuel
2018-10-09 22:37:27 +02:00
committed by Martin Kleusberg
parent fb1eba1391
commit 16ba6db2dc
3 changed files with 12 additions and 3 deletions

View File

@@ -775,6 +775,7 @@ void MainWindow::closeEvent( QCloseEvent* event )
void MainWindow::addRecord()
{
int row = m_browseTableModel->rowCount();
if(m_browseTableModel->insertRow(row))
{
selectTableLine(row);