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 my ($form, $dbh, $query) = splice(@_, 0, 3);
34 dump_query(LXDebug::QUERY, '', $query, @_);
36 if (0 == scalar(@_)) {
37 $dbh->do($query) || $form->dberror($query);
39 $dbh->do($query, undef, @_) ||
40 $form->dberror($query . " (" . join(", ", @_) . ")");
44 sub selectrow_query { &selectfirst_array_query }
47 my ($form, $sth, $query) = splice(@_, 0, 3);
49 dump_query(LXDebug::QUERY, '', $query, @_);
51 if (0 == scalar(@_)) {
52 $sth->execute() || $form->dberror($query);
55 $form->dberror($query . " (" . join(", ", @_) . ")");
60 my ($level, $msg, $query) = splice(@_, 0, 3);
62 while ($query =~ /\?/) {
63 my $value = shift(@_);
64 $value =~ s/\'/\\\'/g;
65 $value = "'${value}'";
66 $query =~ s/\?/$value/;
69 $query =~ s/[\n\s]+/ /g;
71 $msg .= " " if ($msg);
73 $main::lxdebug->message($level, $msg . $query);
79 return "NULL" unless defined $str;
80 return "current_date" if $str =~ /current_date/;
87 my ($form, $dbh, $query) = splice(@_, 0, 3);
89 dump_query(LXDebug::QUERY, '', $query, @_);
91 my $sth = $dbh->prepare($query) || $form->dberror($query);
95 sub prepare_execute_query {
96 my ($form, $dbh, $query) = splice(@_, 0, 3);
98 dump_query(LXDebug::QUERY, '', $query, @_);
100 my $sth = $dbh->prepare($query) || $form->dberror($query);
101 if (scalar(@_) != 0) {
102 $sth->execute(@_) || $form->dberror($query . " (" . join(", ", @_) . ")");
104 $sth->execute() || $form->dberror($query);
110 sub selectall_hashref_query {
111 my ($form, $dbh, $query) = splice(@_, 0, 3);
113 my $sth = prepare_execute_query($form, $dbh, $query, @_);
115 while (my $ref = $sth->fetchrow_hashref()) {
116 push(@{ $result }, $ref);
123 sub selectall_array_query {
124 my ($form, $dbh, $query) = splice(@_, 0, 3);
126 my $sth = prepare_execute_query($form, $dbh, $query, @_);
128 while (my ($value) = $sth->fetchrow_array()) {
129 push(@result, $value);
136 sub selectfirst_hashref_query {
137 my ($form, $dbh, $query) = splice(@_, 0, 3);
139 my $sth = prepare_execute_query($form, $dbh, $query, @_);
140 my $ref = $sth->fetchrow_hashref();
146 sub selectfirst_array_query {
147 my ($form, $dbh, $query) = splice(@_, 0, 3);
149 my $sth = prepare_execute_query($form, $dbh, $query, @_);
150 my @ret = $sth->fetchrow_array();
163 SL::DBUTils.pm: All about Databaseconections in Lx
174 do_query($form, $dbh, $query)
175 do_statement($form, $sth, $query)
177 dump_query($level, $msg, $query)
178 prepare_execute_query($form, $dbh, $query)
180 my $all_results_ref = selectall_hashref_query($form, $dbh, $query)
181 my $first_result_hash_ref = selectfirst_hashref_query($form, $dbh, $query);
183 my @first_result = selectfirst_array_query($form, $dbh, $query); # ==
184 my @first_result = selectrow_query($form, $dbh, $query);
199 =item quote_db_date($str)
201 =item do_query($form, $dbh, $query)
203 =item do_statement($form, $sth, $query)
205 =item dump_query($level, $msg, $query)
207 =item prepare_execute_query($form, $dbh, $query)
209 =item selectall_hashref_query($form, $dbh, $query)
211 =item selectfirst_hashref_query($form, $dbh, $query);
213 =item selectfirst_array_query($form, $dbh, $query); # ==
215 =item selectrow_query($form, $dbh, $query);
223 =head1 MODULE AUTHORS
225 Moritz Bunkus E<lt>m.bunkus@linet-services.de<gt>
226 Sven Schoeling E<lt>s.schoeling@linet-services.de<gt>
228 =head1 DOCUMENTATION AUTHORS
230 Udo Spallek E<lt>udono@gmx.netE<gt>
232 =head1 COPYRIGHT AND LICENSE
234 Copyright 2007 by Lx-Office Community
236 This program is free software; you can redistribute it and/or modify
237 it under the terms of the GNU General Public License as published by
238 the Free Software Foundation; either version 2 of the License, or
239 (at your option) any later version.
241 This program is distributed in the hope that it will be useful,
242 but WITHOUT ANY WARRANTY; without even the implied warranty of
243 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
244 GNU General Public License for more details.
245 You should have received a copy of the GNU General Public License
246 along with this program; if not, write to the Free Software
247 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.