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

(-)a/C4/Members.pm (-2 / +46 lines)
Lines 695-704 sub GetMemberIssuesAndFines { Link Here
695
    return ($overdue_count, $issue_count, $total_fines);
695
    return ($overdue_count, $issue_count, $total_fines);
696
}
696
}
697
697
698
sub columns(;$) {
698
699
    return @{C4::Context->dbh->selectcol_arrayref("SHOW columns from borrowers")};
699
=head2 columns
700
701
  C4::Member->columns
702
703
=head3 USAGE
704
705
 use C4::Member;
706
 my @borrower_columns = C4::Member->columns;
707
708
=head3 RETURNS
709
710
 The array of borrowers' table columns on success.
711
 An empty array on failure.
712
713
=head3 NOTES
714
715
 This runs significantly faster than the previous code while
716
 being mostly SQL-agnostic.
717
718
=cut
719
720
sub columns {
721
722
    # Pure ANSI SQL goodness.
723
    my $sql = 'SELECT * FROM borrowers WHERE 1=0;';
724
725
    # Get the database handle.
726
    my $dbh = C4::Context->dbh;
727
728
    # Run the SQL statement to load STH's readonly properties.
729
    my $sth = $dbh->prepare($sql);
730
    my $rv = $sth->execute();
731
732
    # This only fails if the table doesn't exist.
733
    # This will always be called AFTER an install or upgrade,
734
    # so borrowers will exist!
735
    my @data;
736
    if ($sth->{NUM_OF_FIELDS}>0) {
737
        @data = @{$sth->{NAME}};
738
    }
739
    else {
740
        @data = ();
741
    }
742
    return @data;
700
}
743
}
701
744
745
702
=head2 ModMember
746
=head2 ModMember
703
747
704
  my $success = ModMember(borrowernumber => $borrowernumber,
748
  my $success = ModMember(borrowernumber => $borrowernumber,
(-)a/t/db_dependent/Members_columns.t (-1 / +24 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
#
3
# This is to test C4/Members
4
# It requires a working Koha database with the sample data
5
6
use Modern::Perl;
7
8
use Test::More tests => 2;
9
10
BEGIN {
11
    use_ok('C4::Members');
12
}
13
14
my @borrowers_columns = C4::Members->columns;
15
ok(
16
    $#borrowers_columns > 1,
17
    'C4::Member->column returned a reasonable number of columns ('
18
      . ( $#borrowers_columns + 1 ) . ')'
19
  )
20
  or diag(
21
'WARNING: Check that the borrowers table exists and has the correct fields defined.'
22
  );
23
24
exit;

Return to bug 7785