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

(-)a/C4/Members.pm (-2 / +60 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
    # Check what DB we are using (current only returns mysql)
723
    my $db=C4::Context->db_scheme2dbi(C4::Context->config("db_scheme"));
724
725
    # FIXME: Other DB's may require an additional elsif,
726
    #        or revision to the if. :)
727
    #        Not limiting the SQL query causes a drastic drop
728
    #        in speed (~3-4 seconds for ~1 million records
729
    #        compared to <1s with limit 1).
730
    my $sql;
731
    if ( 'mysql,' =~ /$db/ ) {
732
        $sql = 'SELECT * FROM borrowers LIMIT 1;';
733
    }
734
    else {
735
        $sql = 'SELECT * FROM borrowers;';
736
    }
737
738
    # Get the database handle.
739
    my $dbh = C4::Context->dbh;
740
741
    # Run the SQL statement to load STH's readonly properties.
742
    my $sth = $dbh->prepare($sql);
743
    my $rv = $sth->execute();
744
745
    # This only fails if the table doesn't exist.
746
    # This will always be called AFTER an install or upgrade,
747
    # so borrowers will exist!
748
    my @data;
749
    if ($sth->{NUM_OF_FIELDS}>0) {
750
        @data = @{$sth->{NAME}};
751
    }
752
    else {
753
        @data = ();
754
    }
755
    $sth->finish();
756
    return @data;
700
}
757
}
701
758
759
702
=head2 ModMember
760
=head2 ModMember
703
761
704
  my $success = ModMember(borrowernumber => $borrowernumber,
762
  my $success = ModMember(borrowernumber => $borrowernumber,
(-)a/t/db_dependent/Members.t (-2 / +4 lines)
Lines 6-12 Link Here
6
use strict;
6
use strict;
7
use warnings;
7
use warnings;
8
8
9
use Test::More tests => 22;
9
use Test::More tests => 23;
10
use Data::Dumper;
10
use Data::Dumper;
11
11
12
BEGIN {
12
BEGIN {
Lines 169-174 C4::Context->clear_syspref_cache(); Link Here
169
my $notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
169
my $notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
170
is ($notice_email, $EMAILPRO, "GetNoticeEmailAddress returns correct value when AutoEmailPrimaryAddress is emailpro");
170
is ($notice_email, $EMAILPRO, "GetNoticeEmailAddress returns correct value when AutoEmailPrimaryAddress is emailpro");
171
171
172
my @borrowers_columns = C4::Members->columns;
173
ok ( $#borrowers_columns > 1, "C4::Member->column returned a reasonable number of columns (" . ($#borrowers_columns + 1) . ")")
174
  or diag("WARNING: Check that the borrowers table exists and has the correct fields defined.");
172
175
173
# clean up 
176
# clean up 
174
DelMember($member->{borrowernumber});
177
DelMember($member->{borrowernumber});
175
- 

Return to bug 7785