X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FProducer%2FSybase.pm;h=1cf47b5d62b5d4db4eb7ce2fc9ec8ddfb623f183;hb=4ab3763d2ad756c236b757306989cafa08e7f35e;hp=7601ed97cf0fd8fe1f4db4180075a0c6328a47ec;hpb=54c9812da023ca2347aa5f55a1e864305b5a9bfa;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Producer/Sybase.pm b/lib/SQL/Translator/Producer/Sybase.pm index 7601ed9..1cf47b5 100644 --- a/lib/SQL/Translator/Producer/Sybase.pm +++ b/lib/SQL/Translator/Producer/Sybase.pm @@ -1,12 +1,7 @@ package SQL::Translator::Producer::Sybase; # ------------------------------------------------------------------- -# $Id: Sybase.pm,v 1.3 2003-06-09 02:00:41 kycl4rk Exp $ -# ------------------------------------------------------------------- -# Copyright (C) 2003 Ken Y. Clark , -# darren chamberlain , -# Chris Mungall , -# Sam Angiuoli +# Copyright (C) 2002-2009 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 @@ -27,11 +22,22 @@ package SQL::Translator::Producer::Sybase; SQL::Translator::Producer::Sybase - Sybase producer for SQL::Translator +=head1 SYNOPSIS + + use SQL::Translator; + + my $t = SQL::Translator->new( parser => '...', producer => 'Sybase' ); + $t->translate; + +=head1 DESCRIPTION + +This module will produce text output of the schema suitable for Sybase. + =cut use strict; use vars qw[ $DEBUG $WARN $VERSION ]; -$VERSION = sprintf "%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/; +$VERSION = '1.59'; $DEBUG = 1 unless defined $DEBUG; use Data::Dumper; @@ -128,12 +134,12 @@ and table_constraint is: # ------------------------------------------------------------------- sub produce { - my ( $translator, $data ) = @_; - $DEBUG = $translator->debug; - $WARN = $translator->show_warnings; - my $no_comments = $translator->no_comments; - my $add_drop_table = $translator->add_drop_table; - my $schema = $translator->schema; + my $translator = shift; + $DEBUG = $translator->debug; + $WARN = $translator->show_warnings; + my $no_comments = $translator->no_comments; + my $add_drop_table = $translator->add_drop_table; + my $schema = $translator->schema; my $output; $output .= header_comment unless ($no_comments); @@ -171,7 +177,8 @@ sub produce { my $orig_data_type = $data_type; my %extra = $field->extra; my $list = $extra{'list'} || []; - my $commalist = join ",", @$list; + # \todo deal with embedded quotes + my $commalist = join( ', ', map { qq['$_'] } @$list ); my $seq_name; if ( $data_type eq 'enum' ) { @@ -313,6 +320,40 @@ sub produce { ); } + foreach my $view ( $schema->get_views ) { + my (@comments, $view_name); + + $view_name = $view->name(); + push @comments, "--\n-- View: $view_name\n--" unless $no_comments; + + # text of view is already a 'create view' statement so no need + # to do anything fancy. + + $output .= join("\n\n", + @comments, + $view->sql(), + ); + } + + + foreach my $procedure ( $schema->get_procedures ) { + my (@comments, $procedure_name); + + $procedure_name = $procedure->name(); + push @comments, + "--\n-- Procedure: $procedure_name\n--" unless $no_comments; + + # text of procedure already has the 'create procedure' stuff + # so there is no need to do anything fancy. However, we should + # think about doing fancy stuff with granting permissions and + # so on. + + $output .= join("\n\n", + @comments, + $procedure->sql(), + ); + } + if ( $WARN ) { if ( %truncated ) { warn "Truncated " . keys( %truncated ) . " names:\n"; @@ -394,9 +435,14 @@ sub unreserve { =pod +=head1 SEE ALSO + +SQL::Translator. + =head1 AUTHORS Sam Angiuoli Eangiuoli@users.sourceforge.netE, -Ken Y. Clark Ekclark@cpan.orgE +Paul Harrington Eharringp@deshaw.comE, +Ken Y. Clark Ekclark@cpan.orgE. =cut