Skip to content

Commit

Permalink
Fix behaviour of triggers when logging an existing layer
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
autra authored and nyalldawson committed Oct 6, 2021
1 parent 9e37db3 commit 061b810
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Expand Up @@ -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>
Expand Down
Expand Up @@ -175,7 +175,7 @@ def showHelp(self):
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):
Expand Down

0 comments on commit 061b810

Please sign in to comment.