From: Moritz Bunkus Date: Fri, 15 Feb 2013 09:10:36 +0000 (+0100) Subject: Console: Hilfsfunktion sql() X-Git-Tag: release-3.1.0beta1~612 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=665fb6bc2c19a5d75aa538b68c2b6f443095dd1d;p=kivitendo-erp.git Console: Hilfsfunktion sql() --- diff --git a/scripts/console b/scripts/console index 19db86bfb..d264a8941 100755 --- a/scripts/console +++ b/scripts/console @@ -156,6 +156,17 @@ sub pobj { return "<${ref} " . join(' ', @columns) . '>'; } +sub sql { + my $dbh = ref($_[0]) ? shift : $::form->get_standard_dbh; + my ($query, @args) = @_; + + if ($query =~ m/^\s*select/i) { + ptab($dbh->selectall_arrayref($query, { Slice => {} }, @args)); + } else { + $dbh->do($query, { Slice => {} }, @args); + } +} + 1; __END__ @@ -216,6 +227,23 @@ Example usage: pobj(SL::DB::Manager::Employee->find_by(login => 'demo')); +=head2 sql C<[ $dbh, ] $query, @bind_values> + +Executes an SQL query using the optional bind values. If the first +parameter is a database handle then that database handle is used; +otherwise the handle returned by L is used. + +If the query is a C