From: Andrew Rodland Date: Wed, 19 May 2010 10:37:55 +0000 (-0500) Subject: Detect autoinc PKs properly for SQLite X-Git-Tag: 0.07000~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=97ab24bcade2cdc5a8fd83c3ecfefb73d3418005;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Detect autoinc PKs properly for SQLite --- diff --git a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm index 57b5202..d22ff6b 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm @@ -58,27 +58,16 @@ sub _columns_info_for { my $dbh = $self->schema->storage->dbh; local $dbh->{FetchHashKeyName} = 'NAME_lc'; - my $has_autoinc = eval { - 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; - $get_seq->finish; - $ret; - }; - - if (!$@ && $has_autoinc) { - my $sth = $dbh->prepare( - "pragma table_info(" . $dbh->quote_identifier($table) . ")" - ); - $sth->execute; - my $cols = $sth->fetchall_hashref('name'); - - while (my ($col_name, $info) = each %$result) { - if ($cols->{$col_name}{pk}) { - $info->{is_auto_increment} = 1; - } - } + my $sth = $dbh->prepare( + "pragma table_info(" . $dbh->quote_identifier($table) . ")" + ); + $sth->execute; + my $cols = $sth->fetchall_hashref('name'); + + while (my ($col_name, $info) = each %$result) { + if ($cols->{$col_name}{pk} && lc($cols->{$col_name}{type}) eq 'integer') { + $info->{is_auto_increment} = 1; + } } while (my ($col, $info) = each %$result) {