DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault
DBIx::Class::Schema::Loader::DBI
/;
-use Carp::Clan qw/^DBIx::Class/;
use mro 'c3';
+use DBIx::Class::Schema::Loader::Table ();
-our $VERSION = '0.07002';
+our $VERSION = '0.07010';
=head1 NAME
DBIx::Class::Schema::Loader::DBI::Pg - DBIx::Class::Schema::Loader::DBI
PostgreSQL Implementation.
-=head1 SYNOPSIS
-
- package My::Schema;
- use base qw/DBIx::Class::Schema::Loader/;
-
- __PACKAGE__->loader_options( debug => 1 );
-
- 1;
-
=head1 DESCRIPTION
-See L<DBIx::Class::Schema::Loader::Base>.
+See L<DBIx::Class::Schema::Loader> and L<DBIx::Class::Schema::Loader::Base>.
=cut
$self->next::method(@_);
- $self->{db_schema} ||= 'public';
+ $self->{db_schema} ||= ['public'];
if (not defined $self->preserve_case) {
$self->preserve_case(0);
}
}
+sub _tables_list {
+ my ($self, $opts) = @_;
+
+ my $dbh = $self->schema->storage->dbh;
+
+ my @tables;
+
+ foreach my $schema (@{ $self->db_schema }) {
+ my @raw_tables = $dbh->tables(undef, $schema, '%', '%');
+
+ foreach my $table_name (@raw_tables) {
+ my $schema_quoted = $table_name =~ /^"/;
+
+ if ($schema_quoted) {
+ $table_name =~ s/^"([^"]+)"\.//;
+ }
+ else {
+ $table_name =~ s/^([^.]+)\.//;
+ }
+ my $table = DBIx::Class::Schema::Loader::Table->new(schema => $1);
+
+ $table_name =~ s/^"([^"]+)"\z/$1/;
+
+ $table->name($table_name);
+
+ push @tables, $table;
+ }
+ }
+
+ return $self->_filter_tables(\@tables, $opts);
+}
+
sub _table_uniq_info {
my ($self, $table) = @_;
c.relname = ?}
);
- $uniq_sth->execute($self->db_schema, $table);
+ $uniq_sth->execute($table->schema, $table);
while(my $row = $uniq_sth->fetchrow_arrayref) {
my ($tableid, $indexname, $col_nums) = @$row;
$col_nums =~ s/^\s+//;
FROM pg_class
WHERE relname=? AND relnamespace=(
SELECT oid FROM pg_namespace WHERE nspname=?)
- }, undef, $table, $self->db_schema
+ }, undef, $table, $table->schema
);
return $table_comment
}
FROM pg_class
WHERE relname=? AND relnamespace=(
SELECT oid FROM pg_namespace WHERE nspname=?)
- }, undef, $table, $self->db_schema
+ }, undef, $table, $table->schema
);
return $self->schema->storage->dbh->selectrow_array('SELECT col_description(?,?)', undef, $table_oid,
$column_number );
FROM pg_catalog.pg_type
WHERE typname = ?
EOF
- if ($typetype eq 'e') {
+ if ($typetype && $typetype eq 'e') {
+ # The following will extract a list of allowed values for the
+ # enum.
+ my $typevalues = $self->schema->storage->dbh
+ ->selectall_arrayref(<<EOF, {}, $info->{data_type});
+SELECT e.enumlabel
+FROM pg_catalog.pg_enum e
+JOIN pg_catalog.pg_type t ON t.oid = e.enumtypid
+WHERE t.typname = ?
+EOF
+
+ $info->{extra}{list} = [ map { $_->[0] } @$typevalues ];
+
+ # Store its original name in extra for SQLT to pick up.
+ $info->{extra}{custom_type_name} = $info->{data_type};
+
$info->{data_type} = 'enum';
+
+ delete $info->{size};
}
}
-
# process SERIAL columns
- if (ref($info->{default_value}) eq 'SCALAR' && ${ $info->{default_value} } =~ /\bnextval\(['"]([.\w]+)/i) {
+ if (ref($info->{default_value}) eq 'SCALAR'
+ && ${ $info->{default_value} } =~ /\bnextval\('([^:]+)'/i) {
$info->{is_auto_increment} = 1;
$info->{sequence} = $1;
delete $info->{default_value};
return $result;
}
-sub _extra_column_info {
- my ($self, $table, $col, $info, $dbi_info) = @_;
- my %extra_info;
-
- # The following will extract a list of allowed values if this
- # is an enumerated type. Otherwise, no results and we do nothing.
- my $typevalues = $self->schema->storage->dbh
- ->selectall_arrayref(<<EOF, {}, $info->{data_type});
-SELECT e.enumlabel
-FROM pg_catalog.pg_enum e
-JOIN pg_catalog.pg_type t ON t.oid = e.enumtypid
-WHERE t.typname = ?
-EOF
-
- if (@$typevalues) {
- $extra_info{extra}{list} = [ map { $_->[0] } @$typevalues ];
- }
-
- return \%extra_info;
-}
-
-
=head1 SEE ALSO
L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,