1 package DBIx::DBSchema::DBD::SQLite;
4 use vars qw($VERSION @ISA %typemap);
5 use DBIx::DBSchema::DBD;
8 @ISA = qw(DBIx::DBSchema::DBD);
11 'SERIAL' => 'INTEGER PRIMARY KEY AUTOINCREMENT',
16 DBIx::DBSchema::DBD::SQLite - SQLite native driver for DBIx::DBSchema
23 $dbh = DBI->connect('dbi:SQLite:tns_service_name', 'user','pass');
24 $schema = new_native DBIx::DBSchema $dbh;
28 This module implements a SQLite-native driver for DBIx::DBSchema.
32 Jesse Vincent <jesse@bestpractical.com>
41 =item columns CLASS DBI_DBH TABLE
43 Given an active DBI database handle, return a listref of listrefs (see
44 L<perllol>), each containing six elements: column name, column type,
45 nullability, column length, column default, and a field reserved for
46 driver-specific use (which for sqlite is whether this col is a primary key)
52 my ( $proto, $dbh, $table ) = @_;
53 my $sth = $dbh->prepare('PRAGMA table_info($table)');
57 while ( my $row = $sth->fetchrow_hashref ) {
59 # notnull # pk # name # type # cid # dflt_value
64 ( $row->{'notnull'} ? 0 : 1 ),
76 =item primary_key CLASS DBI_DBH TABLE
78 Given an active DBI database handle, return the primary key for the specified
84 my ($proto, $dbh, $table) = @_;
86 my $cols = $proto->columns($dbh,$table);
87 foreach my $col (@$cols) {
88 return ($col->[1]) if ($col->[5]);
96 =item unique CLASS DBI_DBH TABLE
98 Given an active DBI database handle, return a hashref of unique indices. The
99 keys of the hashref are index names, and the values are arrayrefs which point
100 a list of column names for each. See L<perldsc/"HASHES OF LISTS"> and
101 L<DBIx::DBSchema::ColGroup>.
106 my ($proto, $dbh, $table) = @_;
108 my $indexes = $proto->_index_info($dbh, $table);
109 foreach my $row (@$indexes) {
110 push @names, $row->{'name'} if ($row->{'unique'});
114 foreach my $name (@names) {
115 $info->{'name'} = $proto->_index_cols($dbh, $name);
121 =item index CLASS DBI_DBH TABLE
123 Given an active DBI database handle, return a hashref of (non-unique) indices.
124 The keys of the hashref are index names, and the values are arrayrefs which
125 point a list of column names for each. See L<perldsc/"HASHES OF LISTS"> and
126 L<DBIx::DBSchema::ColGroup>.
131 my ($proto, $dbh, $table) = @_;
133 my $indexes = $proto->_index_info($dbh, $table);
134 foreach my $row (@$indexes) {
135 push @names, $row->{'name'} if not ($row->{'unique'});
139 foreach my $name (@names) {
140 $info->{'name'} = $proto->_index_cols($dbh, $name);
154 my $sth = $dbh->prepare('PRAGMA index_list($table)');
158 while ( my $row = $sth->fetchrow_hashref ) {
159 # Keys are "name" and "unique"
174 my $sth = $dbh->prepare('PRAGMA index_info($index)');
177 while ( my $row = $sth->fetchrow_hashref ) {
178 # Keys are "name" and "seqno"
179 $data->{$row->{'seqno'}} = $data->{'name'};
182 foreach my $key (sort keys %$data) {
183 push @results, $data->{$key};