Menu

#702 [SQLite] DEFAULT timestamp function forcibly "filtered" into a string

4.7.2
closed-fixed
nobody
None
5
2021-05-23
2019-08-14
ephestione
No

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

Discussion

  • Jakub Vrána

    Jakub Vrána - 2019-08-19
    • status: open --> closed-wont-fix
     
  • Jakub Vrána

    Jakub Vrána - 2019-08-19

    Adminer doesn't support arbitrary expressions as default values. However CURRENT_TIMESTAMP is supported which should be equivalent here.

     
  • ephestione

    ephestione - 2019-08-19

    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 ;)

     
  • Jakub Vrána

    Jakub Vrána - 2019-08-20
    • status: closed-wont-fix --> open-accepted
     
  • Olaf van der Spek

    This applies to MariaDB and MySQL as well.

     

    Last edit: Olaf van der Spek 2020-02-14
  • Jakub Vrána

    Jakub Vrána - 2021-02-09
    • status: open-accepted --> closed-fixed
     
  • Jakub Vrána

    Jakub Vrána - 2021-02-09

    This should work for some time now (without the wrapping into braces).

     
  • ephestione

    ephestione - 2021-03-13

    Currently using the compiled version of 4.8.1-dev with passwordless sqlite... and behaviour is the same as described in OP

     
    • Jakub Vrána

      Jakub Vrána - 2021-05-23

      Please provide precise reproduction steps.

       
      • ephestione

        ephestione - 2021-05-23

        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

Log in to post a comment.