line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Xtract::Scan::SQLite; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
73
|
use 5.008005; |
|
4
|
|
|
|
|
15
|
|
|
4
|
|
|
|
|
163
|
|
4
|
4
|
|
|
4
|
|
23
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
116
|
|
5
|
4
|
|
|
4
|
|
20
|
use Xtract::Scan (); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
2263
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.16'; |
8
|
|
|
|
|
|
|
our @ISA = 'Xtract::Scan'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
###################################################################### |
15
|
|
|
|
|
|
|
# Introspection Methods |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub tables { |
18
|
12
|
|
|
|
|
51
|
grep { |
19
|
12
|
50
|
|
|
|
534327
|
! /^sqlite_/ |
20
|
|
|
|
|
|
|
} map { |
21
|
4
|
|
|
4
|
0
|
18
|
/"([^\"]+)"$/ ? "$1" : $_ |
22
|
|
|
|
|
|
|
} $_[0]->dbh->tables; |
23
|
|
|
|
|
|
|
}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
###################################################################### |
30
|
|
|
|
|
|
|
# SQL Generation |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub add_table { |
33
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
34
|
1
|
|
|
|
|
3
|
my $table = shift; |
35
|
1
|
|
|
|
|
4
|
my $tname = $table->name; |
36
|
1
|
|
33
|
|
|
8
|
my $from = shift || $tname; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# With a direct table copy, we can interrogate types from the |
39
|
|
|
|
|
|
|
# source table directly (hopefully). |
40
|
1
|
|
|
|
|
4
|
my $info = eval { |
41
|
1
|
|
|
|
|
7
|
$self->dbh->column_info( |
42
|
|
|
|
|
|
|
'', 'main', $from, '%' |
43
|
|
|
|
|
|
|
)->fetchall_arrayref( {} ); |
44
|
|
|
|
|
|
|
}; |
45
|
1
|
50
|
33
|
|
|
4799
|
unless ( $@ eq '' and $info ) { |
46
|
|
|
|
|
|
|
# Fallback to the generic approach |
47
|
0
|
|
|
|
|
0
|
return $self->SUPER::add_table( $table => $from ); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Generate the column metadata |
51
|
1
|
|
|
|
|
4
|
my @type = (); |
52
|
1
|
|
|
|
|
3
|
my @bind = (); |
53
|
1
|
|
|
|
|
4
|
foreach my $column ( @$info ) { |
54
|
2
|
|
|
|
|
9
|
$column->{TYPE_NAME} = uc $column->{TYPE_NAME}; |
55
|
2
|
|
|
|
|
4
|
my $name = $column->{COLUMN_NAME}; |
56
|
2
|
50
|
|
|
|
7
|
my $type = defined($column->{COLUMN_SIZE}) |
57
|
|
|
|
|
|
|
? "$column->{TYPE_NAME}($column->{COLUMN_SIZE})" |
58
|
|
|
|
|
|
|
: $column->{TYPE_NAME}; |
59
|
2
|
100
|
|
|
|
6
|
my $null = $column->{NULLABLE} ? "NULL" : "NOT NULL"; |
60
|
2
|
|
|
|
|
6
|
push @type, "$name $type $null"; |
61
|
2
|
50
|
|
|
|
10
|
push @bind, $column->{TYPE_NAME} eq 'BLOB' ? 1 : 0; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
return ( |
65
|
2
|
|
|
|
|
13
|
create => [ |
66
|
|
|
|
|
|
|
"CREATE TABLE $tname (\n" |
67
|
2
|
|
|
|
|
7
|
. join( ",\n", map { "\t$_" } @type ) |
68
|
|
|
|
|
|
|
. "\n)" |
69
|
|
|
|
|
|
|
], |
70
|
|
|
|
|
|
|
select => [ |
71
|
|
|
|
|
|
|
"SELECT * FROM $from" |
72
|
|
|
|
|
|
|
], |
73
|
|
|
|
|
|
|
insert => ( |
74
|
|
|
|
|
|
|
"INSERT INTO $tname VALUES ( " |
75
|
|
|
|
|
|
|
. join( ", ", |
76
|
2
|
|
|
|
|
23
|
map { '?' } @$info |
77
|
|
|
|
|
|
|
) |
78
|
|
|
|
|
|
|
. " )", |
79
|
|
|
|
|
|
|
), |
80
|
1
|
50
|
|
|
|
6
|
blobs => scalar( grep { $_ } @bind ) ? \@bind : undef, |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |