line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::DBSchema::DBD::SQLite; |
2
|
1
|
|
|
1
|
|
470
|
use base qw( DBIx::DBSchema::DBD ); |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
370
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
5
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION %typemap); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
678
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$VERSION = '0.04'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
%typemap = ( |
10
|
|
|
|
|
|
|
'SERIAL' => 'INTEGER PRIMARY KEY AUTOINCREMENT', |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
DBIx::DBSchema::DBD::SQLite - SQLite native driver for DBIx::DBSchema |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use DBI; |
20
|
|
|
|
|
|
|
use DBIx::DBSchema; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$dbh = DBI->connect('dbi:SQLite:tns_service_name', 'user','pass'); |
23
|
|
|
|
|
|
|
$schema = new_native DBIx::DBSchema $dbh; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 DESCRIPTION |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
This module implements a SQLite-native driver for DBIx::DBSchema. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 AUTHORS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Jesse Vincent |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Nathan Anderson |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 API |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=over |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=item columns CLASS DBI_DBH TABLE |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Given an active DBI database handle, return a listref of listrefs (see |
45
|
|
|
|
|
|
|
L), each containing six elements: column name, column type, |
46
|
|
|
|
|
|
|
nullability, column length, column default, and a field reserved for |
47
|
|
|
|
|
|
|
driver-specific use (which for sqlite is whether this col is a primary key) |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub columns { |
53
|
0
|
|
|
0
|
1
|
|
my ( $proto, $dbh, $table ) = @_; |
54
|
0
|
|
|
|
|
|
my $sth = $dbh->prepare("PRAGMA table_info($table)"); |
55
|
0
|
|
|
|
|
|
$sth->execute(); |
56
|
0
|
|
|
|
|
|
my $rows = []; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
while ( my $row = $sth->fetchrow_hashref ) { |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# notnull # pk # name # type # cid # dflt_value |
61
|
|
|
|
|
|
|
push @$rows, |
62
|
|
|
|
|
|
|
[ |
63
|
|
|
|
|
|
|
$row->{'name'}, |
64
|
|
|
|
|
|
|
$row->{'type'}, |
65
|
|
|
|
|
|
|
( $row->{'notnull'} ? 0 : 1 ), |
66
|
|
|
|
|
|
|
undef, |
67
|
|
|
|
|
|
|
$row->{'dflt_value'}, |
68
|
0
|
0
|
|
|
|
|
$row->{'pk'} |
69
|
|
|
|
|
|
|
]; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
return $rows; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item primary_key CLASS DBI_DBH TABLE |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Given an active DBI database handle, return the primary key for the specified |
80
|
|
|
|
|
|
|
table. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub primary_key { |
85
|
0
|
|
|
0
|
1
|
|
my ($proto, $dbh, $table) = @_; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
my $cols = $proto->columns($dbh,$table); |
88
|
0
|
|
|
|
|
|
foreach my $col (@$cols) { |
89
|
0
|
0
|
|
|
|
|
return ($col->[1]) if ($col->[5]); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
return undef; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item unique CLASS DBI_DBH TABLE |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Given an active DBI database handle, return a hashref of unique indices. The |
100
|
|
|
|
|
|
|
keys of the hashref are index names, and the values are arrayrefs which point |
101
|
|
|
|
|
|
|
a list of column names for each. See L and |
102
|
|
|
|
|
|
|
L. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub unique { |
107
|
0
|
|
|
0
|
1
|
|
my ($proto, $dbh, $table) = @_; |
108
|
0
|
|
|
|
|
|
my @names; |
109
|
0
|
|
|
|
|
|
my $indexes = $proto->_index_info($dbh, $table); |
110
|
0
|
|
|
|
|
|
foreach my $row (@$indexes) { |
111
|
0
|
0
|
|
|
|
|
push @names, $row->{'name'} if ($row->{'unique'}); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
} |
114
|
0
|
|
|
|
|
|
my $info = {}; |
115
|
0
|
|
|
|
|
|
foreach my $name (@names) { |
116
|
0
|
|
|
|
|
|
$info->{'name'} = $proto->_index_cols($dbh, $name); |
117
|
|
|
|
|
|
|
} |
118
|
0
|
|
|
|
|
|
return $info; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item index CLASS DBI_DBH TABLE |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Given an active DBI database handle, return a hashref of (non-unique) indices. |
125
|
|
|
|
|
|
|
The keys of the hashref are index names, and the values are arrayrefs which |
126
|
|
|
|
|
|
|
point a list of column names for each. See L and |
127
|
|
|
|
|
|
|
L. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub index { |
132
|
0
|
|
|
0
|
1
|
|
my ($proto, $dbh, $table) = @_; |
133
|
0
|
|
|
|
|
|
my @names; |
134
|
0
|
|
|
|
|
|
my $indexes = $proto->_index_info($dbh, $table); |
135
|
0
|
|
|
|
|
|
foreach my $row (@$indexes) { |
136
|
0
|
0
|
|
|
|
|
push @names, $row->{'name'} if not ($row->{'unique'}); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
} |
139
|
0
|
|
|
|
|
|
my $info = {}; |
140
|
0
|
|
|
|
|
|
foreach my $name (@names) { |
141
|
0
|
|
|
|
|
|
$info->{'name'} = $proto->_index_cols($dbh, $name); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
return $info; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub _index_list { |
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
|
0
|
|
|
0
|
1
|
|
sub default_db_schema { '%'; } |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
sub tables { |
193
|
0
|
|
|
0
|
0
|
|
my($proto, $dbh) = @_; |
194
|
0
|
|
|
|
|
|
my $db_catalog = $proto->default_db_catalog; |
195
|
0
|
|
|
|
|
|
my $db_schema = $proto->default_db_schema; |
196
|
|
|
|
|
|
|
|
197
|
0
|
0
|
|
|
|
|
my $sth = $dbh->table_info($db_catalog, $db_schema, '%', 'TABLE') |
198
|
|
|
|
|
|
|
or die $dbh->errstr; |
199
|
|
|
|
|
|
|
|
200
|
0
|
|
|
|
|
|
$proto->SUPER::tables($dbh, $sth); |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=pod |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=back |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=cut |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
1; |