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.
This also affects the PostgreSQL database.
In both includes/database.mysql-common.inc
and includes/database.pgsql.inc
, the function _db_create_field_sql
has the precision and scale arguments in the wrong order for numeric fields. They should be precision then scale.
That is, the lines:
elseif (isset($spec['precision']) && isset($spec['scale'])) {
$sql .= '('. $spec['scale'] .', '. $spec['precision'] .')';
}
should be
elseif (isset($spec['precision']) && isset($spec['scale'])) {
$sql .= '('. $spec['precision'] .', '. $spec['scale'] .')';
}
I'm sorry I can't roll an official patch — I'm not set up for that right now.
Comment | File | Size | Author |
---|---|---|---|
#1 | database-scale-precision-swap-218054-1.patch | 1.4 KB | cburschka |
Comments
Comment #1
cburschkaHere you go. The MySQL docs say you're right, but I haven't tested one bit of this myself.
Comment #2
mfbsee also http://www.postgresql.org/docs/8.3/interactive/datatype-numeric.html#DAT...
Comment #3
pukku CreditAttribution: pukku commentedI don't know if I'm really allowed to make this ready to be committed, but the code looks right...
Comment #4
mfbI tested the patch with precision 5, scale 2. The table is now created (where before there was an error) and it all looks good in mysql:
Comment #5
Gábor HojtsyIs this used anywhere in Drupal core? Where we would need an update function to correct previously miscreated fields?
Comment #6
cburschkaIt's impossible to miscreate a field this way - as mfb tested, MySQL returns an error if the precision is smaller than the scale.
I grepped for "precision" to make sure that we didn't "work around" the bug by switching precision and scale elsewhere, but didn't find anything.
Comment #7
Gábor HojtsyGreat, thanks, committed to 6.x. Still needs to be committed to 7.x.
Comment #8
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD as well -- thanks folks and good catch.
Comment #9
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.