|
Lines 30-36
use vars qw(@ISA @EXPORT);
Link Here
|
| 30 |
BEGIN { |
30 |
BEGIN { |
| 31 |
require Exporter; |
31 |
require Exporter; |
| 32 |
@ISA = qw( Exporter ); |
32 |
@ISA = qw( Exporter ); |
| 33 |
push @EXPORT, qw( foreign_key_exists index_exists column_exists ); |
33 |
push @EXPORT, qw( foreign_key_exists index_exists column_exists default_exists ); |
| 34 |
}; |
34 |
}; |
| 35 |
|
35 |
|
| 36 |
=head1 NAME |
36 |
=head1 NAME |
|
Lines 525-530
sub index_exists {
Link Here
|
| 525 |
return $exists; |
525 |
return $exists; |
| 526 |
} |
526 |
} |
| 527 |
|
527 |
|
|
|
528 |
=head2 default_exists |
| 529 |
|
| 530 |
my $default_check = default_exists($table_name,$field_name); |
| 531 |
|
| 532 |
Determine if a particular field has a default value. |
| 533 |
This is useful to prevent errors when there is no default value to drop. |
| 534 |
|
| 535 |
=cut |
| 536 |
|
| 528 |
sub column_exists { |
537 |
sub column_exists { |
| 529 |
my ( $table_name, $column_name ) = @_; |
538 |
my ( $table_name, $column_name ) = @_; |
| 530 |
my $dbh = C4::Context->dbh; |
539 |
my $dbh = C4::Context->dbh; |
|
Lines 537-542
sub column_exists {
Link Here
|
| 537 |
return $exists; |
546 |
return $exists; |
| 538 |
} |
547 |
} |
| 539 |
|
548 |
|
|
|
549 |
|
| 550 |
sub default_exists { |
| 551 |
my ( $table_name, $column_name ) = @_; |
| 552 |
my $dbh = C4::Context->dbh; |
| 553 |
my @results = $dbh->selectall_array(qq{SHOW CREATE TABLE $table_name;}); |
| 554 |
my $table_definition = $results[0][1]; # only 1 result, and the 2nd entry is the definition. |
| 555 |
my @lines = split /\n/, $table_definition; |
| 556 |
my @default_lines = grep { /DEFAULT/ } @lines; |
| 557 |
my $return_value = 0; |
| 558 |
if ( grep { /\`$column_name\`/ } @default_lines ) { |
| 559 |
$return_value = 1; |
| 560 |
} |
| 561 |
return $return_value; |
| 562 |
} |
| 563 |
|
| 540 |
=head1 AUTHOR |
564 |
=head1 AUTHOR |
| 541 |
|
565 |
|
| 542 |
C4::Installer is a refactoring of logic originally from installer/installer.pl, which was |
566 |
C4::Installer is a refactoring of logic originally from installer/installer.pl, which was |