From: Ken Youens-Clark Date: Sun, 6 Apr 2003 19:08:49 +0000 (+0000) Subject: Some syntax fixes, package name was wrong, added Mikey's name to AUTHORS. X-Git-Tag: v0.02~205 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7909b81e18166b5d6a0a32221147ff20f423d159;p=dbsrgits%2FSQL-Translator.git Some syntax fixes, package name was wrong, added Mikey's name to AUTHORS. This parser is still broken. The data structure I see coming back from Spreadsheet::ParseExcel is not the same that is being examined by the code. --- diff --git a/lib/SQL/Translator/Parser/Excel.pm b/lib/SQL/Translator/Parser/Excel.pm index aa96be6..e8637b2 100644 --- a/lib/SQL/Translator/Parser/Excel.pm +++ b/lib/SQL/Translator/Parser/Excel.pm @@ -1,10 +1,10 @@ -package SQL::Translator::Parser::MySQL; +package SQL::Translator::Parser::Excel; # ------------------------------------------------------------------- -# ------------------------------------------------------------------- # Copyright (C) 2003 Ken Y. Clark , # darren chamberlain , -# Chris Mungall +# Chris Mungall , +# Mike Mellilo # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -35,8 +35,8 @@ SQL::Translator::Parser::Excel - parser for Excel =head1 DESCRIPTION - The basic point of this module is to parse out any SQL or DB Schema information - from an Excel spreadsheet file. +Parses an Excel spreadsheet file for SQL::Translator. You can then +turn the data into a database tables or graphs. =cut @@ -45,48 +45,50 @@ use vars qw[ $DEBUG $VERSION @EXPORT_OK ]; $DEBUG = 0 unless defined $DEBUG; use Data::Dumper; -#use Spreadsheet::ParseExcel; +use Spreadsheet::ParseExcel; use Exporter; use base qw(Exporter); @EXPORT_OK = qw(parse); - - - # ------------------------------------------------------------------- sub parse { my ( $translator, $data ) = @_; - my $parsed = { - table1 => { - "type" => undef, + my $parsed = { + table1 => { + "type" => undef, "indices" => [ { } ], - "fields" => { }, + "fields" => { }, }, }; - - my $tr = new Spreadsheet::ParseExcel; - $tr->Parse($data); - my ($R, $C); - $R = 1; # For now we will assume all column names are in the first row - - my @parsed = map { return $tr->{Cells}[$R][$C] } ( $C = $tr->{MinCol} ; $C <= $tr->{MaxCol} ; $C++;) ; - - - for (my $i = 0; $i < @parsed; $i++) { - $parsed->{"table1"}->{"fields"}->{$parsed[$i]} = { - type => "field", + my $tr = Spreadsheet::ParseExcel->new; + $tr->Parse( $data ); + my $r = 1; # For now we will assume all column names are in the first row + my $c = 0; + + # + # Mikey, what's going on here? + # + my @parsed = map { return $tr->{'Cells'}[$r][$c] } ( + $c = $tr->{'MinCol'}; + $c <= $tr->{'MaxCol'}; # Is "<=" right? + $c++; + ); + + for ( my $i = 0; $i < @parsed; $i++ ) { + $parsed->{'table1'}->{'fields'}->{$parsed[$i]} = { + type => 'field', order => $i, name => $parsed[$i], - # Default datatype is "char" - data_type => "char", + # Default datatype is 'char' + data_type => 'char', # default size is 8bits; something more reasonable? size => 255, null => 1, - default => "", + default => '', is_auto_inc => undef, # field field is the primary key @@ -96,28 +98,23 @@ sub parse { # Field 0 is primary key, by default, so add an index - for ($parsed->{"table1"}->{"indices"}->[0]) { - $_->{"type"} = "primary_key"; - $_->{"name"} = undef; - $_->{"fields"} = [ $parsed[0] ]; + for ($parsed->{'table1'}->{'indices'}->[0]) { + $_->{'type'} = 'primary_key'; + $_->{'name'} = undef; + $_->{'fields'} = [ $parsed[0] ]; } - - return $parsed; - - } 1; - =pod -=head1 AUTHOR +=head1 AUTHORS -Ken Y. Clark Ekclark@cpan.orgE, -Chris Mungall +Mike Mellilo , +Ken Y. Clark Ekclark@cpan.orgE =head1 SEE ALSO