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.
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 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 commentedCommitted to CVS HEAD as well -- thanks folks and good catch.
Comment #9
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.