View | Details | Raw Unified | Return to bug 17979
Collapse All | Expand All

(-)a/C4/Breeding.pm (-11 / +10 lines)
Lines 71-77 sub BreedingSearch { Link Here
71
    my ($search,$isbn) = @_;
71
    my ($search,$isbn) = @_;
72
    my $dbh   = C4::Context->dbh;
72
    my $dbh   = C4::Context->dbh;
73
    my $count = 0;
73
    my $count = 0;
74
    my ($query,@bind);
74
    my ( $query, @cond, @bind );
75
    my $sth;
75
    my $sth;
76
    my @results;
76
    my @results;
77
77
Lines 81-101 sub BreedingSearch { Link Here
81
    $query = "SELECT import_record_id, file_name, isbn, title, author
81
    $query = "SELECT import_record_id, file_name, isbn, title, author
82
              FROM  import_biblios 
82
              FROM  import_biblios 
83
              JOIN import_records USING (import_record_id)
83
              JOIN import_records USING (import_record_id)
84
              JOIN import_batches USING (import_batch_id)
84
              JOIN import_batches USING (import_batch_id)";
85
              WHERE ";
85
86
    @bind=();
87
    if (defined($search) && length($search)>0) {
86
    if (defined($search) && length($search)>0) {
88
        $search =~ s/(\s+)/\%/g;
87
        $search =~ s/(\s+)/\%/g;
89
        $query .= "title like ? OR author like ?";
88
        push @cond, 'title like ? OR author like ?';
90
        push(@bind,"%$search%", "%$search%");
89
        push @bind, "%$search%", "%$search%";
91
    }
92
    if ($#bind!=-1 && defined($isbn) && length($isbn)>0) {
93
        $query .= " and ";
94
    }
90
    }
95
    if (defined($isbn) && length($isbn)>0) {
91
    if (defined($isbn) && length($isbn)>0) {
96
        $query .= "isbn like ?";
92
        push @cond, 'isbn like ?';
97
        push(@bind,"$isbn%");
93
        push @bind, "$isbn%";
98
    }
94
    }
95
96
    $query .= ' WHERE ' . join( ' AND ', @cond ) if @cond;
97
99
    $sth = $dbh->prepare($query);
98
    $sth = $dbh->prepare($query);
100
    $sth->execute(@bind);
99
    $sth->execute(@bind);
101
    while (my $data = $sth->fetchrow_hashref) {
100
    while (my $data = $sth->fetchrow_hashref) {
(-)a/t/db_dependent/Breeding.t (-2 / +10 lines)
Lines 26-32 Link Here
26
26
27
use Modern::Perl;
27
use Modern::Perl;
28
use File::Temp qw/tempfile/;
28
use File::Temp qw/tempfile/;
29
use Test::More tests => 5;
29
use Test::More tests => 6;
30
use Test::Warn;
30
use Test::Warn;
31
31
32
use t::lib::Mocks qw( mock_preference );
32
use t::lib::Mocks qw( mock_preference );
Lines 84-89 subtest ImportBreedingAuth => sub { Link Here
84
    isnt( $breedingid, $breedingid_2, "For a new record, we get a new id");
84
    isnt( $breedingid, $breedingid_2, "For a new record, we get a new id");
85
};
85
};
86
86
87
subtest 'BreedingSearch' => sub {
88
    plan tests => 2;
89
90
    is( C4::Breeding::BreedingSearch(undef, "400638133393x"), 0 );
91
92
    my $count_import_biblios = C4::Context->dbh->selectrow_array(q|SELECT COUNT(*) FROM import_biblios|);
93
    is( C4::Breeding::BreedingSearch(), $count_import_biblios );
94
};
95
87
$schema->storage->txn_rollback;
96
$schema->storage->txn_rollback;
88
97
89
#-------------------------------------------------------------------------------
98
#-------------------------------------------------------------------------------
90
- 

Return to bug 17979