Bug 22159

Summary: Add ColumnExists method
Product: Koha Reporter: Tomás Cohen Arazi <tomascohen>
Component: Architecture, internals, and plumbingAssignee: Tomás Cohen Arazi <tomascohen>
Status: RESOLVED DUPLICATE QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: josef.moravec
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Bug Depends on:    
Bug Blocks: 22155    
Attachments: Bug 22159: Add ColumnExists method

Description Tomás Cohen Arazi 2019-01-18 01:40:37 UTC
It would be handy to have a method to check if a column exists on a table. This is specially useful when rmaints backport changes to the DB structure.
Comment 1 Tomás Cohen Arazi 2019-01-18 01:53:39 UTC
Created attachment 84174 [details] [review]
Bug 22159: Add ColumnExists method

This patch adds a method for checking if a column exists on a DB table.
The way this is checked is used already on updatedatabase.pl [1] (i.e.
querying INFORMATION_SCHEMA.

To test:
- Create an atomicupdate file like this:
  $ cd installer/data/mysql/atomicupdate
  $ cp skeleton.perl test.perl
- Change the contents of test.perl so it looks like this:
$DBversion = 'XXX';
if( CheckVersion( $DBversion ) ) {

    if ( ColumnExists( 'borrowers', 'firstname' ) ) {
        print "Column borrowers.firstname exists!";
    }
    else {
        print "Boo, borrowers.firstname wasn't detected";
    }

    if ( ColumnExists( 'borrowers', 'friendly_alias' ) ) {
        print "Great, there's no borrowers.firend_alias";
    }
    else {
        print "Boo, this is really wrong";
    }
}

- Run:
  $ updatedatabase
  or
  $ kshell
 k$ perl installer/data/mysql/updatedatabase.pl
=> SUCCESS: No 'Boo' message is printed
- Sign off :-D

[1] See 3.03.00.023 or 18.12.00.002
Comment 2 Josef Moravec 2019-01-18 10:31:59 UTC
Tomás, why do we need this? We have column_exists defined in C4/Installer.pm and it could be used in atomic updates...
Comment 3 Tomás Cohen Arazi 2019-01-18 10:34:30 UTC
(In reply to Josef Moravec from comment #2)
> Tomás, why do we need this? We have column_exists defined in C4/Installer.pm
> and it could be used in atomic updates...

LOL. This is because I failed to find it yesterday =D

*** This bug has been marked as a duplicate of bug 17234 ***