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; |
f27f9229 |
20 | use warnings; |
34d79f68 |
21 | use DBI; |
22 | use Data::Dumper; |
23 | use SQL::Translator::Schema::Constants; |
24bc7217 |
24 | use SQL::Translator::Parser::MySQL; |
34d79f68 |
25 | |
0c04c5a2 |
26 | our ( $DEBUG, @EXPORT_OK ); |
27 | our $VERSION = '1.59'; |
34d79f68 |
28 | $DEBUG = 0 unless defined $DEBUG; |
29 | |
34d79f68 |
30 | sub 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 | |
40 | my $create; |
34d79f68 |
41 | for my $table_name ( @table_names ) { |
7d89539d |
42 | next if (grep /^$table_name$/, @skip_tables); |
24bc7217 |
43 | my $sth = $dbh->prepare("show create table $table_name"); |
44 | $sth->execute; |
45 | my $table = $sth->fetchrow_hashref; |
46 | $create .= $table->{'create table'} . ";\n\n"; |
34d79f68 |
47 | } |
48 | |
24bc7217 |
49 | SQL::Translator::Parser::MySQL::parse( $tr, $create ); |
50 | |
34d79f68 |
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 | |
24bc7217 |
65 | Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>. |
34d79f68 |
66 | |
67 | =head1 SEE ALSO |
68 | |
171fd49f |
69 | SQL::Translator. |
34d79f68 |
70 | |
71 | =cut |