use Text::Balanced qw( extract_bracketed );
use Class::C3;
+our $VERSION = '0.04999_07';
+
=head1 NAME
DBIx::Class::Schema::Loader::DBI::SQLite - DBIx::Class::Schema::Loader::DBI SQLite Implementation.
package My::Schema;
use base qw/DBIx::Class::Schema::Loader/;
- __PACKAGE__->loader_optoins( relationships => 1 );
+ __PACKAGE__->loader_options( debug => 1 );
1;
See L<DBIx::Class::Schema::Loader::Base>.
+=head1 METHODS
+
+=head2 rescan
+
+SQLite will fail all further commands on a connection if the
+underlying schema has been modified. Therefore, any runtime
+changes requiring C<rescan> also require us to re-connect
+to the database. The C<rescan> method here handles that
+reconnection for you, but beware that this must occur for
+any other open sqlite connections as well.
+
=cut
+sub rescan {
+ my ($self, $schema) = @_;
+
+ $schema->storage->disconnect if $schema->storage;
+ $self->next::method($schema);
+}
+
# XXX this really needs a re-factor
sub _sqlite_parse_table {
my ($self, $table) = @_;
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 _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 {
next if $row->{tbl_name} =~ /^sqlite_/;
push @tables, $row->{tbl_name};
}
+ $sth->finish;
return @tables;
}