$self->_dbic_stmt($table_class,'table',$table_name);
my $cols = $self->_table_columns($table);
- my $col_info;
- eval { $col_info = $self->__columns_info_for($table) };
- if($@) {
- $self->_dbic_stmt($table_class,'add_columns',@$cols);
- }
- else {
- if ($self->_is_case_sensitive) {
- for my $col (keys %$col_info) {
- $col_info->{$col}{accessor} = lc $col
- if $col ne lc($col);
- }
- } else {
- $col_info = { map { lc($_), $col_info->{$_} } keys %$col_info };
+ my $col_info = $self->__columns_info_for($table);
+ if ($self->_is_case_sensitive) {
+ for my $col (keys %$col_info) {
+ $col_info->{$col}{accessor} = lc $col
+ if $col ne lc($col);
}
+ } else {
+ $col_info = { map { lc($_), $col_info->{$_} } keys %$col_info };
+ }
- my $fks = $self->_table_fk_info($table);
+ my $fks = $self->_table_fk_info($table);
- for my $fkdef (@$fks) {
- for my $col (@{ $fkdef->{local_columns} }) {
- $col_info->{$col}{is_foreign_key} = 1;
- }
+ for my $fkdef (@$fks) {
+ for my $col (@{ $fkdef->{local_columns} }) {
+ $col_info->{$col}{is_foreign_key} = 1;
}
- $self->_dbic_stmt(
- $table_class,
- 'add_columns',
- map { $_, ($col_info->{$_}||{}) } @$cols
- );
}
+ $self->_dbic_stmt(
+ $table_class,
+ 'add_columns',
+ map { $_, ($col_info->{$_}||{}) } @$cols
+ );
my %uniq_tag; # used to eliminate duplicate uniqs
my $col_name = $info->{COLUMN_NAME};
$col_name =~ s/^\"(.*)\"$/$1/;
- my $extra_info = $self->_extra_column_info($info) || {};
+ my $extra_info = $self->_extra_column_info(
+ $table, $col_name, $column_info, $info
+ ) || {};
$column_info = { %$column_info, %$extra_info };
$result{$col_name} = $column_info;
$column_info->{size} = $2;
}
- my $extra_info = $self->_extra_column_info($table, $columns[$i], $sth, $i) || {};
+ my $extra_info = $self->_extra_column_info($table, $columns[$i], $column_info) || {};
$column_info = { %$column_info, %$extra_info };
$result{$columns[$i]} = $column_info;
}
sub _extra_column_info {
- my ($self, $info) = @_;
+ my ($self, $table, $column, $info, $dbi_info) = @_;
my %extra_info;
- my ($table, $column) = @$info{qw/TABLE_NAME COLUMN_NAME/};
-
my $dbh = $self->schema->storage->dbh;
my $sth = $dbh->prepare_cached(
q{
use strict;
use warnings;
-use namespace::autoclean;
use Class::C3;
use base qw/DBIx::Class::Schema::Loader::DBI/;
use Carp::Clan qw/^DBIx::Class/;
return \@uniqs;
}
+sub _extra_column_info {
+ my ($self, $table, $column, $info, $dbi_info) = @_;
+ my %extra_info;
+
+ my $dbh = $self->schema->storage->dbh;
+
+ local $dbh->{LongReadLen} = 100000;
+ local $dbh->{LongTruncOk} = 1;
+
+ my $sth = $dbh->prepare(<<'EOF');
+SELECT t.rdb$trigger_source
+FROM rdb$triggers t
+WHERE t.rdb$relation_name = ?
+EOF
+
+ $sth->execute($table);
+
+ while (my ($trigger) = $sth->fetchrow_array) {
+ my ($trig_col, $generator) = $trigger =~
+/new\s*.\s*(\w+) \s* = \s* gen_id\s* \( \s* (\w+)/ix;
+
+ if ($trig_col eq $column) {
+ $extra_info{is_auto_increment} = 1;
+ $extra_info{sequence} = $generator;
+ }
+ }
+
+ return \%extra_info;
+}
+
=head1 SEE ALSO
L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
}
sub _extra_column_info {
- my ($self, $info) = @_;
+ my ($self, $table, $column, $info, $dbi_info) = @_;
my %extra_info;
- my ($table, $column) = @$info{qw/TABLE_NAME COLUMN_NAME/};
-
my $dbh = $self->schema->storage->dbh;
my $sth = $dbh->prepare(qq{
SELECT COLUMN_NAME
}
sub _extra_column_info {
- my ($self, $info) = @_;
+ my ($self, $table, $column, $info, $dbi_info) = @_;
my %extra_info;
- my ($table, $column) = @$info{qw/TABLE_NAME COLUMN_NAME/};
-
my $dbh = $self->schema->storage->dbh;
my $sth = $dbh->prepare_cached(
q{
}
sub _extra_column_info {
- my ($self, $info) = @_;
+ my ($self, $table, $column, $info, $dbi_info) = @_;
my %extra_info;
- if ($info->{COLUMN_DEF} && $info->{COLUMN_DEF} =~ /\bnextval\(/i) {
+ if ($dbi_info->{COLUMN_DEF} && $dbi_info->{COLUMN_DEF} =~ /\bnextval\(/i) {
$extra_info{is_auto_increment} = 1;
}
}
sub _extra_column_info {
- my ($self, $table, $col_name, $sth, $col_num) = @_;
- ($table, $col_name) = @{$table}{qw/TABLE_NAME COLUMN_NAME/} if ref $table;
+ my ($self, $table, $col_name, $info, $dbi_info) = @_;
my %extra_info;
my $dbh = $self->schema->storage->dbh;
my $has_autoinc = eval {
- my $get_seq = $self->{_cache}->{sqlite_sequence}
+ my $get_seq = $self->{_cache}{sqlite_sequence}
||= $dbh->prepare(q{SELECT count(*) FROM sqlite_sequence WHERE name = ?});
$get_seq->execute($table);
my ($ret) = $get_seq->fetchrow_array;
}
sub _extra_column_info {
- my ($self, $info) = @_;
+ my ($self, $table, $column, $info, $dbi_info) = @_;
my %extra_info;
- my ($table, $column) = @$info{qw/TABLE_NAME COLUMN_NAME/};
-
my $dbh = $self->schema->storage->dbh;
my $sth = $dbh->prepare(qq{SELECT name FROM syscolumns WHERE id = (SELECT id FROM sysobjects WHERE name = @{[ $dbh->quote($table) ]}) AND (status & 0x80) = 0x80 AND name = @{[ $dbh->quote($column) ]}});
$sth->execute();
sub _extra_column_info {
no warnings 'uninitialized';
- my ($self, $info) = @_;
+ my ($self, $table, $col, $info, $dbi_info) = @_;
my %extra_info;
- if ($info->{mysql_is_auto_increment}) {
+ if ($dbi_info->{mysql_is_auto_increment}) {
$extra_info{is_auto_increment} = 1
}
- if ($info->{mysql_type_name} =~ /\bunsigned\b/i) {
+ if ($dbi_info->{mysql_type_name} =~ /\bunsigned\b/i) {
$extra_info{extra}{unsigned} = 1;
}
- if ($info->{mysql_values}) {
- $extra_info{extra}{list} = $info->{mysql_values};
+ if ($dbi_info->{mysql_values}) {
+ $extra_info{extra}{list} = $dbi_info->{mysql_values};
}
- if ( $info->{COLUMN_DEF} =~ /^CURRENT_TIMESTAMP\z/i
- && $info->{mysql_type_name} =~ /^TIMESTAMP\z/i) {
+ if ( $dbi_info->{COLUMN_DEF} =~ /^CURRENT_TIMESTAMP\z/i
+ && $dbi_info->{mysql_type_name} =~ /^TIMESTAMP\z/i) {
$extra_info{default_value} = \'CURRENT_TIMESTAMP';
}
# First, with in-memory classes
my $schema_class = $self->setup_schema(@connect_info);
$self->test_schema($schema_class);
- $self->drop_tables;
}
# defined in sub create