[SQLite] DEFAULT timestamp function forcibly "filtered" into a string
Database management in a single PHP file
Brought to you by:
jakubvrana
Trying to define (datetime('now','localtime'))
as the DEFAULT for a timestamp text column, it always gets translated to an escaped string, with double ''
.
I have to edit the SQL statement and manually un-escape the value.
Also, when opening the "new item" page, it will display now','localtime
in the defaulted column
Adminer doesn't support arbitrary expressions as default values. However
CURRENT_TIMESTAMP
is supported which should be equivalent here.I understand what you mean, and I kind of accounted for this reply.
Though, if you'd let me justify my request, in the specific case of SQLite, since CURRENT_TIMESTAMP refers to GMT time, and SQLite is serverless, anyone outside of GMT will be inserting (and hence fetching) a different time from the actual local time, and there would be the -ugly- need to compensate for it in the code since there isn't a server automatically compensating for that.
Since SQLite is basically used only for local applications, it makes sense to record the local time in the database instead of the GMT time.
In any case thank you for this precious software ;)
This applies to MariaDB and MySQL as well.
Last edit: Olaf van der Spek 2020-02-14
This should work for some time now (without the wrapping into braces).
Currently using the compiled version of 4.8.1-dev with passwordless sqlite... and behaviour is the same as described in OP
Please provide precise reproduction steps.
Your request prompted me to try something different.
I was placing
(datetime('now','localtime'))
insde the default field in the editor, and when I did that, adminer still escaped everything so the field evaluated to the string, not to the result of the function call.Just now, I tried removing the outside parentheses, so that the default field in the table editor looked like
datetime('now','localtime')
and it solved the problem... only while manually inserting values from adminer itself, as the correct datetime is saved. But if I let the PHP code call the insert query, then what gets saved into the datetime field is a literal string, "datetime('now','localtime')". So back to square one, I need to re-edit the SQL command that adminer uses to alter the table (SQL Command > history), replacing the time row instruction manually with:"time" text NOT NULL DEFAULT (datetime('now','localtime')),
Last edit: ephestione 2021-05-23