Bugzilla – Attachment 87513 Details for
Bug 22472
Should column_exists explode if the table does not exist?
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22472: Make column_exists early return if the table does not exist
Bug-22472-Make-columnexists-early-return-if-the-ta.patch (text/plain), 2.48 KB, created by
Martin Renvoize (ashimema)
on 2019-04-08 12:52:23 UTC
(
hide
)
Description:
Bug 22472: Make column_exists early return if the table does not exist
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2019-04-08 12:52:23 UTC
Size:
2.48 KB
patch
obsolete
>From ee11ea4c1af1b80f7e77c7596f261a831868b88b Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >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 <katrin.fischer.83@web.de> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > 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 8dc7e04671..39adb9e9ae 100755 >--- a/installer/data/mysql/updatedatabase.pl >+++ b/installer/data/mysql/updatedatabase.pl >@@ -17888,21 +17888,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.20.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 22472
:
86240
|
86241
|
87381
|
87382
|
87512
| 87513 |
89566
|
89567