Fix behaviour of triggers when logging an existing layer

When adding logging via db manager to an existing layer, all the
time_start of existing features are still null. When we modify one
feature for the first time, the update trigger fires and insert a row
for the past state of the feature. In turn, this fires the INSERT
trigger for this row, and the execution goes inside the `if
NEW.time_start is NULL`, which set the end timestamp to NULL, making the
old row still visible in the _current view.

In other word, the insert trigger makes the assumption that a null start
timestamp means now, which is not true in the case described above.

This commit fixes this assumption by initially setting it to `-infinity`
for existing rows.
This commit is contained in:
Augustin Trancart 2021-08-26 16:31:12 +02:00 committed by Nyall Dawson
parent 9e37db3836
commit 061b810dac
2 changed files with 2 additions and 2 deletions

View File

@ -19,7 +19,7 @@
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Table should be empty, with a primary key</string>
<string>Table should have a primary key</string>
</property>
</widget>
</item>

View File

@ -175,7 +175,7 @@ class DlgVersioning(QDialog, Ui_DlgVersioning):
QMessageBox.information(self, "Help", helpText)
def sql_alterTable(self):
return u"ALTER TABLE %s ADD %s serial, ADD %s timestamp, ADD %s timestamp, ADD %s varchar;" % (
return u"ALTER TABLE %s ADD %s serial, ADD %s timestamp default '-infinity', ADD %s timestamp, ADD %s varchar;" % (
self.schematable, self.colPkey, self.colStart, self.colEnd, self.colUser)
def sql_setPkey(self):