Index: content_admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/cck/content_admin.inc,v retrieving revision 1.12.2.6 diff -u -r1.12.2.6 content_admin.inc --- content_admin.inc 19 Aug 2006 22:48:40 -0000 1.12.2.6 +++ content_admin.inc 21 Aug 2006 13:01:12 -0000 @@ -163,8 +163,8 @@ case 'pgsql': db_query("CREATE TABLE {node_". $form_values['type_name'] ."} ( - vid integer unsigned NOT NULL default '0', - nid integer unsigned NOT NULL default '0', + vid integer NOT NULL default '0' CHECK (vid >= 0), + nid integer NOT NULL default '0' CHECK (nid >= 0), PRIMARY KEY (vid) )"); break; @@ -715,9 +715,9 @@ case 'pgsql': db_query("CREATE TABLE {". $new_db_info['table'] ."} ( - vid integer unsigned NOT NULL default '0', - delta integer unsigned NOT NULL default '0', - nid integer unsigned NOT NULL default '0', + vid integer NOT NULL default '0' CHECK(vid >= 0), + delta integer NOT NULL default '0' CHECK(delta >= 0), + nid integer NOT NULL default '0' CHECK(nid >= 0), PRIMARY KEY (vid,delta) )"); break; @@ -736,8 +736,8 @@ case 'pgsql': db_query("CREATE TABLE {". $new_db_info['table'] ."} ( - vid integer unsigned NOT NULL default '0', - nid integer unsigned NOT NULL default '0', + vid integer NOT NULL default '0' CHECK(vid >= 0), + nid integer NOT NULL default '0' CHECK(nid >= 0), PRIMARY KEY (vid) )"); break; @@ -854,34 +854,42 @@ } /** - * Add a column to a database table. + * Handle postgresql column type creation. + * Translates int types. + * Supports bigint types. * - * @param $table - * Name of the table, without {} * @param $column * Name of the column * @param $type * Type of column * @param $attributes * Additional optional attributes. Recognized attributes: - * not null => TRUE|FALSE - * default => NULL|FALSE|value (with or without '', it won't be added) + * length + * unsigned + * @param &$not_null + * @param &$default_val + * @param &$default */ -function content_db_add_column($table, $column, $type, $attributes = array()) { +function content_db_construct_column_type($column, $type, &$attributes, &$not_null, &$default_val, &$default) { + + $basetype = $type; + $type = ''; switch ($GLOBALS['db_type']) { case 'pgsql': - $mappings = array('int' => 'integer', 'mediumint' => 'integer', 'bigint' => 'integer', + $mappings = array('int' => 'integer', 'mediumint' => 'integer', 'bigint' => 'bigint', 'tinyint' => 'smallint', 'float' => 'float', 'varchar' => 'varchar', 'text' => 'text', 'mediumtext' => 'text', 'longtext' => 'text'); - if (isset($mappings[$type])) { - $type = $mappings[$type]; + + if (isset($mappings[$basetype])) { + $basetype = $mappings[$basetype]; } else { watchdog('database', t('No PostgreSQL mapping found for %type data type.', array('%type' => theme('placeholder', $type))), WATCHDOG_WARNING); } - if ($type != 'varchar') { + + if ($basetype != 'varchar') { unset($attributes['length']); } break; @@ -911,9 +919,41 @@ $type .= '('. $attributes['length'] .')'; } if (array_key_exists('unsigned', $attributes) && $attributes['unsigned']) { - $type .= ' unsigned'; + switch ($GLOBALS['db_type']) { + case 'pgsql': + $basetype .= ' CHECK('.$column.' >= 0)'; + unset($attributes['unsigned']); + break; + default: + $type .= ' unsigned'; + break; + } } + $type = $basetype . $type; + $basetype = ''; + + return $type; +} + + +/** + * Add a column to a database table. + * + * @param $table + * Name of the table, without {} + * @param $column + * Name of the column + * @param $type + * Type of column + * @param $attributes + * Additional optional attributes. Recognized attributes: + * not null => TRUE|FALSE + * default => NULL|FALSE|value (with or without '', it won't be added) + */ +function content_db_add_column($table, $column, $type, $attributes = array()) { + $type = content_db_construct_column_type($column, $type, $attributes, &$not_null, &$default_val, &$default); + switch ($GLOBALS['db_type']) { case 'pgsql': db_query("ALTER TABLE {". $table ."} ADD $column $type"); @@ -957,51 +997,7 @@ * default => NULL|FALSE|value (with or without '', it won't be added) */ function content_db_change_column($table, $column, $column_new, $type, $attributes = array()) { - switch ($GLOBALS['db_type']) { - case 'pgsql': - $mappings = array('int' => 'integer', 'mediumint' => 'integer', 'bigint' => 'integer', - 'tinyint' => 'smallint', - 'float' => 'float', - 'varchar' => 'varchar', - 'text' => 'text', 'mediumtext' => 'text', 'longtext' => 'text'); - if (isset($mappings[$type])) { - $type = $mappings[$type]; - } - else { - watchdog('database', t('No PostgreSQL mapping found for %type data type.', array('%type' => theme('placeholder', $type))), WATCHDOG_WARNING); - } - if ($type != 'varchar') { - unset($attributes['length']); - } - break; - - case 'mysql': - case 'mysqli': - break; - } - - if (array_key_exists('not null', $attributes) and $attributes['not null']) { - $not_null = 'NOT NULL'; - } - if (array_key_exists('default', $attributes)) { - if (is_null($attributes['default'])) { - $default_val = 'NULL'; - $default = 'default NULL'; - } - elseif ($attributes['default'] === FALSE) { - $default = ''; - } - else { - $default_val = "$attributes[default]"; - $default = "default $attributes[default]"; - } - } - if (array_key_exists('length', $attributes)) { - $type .= '('. $attributes['length'] .')'; - } - if (array_key_exists('unsigned', $attributes) && $attributes['unsigned']) { - $type .= ' unsigned'; - } + $type = content_db_construct_column_type($column_new, $type, $attributes, &$not_null, &$default_val, &$default); switch ($GLOBALS['db_type']) { case 'pgsql': @@ -1023,4 +1019,3 @@ break; } } - Index: content.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/cck/content.install,v retrieving revision 1.9.2.4 diff -u -r1.9.2.4 content.install --- content.install 20 Aug 2006 21:49:31 -0000 1.9.2.4 +++ content.install 21 Aug 2006 13:01:12 -0000 @@ -129,8 +129,8 @@ case 'pgsql': $ret[] = update_sql("CREATE TABLE {node_". strtr($type->type_name, '-', '_') ."} ( - vid integer unsigned NOT NULL default '0', - nid integer unsigned NOT NULL default '0', + vid integer NOT NULL default '0' CHECK(vid >= 0), + nid integer NOT NULL default '0' CHECK(nid >= 0), PRIMARY KEY (vid) )"); break;