X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FLoader%2FDBI%2FSQLite.pm;h=cbe9ae01f66c071ab5f7d44a8e4b3a5e9cf96d0e;hb=dc767cd32c6728d4d9c3504acd259c0b2f19da2b;hp=a26a4672353ff663518c1b7cfa04c6d184f8a240;hpb=d7928f663c62e37cbbf7b6310b1fb11e7d6f1176;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 a26a467..cbe9ae0 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm @@ -2,12 +2,15 @@ package DBIx::Class::Schema::Loader::DBI::SQLite; use strict; use warnings; -use base qw/DBIx::Class::Schema::Loader::DBI/; +use base qw/ + DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault + DBIx::Class::Schema::Loader::DBI +/; use Carp::Clan qw/^DBIx::Class/; use Text::Balanced qw( extract_bracketed ); use Class::C3; -our $VERSION = '0.03999_01'; +our $VERSION = '0.05001'; =head1 NAME @@ -52,6 +55,7 @@ sub _sqlite_parse_table { my @rels; my @uniqs; + my %auto_inc; my $dbh = $self->schema->storage->dbh; my $sth = $self->{_cache}->{sqlite_master} @@ -62,7 +66,7 @@ sub _sqlite_parse_table { $sth->finish; # Cut "CREATE TABLE ( )" blabla... - $sql =~ /^[\w\s]+\((.*)\)$/si; + $sql =~ /^[\w\s']+\((.*)\)$/si; my $cols = $1; # strip single-line comments @@ -110,6 +114,11 @@ sub _sqlite_parse_table { 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); @@ -137,7 +146,22 @@ sub _sqlite_parse_table { }); } - return { rels => \@rels, uniqs => \@uniqs }; + return { rels => \@rels, uniqs => \@uniqs, auto_inc => \%auto_inc }; +} + +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 %extra_info; + + $self->{_sqlite_parse_data}->{$table} ||= + $self->_sqlite_parse_table($table); + + if ($self->{_sqlite_parse_data}->{$table}->{auto_inc}->{$col_name}) { + $extra_info{is_auto_increment} = 1; + } + + return \%extra_info; } sub _table_fk_info { @@ -167,6 +191,7 @@ sub _tables_list { my @tables; while ( my $row = $sth->fetchrow_hashref ) { next unless lc( $row->{type} ) eq 'table'; + next if $row->{tbl_name} =~ /^sqlite_/; push @tables, $row->{tbl_name}; } $sth->finish; @@ -178,6 +203,15 @@ sub _tables_list { L, L, L +=head1 AUTHOR + +See L and L. + +=head1 LICENSE + +This library is free software; you can redistribute it and/or modify it under +the same terms as Perl itself. + =cut 1;