From cc1ea95a8d28654d211f7061471720712f418f58 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 5 Mar 2014 11:06:41 +0100 Subject: [PATCH] Bug 11023: Use DBIx-Class to retrieve column names --- C4/Items.pm | 47 +++++------------------------------------------ 1 file changed, 5 insertions(+), 42 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 0d7eb0b..81b9b84 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -35,6 +35,7 @@ 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 Koha::Database; use vars qw($VERSION @ISA @EXPORT); @@ -2922,27 +2923,8 @@ and an empty array on failure. =cut sub columns { - # Pure ANSI SQL goodness. - my $sql = 'SELECT * FROM items 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; + my $rs = Koha::Database->new->schema->resultset('Item'); + return $rs->result_source->columns; } =head2 biblioitems_columns @@ -2955,27 +2937,8 @@ and an empty array on failure. =cut sub biblioitems_columns { - # Pure ANSI SQL goodness. - my $sql = 'SELECT * FROM biblioitems 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; + my $rs = Koha::Database->new->schema->resultset('Biblioitem'); + return $rs->result_source->columns; } sub ToggleNewStatus { -- 2.1.0