[Bast-commits] r8491 - in branches/DBIx-Class-Schema-Loader/current:
lib/DBIx/Class/Schema/Loader/DBI t
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Sun Jan 31 15:18:57 GMT 2010
Author: caelum
Date: 2010-01-31 15:18:57 +0000 (Sun, 31 Jan 2010)
New Revision: 8491
Modified:
branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/Sybase.pm
branches/DBIx-Class-Schema-Loader/current/t/15sybase_common.t
Log:
better type mapping and default introspection for Sybase
Modified: branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/Sybase.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/Sybase.pm 2010-01-31 12:39:32 UTC (rev 8490)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/Sybase.pm 2010-01-31 15:18:57 UTC (rev 8491)
@@ -229,7 +229,7 @@
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) = @_;
@@ -237,18 +237,31 @@
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;
Modified: branches/DBIx-Class-Schema-Loader/current/t/15sybase_common.t
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/t/15sybase_common.t 2010-01-31 12:39:32 UTC (rev 8490)
+++ branches/DBIx-Class-Schema-Loader/current/t/15sybase_common.t 2010-01-31 15:18:57 UTC (rev 8491)
@@ -34,32 +34,25 @@
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,
@@ -72,21 +65,17 @@
$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' };
},
},
);
More information about the Bast-commits
mailing list