Lines 400-421
sub nb_rows {
Link Here
|
400 |
|
400 |
|
401 |
=head2 execute_query |
401 |
=head2 execute_query |
402 |
|
402 |
|
403 |
($results, $error) = execute_query($sql, $offset, $limit) |
403 |
($sth, $error) = execute_query($sql, $offset, $limit[, \@sql_params]) |
404 |
|
404 |
|
405 |
|
405 |
|
406 |
When passed C<$sql>, this function returns an array ref containing a result set |
406 |
This function returns a DBI statement handler from which the caller can |
407 |
suitably formatted for display in html or for output as a flat file when passed in |
407 |
fetch the results of the SQL passed via C<$sql>. |
408 |
C<$format> and C<$id>. It also returns the C<$total> records available for the |
408 |
|
409 |
supplied query. If passed any query other than a SELECT, or if there is a db error, |
409 |
If passed any query other than a SELECT, or if there is a db error, |
410 |
C<$errors> an array ref is returned containing the error after this manner: |
410 |
C<$errors> an array ref is returned containing the error after this |
|
|
411 |
manner: |
411 |
|
412 |
|
412 |
C<$error->{'sqlerr'}> contains the offending SQL keyword. |
413 |
C<$error->{'sqlerr'}> contains the offending SQL keyword. |
413 |
C<$error->{'queryerr'}> contains the native db engine error returned for the query. |
414 |
C<$error->{'queryerr'}> contains the native db engine error returned |
|
|
415 |
for the query. |
416 |
|
417 |
C<$offset>, and C<$limit> are required parameters. |
414 |
|
418 |
|
415 |
Valid values for C<$format> are 'text,' 'tab,' 'csv,' or 'url. C<$sql>, C<$type>, |
419 |
C<\@sql_params> is an optional list of parameter values to paste in. |
416 |
C<$offset>, and C<$limit> are required parameters. If a valid C<$format> is passed |
420 |
The caller is reponsible for making sure that C<$sql> has placeholders |
417 |
in, C<$offset> and C<$limit> are ignored for obvious reasons. A LIMIT specified by |
421 |
and that the number placeholders matches the number of parameters. |
418 |
the user in a user-supplied SQL query WILL apply in any case. |
|
|
419 |
|
422 |
|
420 |
=cut |
423 |
=cut |
421 |
|
424 |
|
Lines 470-478
sub strip_limit {
Link Here
|
470 |
} |
473 |
} |
471 |
} |
474 |
} |
472 |
|
475 |
|
473 |
sub execute_query ($;$$$) { |
476 |
sub execute_query { |
|
|
477 |
|
478 |
my ( $sql, $offset, $limit, $sql_params ) = @_; |
474 |
|
479 |
|
475 |
my ( $sql, $offset, $limit, $no_count ) = @_; |
480 |
$sql_params = [] unless defined $sql_params; |
476 |
|
481 |
|
477 |
# check parameters |
482 |
# check parameters |
478 |
unless ($sql) { |
483 |
unless ($sql) { |
Lines 506-512
sub execute_query ($;$$$) {
Link Here
|
506 |
$sql .= " LIMIT ?, ?"; |
511 |
$sql .= " LIMIT ?, ?"; |
507 |
|
512 |
|
508 |
my $sth = C4::Context->dbh->prepare($sql); |
513 |
my $sth = C4::Context->dbh->prepare($sql); |
509 |
$sth->execute($offset, $limit); |
514 |
$sth->execute(@$sql_params, $offset, $limit); |
510 |
return ( $sth ); |
515 |
return ( $sth ); |
511 |
# my @xmlarray = ... ; |
516 |
# my @xmlarray = ... ; |
512 |
# my $url = "/cgi-bin/koha/reports/guided_reports.pl?phase=retrieve%20results&id=$id"; |
517 |
# my $url = "/cgi-bin/koha/reports/guided_reports.pl?phase=retrieve%20results&id=$id"; |