Revision history for Perl extension DBIx::Class::Schema::Loader
0.04999_01 Not yet released
+ - Set is_auto_increment for auto-increment columns (RT #31473)
+ (Only SQLite, MySQL and PostgreSQL are currently supported)
- Generate one-to-one accessors for unique foreign keys (ilmari)
- Fix Win32 test skip counts for good (RT #30568, Kenichi Ishigaki)
- Default Oracle db_schema to db username (patch
my $col_name = $info->{COLUMN_NAME};
$col_name =~ s/^\"(.*)\"$/$1/;
+ if ($self->_column_is_auto_increment($info)) {
+ $column_info{is_auto_increment} = 1;
+ }
+
$result{$col_name} = \%column_info;
}
$sth->finish;
$column_info{size} = $2;
}
+ if ($self->_column_is_auto_increment($table, $columns[$i], $sth, $i)) {
+ $column_info{is_auto_increment} = 1;
+ }
+
$result{$columns[$i]} = \%column_info;
}
$sth->finish;
return \%result;
}
+# Override this in vendor class to return whether a column is
+# auto-incremented
+sub _column_is_auto_increment {}
+
=head1 SEE ALSO
L<DBIx::Class::Schema::Loader>
return \@uniqs;
}
+sub _column_is_auto_increment {
+ my ($self, $info) = @_;
+
+ return $info->{COLUMN_DEF} && $info->{COLUMN_DEF} =~ /\bnextval\(/i;
+}
+
=head1 SEE ALSO
L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
my @rels;
my @uniqs;
+ my %auto_inc;
my $dbh = $self->schema->storage->dbh;
my $sth = $self->{_cache}->{sqlite_master}
push(@uniqs, [ $name => \@cols ]);
}
+ if ($col =~ /AUTOINCREMENT/i) {
+ $col =~ /^(\S+)/;
+ $auto_inc{lc $1} = 1;
+ }
+
next if $col !~ /^(.*\S)\s+REFERENCES\s+(\w+) (?: \s* \( (.*) \) )? /ix;
my ($cols, $f_table, $f_cols) = ($1, $2, $3);
});
}
- return { rels => \@rels, uniqs => \@uniqs };
+ return { rels => \@rels, uniqs => \@uniqs, auto_inc => \%auto_inc };
+}
+
+sub _column_is_auto_increment {
+ my ($self, $table, $col_name, $sth, $col_num) = @_;
+
+ $self->{_sqlite_parse_data}->{$table} ||=
+ $self->_sqlite_parse_table($table);
+
+ return $self->{_sqlite_parse_data}->{$table}->{auto_inc}->{$col_name};
}
sub _table_fk_info {
return \@uniqs;
}
+sub _column_is_auto_increment {
+ my ($self, $info) = @_;
+
+ return $info->{mysql_is_auto_increment};
+}
+
=head1 SEE ALSO
L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
{
my $tester = dbixcsl_common_tests->new(
vendor => 'SQLite',
- auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY',
+ auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT',
dsn => "dbi:$class:dbname=./t/sqlite_test",
user => '',
password => '',
user => $user,
password => $password,
db_schema => uc $user,
+ no_auto_increment => 1
);
if( !$dsn || !$user ) {
dsn => $dsn,
user => $user,
password => $password,
+ no_auto_increment => 1,
);
if( !$dsn || !$user ) {
sub run_tests {
my $self = shift;
- plan tests => 97;
+ plan tests => 98;
$self->create();
#}
}
+ SKIP: {
+ skip "This vendor doesn't detect auto-increment columns", 1
+ if $self->{no_auto_increment};
+
+ is( $rsobj1->result_source->column_info('id')->{is_auto_increment}, 1,
+ 'Setting is_auto_incrment works'
+ );
+ }
my $obj = $rsobj1->find(1);
is( $obj->id, 1 );