line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Xtract::Scan::mysql; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
71
|
use 5.008005; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
164
|
|
4
|
4
|
|
|
4
|
|
21
|
use strict; |
|
4
|
|
|
|
|
120
|
|
|
4
|
|
|
|
|
2142
|
|
5
|
4
|
|
|
4
|
|
30
|
use DBI 1.57 ':sql_types'; |
|
4
|
|
|
|
|
101
|
|
|
4
|
|
|
|
|
2562
|
|
6
|
4
|
|
|
4
|
|
26
|
use Xtract::Scan (); |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
2602
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.16'; |
9
|
|
|
|
|
|
|
our @ISA = 'Xtract::Scan'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
###################################################################### |
16
|
|
|
|
|
|
|
# Introspection Methods |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub tables { |
19
|
0
|
0
|
|
|
|
|
map { |
20
|
0
|
|
|
0
|
0
|
|
/`([^`]+)`$/ ? "$1" : $_ |
21
|
|
|
|
|
|
|
} $_[0]->dbh->tables; |
22
|
|
|
|
|
|
|
}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
###################################################################### |
29
|
|
|
|
|
|
|
# SQL Generation |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub add_table { |
32
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
33
|
0
|
|
|
|
|
|
my $table = shift; |
34
|
0
|
|
|
|
|
|
my $tname = $table->name; |
35
|
0
|
|
0
|
|
|
|
my $from = shift || $tname; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Capture table metadata from a select on the table |
38
|
0
|
|
|
|
|
|
my $sth = $self->from_dbh->prepare("select * from $from"); |
39
|
0
|
0
|
0
|
|
|
|
unless ( $sth and $sth->execute ) { |
40
|
0
|
|
|
|
|
|
return $self->SUPER::add_table( $table, $from ); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my @name = @{$sth->{NAME_lc}}; |
|
0
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my @type = @{$sth->{TYPE}}; |
|
0
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my @null = @{$sth->{NULLABLE}}; |
|
0
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my @blob = @{$sth->{mysql_is_blob}}; |
|
0
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$sth->finish; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Generate the create fragments |
50
|
0
|
|
|
|
|
|
foreach my $i ( 0 .. $#name ) { |
51
|
0
|
0
|
|
|
|
|
if ( $blob[$i] ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
$type[$i] = 'BLOB'; |
53
|
|
|
|
|
|
|
} elsif ( $type[$i] == SQL_INTEGER ) { |
54
|
0
|
|
|
|
|
|
$type[$i] = 'INTEGER'; |
55
|
|
|
|
|
|
|
} elsif ( $type[$i] == SQL_FLOAT ) { |
56
|
0
|
|
|
|
|
|
$type[$i] = 'REAL'; |
57
|
|
|
|
|
|
|
} elsif ( $type[$i] == SQL_REAL ) { |
58
|
0
|
|
|
|
|
|
$type[$i] = 'REAL'; |
59
|
|
|
|
|
|
|
} elsif ( $type[$i] == -6 ) { |
60
|
0
|
|
|
|
|
|
$type[$i] = 'INTEGER'; |
61
|
|
|
|
|
|
|
} else { |
62
|
0
|
|
|
|
|
|
$type[$i] = 'TEXT'; |
63
|
|
|
|
|
|
|
} |
64
|
0
|
0
|
|
|
|
|
$null[$i] = $null[$i] ? 'NULL' : 'NOT NULL'; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
return ( |
68
|
0
|
|
|
|
|
|
create => [ |
69
|
|
|
|
|
|
|
"CREATE TABLE $tname (\n" |
70
|
|
|
|
|
|
|
. join( ",\n", |
71
|
|
|
|
|
|
|
map { |
72
|
0
|
|
|
|
|
|
"\t$name[$_] $type[$_] $null[$_]" |
73
|
|
|
|
|
|
|
} (0 .. $#name) |
74
|
|
|
|
|
|
|
) |
75
|
|
|
|
|
|
|
. "\n)" |
76
|
|
|
|
|
|
|
], |
77
|
|
|
|
|
|
|
select => [ |
78
|
|
|
|
|
|
|
"SELECT * FROM $from" |
79
|
|
|
|
|
|
|
], |
80
|
|
|
|
|
|
|
insert => ( |
81
|
|
|
|
|
|
|
"INSERT INTO $tname VALUES ( " |
82
|
|
|
|
|
|
|
. join( ", ", |
83
|
0
|
|
|
|
|
|
map { '?' } @name |
84
|
|
|
|
|
|
|
) |
85
|
|
|
|
|
|
|
. " )", |
86
|
|
|
|
|
|
|
), |
87
|
0
|
0
|
|
|
|
|
blobs => scalar( grep { $_ } @blob ) ? \@blob : undef, |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |