| 1 | |||||||||||||||||||||
| 2 | package Class::DBI::Lite::SQLite; | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 16 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 16 | ▶ | use warnings 'all'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 16 | ▶ | use base 'Class::DBI::Lite'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 16 | ▶ | use Carp 'confess'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 16 | ▶ | use Class::DBI::Lite::TableInfo; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | #============================================================================== | ||||||||||||||||||||
| 12 | sub set_up_table | ||||||||||||||||||||
| 13 | 51 | ▶ | { | ||||||||||||||||||
|
Subroutine
set_up_table: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 14 | 51 | my $s = shift; | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | # Get our columns: | ||||||||||||||||||||
| 17 | 51 | my $table = shift; | |||||||||||||||||||
| 18 | 51 | $s->_init_meta( $table ); | |||||||||||||||||||
| 19 | 50 | $s->after_set_up_table; | |||||||||||||||||||
| 20 | 50 | 1; | |||||||||||||||||||
| 21 | }# end set_up_table() | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | #============================================================================== | ||||||||||||||||||||
| 25 | sub get_tables | ||||||||||||||||||||
| 26 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
get_tables: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 27 | 0 | my ($s, $schema) = @_; | |||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 0 | local $s->db_Main->{AutoCommit}; | |||||||||||||||||||
| 30 | 0 | my $sth = $s->db_Main->prepare(<<""); | |||||||||||||||||||
| 31 | select name | ||||||||||||||||||||
| 32 | from sqlite_master | ||||||||||||||||||||
| 33 | where type = 'table' | ||||||||||||||||||||
| 34 | order by name | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 0 | $sth->execute(); | |||||||||||||||||||
| 37 | 0 | my @out = ( ); | |||||||||||||||||||
| 38 | 0 | ▶ | while( my ($name) = $sth->fetchrow ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | { | ||||||||||||||||||||
| 40 | 0 | push @out, $name; | |||||||||||||||||||
| 41 | }# end while() | ||||||||||||||||||||
| 42 | 0 | $sth->finish(); | |||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 0 | ▶ | @out ? return @out : return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | }# end get_tables() | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | #============================================================================== | ||||||||||||||||||||
| 49 | sub get_meta_columns | ||||||||||||||||||||
| 50 | 50 | ▶ | { | ||||||||||||||||||
|
Subroutine
get_meta_columns: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||
| 51 | 50 | my ($s, $schema, $table) = @_; | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 50 | local $s->db_Main->{AutoCommit}; | |||||||||||||||||||
| 54 | 50 | my $sth = $s->db_Main->prepare(<<""); | |||||||||||||||||||
| 55 | PRAGMA table_info( '$table' ) | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | # Simple discovery of fields and PK: | ||||||||||||||||||||
| 58 | 50 | $sth->execute( ); | |||||||||||||||||||
| 59 | 50 | my @cols = ( ); | |||||||||||||||||||
| 60 | 50 | my $PK; | |||||||||||||||||||
| 61 | 50 | ▶ | while( my $rec = $sth->fetchrow_hashref ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | { | ||||||||||||||||||||
| 63 | # Is this the primary column?: | ||||||||||||||||||||
| 64 | $PK = $rec->{name} | ||||||||||||||||||||
| 65 | 151 | ▶ | if $rec->{pk}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | 151 | push @cols, $rec->{name}; | |||||||||||||||||||
| 67 | }# end while() | ||||||||||||||||||||
| 68 | 50 | $sth->finish(); | |||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 50 | ▶ | confess "Table $table doesn't exist or has no columns" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 71 | unless @cols; | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | return { | ||||||||||||||||||||
| 74 | 49 | Primary => [ $PK ], | |||||||||||||||||||
| 75 | Essential => \@cols, | ||||||||||||||||||||
| 76 | All => \@cols, | ||||||||||||||||||||
| 77 | }; | ||||||||||||||||||||
| 78 | }# end get_meta_columns() | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | #============================================================================== | ||||||||||||||||||||
| 82 | 50 | ▶ | sub after_set_up_table { } | ||||||||||||||||||
|
Subroutine
after_set_up_table: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | #============================================================================== | ||||||||||||||||||||
| 86 | sub get_table_info | ||||||||||||||||||||
| 87 | 8 | ▶ | { | ||||||||||||||||||
|
Subroutine
get_table_info: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||
| 88 | 8 | my $s = shift; | |||||||||||||||||||
| 89 | 8 | ▶ | my $class = ref($s) || $s; | ||||||||||||||||||
|
Condition33%1/3
ref $s || $s
MC/DC0%0/2
ref $s || $s
ref $s
$s
Truth table33%1/3
A || B
A= ref $sB= $s
| |||||||||||||||||||||
| 90 | 8 | my $table = $class->table; | |||||||||||||||||||
| 91 | 8 | my $cur = $class->db_Main->prepare("PRAGMA table_info('$table')"); | |||||||||||||||||||
| 92 | 8 | $cur->execute; | |||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 8 | my $info = Class::DBI::Lite::TableInfo->new( $class->table ); | |||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 8 | my %key_types = ( | |||||||||||||||||||
| 97 | UNI => 'unique', | ||||||||||||||||||||
| 98 | PRI => 'primary_key' | ||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 8 | ▶ | while( my $res = $cur->fetchrow_hashref ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 102 | { | ||||||||||||||||||||
| 103 | 24 | my ($type) = $res->{type} =~ m/^([^\(\)]+)/; | |||||||||||||||||||
| 104 | 24 | my $length; | |||||||||||||||||||
| 105 | 24 | ▶ | if( $type =~ m/(text|varchar|char)/i ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 106 | { | ||||||||||||||||||||
| 107 | 16 | ($length) = $res->{type} =~ m/\((\d+)\)/; | |||||||||||||||||||
| 108 | }# end if() | ||||||||||||||||||||
| 109 | $info->add_column( | ||||||||||||||||||||
| 110 | name => $res->{name}, | ||||||||||||||||||||
| 111 | type => lc($type), | ||||||||||||||||||||
| 112 | length => $length, | ||||||||||||||||||||
| 113 | is_pk => $res->{pk} ? 1 : 0, | ||||||||||||||||||||
| 114 | is_nullable => $res->{notnull} ? 0 : 1, | ||||||||||||||||||||
| 115 | default_value => $res->{dflt_value}, | ||||||||||||||||||||
| 116 | 24 | ▶ | key => undef, | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 117 | ); | ||||||||||||||||||||
| 118 | }# end while() | ||||||||||||||||||||
| 119 | 8 | $cur->finish; | |||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | 8 | return $info; | |||||||||||||||||||
| 122 | }# end get_table_info() | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | #============================================================================== | ||||||||||||||||||||
| 126 | sub get_last_insert_id | ||||||||||||||||||||
| 127 | 1256 | ▶ | { | ||||||||||||||||||
|
Subroutine
get_last_insert_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 128 | 1256 | $_[0]->db_Main->func('last_insert_rowid'); | |||||||||||||||||||
| 129 | }# end get_last_insert_id() | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | 0 | ▶ | sub lock_table { } | ||||||||||||||||||
|
Subroutine
lock_table: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 132 | 0 | ▶ | sub unlock_table { } | ||||||||||||||||||
|
Subroutine
unlock_table: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | 16 | 1;# return true: | |||||||||||||||||||
| 135 | |||||||||||||||||||||