From 742675a46874e788e6bc9c16bcb18f94db251e16 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 1c5a228..b33030d 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); @@ -2883,27 +2884,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 @@ -2916,27 +2898,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 { -- 1.7.10.4