Posted by wienczny on January 30, 2008 at 1:04pm
Jump to:
| Project: | Drupal core |
| Version: | 6.x-dev |
| Component: | database system |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
Issue Summary
It's not possible to create tables with datetime fields using the schema api if you want to have a default value of now() or current_timestamp. This happens because all strings are escaped with ' before going to the database. Database function calls like now() do not work if escaped. The attached patch allows now() to be used for datetime fields.
| Attachment | Size | Status | Test result | Operations |
|---|---|---|---|---|
| patch.txt | 2.73 KB | Ignored: Check issue status. | None | None |
Comments
#1
This is a bug, as it's torpeding usage of the Schema API and therefore endangering the dbs abstraction.
#2
what about current_timestamp? any others like this?
#3
The behaviour of Drupal's database system does not deviate from what is documented. Also, having the database take care of setting the time by itself is nice to have, but not critical to the usage of a database abstraction layer. So this is a feature request.
The MySQL implementation of the Schema API implements the
datetimefield using MySQL's DATETIME type. That type does not support automatic initializiation/update to the current time.MySQL's type TIMESTAMP supports automatic initializiation/update to the current time. Switching from DATETIME to TIMESTAMP is not an option, though:
See http://dev.mysql.com/doc/refman/4.1/en/timestamp.html for details.
#4
As a feature request, I'm moving this to D7.
#5
And now to D8.
#6
And now I subscribe.
#7
0.0
#8
running into this issue currently. So this appears to be an issue that looking for a solution that tells the DB to properly set a default value when the row is created in the DB.
But I need a solution now. Can I just set the type of the field to datetime and set it's value on node_create?
#9
7.x and 8.x do *not* support datetime fields.