WordPress / sqlite-database-integration

Feature Plugin to add SQLite support to WordPress. Under Development.
GNU General Public License v2.0
237 stars 41 forks source link

Support `ON UPDATE CURRENT_TIMESTAMP` columns #148

Closed JanJakes closed 3 months ago

JanJakes commented 3 months ago

Unfortunately, ON UPDATE current_timestamp doesn't seem to be supported by SQLite.

While for creating a table the test following case passes, I don't think it has any effect:

$this->assertQuery(
    'CREATE TABLE _tmp_table (
        id int(11) NOT NULL,
        created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
    );'
);

For altering a table, the following test case fails with SQLSTATE[HY000]: General error: 1 near "ON": syntax error.:

$this->assertQuery(
    'CREATE TABLE _tmp_table (
        id int(11) NOT NULL
    );'
);

$this->assertQuery(
    'ALTER TABLE _tmp_table ADD COLUMN created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'
);

I think the only way to support this would be to create a trigger, but I suppose it would also need to be removed before any other ALTER TABLE statement for the same column, as if the statement omits the ON UPDATE part, it would need to be removed.