return \@uniqs;
}
-# set data_type to 'undef' for computed columns
+# get the correct data types and defaults
sub _columns_info_for {
my $self = shift;
my ($table) = @_;
my $dbh = $self->schema->storage->dbh;
my $sth = $dbh->prepare(qq{
-SELECT c.name name, c.computedcol computedcol
+SELECT c.name name, t.name type, cm.text deflt
FROM syscolumns c
JOIN sysobjects o ON c.id = o.id
+LEFT JOIN systypes t ON c.type = t.type AND c.usertype = t.usertype
+LEFT JOIN syscomments cm
+ ON cm.id = CASE WHEN c.cdefault = 0 THEN c.computedcol ELSE c.cdefault END
WHERE o.name = @{[ $dbh->quote($table) ]} AND o.type = 'U'
});
$sth->execute;
local $dbh->{FetchHashKeyName} = 'NAME_lc';
- my $computed_info = $sth->fetchall_hashref('name');
+ my $info = $sth->fetchall_hashref('name');
- for my $col (keys %$result) {
- $result->{$col}{data_type} = undef
- if $computed_info->{$col}{computedcol};
+ while (my ($col, $res) = each %$result) {
+ $res->{data_type} = $info->{$col}{type};
+
+ if (my $default = $info->{$col}{deflt}) {
+ if ($default =~ /^AS \s+ (\S+)/ix) {
+ my $function = $1;
+ $res->{default_value} = \$function;
+ }
+ elsif ($default =~ /^DEFAULT \s+ (\S+)/ix) {
+ my ($constant_default) = $1 =~ /^['"\[\]]?(.*?)['"\[\]]\z/;
+ $res->{default_value} = $constant_default;
+ }
+ }
}
return $result;
my $rsrc = $rs->result_source;
is $rsrc->column_info('id')->{data_type},
- 'numeric',
+ 'int',
'INTEGER IDENTITY data_type is correct';
is $rsrc->column_info('id')->{is_auto_increment},
1,
'INTEGER IDENTITY is_auto_increment => 1';
- {
- local $TODO = 'timestamp introspection broken';
-
- is $rsrc->column_info('ts')->{data_type},
- 'timestamp',
- 'timestamps have the correct data_type';
- }
+ is $rsrc->column_info('ts')->{data_type},
+ 'timestamp',
+ 'timestamps have the correct data_type';
is $rsrc->column_info('charfield')->{data_type},
'varchar',
'VARCHAR has correct data_type';
- {
- local $TODO = 'constant DEFAULT introspection';
- is $rsrc->column_info('charfield')->{default_value},
- 'foo',
- 'constant DEFAULT is correct';
- }
+ is $rsrc->column_info('charfield')->{default_value},
+ 'foo',
+ 'constant DEFAULT is correct';
is $rsrc->column_info('charfield')->{size},
10,
$rsrc->column_info('computed_dt')->{data_type}
;
- {
- local $TODO = 'default_value for computed columns';
-
- my $computed_dt_default =
- $rsrc->column_info('computed_dt')->{default_value};
+ my $computed_dt_default =
+ $rsrc->column_info('computed_dt')->{default_value};
- ok ((ref $computed_dt_default eq 'SCALAR'),
- 'default_value for computed column is a scalar ref')
-# or diag "default_value is: ", $computed_dt_default
- ;
+ ok ((ref $computed_dt_default eq 'SCALAR'),
+ 'default_value for computed column is a scalar ref')
+ or diag "default_value is: ", $computed_dt_default
+ ;
- eval { is $$computed_dt_default,
- 'getdate()',
- 'default_value for computed column is correct' };
- }
+ eval { is $$computed_dt_default,
+ 'getdate()',
+ 'default_value for computed column is correct' };
},
},
);