Revision 12451e34
Von Udo Spallek vor fast 18 Jahren hinzugefügt
SL/DBUtils.pm | ||
---|---|---|
29 | 29 |
|
30 | 30 |
sub do_query { |
31 | 31 |
my ($form, $dbh, $query) = splice(@_, 0, 3); |
32 |
|
|
32 | 33 |
dump_query(LXDebug::QUERY, '', $query . " (" . join(", ", @_) . ")", @_); |
34 |
|
|
33 | 35 |
if (0 == scalar(@_)) { |
34 | 36 |
$dbh->do($query) || $form->dberror($query); |
35 | 37 |
} else { |
... | ... | |
43 | 45 |
sub do_statement { |
44 | 46 |
my ($form, $sth, $query) = splice(@_, 0, 3); |
45 | 47 |
|
48 |
dump_query(LXDebug::QUERY, '', $query . " (" . join(", ", @_) . ")", @_); |
|
49 |
|
|
46 | 50 |
if (0 == scalar(@_)) { |
47 | 51 |
$sth->execute() || $form->dberror($query); |
48 | 52 |
} else { |
... | ... | |
53 | 57 |
|
54 | 58 |
sub dump_query { |
55 | 59 |
my ($level, $msg, $query) = splice(@_, 0, 3); |
60 |
|
|
56 | 61 |
while ($query =~ /\?/) { |
57 | 62 |
my $value = shift(@_); |
58 | 63 |
$value =~ s/\'/\\\'/g; |
... | ... | |
69 | 74 |
|
70 | 75 |
sub quote_db_date { |
71 | 76 |
my ($str) = @_; |
77 |
|
|
72 | 78 |
return "NULL" unless defined $str; |
73 | 79 |
return "current_date" if $str =~ /current_date/; |
80 |
|
|
74 | 81 |
$str =~ s/'/''/g; |
75 | 82 |
return "'$str'"; |
76 | 83 |
} |
77 | 84 |
|
78 | 85 |
sub prepare_execute_query { |
79 | 86 |
my ($form, $dbh, $query) = splice(@_, 0, 3); |
80 |
my $sth = $dbh->prepare($query) || $form->dberror($query); |
|
87 |
|
|
81 | 88 |
dump_query(LXDebug::QUERY, '', $query . " (" . join(", ", @_) . ")", @_); |
89 |
|
|
90 |
my $sth = $dbh->prepare($query) || $form->dberror($query); |
|
82 | 91 |
if (scalar(@_) != 0) { |
83 | 92 |
$sth->execute(@_) || $form->dberror($query . " (" . join(", ", @_) . ")"); |
84 | 93 |
} else { |
... | ... | |
91 | 100 |
sub selectall_hashref_query { |
92 | 101 |
my ($form, $dbh, $query) = splice(@_, 0, 3); |
93 | 102 |
|
103 |
dump_query(LXDebug::QUERY, '', $query . " (" . join(", ", @_) . ")", @_); |
|
104 |
|
|
94 | 105 |
my $sth = prepare_execute_query($form, $dbh, $query, @_); |
95 | 106 |
my $result = []; |
96 | 107 |
while (my $ref = $sth->fetchrow_hashref()) { |
... | ... | |
104 | 115 |
sub selectfirst_hashref_query { |
105 | 116 |
my ($form, $dbh, $query) = splice(@_, 0, 3); |
106 | 117 |
|
118 |
dump_query(LXDebug::QUERY, '', $query . " (" . join(", ", @_) . ")", @_); |
|
119 |
|
|
107 | 120 |
my $sth = prepare_execute_query($form, $dbh, $query, @_); |
108 | 121 |
my $ref = $sth->fetchrow_hashref(); |
109 | 122 |
$sth->finish(); |
... | ... | |
114 | 127 |
sub selectfirst_array_query { |
115 | 128 |
my ($form, $dbh, $query) = splice(@_, 0, 3); |
116 | 129 |
|
130 |
dump_query(LXDebug::QUERY, '', $query . " (" . join(", ", @_) . ")", @_); |
|
131 |
|
|
117 | 132 |
my $sth = prepare_execute_query($form, $dbh, $query, @_); |
118 | 133 |
my @ret = $sth->fetchrow_array(); |
119 | 134 |
$sth->finish(); |
... | ... | |
122 | 137 |
} |
123 | 138 |
|
124 | 139 |
1; |
140 |
|
|
141 |
|
|
142 |
__END__ |
|
143 |
|
|
144 |
=head1 NAME |
|
145 |
|
|
146 |
SL::DBUTils.pm: All about Databaseconections in Lx |
|
147 |
|
|
148 |
=head1 SYNOPSIS |
|
149 |
|
|
150 |
use DBUtils; |
|
151 |
|
|
152 |
conv_i |
|
153 |
conv_date |
|
154 |
conv_dateq |
|
155 |
quote_db_date($str) |
|
156 |
|
|
157 |
do_query($form, $dbh, $query) |
|
158 |
do_statement($form, $sth, $query) |
|
159 |
|
|
160 |
dump_query($level, $msg, $query) |
|
161 |
prepare_execute_query($form, $dbh, $query) |
|
162 |
|
|
163 |
my $all_results_ref = selectall_hashref_query($form, $dbh, $query) |
|
164 |
my $first_result_hash_ref = selectfirst_hashref_query($form, $dbh, $query); |
|
165 |
|
|
166 |
my @first_result = selectfirst_array_query($form, $dbh, $query); # == |
|
167 |
my @first_result = selectrow_query($form, $dbh, $query); |
|
168 |
|
|
169 |
|
|
170 |
=head1 DESCRIPTION |
|
171 |
|
|
172 |
=head1 FUNCTIONS |
|
173 |
|
|
174 |
=over 4 |
|
175 |
|
|
176 |
=item conv_i |
|
177 |
|
|
178 |
=item conv_date |
|
179 |
|
|
180 |
=item conv_dateq |
|
181 |
|
|
182 |
=item quote_db_date($str) |
|
183 |
|
|
184 |
=item do_query($form, $dbh, $query) |
|
185 |
|
|
186 |
=item do_statement($form, $sth, $query) |
|
187 |
|
|
188 |
=item dump_query($level, $msg, $query) |
|
189 |
|
|
190 |
=item prepare_execute_query($form, $dbh, $query) |
|
191 |
|
|
192 |
=item selectall_hashref_query($form, $dbh, $query) |
|
193 |
|
|
194 |
=item selectfirst_hashref_query($form, $dbh, $query); |
|
195 |
|
|
196 |
=item selectfirst_array_query($form, $dbh, $query); # == |
|
197 |
|
|
198 |
=item selectrow_query($form, $dbh, $query); |
|
199 |
|
|
200 |
=back |
|
201 |
|
|
202 |
=head1 EXAMPLE |
|
203 |
|
|
204 |
=head1 SEE ALSO |
|
205 |
|
|
206 |
=head1 MODULE AUTHORS |
|
207 |
|
|
208 |
Sven Schoeling |
|
209 |
|
|
210 |
=head1 DOCUMENTATION AUTHORS |
|
211 |
|
|
212 |
Udo Spallek E<lt>udono@gmx.netE<gt> |
|
213 |
|
|
214 |
=head1 COPYRIGHT AND LICENSE |
|
215 |
|
|
216 |
Copyright 2007 by Lx-Office Community |
|
217 |
|
|
218 |
This program is free software; you can redistribute it and/or modify |
|
219 |
it under the terms of the GNU General Public License as published by |
|
220 |
the Free Software Foundation; either version 2 of the License, or |
|
221 |
(at your option) any later version. |
|
222 |
|
|
223 |
This program is distributed in the hope that it will be useful, |
|
224 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
225 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
226 |
GNU General Public License for more details. |
|
227 |
You should have received a copy of the GNU General Public License |
|
228 |
along with this program; if not, write to the Free Software |
|
229 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
230 |
=cut |
Auch abrufbar als: Unified diff
SL::DBUtils etwas verbessert. Bei jedem Query wird geprüft ob der Debugmodus
eingeschaltet ist-> Eintrag ins Log.
Auch habe ich eine Anleitung für das Modul angefangen, aber bisher nur den
Aufruf einiger Funktionen beschrieben siehe perldoc SL/DBUtils.