| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package DBIx::DBSchema::DBD::SQLite; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
797
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
45
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA %typemap); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
87
|
|
|
5
|
1
|
|
|
1
|
|
609
|
use DBIx::DBSchema::DBD; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
866
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$VERSION = '0.02'; |
|
8
|
|
|
|
|
|
|
@ISA = qw(DBIx::DBSchema::DBD); |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
%typemap = ( |
|
11
|
|
|
|
|
|
|
'SERIAL' => 'INTEGER PRIMARY KEY AUTOINCREMENT', |
|
12
|
|
|
|
|
|
|
); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
DBIx::DBSchema::DBD::SQLite - SQLite native driver for DBIx::DBSchema |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use DBI; |
|
21
|
|
|
|
|
|
|
use DBIx::DBSchema; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$dbh = DBI->connect('dbi:SQLite:tns_service_name', 'user','pass'); |
|
24
|
|
|
|
|
|
|
$schema = new_native DBIx::DBSchema $dbh; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
This module implements a SQLite-native driver for DBIx::DBSchema. |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 AUTHOR |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Jesse Vincent |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 API |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=over |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item columns CLASS DBI_DBH TABLE |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Given an active DBI database handle, return a listref of listrefs (see |
|
44
|
|
|
|
|
|
|
L), 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) |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub columns { |
|
52
|
0
|
|
|
0
|
1
|
|
my ( $proto, $dbh, $table ) = @_; |
|
53
|
0
|
|
|
|
|
|
my $sth = $dbh->prepare('PRAGMA table_info($table)'); |
|
54
|
0
|
|
|
|
|
|
$sth->execute(); |
|
55
|
0
|
|
|
|
|
|
my $rows = []; |
|
56
|
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
while ( my $row = $sth->fetchrow_hashref ) { |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# notnull # pk # name # type # cid # dflt_value |
|
60
|
0
|
0
|
|
|
|
|
push @$rows, |
|
61
|
|
|
|
|
|
|
[ |
|
62
|
|
|
|
|
|
|
$row->{'name'}, |
|
63
|
|
|
|
|
|
|
$row->{'type'}, |
|
64
|
|
|
|
|
|
|
( $row->{'notnull'} ? 0 : 1 ), |
|
65
|
|
|
|
|
|
|
undef, |
|
66
|
|
|
|
|
|
|
$row->{'dflt_value'}, |
|
67
|
|
|
|
|
|
|
$row->{'pk'} |
|
68
|
|
|
|
|
|
|
]; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
return $rows; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=item primary_key CLASS DBI_DBH TABLE |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Given an active DBI database handle, return the primary key for the specified |
|
79
|
|
|
|
|
|
|
table. |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub primary_key { |
|
84
|
0
|
|
|
0
|
1
|
|
my ($proto, $dbh, $table) = @_; |
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $cols = $proto->columns($dbh,$table); |
|
87
|
0
|
|
|
|
|
|
foreach my $col (@$cols) { |
|
88
|
0
|
0
|
|
|
|
|
return ($col->[1]) if ($col->[5]); |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
return undef; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=item unique CLASS DBI_DBH TABLE |
|
97
|
|
|
|
|
|
|
|
|
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 and |
|
101
|
|
|
|
|
|
|
L. |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub unique { |
|
106
|
0
|
|
|
0
|
1
|
|
my ($proto, $dbh, $table) = @_; |
|
107
|
0
|
|
|
|
|
|
my @names; |
|
108
|
0
|
|
|
|
|
|
my $indexes = $proto->_index_info($dbh, $table); |
|
109
|
0
|
|
|
|
|
|
foreach my $row (@$indexes) { |
|
110
|
0
|
0
|
|
|
|
|
push @names, $row->{'name'} if ($row->{'unique'}); |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
} |
|
113
|
0
|
|
|
|
|
|
my $info = {}; |
|
114
|
0
|
|
|
|
|
|
foreach my $name (@names) { |
|
115
|
0
|
|
|
|
|
|
$info->{'name'} = $proto->_index_cols($dbh, $name); |
|
116
|
|
|
|
|
|
|
} |
|
117
|
0
|
|
|
|
|
|
return $info; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item index CLASS DBI_DBH TABLE |
|
122
|
|
|
|
|
|
|
|
|
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 and |
|
126
|
|
|
|
|
|
|
L. |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub index { |
|
131
|
0
|
|
|
0
|
1
|
|
my ($proto, $dbh, $table) = @_; |
|
132
|
0
|
|
|
|
|
|
my @names; |
|
133
|
0
|
|
|
|
|
|
my $indexes = $proto->_index_info($dbh, $table); |
|
134
|
0
|
|
|
|
|
|
foreach my $row (@$indexes) { |
|
135
|
0
|
0
|
|
|
|
|
push @names, $row->{'name'} if not ($row->{'unique'}); |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
} |
|
138
|
0
|
|
|
|
|
|
my $info = {}; |
|
139
|
0
|
|
|
|
|
|
foreach my $name (@names) { |
|
140
|
0
|
|
|
|
|
|
$info->{'name'} = $proto->_index_cols($dbh, $name); |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
return $info; |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub _index_list { |
|
149
|
|
|
|
|
|
|
|
|
150
|
0
|
|
|
0
|
|
|
my $proto = shift; |
|
151
|
0
|
|
|
|
|
|
my $dbh = shift; |
|
152
|
0
|
|
|
|
|
|
my $table = shift; |
|
153
|
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
my $sth = $dbh->prepare('PRAGMA index_list($table)'); |
|
155
|
0
|
|
|
|
|
|
$sth->execute(); |
|
156
|
0
|
|
|
|
|
|
my $rows = []; |
|
157
|
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
while ( my $row = $sth->fetchrow_hashref ) { |
|
159
|
|
|
|
|
|
|
# Keys are "name" and "unique" |
|
160
|
0
|
|
|
|
|
|
push @$rows, $row; |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
return $rows; |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub _index_cols { |
|
170
|
0
|
|
|
0
|
|
|
my $proto = shift; |
|
171
|
0
|
|
|
|
|
|
my $dbh = shift; |
|
172
|
0
|
|
|
|
|
|
my $index = shift; |
|
173
|
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
|
my $sth = $dbh->prepare('PRAGMA index_info($index)'); |
|
175
|
0
|
|
|
|
|
|
$sth->execute(); |
|
176
|
0
|
|
|
|
|
|
my $data = {}; |
|
177
|
0
|
|
|
|
|
|
while ( my $row = $sth->fetchrow_hashref ) { |
|
178
|
|
|
|
|
|
|
# Keys are "name" and "seqno" |
|
179
|
0
|
|
|
|
|
|
$data->{$row->{'seqno'}} = $data->{'name'}; |
|
180
|
|
|
|
|
|
|
} |
|
181
|
0
|
|
|
|
|
|
my @results; |
|
182
|
0
|
|
|
|
|
|
foreach my $key (sort keys %$data) { |
|
183
|
0
|
|
|
|
|
|
push @results, $data->{$key}; |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
return \@results; |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
} |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=pod |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=back |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=cut |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
1; |