1 package DBIx::Class::Schema::Loader::DBI::SQLite;
6 DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault
7 DBIx::Class::Schema::Loader::DBI
9 use Carp::Clan qw/^DBIx::Class/;
10 use Text::Balanced qw( extract_bracketed );
13 our $VERSION = '0.07000';
17 DBIx::Class::Schema::Loader::DBI::SQLite - DBIx::Class::Schema::Loader::DBI SQLite Implementation.
21 See L<DBIx::Class::Schema::Loader> and L<DBIx::Class::Schema::Loader::Base>.
27 SQLite will fail all further commands on a connection if the underlying schema
28 has been modified. Therefore, any runtime changes requiring C<rescan> also
29 require us to re-connect to the database. The C<rescan> method here handles
30 that reconnection for you, but beware that this must occur for any other open
31 sqlite connections as well.
38 $self->next::method(@_);
40 if (not defined $self->preserve_case) {
41 $self->preserve_case(0);
46 my ($self, $schema) = @_;
48 $schema->storage->disconnect if $schema->storage;
49 $self->next::method($schema);
52 sub _extra_column_info {
53 my ($self, $table, $col_name, $info, $dbi_info) = @_;
56 my $dbh = $self->schema->storage->dbh;
57 my $has_autoinc = eval {
58 my $get_seq = $self->{_cache}{sqlite_sequence}
59 ||= $dbh->prepare(q{SELECT count(*) FROM sqlite_sequence WHERE name = ?});
60 $get_seq->execute($table);
61 my ($ret) = $get_seq->fetchrow_array;
66 if (!$@ && $has_autoinc) {
67 my $sth = $dbh->prepare(
68 "pragma table_info(" . $dbh->quote_identifier($table) . ")"
71 my $cols = $sth->fetchall_hashref('name');
72 if ($cols->{$col_name}{pk}) {
73 $extra_info{is_auto_increment} = 1;
81 my ($self, $table) = @_;
83 my $dbh = $self->schema->storage->dbh;
84 my $sth = $dbh->prepare(
85 "pragma foreign_key_list(" . $dbh->quote_identifier($table) . ")"
90 while (my $fk = $sth->fetchrow_hashref) {
91 my $rel = $rels[ $fk->{id} ] ||= {
93 remote_columns => undef,
94 remote_table => $fk->{table}
97 push @{ $rel->{local_columns} }, $self->_lc($fk->{from});
98 push @{ $rel->{remote_columns} }, $self->_lc($fk->{to}) if defined $fk->{to};
99 warn "This is supposed to be the same rel but remote_table changed from ",
100 $rel->{remote_table}, " to ", $fk->{table}
101 if $rel->{remote_table} ne $fk->{table};
107 sub _table_uniq_info {
108 my ($self, $table) = @_;
110 my $dbh = $self->schema->storage->dbh;
111 my $sth = $dbh->prepare(
112 "pragma index_list(" . $dbh->quote($table) . ")"
117 while (my $idx = $sth->fetchrow_hashref) {
118 next unless $idx->{unique};
119 my $name = $idx->{name};
121 my $get_idx_sth = $dbh->prepare("pragma index_info(" . $dbh->quote($name) . ")");
122 $get_idx_sth->execute;
124 while (my $idx_row = $get_idx_sth->fetchrow_hashref) {
125 push @cols, $self->_lc($idx_row->{name});
127 $get_idx_sth->finish;
128 push @uniqs, [ $name => \@cols ];
135 my ($self, $opts) = @_;
137 my $dbh = $self->schema->storage->dbh;
138 my $sth = $dbh->prepare("SELECT * FROM sqlite_master");
141 while ( my $row = $sth->fetchrow_hashref ) {
142 next unless $row->{type} =~ /^(?:table|view)\z/i;
143 next if $row->{tbl_name} =~ /^sqlite_/;
144 push @tables, $row->{tbl_name};
147 return $self->_filter_tables(\@tables, $opts);
152 L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
153 L<DBIx::Class::Schema::Loader::DBI>
157 See L<DBIx::Class::Schema::Loader/AUTHOR> and L<DBIx::Class::Schema::Loader/CONTRIBUTORS>.
161 This library is free software; you can redistribute it and/or modify it under
162 the same terms as Perl itself.