package SQL::Translator::Parser::DBI::MySQL;
# -------------------------------------------------------------------
-# $Id: MySQL.pm,v 1.1 2003-10-03 19:29:31 kycl4rk Exp $
+# $Id: MySQL.pm,v 1.5 2005-07-12 16:05:35 duality72 Exp $
# -------------------------------------------------------------------
-# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>.
+# Copyright (C) 2002-4 SQLFairy Authors
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
=head1 SYNOPSIS
-See SQL::Translator::Parser::DBI.
+This module will be invoked automatically by SQL::Translator::Parser::DBI,
+so there is no need to use it directly.
=head1 DESCRIPTION
-Queries the "sqlite_master" table for schema definition.
+Uses SQL calls to query database directly for schema rather than parsing
+a create file. Should be much faster for larger schemas.
=cut
use SQL::Translator::Schema::Constants;
use vars qw[ $DEBUG $VERSION @EXPORT_OK ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/;
$DEBUG = 0 unless defined $DEBUG;
# -------------------------------------------------------------------
sub parse {
my ( $tr, $dbh ) = @_;
-
- my @table_names = @{ $dbh->selectcol_arrayref( 'show tables') };
-
- my $schema = $tr->schema;
+ my $schema = $tr->schema;
+ my @table_names = @{ $dbh->selectcol_arrayref( 'show tables') };
for my $table_name ( @table_names ) {
my $table = $schema->add_table(
);
for my $col ( @$cols ) {
- my $fname = $col->{'field'} or next;
- my $type = $col->{'type'} or next;
- my $collation = $col->{'collation'} || '';
+ my $fname = $col->{'field'} or next;
+ my $type = $col->{'type'} or next;
+ my $collation = $col->{'collation'} || '';
my $is_nullable = uc $col->{'null'} eq 'YES' ? 1 : 0;
my $key = $col->{'key'};
my $default = $col->{'default'};
my $extra = $col->{'extra'};
+ my $is_auto_inc = $extra =~ s/auto_increment//i;
my ( $data_type, $size, $char_set );
data_type => $data_type,
size => $size,
default_value => $default,
- is_auto_increment => $extra eq 'auto_increment',
+ is_auto_increment => $is_auto_inc,
is_nullable => $is_nullable,
comments => $extra,
) or die $table->error;
sort { $constraints{ $a }{'order'} <=> $constraints{ $b }{'order'} }
keys %constraints
) {
- my $def = $constraints{ $constraint_name };
+ my $def = $constraints{ $constraint_name };
my $constraint = $table->add_constraint(
name => $constraint_name,
type => $def->{'type'},
=head1 AUTHOR
-Ken Y. Clark E<lt>kclark@cpan.orgE<gt>,
-Chris Mungall E<lt>cjm@fruitfly.orgE<gt>.
+Ken Y. Clark E<lt>kclark@cpan.orgE<gt>.
=head1 SEE ALSO
-perl(1), Parse::RecDescent, SQL::Translator::Schema.
+SQL::Translator.
=cut