View | Details | Raw Unified | Return to bug 29336
Collapse All | Expand All

(-)a/C4/Installer.pm (-2 / +3 lines)
Lines 642-651 sub primary_key_exists { Link Here
642
}
642
}
643
643
644
sub foreign_key_exists {
644
sub foreign_key_exists {
645
    my ( $table_name, $constraint_name ) = @_;
645
    my ( $table_name, $constraint_name, $field_name ) = @_;
646
    my $dbh = C4::Context->dbh;
646
    my $dbh = C4::Context->dbh;
647
    my (undef, $infos) = $dbh->selectrow_array(qq|SHOW CREATE TABLE $table_name|);
647
    my (undef, $infos) = $dbh->selectrow_array(qq|SHOW CREATE TABLE $table_name|);
648
    return $infos =~ m|CONSTRAINT `$constraint_name` FOREIGN KEY|;
648
    return $infos =~ m|CONSTRAINT `$constraint_name` FOREIGN KEY| if $constraint_name;
649
    return $infos =~ m|FOREIGN KEY \(`$field_name`\)| if $field_name;
649
}
650
}
650
651
651
sub unique_key_exists {
652
sub unique_key_exists {
(-)a/t/db_dependent/Installer.t (-2 / +3 lines)
Lines 22-28 Link Here
22
# Add more tests here!!!
22
# Add more tests here!!!
23
23
24
use Modern::Perl;
24
use Modern::Perl;
25
use Test::More tests => 21;
25
use Test::More tests => 22;
26
use File::Temp qw(tempfile);
26
use File::Temp qw(tempfile);
27
use utf8;
27
use utf8;
28
28
Lines 69-74 ok( ! index_exists( 'borrowers', 'xxx'), 'Constraint xxx does not exist' ); Link Here
69
69
70
ok( foreign_key_exists( 'borrowers', 'borrowers_ibfk_1' ), 'FK borrowers_ibfk_1 exists' );
70
ok( foreign_key_exists( 'borrowers', 'borrowers_ibfk_1' ), 'FK borrowers_ibfk_1 exists' );
71
ok( ! foreign_key_exists( 'borrowers', 'xxx' ), 'FK xxxx does not exist' );
71
ok( ! foreign_key_exists( 'borrowers', 'xxx' ), 'FK xxxx does not exist' );
72
# test new third parameter:
73
ok( foreign_key_exists( 'borrowers', undef, 'categorycode' ), 'FK on categorycode exists' );
72
74
73
ok( unique_key_exists( 'items', 'itembarcodeidx' ), 'UNIQUE KEY itembarcodeidx exists' );
75
ok( unique_key_exists( 'items', 'itembarcodeidx' ), 'UNIQUE KEY itembarcodeidx exists' );
74
ok( ! unique_key_exists( 'borrowers', 'xxx' ), 'UNIQUE KEY xxxx does not exist' );
76
ok( ! unique_key_exists( 'borrowers', 'xxx' ), 'UNIQUE KEY xxxx does not exist' );
75
- 

Return to bug 29336