| 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.66'; | ||
| 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 | ||
| 35 | = defined $tr->parser_args->{skip} | ||
| 36 | ? split(/,/, $tr->parser_args->{skip}) | ||
| 37 | : (); | ||
| 38 | |||
| 39 | $dbh->{'FetchHashKeyName'} = 'NAME_lc'; | ||
| 40 | |||
| 41 | my $create = q{}; | ||
| 42 | for my $table_name (@table_names) { | ||
| 43 | next if (grep /^$table_name$/, @skip_tables); | ||
| 44 | my $sth = $dbh->prepare("show create table " . $dbh->quote_identifier($table_name)); | ||
| 45 | $sth->execute; | ||
| 46 | my $table = $sth->fetchrow_hashref; | ||
| 47 | $create .= ($table->{'create table'} || $table->{'create view'}) . ";\n\n"; | ||
| 48 | } | ||
| 49 | |||
| 50 | SQL::Translator::Parser::MySQL::parse($tr, $create); | ||
| 51 | |||
| 52 | return 1; | ||
| 53 | } | ||
| 54 | |||
| 55 | 1; | ||
| 56 | |||
| 57 | # ------------------------------------------------------------------- | ||
| 58 | # Where man is not nature is barren. | ||
| 59 | # William Blake | ||
| 60 | # ------------------------------------------------------------------- | ||
| 61 | |||
| 62 | =pod | ||
| 63 | |||
| 64 | =head1 AUTHOR | ||
| 65 | |||
| 66 | Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>. | ||
| 67 | |||
| 68 | =head1 SEE ALSO | ||
| 69 | |||
| 70 | SQL::Translator. | ||
| 71 | |||
| 72 | =cut |