From 665fb6bc2c19a5d75aa538b68c2b6f443095dd1d Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 15 Feb 2013 10:10:36 +0100 Subject: [PATCH] Console: Hilfsfunktion sql() --- scripts/console | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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