Lines 425-443
sub nb_rows {
Link Here
|
425 |
$derived_name .= 'x'; |
425 |
$derived_name .= 'x'; |
426 |
} |
426 |
} |
427 |
|
427 |
|
428 |
my $sth = C4::Context->dbh->prepare(qq{ |
|
|
429 |
SELECT COUNT(*) FROM |
430 |
( $sql ) $derived_name |
431 |
}); |
432 |
|
428 |
|
433 |
$sth->execute(); |
429 |
my $dbh = C4::Context->dbh; |
|
|
430 |
my ( $sth, $n ); |
431 |
|
432 |
my $RaiseError = $dbh->{RaiseError}; |
433 |
my $PrintError = $dbh->{PrintError}; |
434 |
$dbh->{RaiseError} = 1; |
435 |
$dbh->{PrintError} = 0; |
436 |
eval { |
437 |
$sth = $dbh->prepare(qq{ |
438 |
SELECT COUNT(*) FROM |
439 |
( $sql ) $derived_name |
440 |
}); |
434 |
|
441 |
|
435 |
if ( $sth->errstr ) { |
442 |
$sth->execute(); |
436 |
return 0; |
443 |
}; |
437 |
} |
444 |
$dbh->{RaiseError} = $RaiseError; |
438 |
else { |
445 |
$dbh->{PrintError} = $PrintError; |
439 |
return $sth->fetch->[0]; |
446 |
if ($@) { # To catch "Duplicate column name" caused by the derived table, or any other syntax error |
|
|
447 |
$sth = $dbh->prepare($sql); |
448 |
$sth->execute; |
449 |
# Loop through the complete results, fetching 1,000 rows at a time. This |
450 |
# lowers memory requirements but increases execution time. |
451 |
while (my $rows = $sth->fetchall_arrayref(undef, 1000)) { |
452 |
$n += @$rows; |
453 |
} |
454 |
return $n; |
440 |
} |
455 |
} |
|
|
456 |
|
457 |
my $results = $sth->fetch; |
458 |
return $results ? $results->[0] : 0; |
441 |
} |
459 |
} |
442 |
|
460 |
|
443 |
=head2 execute_query |
461 |
=head2 execute_query |
444 |
- |
|
|