1 package DBIx::DBSchema::DBD::SQLite;
2 use base qw( DBIx::DBSchema::DBD );
5 use vars qw($VERSION %typemap);
10 'SERIAL' => 'INTEGER PRIMARY KEY AUTOINCREMENT',
15 DBIx::DBSchema::DBD::SQLite - SQLite native driver for DBIx::DBSchema
22 $dbh = DBI->connect('dbi:SQLite:tns_service_name', 'user','pass');
23 $schema = new_native DBIx::DBSchema $dbh;
27 This module implements a SQLite-native driver for DBIx::DBSchema.
31 Jesse Vincent <jesse@bestpractical.com>
33 Nathan Anderson <http://1id.com/=nathan.anderson>
42 =item columns CLASS DBI_DBH TABLE
44 Given an active DBI database handle, return a listref of listrefs (see
45 L<perllol>), each containing six elements: column name, column type,
46 nullability, column length, column default, and a field reserved for
47 driver-specific use (which for sqlite is whether this col is a primary key)
53 my ( $proto, $dbh, $table ) = @_;
54 my $sth = $dbh->prepare("PRAGMA table_info($table)");
58 while ( my $row = $sth->fetchrow_hashref ) {
60 # notnull # pk # name # type # cid # dflt_value
65 ( $row->{'notnull'} ? 0 : 1 ),
77 =item primary_key CLASS DBI_DBH TABLE
79 Given an active DBI database handle, return the primary key for the specified
85 my ($proto, $dbh, $table) = @_;
87 my $cols = $proto->columns($dbh,$table);
88 foreach my $col (@$cols) {
89 return ($col->[1]) if ($col->[5]);
97 =item unique CLASS DBI_DBH TABLE
99 Given an active DBI database handle, return a hashref of unique indices. The
100 keys of the hashref are index names, and the values are arrayrefs which point
101 a list of column names for each. See L<perldsc/"HASHES OF LISTS"> and
102 L<DBIx::DBSchema::ColGroup>.
107 my ($proto, $dbh, $table) = @_;
109 my $indexes = $proto->_index_info($dbh, $table);
110 foreach my $row (@$indexes) {
111 push @names, $row->{'name'} if ($row->{'unique'});
115 foreach my $name (@names) {
116 $info->{'name'} = $proto->_index_cols($dbh, $name);
122 =item index CLASS DBI_DBH TABLE
124 Given an active DBI database handle, return a hashref of (non-unique) indices.
125 The keys of the hashref are index names, and the values are arrayrefs which
126 point a list of column names for each. See L<perldsc/"HASHES OF LISTS"> and
127 L<DBIx::DBSchema::ColGroup>.
132 my ($proto, $dbh, $table) = @_;
134 my $indexes = $proto->_index_info($dbh, $table);
135 foreach my $row (@$indexes) {
136 push @names, $row->{'name'} if not ($row->{'unique'});
140 foreach my $name (@names) {
141 $info->{'name'} = $proto->_index_cols($dbh, $name);
155 my $sth = $dbh->prepare('PRAGMA index_list($table)');
159 while ( my $row = $sth->fetchrow_hashref ) {
160 # Keys are "name" and "unique"
175 my $sth = $dbh->prepare('PRAGMA index_info($index)');
178 while ( my $row = $sth->fetchrow_hashref ) {
179 # Keys are "name" and "seqno"
180 $data->{$row->{'seqno'}} = $data->{'name'};
183 foreach my $key (sort keys %$data) {
184 push @results, $data->{$key};
191 sub default_db_schema { '%'; }
194 my($proto, $dbh) = @_;
195 my $db_catalog = $proto->default_db_catalog;
196 my $db_schema = $proto->default_db_schema;
198 my $sth = $dbh->table_info($db_catalog, $db_schema, '%', 'TABLE')
201 $proto->SUPER::tables($dbh, $sth);