Commit 51c74fee authored by Francesc Guasch's avatar Francesc Guasch
Browse files

db(sqlite): create timestamps as triggers in SQLite

issue #1280
parent d341265f
......@@ -1169,11 +1169,31 @@ sub _upgrade_table {
return if $row;
my $sqlite_trigger;
if ($dbh->{Driver}{Name} =~ /sqlite/i) {
$definition =~ s/DEFAULT.*ON UPDATE(.*)//i;
$sqlite_trigger = $1;
}
warn "INFO: adding $field $definition to $table\n" if $0 !~ /\.t$/;
$dbh->do("alter table $table add $field $definition");
$self->_sqlite_trigger($dbh,$table, $field, $sqlite_trigger) if $sqlite_trigger;
return 1;
}
sub _sqlite_trigger($self, $dbh, $table,$field, $trigger) {
my $sql =
"CREATE TRIGGER Update$field
AFTER UPDATE
ON $table
FOR EACH ROW
WHEN NEW.$field < OLD.$field
BEGIN
UPDATE $table SET $field=$trigger WHERE id=OLD.id;
END;
";
$dbh->do($sql);
}
sub _remove_field {
my $self = shift;
my ($table, $field ) = @_;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment