Bugzilla – Attachment 19527 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.20 KB, created by
Mark Tompsett
on 2013-07-10 17:59:27 UTC
(
hide
)
Description:
Pure ANSI SQL code to replace MySQLism
Filename:
MIME Type:
Creator:
Mark Tompsett
Created:
2013-07-10 17:59:27 UTC
Size:
3.20 KB
patch
obsolete
>From 51e39d50e6c519d30e539c2c54ab0f2b3eb95fe9 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 >difference of 35 seconds for 40k iterations versus 19 seconds >for the same amount of iterations on regardless of the size of >the borrowers table. >--- > C4/Members.pm | 49 ++++++++++++++++++++++++++++++++++++-- > t/db_dependent/Members_columns.t | 25 +++++++++++++++++++ > 2 files changed, 72 insertions(+), 2 deletions(-) > create mode 100644 t/db_dependent/Members_columns.t > >diff --git a/C4/Members.pm b/C4/Members.pm >index 3221f53..bb29708 100644 >--- a/C4/Members.pm >+++ b/C4/Members.pm >@@ -695,10 +695,55 @@ 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 = (); >+ } >+ $sth->finish(); >+ 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..1a68744 >--- /dev/null >+++ b/t/db_dependent/Members_columns.t >@@ -0,0 +1,25 @@ >+#!/usr/bin/perl >+# >+# This is to test C4/Members >+# It requires a working Koha database with the sample data >+ >+use strict; >+use warnings; >+ >+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