line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ORLite::Migrate::Patch; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# A convenience module for writing migration patches. |
4
|
|
|
|
|
|
|
# Based on Padre::DB::Patch. |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5996
|
use 5.006; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
46
|
|
7
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
8
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
9
|
1
|
|
|
1
|
|
5
|
use Exporter (); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
14
|
|
10
|
1
|
|
|
1
|
|
5
|
use DBI (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
6
|
use vars qw{$VERSION @ISA @EXPORT $FILE}; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
154
|
|
13
|
|
|
|
|
|
|
BEGIN { |
14
|
1
|
|
|
1
|
|
8
|
$VERSION = '1.10'; |
15
|
1
|
|
|
|
|
21
|
@ISA = 'Exporter'; |
16
|
1
|
|
|
|
|
4
|
@EXPORT = qw{ |
17
|
|
|
|
|
|
|
file |
18
|
|
|
|
|
|
|
dbh |
19
|
|
|
|
|
|
|
do |
20
|
|
|
|
|
|
|
selectall_arrayref |
21
|
|
|
|
|
|
|
selectall_hashref |
22
|
|
|
|
|
|
|
selectcol_arrayref |
23
|
|
|
|
|
|
|
selectrow_array |
24
|
|
|
|
|
|
|
selectrow_arrayref |
25
|
|
|
|
|
|
|
selectrow_hashref |
26
|
|
|
|
|
|
|
pragma |
27
|
|
|
|
|
|
|
table_exists |
28
|
|
|
|
|
|
|
column_exists |
29
|
|
|
|
|
|
|
}; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# The location of the SQLite database file |
32
|
1
|
|
|
|
|
628
|
$FILE = undef; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub file { |
36
|
0
|
0
|
|
0
|
0
|
|
unless ( $FILE ) { |
37
|
|
|
|
|
|
|
# The filename is passed on STDIN |
38
|
0
|
|
|
|
|
|
$FILE = ; |
39
|
0
|
|
|
|
|
|
chomp($FILE); |
40
|
0
|
0
|
0
|
|
|
|
unless ( -f $FILE and -w $FILE ) { |
41
|
0
|
|
|
|
|
|
die "SQLite file $FILE does not exist"; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
0
|
|
|
|
|
|
return $FILE; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub dbh { |
48
|
0
|
|
|
0
|
0
|
|
my $file = file(); |
49
|
0
|
|
|
|
|
|
my $dbh = DBI->connect( |
50
|
|
|
|
|
|
|
"dbi:SQLite:$file", |
51
|
|
|
|
|
|
|
undef, undef, |
52
|
|
|
|
|
|
|
{ RaiseError => 1, |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
); |
55
|
0
|
0
|
|
|
|
|
unless ($dbh) { |
56
|
0
|
|
|
|
|
|
die "Failed to connect to $file"; |
57
|
|
|
|
|
|
|
} |
58
|
0
|
|
|
|
|
|
return $dbh; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub do { |
62
|
0
|
|
|
0
|
0
|
|
dbh()->do(@_); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub selectall_arrayref { |
66
|
0
|
|
|
0
|
0
|
|
dbh()->selectall_arrayref(@_); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub selectall_hashref { |
70
|
0
|
|
|
0
|
0
|
|
dbh()->selectall_hashref(@_); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub selectcol_arrayref { |
74
|
0
|
|
|
0
|
0
|
|
dbh()->selectcol_arrayref(@_); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub selectrow_array { |
78
|
0
|
|
|
0
|
0
|
|
dbh()->selectrow_array(@_); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub selectrow_arrayref { |
82
|
0
|
|
|
0
|
0
|
|
dbh()->selectrow_arrayref(@_); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub selectrow_hashref { |
86
|
0
|
|
|
0
|
0
|
|
dbh()->selectrow_hashref(@_); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub pragma { |
90
|
0
|
0
|
|
0
|
0
|
|
do("pragma $_[0] = $_[1]") if @_ > 2; |
91
|
0
|
|
|
|
|
|
selectrow_arrayref("pragma $_[0]")->[0]; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub table_exists { |
95
|
0
|
|
|
0
|
0
|
|
selectrow_array( |
96
|
|
|
|
|
|
|
"select count(*) from sqlite_master where type = 'table' and name = ?", |
97
|
|
|
|
|
|
|
{}, $_[0], |
98
|
|
|
|
|
|
|
); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub column_exists { |
102
|
0
|
0
|
|
0
|
0
|
|
table_exists( $_[0] ) |
103
|
|
|
|
|
|
|
or selectrow_array( "select count($_[1]) from $_[0]", {} ); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |