Bug 22159 - Add ColumnExists method
Summary: Add ColumnExists method
Status: RESOLVED DUPLICATE of bug 17234
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: master
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Tomás Cohen Arazi
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks: 22155
  Show dependency treegraph
 
Reported: 2019-01-18 01:40 UTC by Tomás Cohen Arazi
Modified: 2019-01-18 10:34 UTC (History)
1 user (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 22159: Add ColumnExists method (2.06 KB, patch)
2019-01-18 01:53 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
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 ***