6 @EXPORT = qw(conv_i conv_date conv_dateq do_query selectrow_query do_statement
7 dump_query quote_db_date
8 selectfirst_hashref_query selectfirst_array_query
9 selectall_hashref_query selectall_array_query
10 prepare_execute_query prepare_query);
13 my ($value, $default) = @_;
14 return (defined($value) && "$value" ne "") ? $value * 1 : $default;
19 return (defined($value) && "$value" ne "") ? $value : undef;
24 if (defined($value) && "$value" ne "") {
25 $value =~ s/\'/\'\'/g;
32 $main::lxdebug->enter_sub(2);
34 my ($form, $dbh, $query) = splice(@_, 0, 3);
36 dump_query(LXDebug::QUERY, '', $query, @_);
38 if (0 == scalar(@_)) {
39 $dbh->do($query) || $form->dberror($query);
41 $dbh->do($query, undef, @_) ||
42 $form->dberror($query . " (" . join(", ", @_) . ")");
45 $main::lxdebug->leave_sub(2);
48 sub selectrow_query { &selectfirst_array_query }
51 $main::lxdebug->enter_sub(2);
53 my ($form, $sth, $query) = splice(@_, 0, 3);
55 dump_query(LXDebug::QUERY, '', $query, @_);
57 if (0 == scalar(@_)) {
58 $sth->execute() || $form->dberror($query);
61 $form->dberror($query . " (" . join(", ", @_) . ")");
64 $main::lxdebug->leave_sub(2);
68 my ($level, $msg, $query) = splice(@_, 0, 3);
70 while ($query =~ /\?/) {
71 my $value = shift(@_);
72 $value =~ s/\'/\\\'/g;
73 $value = "'${value}'";
74 $query =~ s/\?/$value/;
77 $query =~ s/[\n\s]+/ /g;
79 $msg .= " " if ($msg);
81 $main::lxdebug->message($level, $msg . $query);
87 return "NULL" unless defined $str;
88 return "current_date" if $str =~ /current_date/;
95 $main::lxdebug->enter_sub(2);
97 my ($form, $dbh, $query) = splice(@_, 0, 3);
99 dump_query(LXDebug::QUERY, '', $query, @_);
101 my $sth = $dbh->prepare($query) || $form->dberror($query);
103 $main::lxdebug->leave_sub(2);
108 sub prepare_execute_query {
109 $main::lxdebug->enter_sub(2);
111 my ($form, $dbh, $query) = splice(@_, 0, 3);
113 dump_query(LXDebug::QUERY, '', $query, @_);
115 my $sth = $dbh->prepare($query) || $form->dberror($query);
116 if (scalar(@_) != 0) {
117 $sth->execute(@_) || $form->dberror($query . " (" . join(", ", @_) . ")");
119 $sth->execute() || $form->dberror($query);
122 $main::lxdebug->leave_sub(2);
127 sub selectall_hashref_query {
128 $main::lxdebug->enter_sub(2);
130 my ($form, $dbh, $query) = splice(@_, 0, 3);
132 my $sth = prepare_execute_query($form, $dbh, $query, @_);
134 while (my $ref = $sth->fetchrow_hashref()) {
135 push(@{ $result }, $ref);
139 $main::lxdebug->leave_sub(2);
144 sub selectall_array_query {
145 $main::lxdebug->enter_sub(2);
147 my ($form, $dbh, $query) = splice(@_, 0, 3);
149 my $sth = prepare_execute_query($form, $dbh, $query, @_);
151 while (my ($value) = $sth->fetchrow_array()) {
152 push(@result, $value);
156 $main::lxdebug->leave_sub(2);
161 sub selectfirst_hashref_query {
162 $main::lxdebug->enter_sub(2);
164 my ($form, $dbh, $query) = splice(@_, 0, 3);
166 my $sth = prepare_execute_query($form, $dbh, $query, @_);
167 my $ref = $sth->fetchrow_hashref();
170 $main::lxdebug->leave_sub(2);
175 sub selectfirst_array_query {
176 $main::lxdebug->enter_sub(2);
178 my ($form, $dbh, $query) = splice(@_, 0, 3);
180 my $sth = prepare_execute_query($form, $dbh, $query, @_);
181 my @ret = $sth->fetchrow_array();
184 $main::lxdebug->leave_sub(2);
196 SL::DBUTils.pm: All about Databaseconections in Lx
207 do_query($form, $dbh, $query)
208 do_statement($form, $sth, $query)
210 dump_query($level, $msg, $query)
211 prepare_execute_query($form, $dbh, $query)
213 my $all_results_ref = selectall_hashref_query($form, $dbh, $query)
214 my $first_result_hash_ref = selectfirst_hashref_query($form, $dbh, $query);
216 my @first_result = selectfirst_array_query($form, $dbh, $query); # ==
217 my @first_result = selectrow_query($form, $dbh, $query);
232 =item quote_db_date($str)
234 =item do_query($form, $dbh, $query)
236 =item do_statement($form, $sth, $query)
238 =item dump_query($level, $msg, $query)
240 =item prepare_execute_query($form, $dbh, $query)
242 =item selectall_hashref_query($form, $dbh, $query)
244 =item selectfirst_hashref_query($form, $dbh, $query);
246 =item selectfirst_array_query($form, $dbh, $query); # ==
248 =item selectrow_query($form, $dbh, $query);
256 =head1 MODULE AUTHORS
258 Moritz Bunkus E<lt>m.bunkus@linet-services.de<gt>
259 Sven Schoeling E<lt>s.schoeling@linet-services.de<gt>
261 =head1 DOCUMENTATION AUTHORS
263 Udo Spallek E<lt>udono@gmx.netE<gt>
265 =head1 COPYRIGHT AND LICENSE
267 Copyright 2007 by Lx-Office Community
269 This program is free software; you can redistribute it and/or modify
270 it under the terms of the GNU General Public License as published by
271 the Free Software Foundation; either version 2 of the License, or
272 (at your option) any later version.
274 This program is distributed in the hope that it will be useful,
275 but WITHOUT ANY WARRANTY; without even the implied warranty of
276 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
277 GNU General Public License for more details.
278 You should have received a copy of the GNU General Public License
279 along with this program; if not, write to the Free Software
280 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.