X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=scripts%2Fconsole;h=d264a8941f05e16c3f83fd0b5702dc4b969eda98;hb=7b38e23d6509d1e4520caf77c9698bdb077c215f;hp=19db86bfb5b49cd7b58f89140393e2c6f963ddfc;hpb=3307dfcae96e3c273f886998edb24ca2e80b7287;p=kivitendo-erp.git 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