line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Class::DBI::Lite::SQLite; |
3
|
|
|
|
|
|
|
|
4
|
16
|
|
|
16
|
|
50787
|
use strict; |
|
16
|
|
|
|
|
31
|
|
|
16
|
|
|
|
|
407
|
|
5
|
16
|
|
|
16
|
|
71
|
use warnings 'all'; |
|
16
|
|
|
|
|
25
|
|
|
16
|
|
|
|
|
421
|
|
6
|
16
|
|
|
16
|
|
73
|
use base 'Class::DBI::Lite'; |
|
16
|
|
|
|
|
26
|
|
|
16
|
|
|
|
|
6958
|
|
7
|
16
|
|
|
16
|
|
105
|
use Carp 'confess'; |
|
16
|
|
|
|
|
26
|
|
|
16
|
|
|
|
|
737
|
|
8
|
16
|
|
|
16
|
|
5866
|
use Class::DBI::Lite::TableInfo; |
|
16
|
|
|
|
|
40
|
|
|
16
|
|
|
|
|
8538
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
#============================================================================== |
12
|
|
|
|
|
|
|
sub set_up_table |
13
|
|
|
|
|
|
|
{ |
14
|
51
|
|
|
51
|
0
|
28215
|
my $s = shift; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Get our columns: |
17
|
51
|
|
|
|
|
94
|
my $table = shift; |
18
|
51
|
|
|
|
|
566
|
$s->_init_meta( $table ); |
19
|
50
|
|
|
|
|
271
|
$s->after_set_up_table; |
20
|
50
|
|
|
|
|
96
|
1; |
21
|
|
|
|
|
|
|
}# end set_up_table() |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
#============================================================================== |
25
|
|
|
|
|
|
|
sub get_tables |
26
|
|
|
|
|
|
|
{ |
27
|
0
|
|
|
0
|
0
|
0
|
my ($s, $schema) = @_; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
0
|
local $s->db_Main->{AutoCommit}; |
30
|
0
|
|
|
|
|
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
|
|
|
|
|
0
|
$sth->execute(); |
37
|
0
|
|
|
|
|
0
|
my @out = ( ); |
38
|
0
|
|
|
|
|
0
|
while( my ($name) = $sth->fetchrow ) |
39
|
|
|
|
|
|
|
{ |
40
|
0
|
|
|
|
|
0
|
push @out, $name; |
41
|
|
|
|
|
|
|
}# end while() |
42
|
0
|
|
|
|
|
0
|
$sth->finish(); |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
0
|
@out ? return @out : return; |
45
|
|
|
|
|
|
|
}# end get_tables() |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
#============================================================================== |
49
|
|
|
|
|
|
|
sub get_meta_columns |
50
|
|
|
|
|
|
|
{ |
51
|
50
|
|
|
50
|
0
|
120
|
my ($s, $schema, $table) = @_; |
52
|
|
|
|
|
|
|
|
53
|
50
|
|
|
|
|
242
|
local $s->db_Main->{AutoCommit}; |
54
|
50
|
|
|
|
|
142869
|
my $sth = $s->db_Main->prepare(<<""); |
55
|
|
|
|
|
|
|
PRAGMA table_info( '$table' ) |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Simple discovery of fields and PK: |
58
|
50
|
|
|
|
|
13988
|
$sth->execute( ); |
59
|
50
|
|
|
|
|
188
|
my @cols = ( ); |
60
|
50
|
|
|
|
|
90
|
my $PK; |
61
|
50
|
|
|
|
|
1179
|
while( my $rec = $sth->fetchrow_hashref ) |
62
|
|
|
|
|
|
|
{ |
63
|
|
|
|
|
|
|
# Is this the primary column?: |
64
|
|
|
|
|
|
|
$PK = $rec->{name} |
65
|
151
|
100
|
|
|
|
438
|
if $rec->{pk}; |
66
|
151
|
|
|
|
|
1627
|
push @cols, $rec->{name}; |
67
|
|
|
|
|
|
|
}# end while() |
68
|
50
|
|
|
|
|
241
|
$sth->finish(); |
69
|
|
|
|
|
|
|
|
70
|
50
|
100
|
|
|
|
646
|
confess "Table $table doesn't exist or has no columns" |
71
|
|
|
|
|
|
|
unless @cols; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
return { |
74
|
49
|
|
|
|
|
1984
|
Primary => [ $PK ], |
75
|
|
|
|
|
|
|
Essential => \@cols, |
76
|
|
|
|
|
|
|
All => \@cols, |
77
|
|
|
|
|
|
|
}; |
78
|
|
|
|
|
|
|
}# end get_meta_columns() |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
#============================================================================== |
82
|
|
|
|
50
|
0
|
|
sub after_set_up_table { } |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
#============================================================================== |
86
|
|
|
|
|
|
|
sub get_table_info |
87
|
|
|
|
|
|
|
{ |
88
|
8
|
|
|
8
|
1
|
452
|
my $s = shift; |
89
|
8
|
|
33
|
|
|
37
|
my $class = ref($s) || $s; |
90
|
8
|
|
|
|
|
20
|
my $table = $class->table; |
91
|
8
|
|
|
|
|
22
|
my $cur = $class->db_Main->prepare("PRAGMA table_info('$table')"); |
92
|
8
|
|
|
|
|
1431
|
$cur->execute; |
93
|
|
|
|
|
|
|
|
94
|
8
|
|
|
|
|
34
|
my $info = Class::DBI::Lite::TableInfo->new( $class->table ); |
95
|
|
|
|
|
|
|
|
96
|
8
|
|
|
|
|
26
|
my %key_types = ( |
97
|
|
|
|
|
|
|
UNI => 'unique', |
98
|
|
|
|
|
|
|
PRI => 'primary_key' |
99
|
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
|
101
|
8
|
|
|
|
|
152
|
while( my $res = $cur->fetchrow_hashref ) |
102
|
|
|
|
|
|
|
{ |
103
|
24
|
|
|
|
|
130
|
my ($type) = $res->{type} =~ m/^([^\(\)]+)/; |
104
|
24
|
|
|
|
|
37
|
my $length; |
105
|
24
|
100
|
|
|
|
113
|
if( $type =~ m/(text|varchar|char)/i ) |
106
|
|
|
|
|
|
|
{ |
107
|
16
|
|
|
|
|
64
|
($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
|
100
|
|
|
|
124
|
key => undef, |
|
|
50
|
|
|
|
|
|
117
|
|
|
|
|
|
|
); |
118
|
|
|
|
|
|
|
}# end while() |
119
|
8
|
|
|
|
|
36
|
$cur->finish; |
120
|
|
|
|
|
|
|
|
121
|
8
|
|
|
|
|
118
|
return $info; |
122
|
|
|
|
|
|
|
}# end get_table_info() |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
#============================================================================== |
126
|
|
|
|
|
|
|
sub get_last_insert_id |
127
|
|
|
|
|
|
|
{ |
128
|
1256
|
|
|
1256
|
0
|
4119
|
$_[0]->db_Main->func('last_insert_rowid'); |
129
|
|
|
|
|
|
|
}# end get_last_insert_id() |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
0
|
0
|
|
sub lock_table { } |
132
|
|
|
|
0
|
0
|
|
sub unlock_table { } |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1;# return true: |
135
|
|
|
|
|
|
|
|