File Coverage

blib/lib/Class/DBI/SQLite.pm
Criterion Covered Total %
statement 31 31 100.0
branch 3 4 75.0
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 39 41 95.1


line stmt bran cond sub pod time code
1             package Class::DBI::SQLite;
2              
3 4     4   117465 use strict;
  4         10  
  4         152  
4 4     4   21 use vars qw($VERSION);
  4         8  
  4         312  
5             $VERSION = "0.11";
6              
7             require Class::DBI;
8 4     4   20 use base qw(Class::DBI);
  4         10  
  4         5347  
9              
10             sub _auto_increment_value {
11 21     21   507410 my $self = shift;
12 21         132 return $self->db_Main->func("last_insert_rowid");
13             }
14              
15             sub set_up_table {
16 2     2 0 196092 my($class, $table) = @_;
17              
18             # find all columns.
19 2         78 my $sth = $class->db_Main->prepare("PRAGMA table_info('$table')");
20 2         9384 $sth->execute();
21 2         273 my @columns;
22 2         74 while (my $row = $sth->fetchrow_hashref) {
23 6         159 push @columns, $row->{name};
24             }
25 2         31 $sth->finish;
26              
27             # find primary key. so complex ;-(
28 2         15 $sth = $class->db_Main->prepare(<<'SQL');
29             SELECT sql FROM sqlite_master WHERE tbl_name = ?
30             SQL
31 2         293 $sth->execute($table);
32 2         275 my($sql) = $sth->fetchrow_array;
33 2         17 $sth->finish;
34 2         39 my ($primary) = $sql =~ m/
35             (?:\(|\,) # either a ( to start the definition or a , for next
36             \s* # maybe some whitespace
37             (\w+) # the col name
38             [^,]* # anything but the end or a ',' for next column
39             PRIMARY\sKEY/sxi;
40 2         5 my @pks;
41 2 100       9 if ($primary) {
42 1         3 @pks = ($primary);
43             } else {
44 1         8 my ($pks)= $sql =~ m/PRIMARY\s+KEY\s*\(\s*([^)]+)\s*\)/;
45 1 50       13 @pks = split(m/\s*\,\s*/, $pks) if $pks;
46             }
47 2         29 $class->table($table);
48 2         127 $class->columns(Primary => @pks);
49 2         1397 $class->columns(All => @columns);
50             }
51              
52             1;
53              
54             __END__