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