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