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

(-)a/C4/Items.pm (-7 / +8 lines)
Lines 35-41 use DateTime::Format::MySQL; Link Here
35
use Data::Dumper; # used as part of logging item record changes, not just for
35
use Data::Dumper; # used as part of logging item record changes, not just for
36
                  # debugging; so please don't remove this
36
                  # debugging; so please don't remove this
37
use Koha::DateUtils qw/dt_from_string/;
37
use Koha::DateUtils qw/dt_from_string/;
38
use C4::SQLHelper qw(GetColumns);
38
39
use Koha::Database;
39
40
40
use vars qw($VERSION @ISA @EXPORT);
41
use vars qw($VERSION @ISA @EXPORT);
41
42
Lines 2596-2604 sub _SearchItems_build_where_fragment { Link Here
2596
            };
2597
            };
2597
        }
2598
        }
2598
    } else {
2599
    } else {
2599
        my @columns = GetColumns('items');
2600
        my @columns = Koha::Database->new()->schema()->resultset('Item')->result_source->columns;
2600
        push @columns, GetColumns('biblio');
2601
        push @columns, Koha::Database->new()->schema()->resultset('Biblio')->result_source->columns;
2601
        push @columns, GetColumns('biblioitems');
2602
        push @columns, Koha::Database->new()->schema()->resultset('Biblioitem')->result_source->columns;
2602
        my @operators = qw(= != > < >= <= like);
2603
        my @operators = qw(= != > < >= <= like);
2603
        my $field = $filter->{field};
2604
        my $field = $filter->{field};
2604
        if ( (0 < grep /^$field$/, @columns) or (substr($field, 0, 5) eq 'marc:') ) {
2605
        if ( (0 < grep /^$field$/, @columns) or (substr($field, 0, 5) eq 'marc:') ) {
Lines 2725-2733 sub SearchItems { Link Here
2725
        $query .= qq{ WHERE $where_str };
2726
        $query .= qq{ WHERE $where_str };
2726
    }
2727
    }
2727
2728
2728
    my @columns = GetColumns('items');
2729
    my @columns = Koha::Database->new()->schema()->resultset('Item')->result_source->columns;
2729
    push @columns, GetColumns('biblio');
2730
    push @columns, Koha::Database->new()->schema()->resultset('Biblio')->result_source->columns;
2730
    push @columns, GetColumns('biblioitems');
2731
    push @columns, Koha::Database->new()->schema()->resultset('Biblioitem')->result_source->columns;
2731
    my $sortby = (0 < grep {$params->{sortby} eq $_} @columns)
2732
    my $sortby = (0 < grep {$params->{sortby} eq $_} @columns)
2732
        ? $params->{sortby} : 'itemnumber';
2733
        ? $params->{sortby} : 'itemnumber';
2733
    my $sortorder = (uc($params->{sortorder}) eq 'ASC') ? 'ASC' : 'DESC';
2734
    my $sortorder = (uc($params->{sortorder}) eq 'ASC') ? 'ASC' : 'DESC';
(-)a/C4/SQLHelper.pm (-33 lines)
Lines 56-62 BEGIN { Link Here
56
	UpdateInTable
56
	UpdateInTable
57
	GetPrimaryKeys
57
	GetPrimaryKeys
58
        clear_columns_cache
58
        clear_columns_cache
59
    GetColumns
60
);
59
);
61
	%EXPORT_TAGS = ( all =>[qw( InsertInTable DeleteInTable SearchInTable UpdateInTable GetPrimaryKeys)]
60
	%EXPORT_TAGS = ( all =>[qw( InsertInTable DeleteInTable SearchInTable UpdateInTable GetPrimaryKeys)]
62
				);
61
				);
Lines 297-334 sub _get_columns { Link Here
297
    return $hashref->{$tablename};
296
    return $hashref->{$tablename};
298
}
297
}
299
298
300
=head2 GetColumns
301
302
    my @columns = GetColumns($tablename);
303
304
Given a tablename, returns an array of columns names.
305
306
=cut
307
308
sub GetColumns {
309
    my ($tablename) = @_;
310
311
    return unless $tablename;
312
    return unless $tablename =~ /^[a-zA-Z0-9_]+$/;
313
314
    # Get the database handle.
315
    my $dbh = C4::Context->dbh;
316
317
    # Pure ANSI SQL goodness.
318
    my $sql = "SELECT * FROM $tablename WHERE 1=0;";
319
320
    # Run the SQL statement to load STH's readonly properties.
321
    my $sth = $dbh->prepare($sql);
322
    my $rv = $sth->execute();
323
324
    my @data;
325
    if ($rv) {
326
        @data = @{$sth->{NAME}};
327
    }
328
329
    return @data;
330
}
331
332
=head2 _filter_columns
299
=head2 _filter_columns
333
300
334
=over 4
301
=over 4
(-)a/t/db_dependent/SQLHelper.t (-5 lines)
Lines 64-70 ok($status>0 && !($@), "DeleteInTable OK"); Link Here
64
$status=DeleteInTable("branches", {branchcode => 'ZZZZ'});
64
$status=DeleteInTable("branches", {branchcode => 'ZZZZ'});
65
ok($status>0 && !($@), "DeleteInTable (branch) OK");
65
ok($status>0 && !($@), "DeleteInTable (branch) OK");
66
66
67
my @biblio_columns = C4::SQLHelper::GetColumns('biblio');
68
my @expected_columns = qw(biblionumber frameworkcode author title unititle notes
69
    serial seriestitle copyrightdate timestamp datecreated abstract);
70
is_deeply([sort @biblio_columns], [sort @expected_columns], "GetColumns('biblio') returns all columns of biblio table");
71
- 

Return to bug 11425