From f7a6adc183ad8829c9e9d391ee918aa1deb218fe Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 7 Mar 2019 09:14:25 -0300 Subject: [PATCH] Bug 22472: Make column_exists early return if the table does not exist On the way we move TableExists to C4::Installer, where it belongs to. Signed-off-by: Katrin Fischer Signed-off-by: Martin Renvoize Signed-off-by: Nick Clemens (cherry picked from commit 7208ac6196a8619dbb0cca3b6f01480f4c46cab1) Signed-off-by: Martin Renvoize --- C4/Installer.pm | 16 +++++++++++++++- installer/data/mysql/updatedatabase.pl | 15 --------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/C4/Installer.pm b/C4/Installer.pm index a1c47149f8..4d577156ac 100644 --- a/C4/Installer.pm +++ b/C4/Installer.pm @@ -30,7 +30,7 @@ use vars qw(@ISA @EXPORT); BEGIN { require Exporter; @ISA = qw( Exporter ); - push @EXPORT, qw( foreign_key_exists index_exists column_exists ); + push @EXPORT, qw( foreign_key_exists index_exists column_exists TableExists); }; =head1 NAME @@ -527,6 +527,7 @@ sub index_exists { sub column_exists { my ( $table_name, $column_name ) = @_; + return unless TableExists($table_name); my $dbh = C4::Context->dbh; my ($exists) = $dbh->selectrow_array( qq| @@ -537,6 +538,19 @@ sub column_exists { return $exists; } +sub TableExists { # Could be renamed table_exists for consistency + my $table = shift; + eval { + my $dbh = C4::Context->dbh; + local $dbh->{PrintError} = 0; + local $dbh->{RaiseError} = 1; + $dbh->do(qq{SELECT * FROM $table WHERE 1 = 0 }); + }; + return 1 unless $@; + return 0; +} + + =head1 AUTHOR C4::Installer is a refactoring of logic originally from installer/installer.pl, which was diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index e8793f9987..b378f850ac 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -17385,21 +17385,6 @@ foreach my $file ( sort readdir $dirh ) { =head1 FUNCTIONS -=head2 TableExists($table) - -=cut - -sub TableExists { - my $table = shift; - eval { - local $dbh->{PrintError} = 0; - local $dbh->{RaiseError} = 1; - $dbh->do(qq{SELECT * FROM $table WHERE 1 = 0 }); - }; - return 1 unless $@; - return 0; -} - =head2 DropAllForeignKeys($table) Drop all foreign keys of the table $table -- 2.39.5