script/myutil_dump_table_constraints.pl untested

filter: Statementstmt 0.0% 0 / 40 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 65 CC 4 SCAR 15.9
CC
4
Cov
0%
parse_cmd_line
12.0
check_required
6.0
init
2.0
CRAP 4.9
1 #!/usr/local/bin/perl
2  
3 ###### PACKAGES ######
4  
5 use strict;
6 use warnings;
7 use Getopt::Long;
8 Getopt::Long::Configure('no_ignore_case');
9 use MySQL::Util;
10 use Data::Dumper;
11  
12 ###### CONSTANTS ######
13  
14  
15 ###### GLOBAL VARIABLES ######
16  
17 use vars qw($Util $Host $DbName $User $Pass $Table);
18  
19 ###### MAIN PROGRAM ######
20  
21 parse_cmd_line();
22 init();
23  
24 print Dumper( $Util->get_fk_constraints( $Table) );
25  
26 ###### END MAIN #######
27  
28 sub init {
29 my $dsn = "dbi:mysql:host=$Host;dbname=$DbName";
30
31 $Util = MySQL::Util->new(
32 dsn => $dsn,
33 user => $User,
34 pass => $Pass
35 );
36 }
37  
38 sub check_required
39 {
40 my $opt = shift;
41 my $arg = shift;
42  
43 print_usage("missing arg $opt") if !$arg;
44 }
45  
46 sub parse_cmd_line
47 {
48 my @tmp = @ARGV;
49 my $help;
50
51 my $rc = GetOptions("h=s" => \$Host,
52 "d=s" => \$DbName,
53 "u=s" => \$User,
54 "p=s" => \$Pass,
55 "t=s" => \$Table,
56 "help|?" => \$help);
57  
58 print_usage("usage:") if $help;
59  
60 check_required('-u', $User);
61 check_required('-h', $Host);
62 check_required('-d', $DbName);
63
64 if (!($rc) || (@ARGV != 0)) {
65 ## if rc is false or args are left on line
66 print_usage("parse_cmd_line failed");
67 }
68
69 @ARGV = @tmp;
70 }
71  
72 sub print_usage
73 {
74 print STDERR "@_\n";
75  
76 print "\n$0\n".
77 "\t-u <user>\n".
78 "\t-h <host>\n".
79 "\t-d <dbname>\n".
80 "\t[-p <pass>]\n".
81 "\t-t <table>\n".
82 "\t[-?] (usage)\n".
83 "\n";
84  
85 exit 1;
86 }