Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When specifying TRUE
or FALSE
as default value in the schema API, you’ll get a database error because (string)FALSE === ''
. This means that you’ll end up with invalid SQL. The patch checks whether the value is a boolean and converts it to an int so that we end up with '0'
or '1'
instead of ''
and '1'
.
Comment | File | Size | Author |
---|---|---|---|
#4 | 6dad83e7.patch | 1.64 KB | kkaefer |
#2 | 6dad83e7.patch | 1.06 KB | kkaefer |
6dad83e7.patch | 510 bytes | kkaefer | |
Comments
Comment #1
kkaefer CreditAttribution: kkaefer commentedComment #2
kkaefer CreditAttribution: kkaefer commentedSame for pgsql (untested!)
Comment #3
kkaefer CreditAttribution: kkaefer commentedBTW, I noticed that the pgsql version lacks the
part. Is this on purpose or should that be added to pgsql as well?
Comment #4
kkaefer CreditAttribution: kkaefer commentedAlso ignore the default value when the field is a serial.
Comment #5
Crell CreditAttribution: Crell commentedSince we don't use "real" booleans in the database anyway, shouldn't we just tell people to use 1/0 instead of TRUE/FALSE for an int field? They'll have to write 1/0 to it in insert/update statements anyway rather than TRUE/FALSE, so cleaning up after them here and not elsewhere doesn't make sense.
Comment #6
kkaefer CreditAttribution: kkaefer commentedDo they? when you update an int column, you specify int in the dbal and it converts TRUE/FALSE automatically to int. That was my understanding thus far.
Comment #8
jbrown CreditAttribution: jbrown commentedNote that default values are also not handled correct for fields with 'serialize' => TRUE.
Say you want a default value of array() in a serialized field. The default value should be serialized by the database layer before being put into the create table query, otherwise it will cause an exception.
Simply setting the default value to 'a:0:{}' will not work as then drupal_write_record() will serialize this to s:6:"a:0:{}";
Comment #9
Crell CreditAttribution: Crell commentedkkaefer: Drupal 6 did so implicitly because we preprocessed all values. The D7 API doesn't do that anymore, as it passes (almost) all type juggling off to the database itself via prepared statements where they belong.
Comment #10
BerdirThis is related to #403840: Cast numeric values at the level of the DB driver. If we don't fix that (suggested by Josh Waihi in #403840-14: Cast numeric values at the level of the DB driver, then there is no point in fixing this either.