The current function:
protected function createFieldSql($name, $spec) {
...
if (!empty($spec['unsigned'])) {
$sql .= " CHECK ($name >= 0)";
}
if (!empty($spec['length'])) {
$sql .= '(' . $spec['length'] . ')';
}
elseif (isset($spec['precision']) && isset($spec['scale'])) {
$sql .= '(' . $spec['precision'] . ', ' . $spec['scale'] . ')';
}
...
}
So what happens is if you define a schema element of type numeric with a precision and scale specified, and unsigned, you get this :
colname numeric CHECK (colname >= 0)(10, 2)
The patch switches these two so you get the expected result of
colname numeric(10, 2) CHECK (colname >= 0)
Comments
Comment #1
stormsweeper commentedMarking as postgres specific
Comment #2
damien tournoud commentedThis type of things scream for a test. Would it be possible to extend the Schema API tests to include this case?
Comment #3
stormsweeper commentedLet me see what tests are there now, although I don't think testbot uses Postgres.
Comment #4
stormsweeper commentedAdded a new test that creates a table with unsigned columns of each number type, and then tries to insert a negative value in all of them. The test is db agnostic.
Comment #5
stormsweeper commentedNow let's see if the test bot chokes on this.
Comment #6
stormsweeper commentedNot sure what I did, but it looks like the new test broke the Schema API test class so bad that it didn't load (see the detailed results). Will chew through this.
Comment #7
josh waihi commentedforgot to call function as a method. fixed, this patch works, Thanks.
Comment #8
webchickCouple of minor things with the test:
Please rephrase so this fits within 80 chars.
All comments should be written "With sentence capitalization, ending in a period." There are a few lines like this.
We don't abbreviate variable, etc. names. Please spell it out as "column".
Comment #9
stormsweeper commentedWorking on it now. Is there a compiled addendum anywhere for test coding standards over and above the standard Drupal ones?
Comment #10
stormsweeper commentedLightly refactored the patch, which included catching a small bug with the inserts.
Comment #11
stormsweeper commentedAlso, there's already a D6 version of this patch here: #256001: pgsql driver does not handle unsigned numeric fields
Comment #12
stormsweeper commentedI missed the inline comments before.
Comment #14
stormsweeper commentedI'm going to wait a bit and set this back to CNR. The current HEAD of Drupal is broken, it seems.
Comment #15
stormsweeper commentedOK, sorted out the update, but the same three asserts fail on a clean checkout of HEAD. They're all string comparisons, but as far as I can tell the text has not changed:
In modules/system/system.test, lines 118-122:
The module is enabled just fine, and every other assert passes. I'll check back tomorrow to set this to CNR, as I am certain the patch is not at fault.
Comment #16
stormsweeper commentedis testbot fixed now?
Comment #17
stormsweeper commentedOh, and I think this was the cause of the last fails: #554106: Module enable/disable tests failing on testing servers
Comment #18
gábor hojtsyJust marked #256001: pgsql driver does not handle unsigned numeric fields postponed on this one, since that is the same patch for Drupal 6.
Comment #19
josh waihi commentedI like it. Lets get this in.
Comment #21
stormsweeper commentedIt looks like another test failed before it got to the ones in here.
Comment #23
josh waihi commentedaccording to http://qa.drupal.org/pifr/test/19124 #12 passed the test. Lets get this in.
Comment #24
webchickGreat! Thanks for the expanded test coverage.
Committed to HEAD.
Comment #25
webchickHm. I just got an e-mail about PHP syntax errors in 'schema.inc' and this patch is the only culprit I can think of. Rolled back.
Any ideas?
Comment #26
josh waihi commentedstrange, PHP parses these files over CLI fine (they die when PHP tries to find the parent Classes naturally) - I can't see a php syntax error anywhere. I can run Drupal and tests no problem with this Patch applied. I don't think this is your HEAD killer.
Comment #27
catch#12 is showing up as syntax errors from the bot, we need to resolve that before re-committing.
Comment #28
josh waihi commented@catch, then is it a bot issue, not the patch. I can run Drupal tests with the patch applied. If there was a syntax error, that wouldn't be possible would it?
Comment #29
catchYep, agreed. Bot seems to be down again, and can't see a re-test button on the patch, so re-uploading (with minor re-roll for offset/fuzz) and setting back to RTBC.
Comment #30
scor commentedfix several whitespace issues (no credit please).
Comment #31
webchickOk, since testbot is down for the count for lord knows how long, I went ahead and committed this again. I verified manually with php -l that there were no syntax errors, so hopefully testbot agrees when it lives again. :P
Marking down to 6.x.
Comment #32
berdirNope, testbot does not :)
db_create_table() and db_add_field() don't have a $ret argument anymore.
The attached patch fixes this, schema tests pass again now.
Comment #33
webchickThanks! Committed to HEAD.
Comment #34
josh waihi commentedNice one Berdir