1 package SQL::Translator::Parser::DBI::MySQL;
3 # -------------------------------------------------------------------
5 # -------------------------------------------------------------------
6 # Copyright (C) 2002-4 SQLFairy Authors
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation; version 2.
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 # -------------------------------------------------------------------
25 SQL::Translator::Parser::DBI::MySQL - parser for DBD::mysql
29 This module will be invoked automatically by SQL::Translator::Parser::DBI,
30 so there is no need to use it directly.
34 Uses SQL calls to query database directly for schema rather than parsing
35 a create file. Should be much faster for larger schemas.
42 use SQL::Translator::Schema::Constants;
43 use SQL::Translator::Parser::MySQL;
45 use vars qw[ $DEBUG $VERSION @EXPORT_OK ];
46 $VERSION = sprintf "%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/;
47 $DEBUG = 0 unless defined $DEBUG;
49 # -------------------------------------------------------------------
51 my ( $tr, $dbh ) = @_;
52 my $schema = $tr->schema;
53 my @table_names = @{ $dbh->selectcol_arrayref('show tables') };
54 my @skip_tables = defined $tr->parser_args->{skip}?split(/,/, $tr->parser_args->{skip}):();
56 $dbh->{'FetchHashKeyName'} = 'NAME_lc';
59 for my $table_name ( @table_names ) {
60 next if (grep /^$table_name$/, @skip_tables);
61 my $sth = $dbh->prepare("show create table $table_name");
63 my $table = $sth->fetchrow_hashref;
64 $create .= $table->{'create table'} . ";\n\n";
67 SQL::Translator::Parser::MySQL::parse( $tr, $create );
74 # -------------------------------------------------------------------
75 # Where man is not nature is barren.
77 # -------------------------------------------------------------------
83 Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>.