Upped version numbers, cleaned up code, fixed my name.
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Parser / DBI / MySQL.pm
CommitLineData
34d79f68 1package SQL::Translator::Parser::DBI::MySQL;
2
3# -------------------------------------------------------------------
478f608d 4# Copyright (C) 2002-2009 SQLFairy Authors
34d79f68 5#
6# This program is free software; you can redistribute it and/or
7# modify it under the terms of the GNU General Public License as
8# published by the Free Software Foundation; version 2.
9#
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18# 02111-1307 USA
19# -------------------------------------------------------------------
20
21=head1 NAME
22
23SQL::Translator::Parser::DBI::MySQL - parser for DBD::mysql
24
25=head1 SYNOPSIS
26
171fd49f 27This module will be invoked automatically by SQL::Translator::Parser::DBI,
28so there is no need to use it directly.
34d79f68 29
30=head1 DESCRIPTION
31
171fd49f 32Uses SQL calls to query database directly for schema rather than parsing
33a create file. Should be much faster for larger schemas.
34d79f68 34
35=cut
36
37use strict;
38use DBI;
39use Data::Dumper;
40use SQL::Translator::Schema::Constants;
24bc7217 41use SQL::Translator::Parser::MySQL;
34d79f68 42
da06ac74 43use vars qw[ $DEBUG $VERSION @EXPORT_OK ];
ba506e52 44$VERSION = '1.60';
34d79f68 45$DEBUG = 0 unless defined $DEBUG;
46
47# -------------------------------------------------------------------
48sub parse {
49 my ( $tr, $dbh ) = @_;
171fd49f 50 my $schema = $tr->schema;
24bc7217 51 my @table_names = @{ $dbh->selectcol_arrayref('show tables') };
f0fc3ac0 52 my @skip_tables = defined $tr->parser_args->{skip}
53 ? split(/,/, $tr->parser_args->{skip})
54 : ();
34d79f68 55
24bc7217 56 $dbh->{'FetchHashKeyName'} = 'NAME_lc';
57
58 my $create;
34d79f68 59 for my $table_name ( @table_names ) {
7d89539d 60 next if (grep /^$table_name$/, @skip_tables);
24bc7217 61 my $sth = $dbh->prepare("show create table $table_name");
62 $sth->execute;
63 my $table = $sth->fetchrow_hashref;
64 $create .= $table->{'create table'} . ";\n\n";
34d79f68 65 }
66
24bc7217 67 SQL::Translator::Parser::MySQL::parse( $tr, $create );
68
34d79f68 69 return 1;
70}
71
721;
73
74# -------------------------------------------------------------------
75# Where man is not nature is barren.
76# William Blake
77# -------------------------------------------------------------------
78
79=pod
80
81=head1 AUTHOR
82
24bc7217 83Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>.
34d79f68 84
85=head1 SEE ALSO
86
171fd49f 87SQL::Translator.
34d79f68 88
89=cut