use base 'DBIx::Class::Schema::Loader::DBI::Sybase::Common';
use mro 'c3';
use Try::Tiny;
-use List::MoreUtils 'any';
-use namespace::clean;
-
+use List::Util 'any';
use DBIx::Class::Schema::Loader::Table::Sybase ();
+use namespace::clean;
-our $VERSION = '0.07028';
+our $VERSION = '0.07047';
=head1 NAME
=cut
+# SQL Server 2000: Ancient as time itself, but still out in the wild
+sub _is_2k {
+ return shift->schema->storage->_server_info->{normalized_dbms_version} < 9;
+}
+
sub _system_databases {
return (qw/
master model tempdb msdb
/);
}
-sub _owners {
+sub _schemas {
my ($self, $db) = @_;
- my $owners = $self->dbh->selectcol_arrayref(<<"EOF");
+ my $owners = $self->dbh->selectcol_arrayref($self->_is_2k ? <<"EOF2K" : <<"EOF");
SELECT name
FROM [$db].dbo.sysusers
WHERE uid <> gid
+EOF2K
+SELECT name
+FROM [$db].sys.schemas
EOF
return grep !/^(?:#|guest|INFORMATION_SCHEMA|sys)/, @$owners;
}
+sub _current_schema {
+ my $self = shift;
+
+ if ($self->_is_2k) {
+ return ($self->dbh->selectrow_array('SELECT user_name()'))[0];
+ }
+
+ return ($self->dbh->selectrow_array('SELECT schema_name()'))[0];
+}
+
sub _current_db {
my $self = shift;
return ($self->dbh->selectrow_array('SELECT db_name()'))[0];
}
else {
if ($db ne $current_db) {
- $self->dbh->do("USE [$db]");
+ $self->_switch_db($db);
$self->qualify_objects(1);
}
}
elsif (ref $self->db_schema eq 'ARRAY' || (not defined $self->db_schema)) {
my $owners = $self->db_schema;
- $owners ||= [ $self->dbh->selectrow_array('SELECT user_name()') ];
+ $owners ||= [ $self->_current_schema ];
$self->qualify_objects(1) if @$owners > 1;
foreach my $db (keys %{ $self->db_schema }) {
if ($self->db_schema->{$db} eq '%') {
- $self->db_schema->{$db} = [ $self->_owners($db) ];
+ $self->db_schema->{$db} = [ $self->_schemas($db) ];
$self->qualify_objects(1);
}
}
sub _tables_list {
- my ($self, $opts) = @_;
+ my ($self) = @_;
my @tables;
}
}
- return $self->_filter_tables(\@tables, $opts);
+ return $self->_filter_tables(\@tables);
}
sub _table_pk_info {
JOIN [$db].INFORMATION_SCHEMA.KEY_COLUMN_USAGE fk_kcu
ON fk_kcu.constraint_name = fk_tc.constraint_name
AND fk_kcu.table_name = fk_tc.table_name
- AND fk_kcu.table_schema = fk_tc.table_schema
+ AND fk_kcu.table_schema = fk_tc.table_schema
JOIN [$db].INFORMATION_SCHEMA.TABLE_CONSTRAINTS uk_tc
ON uk_tc.constraint_name = rc.unique_constraint_name
AND uk_tc.table_schema = rc.unique_constraint_schema
$delete_rule, $update_rule) = $sth->fetchrow_array) {
push @{ $rels{$fk}{local_columns} }, $self->_lc($col);
push @{ $rels{$fk}{remote_columns} }, $self->_lc($remote_col);
-
+
$rels{$fk}{remote_table} = DBIx::Class::Schema::Loader::Table::Sybase->new(
loader => $self,
name => $remote_table,
push @{ $uniq{$constr} }, $self->_lc($col);
}
- return [ map [ $_ => $uniq{$_} ], keys %uniq ];
+ return [ map [ $_ => $uniq{$_} ], sort keys %uniq ];
}
sub _columns_info_for {
my $result = $self->next::method(@_);
- # SQL Server: Ancient as time itself, but still out in the wild
- my $is_2k = $self->schema->storage->_server_info->{normalized_dbms_version} < 9;
-
# get type info (and identity)
- my $rows = $self->dbh->selectall_arrayref($is_2k ? <<"EOF2K" : <<"EOF");
+ my $rows = $self->dbh->selectall_arrayref($self->_is_2k ? <<"EOF2K" : <<"EOF");
SELECT c.column_name, c.character_maximum_length, c.data_type, c.datetime_precision, c.column_default, (sc.status & 0x80) is_identity
FROM [$db].INFORMATION_SCHEMA.COLUMNS c
JOIN [$db].dbo.sysusers ss ON
L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
L<DBIx::Class::Schema::Loader::DBI>
-=head1 AUTHOR
+=head1 AUTHORS
-See L<DBIx::Class::Schema::Loader/AUTHOR> and L<DBIx::Class::Schema::Loader/CONTRIBUTORS>.
+See L<DBIx::Class::Schema::Loader/AUTHORS>.
=head1 LICENSE