line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $DBIx::SQL::Abstract.pm,v 1.1 2005/09/06 14:15:53 alex Exp $ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Copyright (c) 2004 Alejandro Juarez |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Permission to use, copy, modify, and distribute this software for any |
6
|
|
|
|
|
|
|
# purpose with or without fee is hereby granted, provided that the above |
7
|
|
|
|
|
|
|
# copyright notice and this permission notice appear in all copies. |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
10
|
|
|
|
|
|
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
11
|
|
|
|
|
|
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
12
|
|
|
|
|
|
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
13
|
|
|
|
|
|
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
14
|
|
|
|
|
|
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
15
|
|
|
|
|
|
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# PURPOSE: This module was created to serve several functions inhereted |
19
|
|
|
|
|
|
|
# from the DBIx and SQL::Abstract modules ... |
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
# USAGE: To read the HOW TO USE instructions you need to run perldoc: |
22
|
|
|
|
|
|
|
# perldoc DBIx::SQL::Abstract |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
package DBIx::SQL::Abstract; |
26
|
1
|
|
|
1
|
|
23925
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
27
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
28
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
90
|
|
29
|
1
|
|
|
1
|
|
6
|
use base 'DBIx'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
618
|
|
30
|
1
|
|
|
1
|
|
2694
|
use SQL::Abstract; |
|
1
|
|
|
|
|
13748
|
|
|
1
|
|
|
|
|
35
|
|
31
|
1
|
|
|
1
|
|
5579
|
use DBI; |
|
1
|
|
|
|
|
45600
|
|
|
1
|
|
|
|
|
83
|
|
32
|
1
|
|
|
1
|
|
13
|
use vars qw(@ISA); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
686
|
|
33
|
|
|
|
|
|
|
require Exporter; |
34
|
|
|
|
|
|
|
@ISA = qw(DBI DBI::db DBI::st SQL::Abstract); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub new { |
39
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
40
|
0
|
|
|
|
|
|
my %params = @_; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Setting the DBIx and database default parameters |
43
|
0
|
|
|
|
|
|
my $db = { driver => 'Pg', |
44
|
|
|
|
|
|
|
dbname => 'db', |
45
|
|
|
|
|
|
|
host => undef, |
46
|
|
|
|
|
|
|
port => undef, |
47
|
|
|
|
|
|
|
user => 'user', |
48
|
|
|
|
|
|
|
passwd => undef, |
49
|
|
|
|
|
|
|
attr => undef, # Used for DBI attributes |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Setting the DBIx and database default attributes |
53
|
0
|
|
|
|
|
|
my $dbiattr = { PrintError => 1, |
54
|
|
|
|
|
|
|
RaiseError => 0, |
55
|
|
|
|
|
|
|
AutoCommit => 0, |
56
|
|
|
|
|
|
|
ChopBlanks => 1 |
57
|
|
|
|
|
|
|
}; |
58
|
0
|
|
|
|
|
|
my $knownargs = join ('|', keys %$db); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Checking for 2 explicit options in the arguments |
61
|
0
|
0
|
|
|
|
|
if ( $#_ >= 3 ) { |
62
|
|
|
|
|
|
|
# Checking if here we had unknown arguments |
63
|
0
|
|
|
|
|
|
my @unknownargs = grep { $_ !~ /^($knownargs)$/ } keys %params; |
|
0
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
|
if ( ! @unknownargs ) { |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Checking for the existence of explicit args: dbname && user |
68
|
0
|
|
|
|
|
|
my @minargs = map { $_ =~ /^(dbname|user)$/ } keys %params; |
|
0
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
if ( $#minargs == 1) { |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Setting the arguments for the database connection |
72
|
0
|
|
|
|
|
|
map { $db->{$_} = $params{$_} } keys %params; |
|
0
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my ($dbLine, @dbargs); |
74
|
0
|
|
|
|
|
|
$dbLine = "dbi:$db->{driver}:dbname='$db->{dbname}'"; |
75
|
0
|
|
|
|
|
|
push @dbargs, $dbLine, $db->{user}, $db->{passwd}; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Setting the DBI Attributes |
78
|
0
|
0
|
|
|
|
|
if ( $db->{attr} ) { |
79
|
0
|
|
|
|
|
|
my $attr = $db->{attr}; #used only for a better style |
80
|
0
|
|
|
|
|
|
map { $dbiattr->{$_} = $attr->{$_} } keys %$attr; |
|
0
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Here, All is Right, we'll open the database connection |
84
|
0
|
0
|
|
|
|
|
my $dbh = DBI->connect(@dbargs, \%$dbiattr) or |
85
|
|
|
|
|
|
|
die ("Failed to open database connection:\n", |
86
|
|
|
|
|
|
|
$DBI::errstr); |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
return bless $dbh, $class; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
} else { |
91
|
0
|
|
|
|
|
|
die 'You need the DSN options: [dbname | user]'; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
} else { |
95
|
0
|
|
|
|
|
|
die 'Unknown argument(s) received: ', join(', ', @unknownargs); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
} else { |
99
|
0
|
|
|
|
|
|
die 'You need the DSN options: dbname => DBNAME, user => USER'; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub DESTROY { |
105
|
|
|
|
|
|
|
# If we are not in autocommit mode, roll back any transactions left |
106
|
|
|
|
|
|
|
# pending. Cleanly disconnect from the database before disappearing. |
107
|
0
|
|
|
0
|
|
|
my $self = shift; |
108
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
if (ref $self ) { |
110
|
0
|
0
|
|
|
|
|
if ($self->{AutoCommit} == 1 ) { |
111
|
0
|
|
|
|
|
|
$self->commit; |
112
|
|
|
|
|
|
|
} else { |
113
|
0
|
|
|
|
|
|
$self->rollback; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
return 1; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
__END__ |