Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 665fb6bc

Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt

  • ID 665fb6bc2c19a5d75aa538b68c2b6f443095dd1d
  • Vorgänger 3307dfca
  • Nachfolger 75603a22

Console: Hilfsfunktion sql()

Unterschiede anzeigen:

scripts/console
156 156
  return "<${ref} " . join(' ', @columns) . '>';
157 157
}
158 158

  
159
sub sql {
160
  my $dbh            = ref($_[0]) ? shift : $::form->get_standard_dbh;
161
  my ($query, @args) = @_;
162

  
163
  if ($query =~ m/^\s*select/i) {
164
    ptab($dbh->selectall_arrayref($query, { Slice => {} }, @args));
165
  } else {
166
    $dbh->do($query, { Slice => {} }, @args);
167
  }
168
}
169

  
159 170
1;
160 171

  
161 172
__END__
......
216 227

  
217 228
    pobj(SL::DB::Manager::Employee->find_by(login => 'demo'));
218 229

  
230
=head2 sql C<[ $dbh, ] $query, @bind_values>
231

  
232
Executes an SQL query using the optional bind values. If the first
233
parameter is a database handle then that database handle is used;
234
otherwise the handle returned by L<SL::Form/get_standard_dbh> is used.
235

  
236
If the query is a C<SELECT> then the result is filtered through
237
L<ptab()>. Otherwise the result of C<$dbh-&gt;do($query, undef, @bind_values)>
238
is returned.
239

  
240
Example usage:
241

  
242
    sql(qq|SELECT * FROM employee|);
243
    sql(SL::DB::Employee->new->db->dbh,
244
        qq|UPDATE employee SET notes = ? WHERE login = ?|,
245
        'This guy is evil!', 'demo');
246

  
219 247
=head2 lxinit C<login>
220 248

  
221 249
Login into lx-office using a specified login. No password will be required, and

Auch abrufbar als: Unified diff