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>
40 =item columns CLASS DBI_DBH TABLE
42 Given an active DBI database handle, return a listref of listrefs (see
43 L<perllol>), each containing six elements: column name, column type,
44 nullability, column length, column default, and a field reserved for
45 driver-specific use (which for sqlite is whether this col is a primary key)
51 my ( $proto, $dbh, $table ) = @_;
52 my $sth = $dbh->prepare("PRAGMA table_info($table)");
56 while ( my $row = $sth->fetchrow_hashref ) {
58 # notnull # pk # name # type # cid # dflt_value
63 ( $row->{'notnull'} ? 0 : 1 ),
75 =item primary_key CLASS DBI_DBH TABLE
77 Given an active DBI database handle, return the primary key for the specified
83 my ($proto, $dbh, $table) = @_;
85 my $cols = $proto->columns($dbh,$table);
86 foreach my $col (@$cols) {
87 return ($col->[1]) if ($col->[5]);
95 =item unique CLASS DBI_DBH TABLE
97 Given an active DBI database handle, return a hashref of unique indices. The
98 keys of the hashref are index names, and the values are arrayrefs which point
99 a list of column names for each. See L<perldsc/"HASHES OF LISTS"> and
100 L<DBIx::DBSchema::ColGroup>.
105 my ($proto, $dbh, $table) = @_;
107 my $indexes = $proto->_index_info($dbh, $table);
108 foreach my $row (@$indexes) {
109 push @names, $row->{'name'} if ($row->{'unique'});
113 foreach my $name (@names) {
114 $info->{'name'} = $proto->_index_cols($dbh, $name);
120 =item index CLASS DBI_DBH TABLE
122 Given an active DBI database handle, return a hashref of (non-unique) indices.
123 The keys of the hashref are index names, and the values are arrayrefs which
124 point a list of column names for each. See L<perldsc/"HASHES OF LISTS"> and
125 L<DBIx::DBSchema::ColGroup>.
130 my ($proto, $dbh, $table) = @_;
132 my $indexes = $proto->_index_info($dbh, $table);
133 foreach my $row (@$indexes) {
134 push @names, $row->{'name'} if not ($row->{'unique'});
138 foreach my $name (@names) {
139 $info->{'name'} = $proto->_index_cols($dbh, $name);
153 my $sth = $dbh->prepare('PRAGMA index_list($table)');
157 while ( my $row = $sth->fetchrow_hashref ) {
158 # Keys are "name" and "unique"
173 my $sth = $dbh->prepare('PRAGMA index_info($index)');
176 while ( my $row = $sth->fetchrow_hashref ) {
177 # Keys are "name" and "seqno"
178 $data->{$row->{'seqno'}} = $data->{'name'};
181 foreach my $key (sort keys %$data) {
182 push @results, $data->{$key};