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
|
|
121957
|
use strict; |
|
13
|
|
|
|
|
26
|
|
|
13
|
|
|
|
|
402
|
|
9
|
13
|
|
|
13
|
|
69
|
use warnings; |
|
13
|
|
|
|
|
26
|
|
|
13
|
|
|
|
|
410
|
|
10
|
13
|
|
|
13
|
|
76
|
use Carp; |
|
13
|
|
|
|
|
29
|
|
|
13
|
|
|
|
|
681
|
|
11
|
13
|
|
|
13
|
|
4331
|
use ClearPress::driver::mysql; |
|
13
|
|
|
|
|
38
|
|
|
13
|
|
|
|
|
414
|
|
12
|
13
|
|
|
13
|
|
4110
|
use ClearPress::driver::SQLite; |
|
13
|
|
|
|
|
38
|
|
|
13
|
|
|
|
|
430
|
|
13
|
13
|
|
|
13
|
|
12320
|
use DBI; |
|
13
|
|
|
|
|
168023
|
|
|
13
|
|
|
|
|
1001
|
|
14
|
13
|
|
|
13
|
|
136
|
use English qw(-no_match_vars); |
|
13
|
|
|
|
|
33
|
|
|
13
|
|
|
|
|
105
|
|
15
|
13
|
|
|
13
|
|
5015
|
use Carp; |
|
13
|
|
|
|
|
28
|
|
|
13
|
|
|
|
|
10436
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = q[476.4.2]; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
25
|
|
|
25
|
1
|
4552
|
my ($class, $ref) = @_; |
21
|
25
|
|
100
|
|
|
123
|
$ref ||= {}; |
22
|
25
|
|
|
|
|
64
|
bless $ref, $class; |
23
|
25
|
|
|
|
|
115
|
return $ref; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub dbh { |
27
|
2
|
|
|
2
|
1
|
1533
|
my $self = shift; |
28
|
2
|
|
|
|
|
200
|
carp q[dbh unimplemented]; |
29
|
2
|
|
|
|
|
152
|
return; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub new_driver { |
33
|
15
|
|
|
15
|
1
|
56
|
my ($self, $drivername, $ref) = @_; |
34
|
|
|
|
|
|
|
|
35
|
15
|
|
|
|
|
63
|
my $drvpkg = "ClearPress::driver::$drivername"; |
36
|
|
|
|
|
|
|
return $drvpkg->new({ |
37
|
|
|
|
|
|
|
drivername => $drivername, |
38
|
15
|
|
|
|
|
39
|
%{$ref}, |
|
15
|
|
|
|
|
215
|
|
39
|
|
|
|
|
|
|
}); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub DESTROY { |
43
|
15
|
|
|
15
|
|
2938
|
my $self = shift; |
44
|
|
|
|
|
|
|
|
45
|
15
|
100
|
66
|
|
|
150
|
if($self->{dbh} && $self->{dbh}->ping()) { |
46
|
|
|
|
|
|
|
######### |
47
|
|
|
|
|
|
|
# flush down any uncommitted transactions & locks |
48
|
|
|
|
|
|
|
# |
49
|
9
|
|
|
|
|
541
|
$self->{dbh}->rollback(); |
50
|
9
|
|
|
|
|
868
|
$self->{dbh}->disconnect(); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
15
|
|
|
|
|
825
|
return 1; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub create_table { |
57
|
137
|
|
|
137
|
1
|
4893
|
my ($self, $t_name, $ref, $t_attrs) = @_; |
58
|
137
|
|
|
|
|
788
|
my $dbh = $self->dbh(); |
59
|
137
|
|
50
|
|
|
1378
|
$t_attrs ||= {}; |
60
|
137
|
|
100
|
|
|
594
|
$ref ||= {}; |
61
|
|
|
|
|
|
|
|
62
|
137
|
|
|
|
|
322
|
my %values = reverse %{$ref}; |
|
137
|
|
|
|
|
1206
|
|
63
|
137
|
|
|
|
|
497
|
my $pk = $values{'primary key'}; |
64
|
|
|
|
|
|
|
|
65
|
137
|
100
|
|
|
|
568
|
if(!$pk) { |
66
|
2
|
|
|
|
|
225
|
croak qq[Could not determine primary key for table $t_name]; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
135
|
|
|
|
|
592
|
my @fields = (qq[$pk @{[$self->type_map('primary key')]}]); |
|
135
|
|
|
|
|
681
|
|
70
|
|
|
|
|
|
|
|
71
|
135
|
|
|
|
|
2805
|
for my $f (grep { $_ ne $pk } keys %{$ref}) { |
|
407
|
|
|
|
|
1468
|
|
|
135
|
|
|
|
|
633
|
|
72
|
272
|
|
|
|
|
3246
|
push @fields, qq[$f @{[$self->type_map($ref->{$f})]}]; |
|
272
|
|
|
|
|
832
|
|
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
135
|
|
|
|
|
2273
|
my $desc = join q[, ], @fields; |
76
|
135
|
|
|
|
|
361
|
my $attrs = join q[ ], map { "$_=$t_attrs->{$_}" } keys %{$t_attrs}; |
|
0
|
|
|
|
|
0
|
|
|
135
|
|
|
|
|
688
|
|
77
|
|
|
|
|
|
|
|
78
|
135
|
|
|
|
|
1678
|
$dbh->do(qq[CREATE TABLE $t_name($desc) $attrs]); |
79
|
135
|
|
|
|
|
2074601
|
$dbh->commit(); |
80
|
|
|
|
|
|
|
|
81
|
135
|
|
|
|
|
2977
|
return 1; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub drop_table { |
85
|
135
|
|
|
135
|
1
|
2166
|
my ($self, $table_name) = @_; |
86
|
135
|
|
|
|
|
903
|
my $dbh = $self->dbh(); |
87
|
|
|
|
|
|
|
|
88
|
135
|
|
|
|
|
1974
|
$dbh->do(qq[DROP TABLE IF EXISTS $table_name]); |
89
|
135
|
|
|
|
|
707507
|
$dbh->commit(); |
90
|
|
|
|
|
|
|
|
91
|
135
|
|
|
|
|
941
|
return 1; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub types { |
95
|
2
|
|
|
2
|
1
|
677
|
return {}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub type_map { |
99
|
409
|
|
|
409
|
1
|
1115
|
my ($self, $type) = @_; |
100
|
409
|
100
|
|
|
|
1184
|
if(!defined $type) { |
101
|
1
|
|
|
|
|
5
|
return; |
102
|
|
|
|
|
|
|
} |
103
|
408
|
|
66
|
|
|
1557
|
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
|
32
|
my ($self, $sth) = @_; |
118
|
8
|
|
|
|
|
35
|
return; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
__END__ |