@@ -, +, @@ - 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: 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 - Sign off :-D --- installer/data/mysql/updatedatabase.pl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -17280,6 +17280,27 @@ sub TableExists { return 0; } +=head2 ColumnExists( $table, $column ) + +=cut + +sub ColumnExists { + my ( $table, $column ) = @_; + + my $database = C4::Context->config("database"); + + my $sth = $dbh->prepare(qq{ + SELECT * FROM INFORMATION_SCHEMA.COLUMNS + WHERE + TABLE_SCHEMA='$database' AND + TABLE_NAME='$table' AND + COLUMN_NAME='$column'; + }); + $sth->execute; + + return ($sth->fetchrow_hashref) ? 1 : 0; +} + =head2 DropAllForeignKeys($table) Drop all foreign keys of the table $table --