Bugzilla – Attachment 19575 Details for
Bug 7785
MySQL-specific syntax in C4::Members columns()
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Pure ANSI SQL code to replace MySQLism
0001-Bug-7785-MySQL-specific-syntax-in-C4-Members-columns.patch (text/plain), 3.22 KB, created by
Mark Tompsett
on 2013-07-11 14:55:38 UTC
(
hide
)
Description:
Pure ANSI SQL code to replace MySQLism
Filename:
MIME Type:
Creator:
Mark Tompsett
Created:
2013-07-11 14:55:38 UTC
Size:
3.22 KB
patch
obsolete
>From 628022b667d74203fa6fe09e923f7633a769fe43 Mon Sep 17 00:00:00 2001 >From: Mark Tompsett <mtompset@hotmail.com> >Date: Sat, 29 Jun 2013 20:46:51 -0400 >Subject: [PATCH] Bug 7785 - MySQL-specific syntax in C4::Members columns() > >The initial thought was to remove this function. However, >tools/import_borrowers.pl uses it. So rather than remove >it to solve the problem, it was reworked to a more generic >solution which runs faster. > >By accessing $sth->{NAME} directly, the driver becomes >responsible for filling it correctly. This happens when a SELECT >is done on the borrowers table. It does not even have to have >data in the result set! > >The columns method could be more generic and used elsewhere too. >Comparison between the old method and the STH method showed a >significant time difference. The old method took 35 seconds >for 40k iterations versus 19 seconds for the same amount of >iterations with the STH method regardless of the size of the >borrowers table. >--- > C4/Members.pm | 48 ++++++++++++++++++++++++++++++++++++-- > t/db_dependent/Members_columns.t | 24 +++++++++++++++++++ > 2 files changed, 70 insertions(+), 2 deletions(-) > create mode 100644 t/db_dependent/Members_columns.t > >diff --git a/C4/Members.pm b/C4/Members.pm >index 3221f53..90ce6ee 100644 >--- a/C4/Members.pm >+++ b/C4/Members.pm >@@ -695,10 +695,54 @@ sub GetMemberIssuesAndFines { > return ($overdue_count, $issue_count, $total_fines); > } > >-sub columns(;$) { >- return @{C4::Context->dbh->selectcol_arrayref("SHOW columns from borrowers")}; >+ >+=head2 columns >+ >+ C4::Member->columns >+ >+=head3 USAGE >+ >+ use C4::Member; >+ my @borrower_columns = C4::Member->columns; >+ >+=head3 RETURNS >+ >+ The array of borrowers' table columns on success. >+ An empty array on failure. >+ >+=head3 NOTES >+ >+ This runs significantly faster than the previous code while >+ being mostly SQL-agnostic. >+ >+=cut >+ >+sub columns { >+ >+ # Pure ANSI SQL goodness. >+ my $sql = 'SELECT * FROM borrowers WHERE 1=0;'; >+ >+ # Get the database handle. >+ my $dbh = C4::Context->dbh; >+ >+ # Run the SQL statement to load STH's readonly properties. >+ my $sth = $dbh->prepare($sql); >+ my $rv = $sth->execute(); >+ >+ # This only fails if the table doesn't exist. >+ # This will always be called AFTER an install or upgrade, >+ # so borrowers will exist! >+ my @data; >+ if ($sth->{NUM_OF_FIELDS}>0) { >+ @data = @{$sth->{NAME}}; >+ } >+ else { >+ @data = (); >+ } >+ return @data; > } > >+ > =head2 ModMember > > my $success = ModMember(borrowernumber => $borrowernumber, >diff --git a/t/db_dependent/Members_columns.t b/t/db_dependent/Members_columns.t >new file mode 100644 >index 0000000..7a70ce4 >--- /dev/null >+++ b/t/db_dependent/Members_columns.t >@@ -0,0 +1,24 @@ >+#!/usr/bin/perl >+# >+# This is to test C4/Members >+# It requires a working Koha database with the sample data >+ >+use Modern::Perl; >+ >+use Test::More tests => 2; >+ >+BEGIN { >+ use_ok('C4::Members'); >+} >+ >+my @borrowers_columns = C4::Members->columns; >+ok( >+ $#borrowers_columns > 1, >+ 'C4::Member->column returned a reasonable number of columns (' >+ . ( $#borrowers_columns + 1 ) . ')' >+ ) >+ or diag( >+'WARNING: Check that the borrowers table exists and has the correct fields defined.' >+ ); >+ >+exit; >-- >1.7.9.5 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 7785
:
8617
|
8874
|
19285
|
19527
|
19534
|
19575
|
19901
|
20274