1 package SQL::Translator::Parser::xSV;
3 # -------------------------------------------------------------------
4 # $Id: xSV.pm,v 1.5 2003-04-17 13:42:45 dlc Exp $
5 # -------------------------------------------------------------------
6 # Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
7 # darren chamberlain <darren@cpan.org>,
8 # Chris Mungall <cjm@fruitfly.org>
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation; version 2.
14 # This program is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 # -------------------------------------------------------------------
26 use vars qw($VERSION @EXPORT);
27 $VERSION = sprintf "%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/;
30 use Text::ParseWords qw(quotewords);
32 use base qw(Exporter);
35 # Passed a SQL::Translator instance and a string containing the data
39 # Skeleton structure, mostly empty
48 # Discard all but the first line
49 $data = (split m,$/,, $data)[0];
51 my @parsed = quotewords(',\s*', 0, $data);
53 for (my $i = 0; $i < @parsed; $i++) {
54 $parsed->{"table1"}->{"fields"}->{$parsed[$i]} = {
59 # Default datatype is "char"
62 # default size is 8bits; something more reasonable?
68 # field field is the primary key
69 is_primary_key => ($i == 0) ? 1 : undef,
73 # Field 0 is primary key, by default, so add an index
74 for ($parsed->{"table1"}->{"indices"}->[0]) {
75 $_->{"type"} = "primary_key";
77 $_->{"fields"} = [ $parsed[0] ];