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.
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
Tomás, why do we need this? We have column_exists defined in C4/Installer.pm and it could be used in atomic updates...
(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 ***