blib/lib/SQL/Translator/Parser/DBI/MySQL.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 53 SCAR 24.8
CC
3
Cov
0%
parse
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 12.0
1 package SQL::Translator::Parser::DBI::MySQL;
2  
3 =head1 NAME
4  
5 SQL::Translator::Parser::DBI::MySQL - parser for DBD::mysql
6  
7 =head1 SYNOPSIS
8  
9 This module will be invoked automatically by SQL::Translator::Parser::DBI,
10 so there is no need to use it directly.
11  
12 =head1 DESCRIPTION
13  
14 Uses SQL calls to query database directly for schema rather than parsing
15 a create file. Should be much faster for larger schemas.
16  
17 =cut
18  
19 use strict;
20 use warnings;
21 use DBI;
22 use Data::Dumper;
23 use SQL::Translator::Schema::Constants;
24 use SQL::Translator::Parser::MySQL;
25  
26 our ( $DEBUG, @EXPORT_OK );
27 our $VERSION = '1.63';
28 $DEBUG = 0 unless defined $DEBUG;
29  
30 sub parse {
31 my ( $tr, $dbh ) = @_;
32 my $schema = $tr->schema;
33 my @table_names = @{ $dbh->selectcol_arrayref('show tables') };
34 my @skip_tables = defined $tr->parser_args->{skip}
35 ? split(/,/, $tr->parser_args->{skip})
36 : ();
37  
38 $dbh->{'FetchHashKeyName'} = 'NAME_lc';
39  
40 my $create = q{};
41 for my $table_name ( @table_names ) {
42 next if (grep /^$table_name$/, @skip_tables);
43 my $sth = $dbh->prepare("show create table " . $dbh->quote_identifier($table_name));
44 $sth->execute;
45 my $table = $sth->fetchrow_hashref;
46 $create .= ($table->{'create table'} || $table->{'create view'}) . ";\n\n";
47 }
48  
49 SQL::Translator::Parser::MySQL::parse( $tr, $create );
50  
51 return 1;
52 }
53  
54 1;
55  
56 # -------------------------------------------------------------------
57 # Where man is not nature is barren.
58 # William Blake
59 # -------------------------------------------------------------------
60  
61 =pod
62  
63 =head1 AUTHOR
64  
65 Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>.
66  
67 =head1 SEE ALSO
68  
69 SQL::Translator.
70  
71 =cut