summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2008-05-09 19:18:11 +0000
committerDries Buytaert <dries@buytaert.net>2008-05-09 19:18:11 +0000
commit0aec71aa560b4bfd7a5f56d75adc6b8bfc46e307 (patch)
treeb1dcaf9a7d20a8eaa83fb3f4247e67e4fd3e1c57
parentf28c0ae55c32e818be546291c5da1c7936d2465f (diff)
downloadbrdo-0aec71aa560b4bfd7a5f56d75adc6b8bfc46e307.tar.gz
brdo-0aec71aa560b4bfd7a5f56d75adc6b8bfc46e307.tar.bz2
- Patch #256001 by bjaspan: pgsql driver does not handle unsigned numeric fields.
-rw-r--r--includes/database.pgsql.inc33
1 files changed, 28 insertions, 5 deletions
diff --git a/includes/database.pgsql.inc b/includes/database.pgsql.inc
index ed5921fe6..83972a1f2 100644
--- a/includes/database.pgsql.inc
+++ b/includes/database.pgsql.inc
@@ -597,12 +597,30 @@ function _db_create_field_sql($name, $spec) {
if ($spec['type'] == 'serial') {
unset($spec['not null']);
}
+
+ // pgsql does not have unsigned types but supports constraints to
+ // restricted a signed field to be non-negative (e.g. CHECK (VALUE
+ // >= 0)). system.module defines {,small,big}int_unsigned as the
+ // corresponding integer type with this constraint but does not do
+ // so for serial or numeric types. It probably would have been
+ // cleaner to unify unsigned handling but, for now, we use the
+ // *int_unsigned types for int and otherwise apply a column
+ // constraint explicitly.
if (!empty($spec['unsigned'])) {
- if ($spec['type'] == 'serial') {
- $sql .= " CHECK ($name >= 0)";
- }
- else {
- $sql .= '_unsigned';
+ switch ($spec['type']) {
+ case 'int':
+ $sql .= '_unsigned';
+ break;
+ case 'serial':
+ case 'float':
+ $sql .= " CHECK ($name >= 0)";
+ break;
+ case 'numeric':
+ // handled below
+ break;
+ default:
+ // unsigned is not supported on other column types
+ break;
}
}
@@ -613,6 +631,11 @@ function _db_create_field_sql($name, $spec) {
$sql .= '(' . $spec['precision'] . ', ' . $spec['scale'] . ')';
}
+ // For numeric columns this has to come after (precision,scale).
+ if ($spec['type'] == 'numeric' && !empty($spec['unsigned'])) {
+ $sql .= " CHECK ($name >= 0)";
+ }
+
if (isset($spec['not null']) && $spec['not null']) {
$sql .= ' NOT NULL';
}