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
|
|
96402
|
use strict; |
|
13
|
|
|
|
|
47
|
|
|
13
|
|
|
|
|
455
|
|
9
|
13
|
|
|
13
|
|
91
|
use warnings; |
|
13
|
|
|
|
|
33
|
|
|
13
|
|
|
|
|
567
|
|
10
|
13
|
|
|
13
|
|
86
|
use Carp; |
|
13
|
|
|
|
|
35
|
|
|
13
|
|
|
|
|
839
|
|
11
|
13
|
|
|
13
|
|
5206
|
use ClearPress::driver::mysql; |
|
13
|
|
|
|
|
52
|
|
|
13
|
|
|
|
|
568
|
|
12
|
13
|
|
|
13
|
|
21212
|
use ClearPress::driver::SQLite; |
|
13
|
|
|
|
|
42
|
|
|
13
|
|
|
|
|
435
|
|
13
|
13
|
|
|
13
|
|
12969
|
use DBI; |
|
13
|
|
|
|
|
194298
|
|
|
13
|
|
|
|
|
1027
|
|
14
|
13
|
|
|
13
|
|
157
|
use English qw(-no_match_vars); |
|
13
|
|
|
|
|
39
|
|
|
13
|
|
|
|
|
114
|
|
15
|
13
|
|
|
13
|
|
10173
|
use Carp; |
|
13
|
|
|
|
|
33
|
|
|
13
|
|
|
|
|
10688
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = q[477.1.2]; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
25
|
|
|
25
|
1
|
9666
|
my ($class, $ref) = @_; |
21
|
25
|
|
100
|
|
|
135
|
$ref ||= {}; |
22
|
25
|
|
|
|
|
1486
|
bless $ref, $class; |
23
|
25
|
|
|
|
|
162
|
return $ref; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub dbh { |
27
|
2
|
|
|
2
|
1
|
2889
|
my $self = shift; |
28
|
2
|
|
|
|
|
467
|
carp q[dbh unimplemented]; |
29
|
2
|
|
|
|
|
232
|
return; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub new_driver { |
33
|
15
|
|
|
15
|
1
|
71
|
my ($self, $drivername, $ref) = @_; |
34
|
|
|
|
|
|
|
|
35
|
15
|
|
|
|
|
78
|
my $drvpkg = "ClearPress::driver::$drivername"; |
36
|
|
|
|
|
|
|
return $drvpkg->new({ |
37
|
|
|
|
|
|
|
drivername => $drivername, |
38
|
15
|
|
|
|
|
89
|
%{$ref}, |
|
15
|
|
|
|
|
291
|
|
39
|
|
|
|
|
|
|
}); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub DESTROY { |
43
|
15
|
|
|
15
|
|
3940
|
my $self = shift; |
44
|
|
|
|
|
|
|
|
45
|
15
|
100
|
66
|
|
|
212
|
if($self->{dbh} && $self->{dbh}->ping()) { |
46
|
|
|
|
|
|
|
######### |
47
|
|
|
|
|
|
|
# flush down any uncommitted transactions & locks |
48
|
|
|
|
|
|
|
# |
49
|
9
|
|
|
|
|
616
|
$self->{dbh}->rollback(); |
50
|
9
|
|
|
|
|
1304
|
$self->{dbh}->disconnect(); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
15
|
|
|
|
|
1148
|
return 1; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub create_table { |
57
|
137
|
|
|
137
|
1
|
9756
|
my ($self, $t_name, $ref, $t_attrs) = @_; |
58
|
137
|
|
|
|
|
962
|
my $dbh = $self->dbh(); |
59
|
137
|
|
50
|
|
|
1874
|
$t_attrs ||= {}; |
60
|
137
|
|
100
|
|
|
780
|
$ref ||= {}; |
61
|
|
|
|
|
|
|
|
62
|
137
|
|
|
|
|
454
|
my %values = reverse %{$ref}; |
|
137
|
|
|
|
|
1630
|
|
63
|
137
|
|
|
|
|
808
|
my $pk = $values{'primary key'}; |
64
|
|
|
|
|
|
|
|
65
|
137
|
100
|
|
|
|
603
|
if(!$pk) { |
66
|
2
|
|
|
|
|
238
|
croak qq[Could not determine primary key for table $t_name]; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
135
|
|
|
|
|
754
|
my @fields = (qq[$pk @{[$self->type_map('primary key')]}]); |
|
135
|
|
|
|
|
830
|
|
70
|
|
|
|
|
|
|
|
71
|
135
|
|
|
|
|
3381
|
for my $f (grep { $_ ne $pk } keys %{$ref}) { |
|
407
|
|
|
|
|
2091
|
|
|
135
|
|
|
|
|
1150
|
|
72
|
272
|
|
|
|
|
3338
|
push @fields, qq[$f @{[$self->type_map($ref->{$f})]}]; |
|
272
|
|
|
|
|
1388
|
|
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
135
|
|
|
|
|
4061
|
my $desc = join q[, ], @fields; |
76
|
135
|
|
|
|
|
399
|
my $attrs = join q[ ], map { "$_=$t_attrs->{$_}" } keys %{$t_attrs}; |
|
0
|
|
|
|
|
0
|
|
|
135
|
|
|
|
|
924
|
|
77
|
|
|
|
|
|
|
|
78
|
135
|
|
|
|
|
2099
|
$dbh->do(qq[CREATE TABLE $t_name($desc) $attrs]); |
79
|
135
|
|
|
|
|
4164889
|
$dbh->commit(); |
80
|
|
|
|
|
|
|
|
81
|
135
|
|
|
|
|
3830
|
return 1; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub drop_table { |
85
|
135
|
|
|
135
|
1
|
2623
|
my ($self, $table_name) = @_; |
86
|
135
|
|
|
|
|
1301
|
my $dbh = $self->dbh(); |
87
|
|
|
|
|
|
|
|
88
|
135
|
|
|
|
|
3375
|
$dbh->do(qq[DROP TABLE IF EXISTS $table_name]); |
89
|
135
|
|
|
|
|
1543894
|
$dbh->commit(); |
90
|
|
|
|
|
|
|
|
91
|
135
|
|
|
|
|
1316
|
return 1; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub types { |
95
|
2
|
|
|
2
|
1
|
2047
|
return {}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub type_map { |
99
|
409
|
|
|
409
|
1
|
1794
|
my ($self, $type) = @_; |
100
|
409
|
100
|
|
|
|
1912
|
if(!defined $type) { |
101
|
1
|
|
|
|
|
8
|
return; |
102
|
|
|
|
|
|
|
} |
103
|
408
|
|
66
|
|
|
1892
|
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
|
47
|
my ($self, $sth) = @_; |
118
|
8
|
|
|
|
|
38
|
return; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
__END__ |