$info->{is_auto_increment} = 1;
}
- if ((eval { lc ${ $info->{default_value} } }||'') eq 'current timestamp') {
- ${ $info->{default_value} } = 'current_timestamp';
+ my $data_type = $info->{data_type};
+
+ if ($data_type !~ /^(?:(?:var)?(?:char|graphic)|decimal)\z/i) {
delete $info->{size};
+ }
+
+ if ($data_type eq 'double') {
+ $info->{data_type} = 'double precision';
+ }
+ elsif ($data_type eq 'decimal') {
+ no warnings 'uninitialized';
+
+ $info->{data_type} = 'numeric';
+
+ my @size = @{ $info->{size} || [] };
+
+ if ($size[0] == 5 && $size[1] == 0) {
+ delete $info->{size};
+ }
+ }
+ elsif ($data_type =~ /^(?:((?:var)?char) \(\) for bit data|(long varchar) for bit data)\z/i) {
+ my $base_type = lc($1 || $2);
+
+ (my $original_type = $data_type) =~ s/[()]+ //;
+
+ $info->{original}{data_type} = $original_type;
+
+ if ($base_type eq 'long varchar') {
+ $info->{data_type} = 'blob';
+ }
+ else {
+ if ($base_type eq 'char') {
+ $info->{data_type} = 'binary';
+ }
+ elsif ($base_type eq 'varchar') {
+ $info->{data_type} = 'varbinary';
+ }
+
+ my ($size) = $dbh->selectrow_array(<<'EOF', {}, $self->db_schema, $self->_uc($table), $self->_uc($col));
+SELECT length
+FROM syscat.columns
+WHERE tabschema = ? AND tabname = ? AND colname = ?
+EOF
+
+ $info->{size} = $size if $size;
+ }
+ }
+
+ if ((eval { lc ${ $info->{default_value} } }||'') =~ /^current (date|time(?:stamp)?)\z/i) {
+ my $type = lc($1);
+
+ ${ $info->{default_value} } = 'current_timestamp';
- my $orig_deflt = 'current timestamp';
+ my $orig_deflt = "current $type";
$info->{original}{default_value} = \$orig_deflt;
}
}
preserve_case_mode_is_exclusive => 1,
quote_char => '"',
data_types => {
- 'timestamp DEFAULT CURRENT TIMESTAMP' => { data_type => 'timestamp', default_value => \'current_timestamp',
- original => { default_value => \'current timestamp' } },
+ # http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/admin/r0008483.htm
+ #
+ # Numeric Types
+ smallint => { data_type => 'smallint' },
+ integer => { data_type => 'integer' },
+ 'int' => { data_type => 'integer' },
+ real => { data_type => 'real' },
+ 'double precision' => { data_type => 'double precision' },
+ double => { data_type => 'double precision' },
+ float => { data_type => 'double precision' },
+ 'float(24)' => { data_type => 'real' },
+ 'float(25)' => { data_type => 'double precision' },
+ 'float(53)' => { data_type => 'double precision' },
+ numeric => { data_type => 'numeric' },
+ decimal => { data_type => 'numeric' },
+ 'numeric(6,3)' => { data_type => 'numeric', size => [6,3] },
+ 'decimal(6,3)' => { data_type => 'numeric', size => [6,3] },
+
+ # Character String Types
+ char => { data_type => 'char', size => 1 },
+ 'char(3)' => { data_type => 'char', size => 3 },
+ 'varchar(3)' => { data_type => 'varchar', size => 3 },
+ 'long varchar' => { data_type => 'long varchar' },
+ 'clob' => { data_type => 'clob' },
+
+ # Graphic String Types (double-byte strings)
+ graphic => { data_type => 'graphic', size => 1 },
+ 'graphic(3)' => { data_type => 'graphic', size => 3 },
+ 'vargraphic(3)' => { data_type => 'vargraphic', size => 3 },
+ 'long vargraphic' => { data_type => 'long vargraphic' },
+ 'dbclob' => { data_type => 'dbclob' },
+
+ # Binary String Types
+ 'char for bit data'=> { data_type => 'binary', size => 1, original => { data_type => 'char for bit data' } },
+ 'char(3) for bit data'
+ => { data_type => 'binary', size => 3, original => { data_type => 'char for bit data' } },
+ 'varchar(3) for bit data'
+ => { data_type => 'varbinary', size => 3, original => { data_type => 'varchar for bit data' } },
+ 'long varchar for bit data'
+ => { data_type => 'blob', original => { data_type => 'long varchar for bit data' } },
+ blob => { data_type => 'blob' },
+
+ # DateTime Types
+ 'date' => { data_type => 'date' },
+ 'date default current date'
+ => { data_type => 'date', default_value => \'current_timestamp',
+ original => { default_value => \'current date' } },
+ 'time' => { data_type => 'time' },
+ 'time default current time'
+ => { data_type => 'time', default_value => \'current_timestamp',
+ original => { default_value => \'current time' } },
+ timestamp => { data_type => 'timestamp' },
+ 'timestamp default current timestamp'
+ => { data_type => 'timestamp', default_value => \'current_timestamp',
+ original => { default_value => \'current timestamp' } },
+
+ # DATALINK Type
+ # XXX I don't know how to make these
+# datalink => { data_type => 'datalink' },
},
);
}
my %DATA_TYPE_MULTI_TABLE_OVERRIDES = (
- oracle => qr/\blong\b/,
- mssql => qr/\b(?:timestamp|rowversion)\b/,
+ oracle => qr/\blong\b/i,
+ mssql => qr/\b(?:timestamp|rowversion)\b/i,
);
sub setup_data_type_tests {
# split types into tables based on overrides
my (@types, @split_off_types, @first_table_types);
{
- no warnings 'uninitialized';
+ my $split_off_re = $DATA_TYPE_MULTI_TABLE_OVERRIDES{lc($self->{vendor})} || qr/(?!)/;
@types = keys %$types;
- @split_off_types = grep /$DATA_TYPE_MULTI_TABLE_OVERRIDES{lc($self->{vendor})}/i, @types;
- @first_table_types = grep !/$DATA_TYPE_MULTI_TABLE_OVERRIDES{lc($self->{vendor})}/i, @types;
+ @split_off_types = grep /$split_off_re/, @types;
+ @first_table_types = grep !/$split_off_re/, @types;
}
@types = +{ map +($_, $types->{$_}), @first_table_types },