remove commented copyright
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Parser / DBI / MySQL.pm
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 DBI;
21 use Data::Dumper;
22 use SQL::Translator::Schema::Constants;
23 use SQL::Translator::Parser::MySQL;
24
25 use vars qw[ $DEBUG $VERSION @EXPORT_OK ];
26 $VERSION = '1.59';
27 $DEBUG   = 0 unless defined $DEBUG;
28
29 sub parse {
30     my ( $tr, $dbh ) = @_;
31     my $schema       = $tr->schema;
32     my @table_names  = @{ $dbh->selectcol_arrayref('show tables') };
33     my @skip_tables  = defined $tr->parser_args->{skip}
34                        ? split(/,/, $tr->parser_args->{skip})
35                        : ();
36
37     $dbh->{'FetchHashKeyName'} = 'NAME_lc';
38
39     my $create;
40     for my $table_name ( @table_names ) {
41         next if (grep /^$table_name$/, @skip_tables);
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";
46     }
47
48     SQL::Translator::Parser::MySQL::parse( $tr, $create );
49
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
64 Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>.
65
66 =head1 SEE ALSO
67
68 SQL::Translator.
69
70 =cut