X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/3307dfcae96e3c273f886998edb24ca2e80b7287..49556f01cfe6a395cf5554e1a00dc61d6da0493e:/scripts/console diff --git a/scripts/console b/scripts/console index 19db86bfb..21644c8c7 100755 --- a/scripts/console +++ b/scripts/console @@ -66,7 +66,10 @@ sub lxinit { $::form = Form->new; $::auth = SL::Auth->new; $::instance_conf = SL::InstanceConfiguration->new; - $::request = { cgi => CGI->new({}) }; + $::request = SL::Request->new( + cgi => CGI->new({}), + layout => SL::Layout::None->new, + ); die 'cannot reach auth db' unless $::auth->session_tables_present; @@ -156,6 +159,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 +230,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