X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FLoader%2FDBI%2FSQLite.pm;h=2cf3e2dbc2d91157e986ecdf42a1fdda08d2f49a;hb=c697835eacc34e76036a6e91cc4b0bc1ccd05f69;hp=b181b9dcad9a4cac05086a89725fb6be8770c66b;hpb=4a1323d2bfc068aa8acec1ca3b85776fafba4783;p=dbsrgits%2FDBIx-Class-Schema-Loader.git diff --git a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm index b181b9d..2cf3e2d 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm @@ -7,10 +7,9 @@ use base qw/ DBIx::Class::Schema::Loader::DBI /; use Carp::Clan qw/^DBIx::Class/; -use Text::Balanced qw( extract_bracketed ); -use Class::C3; +use mro 'c3'; -our $VERSION = '0.07001'; +our $VERSION = '0.07005'; =head1 NAME @@ -80,9 +79,17 @@ sub _columns_info_for { $sth->execute; my $cols = $sth->fetchall_hashref('name'); + my ($num_pk, $pk_col) = (0); + # SQLite doesn't give us the info we need to do this nicely :( + # If there is exactly one column marked PK, and its type is integer, + # set it is_auto_increment. This isn't 100%, but it's better than the + # alternatives. while (my ($col_name, $info) = each %$result) { - if ($cols->{$col_name}{pk} && lc($cols->{$col_name}{type}) eq 'integer') { - $info->{is_auto_increment} = 1; + if ($cols->{$col_name}{pk}) { + $num_pk ++; + if (lc($cols->{$col_name}{type}) eq 'integer') { + $pk_col = $col_name; + } } } @@ -90,6 +97,9 @@ sub _columns_info_for { if ((eval { ${ $info->{default_value} } }||'') eq 'CURRENT_TIMESTAMP') { ${ $info->{default_value} } = 'current_timestamp'; } + if ($num_pk == 1 and defined $pk_col and $pk_col eq $col) { + $info->{is_auto_increment} = 1; + } } return $result;