Add sqlite roundtrip test (probably need to do the same for the rest of the parser...
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Parser / DBI / MySQL.pm
CommitLineData
34d79f68 1package SQL::Translator::Parser::DBI::MySQL;
2
3# -------------------------------------------------------------------
821a0fde 4# $Id$
34d79f68 5# -------------------------------------------------------------------
478f608d 6# Copyright (C) 2002-2009 SQLFairy Authors
34d79f68 7#
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.
11#
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.
16#
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
20# 02111-1307 USA
21# -------------------------------------------------------------------
22
23=head1 NAME
24
25SQL::Translator::Parser::DBI::MySQL - parser for DBD::mysql
26
27=head1 SYNOPSIS
28
171fd49f 29This module will be invoked automatically by SQL::Translator::Parser::DBI,
30so there is no need to use it directly.
34d79f68 31
32=head1 DESCRIPTION
33
171fd49f 34Uses SQL calls to query database directly for schema rather than parsing
35a create file. Should be much faster for larger schemas.
34d79f68 36
37=cut
38
39use strict;
40use DBI;
41use Data::Dumper;
42use SQL::Translator::Schema::Constants;
24bc7217 43use SQL::Translator::Parser::MySQL;
34d79f68 44
478f608d 45use vars qw[ $DEBUG @EXPORT_OK ];
34d79f68 46$DEBUG = 0 unless defined $DEBUG;
47
48# -------------------------------------------------------------------
49sub parse {
50 my ( $tr, $dbh ) = @_;
171fd49f 51 my $schema = $tr->schema;
24bc7217 52 my @table_names = @{ $dbh->selectcol_arrayref('show tables') };
7d89539d 53 my @skip_tables = defined $tr->parser_args->{skip}?split(/,/, $tr->parser_args->{skip}):();
34d79f68 54
24bc7217 55 $dbh->{'FetchHashKeyName'} = 'NAME_lc';
56
57 my $create;
34d79f68 58 for my $table_name ( @table_names ) {
7d89539d 59 next if (grep /^$table_name$/, @skip_tables);
24bc7217 60 my $sth = $dbh->prepare("show create table $table_name");
61 $sth->execute;
62 my $table = $sth->fetchrow_hashref;
63 $create .= $table->{'create table'} . ";\n\n";
34d79f68 64 }
65
24bc7217 66 SQL::Translator::Parser::MySQL::parse( $tr, $create );
67
34d79f68 68 return 1;
69}
70
711;
72
73# -------------------------------------------------------------------
74# Where man is not nature is barren.
75# William Blake
76# -------------------------------------------------------------------
77
78=pod
79
80=head1 AUTHOR
81
24bc7217 82Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>.
34d79f68 83
84=head1 SEE ALSO
85
171fd49f 86SQL::Translator.
34d79f68 87
88=cut