SQL::Translator::Producer::SQLServer - MS SQLServer producer for SQL::Translator


SQL-Translator documentation  | view source Contained in the SQL-Translator distribution.

Index


NAME

Top

SQL::Translator::Producer::SQLServer - MS SQLServer producer for SQL::Translator

SYNOPSIS

Top

  use SQL::Translator;

  my $t = SQL::Translator->new( parser => '...', producer => 'SQLServer' );
  $t->translate;

DESCRIPTION

Top

WARNINGB This is still fairly early code, basically a hacked version of the Sybase Producer (thanks Sam, Paul and Ken for doing the real work ;-)

Extra Attributes

Top

field.list

List of values for an enum field.

TODO

Top

 * !! Write some tests !!
 * Reserved words list needs updating to SQLServer.
 * Triggers, Procedures and Views DO NOT WORK

SQLServer Create Table Syntax

Top

TODO

    # Text of view is already a 'create view' statement so no need to
    # be fancy
    foreach ( $schema->get_views ) {
        my $name = $_->name();
        $output .= "\n\n";
        $output .= "--\n-- View: $name\n--\n\n" unless $no_comments;
        my $text = $_->sql();
        $text =~ s/\r//g;
        $output .= "$text\nGO\n";
    }

    # 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.
    foreach ( $schema->get_procedures ) {
        my $name = $_->name();
        $output .= "\n\n";
        $output .= "--\n-- Procedure: $name\n--\n\n" unless $no_comments;
        my $text = $_->sql();
      $text =~ s/\r//g;
        $output .= "$text\nGO\n";
    }
=cut

    return $output;
}

# ------------------------------------------------------------------- sub mk_name { my ($name, $scope, $critical) = @_;

    $scope ||= \%global_names;
    if ( my $prev = $scope->{ $name } ) {
        my $name_orig = $name;
        $name        .= sprintf( "%02d", ++$prev );
        substr($name, $max_id_length - 3) = "00"
            if length( $name ) > $max_id_length;

        warn "The name '$name_orig' has been changed to ",
             "'$name' to make it unique.\n" if $WARN;

        $scope->{ $name_orig }++;
    }
    $name = substr( $name, 0, $max_id_length )
                        if ((length( $name ) > $max_id_length) && $critical);
    $scope->{ $name }++;
    return unreserve($name);
}

# ------------------------------------------------------------------- sub unreserve { $util->quote($_[0]) }

1;

# -------------------------------------------------------------------

SEE ALSO

Top

SQL::Translator.

AUTHORS

Top

Mark Addison <grommit@users.sourceforge.net> - Bulk of code from Sybase producer, I just tweaked it for SQLServer. Thanks.


SQL-Translator documentation  | view source Contained in the SQL-Translator distribution.