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