Bugzilla – Attachment 32307 Details for
Bug 11425
Search form for items
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11425: Get column names using DBIX
Bug-11425-Get-column-names-using-DBIX.patch (text/plain), 4.04 KB, created by
Chris Cormack
on 2014-10-14 13:36:09 UTC
(
hide
)
Description:
Bug 11425: Get column names using DBIX
Filename:
MIME Type:
Creator:
Chris Cormack
Created:
2014-10-14 13:36:09 UTC
Size:
4.04 KB
patch
obsolete
>From 15cbc9d874b93c904c1195ebb2e362e84e8a86c8 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Wed, 16 Apr 2014 12:25:23 +0200 >Subject: [PATCH] Bug 11425: Get column names using DBIX > >Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> >--- > C4/Items.pm | 15 ++++++++------- > C4/SQLHelper.pm | 33 --------------------------------- > t/db_dependent/SQLHelper.t | 4 ---- > 3 files changed, 8 insertions(+), 44 deletions(-) > >diff --git a/C4/Items.pm b/C4/Items.pm >index 3246aed..1d6f6c7 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -35,7 +35,8 @@ use DateTime::Format::MySQL; > use Data::Dumper; # used as part of logging item record changes, not just for > # debugging; so please don't remove this > use Koha::DateUtils qw/dt_from_string/; >-use C4::SQLHelper qw(GetColumns); >+ >+use Koha::Database; > > use vars qw($VERSION @ISA @EXPORT); > >@@ -2634,9 +2635,9 @@ sub _SearchItems_build_where_fragment { > }; > } > } else { >- my @columns = GetColumns('items'); >- push @columns, GetColumns('biblio'); >- push @columns, GetColumns('biblioitems'); >+ my @columns = Koha::Database->new()->schema()->resultset('Item')->result_source->columns; >+ push @columns, Koha::Database->new()->schema()->resultset('Biblio')->result_source->columns; >+ push @columns, Koha::Database->new()->schema()->resultset('Biblioitem')->result_source->columns; > my @operators = qw(= != > < >= <= like); > my $field = $filter->{field}; > if ( (0 < grep /^$field$/, @columns) or (substr($field, 0, 5) eq 'marc:') ) { >@@ -2763,9 +2764,9 @@ sub SearchItems { > $query .= qq{ WHERE $where_str }; > } > >- my @columns = GetColumns('items'); >- push @columns, GetColumns('biblio'); >- push @columns, GetColumns('biblioitems'); >+ my @columns = Koha::Database->new()->schema()->resultset('Item')->result_source->columns; >+ push @columns, Koha::Database->new()->schema()->resultset('Biblio')->result_source->columns; >+ push @columns, Koha::Database->new()->schema()->resultset('Biblioitem')->result_source->columns; > my $sortby = (0 < grep {$params->{sortby} eq $_} @columns) > ? $params->{sortby} : 'itemnumber'; > my $sortorder = (uc($params->{sortorder}) eq 'ASC') ? 'ASC' : 'DESC'; >diff --git a/C4/SQLHelper.pm b/C4/SQLHelper.pm >index 55204eb..b867094 100644 >--- a/C4/SQLHelper.pm >+++ b/C4/SQLHelper.pm >@@ -56,7 +56,6 @@ BEGIN { > UpdateInTable > GetPrimaryKeys > clear_columns_cache >- GetColumns > ); > %EXPORT_TAGS = ( all =>[qw( InsertInTable DeleteInTable SearchInTable UpdateInTable GetPrimaryKeys)] > ); >@@ -297,38 +296,6 @@ sub _get_columns { > return $hashref->{$tablename}; > } > >-=head2 GetColumns >- >- my @columns = GetColumns($tablename); >- >-Given a tablename, returns an array of columns names. >- >-=cut >- >-sub GetColumns { >- my ($tablename) = @_; >- >- return unless $tablename; >- return unless $tablename =~ /^[a-zA-Z0-9_]+$/; >- >- # Get the database handle. >- my $dbh = C4::Context->dbh; >- >- # Pure ANSI SQL goodness. >- my $sql = "SELECT * FROM $tablename WHERE 1=0;"; >- >- # Run the SQL statement to load STH's readonly properties. >- my $sth = $dbh->prepare($sql); >- my $rv = $sth->execute(); >- >- my @data; >- if ($rv) { >- @data = @{$sth->{NAME}}; >- } >- >- return @data; >-} >- > =head2 _filter_columns > > =over 4 >diff --git a/t/db_dependent/SQLHelper.t b/t/db_dependent/SQLHelper.t >index f585736..6074608 100755 >--- a/t/db_dependent/SQLHelper.t >+++ b/t/db_dependent/SQLHelper.t >@@ -64,7 +64,3 @@ ok($status>0 && !($@), "DeleteInTable OK"); > $status=DeleteInTable("branches", {branchcode => 'ZZZZ'}); > ok($status>0 && !($@), "DeleteInTable (branch) OK"); > >-my @biblio_columns = C4::SQLHelper::GetColumns('biblio'); >-my @expected_columns = qw(biblionumber frameworkcode author title unititle notes >- serial seriestitle copyrightdate timestamp datecreated abstract); >-is_deeply([sort @biblio_columns], [sort @expected_columns], "GetColumns('biblio') returns all columns of biblio table"); >-- >1.9.1
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 11425
:
23674
|
23675
|
26334
|
26335
|
26555
|
26556
|
26557
|
27111
|
27112
|
27113
|
27162
|
27975
|
27976
|
27977
|
27978
|
27979
|
29965
|
30195
|
30196
|
30197
|
30198
|
30199
|
30200
|
32304
|
32305
|
32306
|
32307
|
32308
|
32309
|
32669
|
32670
|
32671
|
32672
|
32673
|
32674
|
32675
|
32918
|
32926
|
32947
|
32948