line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- mode: cperl; tab-width: 8; indent-tabs-mode: nil; basic-offset: 2 -*- |
2
|
|
|
|
|
|
|
# vim:ts=8:sw=2:et:sta:sts=2 |
3
|
|
|
|
|
|
|
######### |
4
|
|
|
|
|
|
|
# Author: rmp |
5
|
|
|
|
|
|
|
# Created: 2006-10-31 |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
package ClearPress::driver; |
8
|
13
|
|
|
13
|
|
122408
|
use strict; |
|
13
|
|
|
|
|
41
|
|
|
13
|
|
|
|
|
414
|
|
9
|
13
|
|
|
13
|
|
78
|
use warnings; |
|
13
|
|
|
|
|
31
|
|
|
13
|
|
|
|
|
451
|
|
10
|
13
|
|
|
13
|
|
81
|
use Carp; |
|
13
|
|
|
|
|
30
|
|
|
13
|
|
|
|
|
832
|
|
11
|
13
|
|
|
13
|
|
4725
|
use ClearPress::driver::mysql; |
|
13
|
|
|
|
|
56
|
|
|
13
|
|
|
|
|
568
|
|
12
|
13
|
|
|
13
|
|
5823
|
use ClearPress::driver::SQLite; |
|
13
|
|
|
|
|
45
|
|
|
13
|
|
|
|
|
465
|
|
13
|
13
|
|
|
13
|
|
13672
|
use DBI; |
|
13
|
|
|
|
|
205255
|
|
|
13
|
|
|
|
|
1075
|
|
14
|
13
|
|
|
13
|
|
150
|
use English qw(-no_match_vars); |
|
13
|
|
|
|
|
33
|
|
|
13
|
|
|
|
|
118
|
|
15
|
13
|
|
|
13
|
|
5853
|
use Carp; |
|
13
|
|
|
|
|
36
|
|
|
13
|
|
|
|
|
10295
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = q[477.1.4]; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
25
|
|
|
25
|
1
|
5021
|
my ($class, $ref) = @_; |
21
|
25
|
|
100
|
|
|
276
|
$ref ||= {}; |
22
|
25
|
|
|
|
|
225
|
bless $ref, $class; |
23
|
25
|
|
|
|
|
146
|
return $ref; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub dbh { |
27
|
2
|
|
|
2
|
1
|
1689
|
my $self = shift; |
28
|
2
|
|
|
|
|
305
|
carp q[dbh unimplemented]; |
29
|
2
|
|
|
|
|
172
|
return; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub new_driver { |
33
|
15
|
|
|
15
|
1
|
65
|
my ($self, $drivername, $ref) = @_; |
34
|
|
|
|
|
|
|
|
35
|
15
|
|
|
|
|
66
|
my $drvpkg = "ClearPress::driver::$drivername"; |
36
|
|
|
|
|
|
|
return $drvpkg->new({ |
37
|
|
|
|
|
|
|
drivername => $drivername, |
38
|
15
|
|
|
|
|
1119
|
%{$ref}, |
|
15
|
|
|
|
|
256
|
|
39
|
|
|
|
|
|
|
}); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub DESTROY { |
43
|
15
|
|
|
15
|
|
2791
|
my $self = shift; |
44
|
|
|
|
|
|
|
|
45
|
15
|
100
|
66
|
|
|
182
|
if($self->{dbh} && $self->{dbh}->ping()) { |
46
|
|
|
|
|
|
|
######### |
47
|
|
|
|
|
|
|
# flush down any uncommitted transactions & locks |
48
|
|
|
|
|
|
|
# |
49
|
9
|
|
|
|
|
18457
|
$self->{dbh}->rollback(); |
50
|
9
|
|
|
|
|
1423
|
$self->{dbh}->disconnect(); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
15
|
|
|
|
|
780
|
return 1; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub create_table { |
57
|
137
|
|
|
137
|
1
|
6055
|
my ($self, $t_name, $ref, $t_attrs) = @_; |
58
|
137
|
|
|
|
|
827
|
my $dbh = $self->dbh(); |
59
|
137
|
|
50
|
|
|
3312
|
$t_attrs ||= {}; |
60
|
137
|
|
100
|
|
|
672
|
$ref ||= {}; |
61
|
|
|
|
|
|
|
|
62
|
137
|
|
|
|
|
455
|
my %values = reverse %{$ref}; |
|
137
|
|
|
|
|
1590
|
|
63
|
137
|
|
|
|
|
922
|
my $pk = $values{'primary key'}; |
64
|
|
|
|
|
|
|
|
65
|
137
|
100
|
|
|
|
563
|
if(!$pk) { |
66
|
2
|
|
|
|
|
262
|
croak qq[Could not determine primary key for table $t_name]; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
135
|
|
|
|
|
716
|
my @fields = (qq[$pk @{[$self->type_map('primary key')]}]); |
|
135
|
|
|
|
|
887
|
|
70
|
|
|
|
|
|
|
|
71
|
135
|
|
|
|
|
3231
|
for my $f (grep { $_ ne $pk } keys %{$ref}) { |
|
407
|
|
|
|
|
2601
|
|
|
135
|
|
|
|
|
888
|
|
72
|
272
|
|
|
|
|
2919
|
push @fields, qq[$f @{[$self->type_map($ref->{$f})]}]; |
|
272
|
|
|
|
|
1187
|
|
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
135
|
|
|
|
|
2564
|
my $desc = join q[, ], @fields; |
76
|
135
|
|
|
|
|
425
|
my $attrs = join q[ ], map { "$_=$t_attrs->{$_}" } keys %{$t_attrs}; |
|
0
|
|
|
|
|
0
|
|
|
135
|
|
|
|
|
819
|
|
77
|
|
|
|
|
|
|
|
78
|
135
|
|
|
|
|
2259
|
$dbh->do(qq[CREATE TABLE $t_name($desc) $attrs]); |
79
|
135
|
|
|
|
|
2085806
|
$dbh->commit(); |
80
|
|
|
|
|
|
|
|
81
|
135
|
|
|
|
|
4499
|
return 1; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub drop_table { |
85
|
135
|
|
|
135
|
1
|
3024
|
my ($self, $table_name) = @_; |
86
|
135
|
|
|
|
|
1654
|
my $dbh = $self->dbh(); |
87
|
|
|
|
|
|
|
|
88
|
135
|
|
|
|
|
2705
|
$dbh->do(qq[DROP TABLE IF EXISTS $table_name]); |
89
|
135
|
|
|
|
|
762610
|
$dbh->commit(); |
90
|
|
|
|
|
|
|
|
91
|
135
|
|
|
|
|
1336
|
return 1; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub types { |
95
|
2
|
|
|
2
|
1
|
975
|
return {}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub type_map { |
99
|
409
|
|
|
409
|
1
|
1749
|
my ($self, $type) = @_; |
100
|
409
|
100
|
|
|
|
1417
|
if(!defined $type) { |
101
|
1
|
|
|
|
|
5
|
return; |
102
|
|
|
|
|
|
|
} |
103
|
408
|
|
66
|
|
|
1816
|
return $self->types->{$type} || $type; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub create { |
107
|
0
|
|
|
0
|
1
|
0
|
return; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub bounded_select { |
111
|
0
|
|
|
0
|
1
|
0
|
my ($self, $query, $start, $len) = @_; |
112
|
0
|
|
|
|
|
0
|
carp q[bounded_select unimplemented by driver ], ref $self; |
113
|
0
|
|
|
|
|
0
|
return q[]; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub sth_has_warnings { |
117
|
8
|
|
|
8
|
1
|
38
|
my ($self, $sth) = @_; |
118
|
8
|
|
|
|
|
35
|
return; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
__END__ |