X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FDBUtils.pm;h=9dfe2715392671da3b882c875e9e7d12d8b44f42;hb=6b92d724ba32af43410d9563e77de6bb1013a5f1;hp=e8cd304eed043bd509481ac821e5e56980c491e5;hpb=88dea78ecdb77761f71c5016ca97e53b2d55d9d3;p=kivitendo-erp.git diff --git a/SL/DBUtils.pm b/SL/DBUtils.pm index e8cd304ee..9dfe27153 100644 --- a/SL/DBUtils.pm +++ b/SL/DBUtils.pm @@ -6,7 +6,7 @@ require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(conv_i conv_date conv_dateq do_query selectrow_query do_statement - dump_query quote_db_date + dump_query quote_db_date like selectfirst_hashref_query selectfirst_array_query selectall_hashref_query selectall_array_query selectall_as_map @@ -348,9 +348,9 @@ sub add_token { id => \&conv_i, bool => \&conv_b, date => \&conv_date, - start => sub { $_[0] . '%' }, - end => sub { '%' . $_[0] }, - substr => sub { '%' . $_[0] . '%' }, + start => sub { trim($_[0]) . '%' }, + end => sub { '%' . trim($_[0]) }, + substr => sub { like($_[0]) }, ); my $_long_token = sub { @@ -386,11 +386,19 @@ sub add_token { return ($token, @vals); } +sub like { + my ($string) = @_; + + return "%" . SL::Util::trim($string // '') . "%"; +} + 1; __END__ +=encoding utf-8 + =head1 NAME SL::DBUTils.pm: All about database connections in kivitendo @@ -420,23 +428,100 @@ SL::DBUTils.pm: All about database connections in kivitendo =head1 DESCRIPTION -DBUtils is the attempt to reduce the amount of overhead it takes to retrieve information from the database in kivitendo. Previously it would take about 15 lines of code just to get one single integer out of the database, including failure procedures and importing the necessary packages. Debugging would take even more. +DBUtils provides wrapper functions for low level database retrieval. It saves +you the trouble of mucking around with statement handles for small databse +queries and does exception handling in the common cases for you. + +Query and retrieval function share the parameter scheme: + + query_or_retrieval(C