Commit | Line | Data |
34d79f68 |
1 | package SQL::Translator::Parser::DBI::MySQL; |
2 | |
3 | # ------------------------------------------------------------------- |
24bc7217 |
4 | # $Id: MySQL.pm,v 1.6 2006-02-22 22:52:51 kycl4rk Exp $ |
34d79f68 |
5 | # ------------------------------------------------------------------- |
90075866 |
6 | # Copyright (C) 2002-4 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 | |
25 | SQL::Translator::Parser::DBI::MySQL - parser for DBD::mysql |
26 | |
27 | =head1 SYNOPSIS |
28 | |
171fd49f |
29 | This module will be invoked automatically by SQL::Translator::Parser::DBI, |
30 | so there is no need to use it directly. |
34d79f68 |
31 | |
32 | =head1 DESCRIPTION |
33 | |
171fd49f |
34 | Uses SQL calls to query database directly for schema rather than parsing |
35 | a create file. Should be much faster for larger schemas. |
34d79f68 |
36 | |
37 | =cut |
38 | |
39 | use strict; |
40 | use DBI; |
41 | use Data::Dumper; |
42 | use SQL::Translator::Schema::Constants; |
24bc7217 |
43 | use SQL::Translator::Parser::MySQL; |
34d79f68 |
44 | |
45 | use vars qw[ $DEBUG $VERSION @EXPORT_OK ]; |
24bc7217 |
46 | $VERSION = sprintf "%d.%02d", q$Revision: 1.6 $ =~ /(\d+)\.(\d+)/; |
34d79f68 |
47 | $DEBUG = 0 unless defined $DEBUG; |
48 | |
49 | # ------------------------------------------------------------------- |
50 | sub parse { |
51 | my ( $tr, $dbh ) = @_; |
171fd49f |
52 | my $schema = $tr->schema; |
24bc7217 |
53 | my @table_names = @{ $dbh->selectcol_arrayref('show tables') }; |
34d79f68 |
54 | |
24bc7217 |
55 | $dbh->{'FetchHashKeyName'} = 'NAME_lc'; |
56 | |
57 | my $create; |
34d79f68 |
58 | for my $table_name ( @table_names ) { |
24bc7217 |
59 | my $sth = $dbh->prepare("show create table $table_name"); |
60 | $sth->execute; |
61 | my $table = $sth->fetchrow_hashref; |
62 | $create .= $table->{'create table'} . ";\n\n"; |
34d79f68 |
63 | } |
64 | |
24bc7217 |
65 | SQL::Translator::Parser::MySQL::parse( $tr, $create ); |
66 | |
34d79f68 |
67 | return 1; |
68 | } |
69 | |
70 | 1; |
71 | |
72 | # ------------------------------------------------------------------- |
73 | # Where man is not nature is barren. |
74 | # William Blake |
75 | # ------------------------------------------------------------------- |
76 | |
77 | =pod |
78 | |
79 | =head1 AUTHOR |
80 | |
24bc7217 |
81 | Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>. |
34d79f68 |
82 | |
83 | =head1 SEE ALSO |
84 | |
171fd49f |
85 | SQL::Translator. |
34d79f68 |
86 | |
87 | =cut |