Skip to content

CREATE VIEW translation invalid, duplicates "CREATE VIEW" in output: #176

@kgoess

Description

@kgoess

AFAICT SQLServer -> SQLite is the only combination where it even almost works, and yet:

$ cat create-view.sql 
CREATE VIEW testview
AS
    select 1
GO
$ perl -Ilib ./script/sqlt --from SQLServer --to SQLite create-view.sql --no-comments
BEGIN TRANSACTION;

CREATE VIEW "testview" AS
    CREATE VIEW testview AS      # <<<--- oops
    select 1
;

COMMIT;

This is because while SQL::Translator:::Producer::SQLite's create_view does this:

  if (my $sql = $view->sql) {
    $create_view .= " AS\n    ${sql}";                                                         
  }

and yet the production in SQL/Translator/Parser/SQLServer.pm has already stuff all of the sql including the CREATE VIEW part into the sql field:

create_view : /create/i /view/i WORD not_go GO
    {
        @table_comments = ();
        my $view_name = $item[3];
        my $sql = "$item[1] $item[2] $item[3] $item[4]";

        $views{ $view_name }{'order'}  = ++$view_order;
        $views{ $view_name }{'name'}   = $view_name;
        $views{ $view_name }{'sql'}    = $sql;
    }

Perhaps a better approach would be what the Sybase producer does:

    # text of view is already a 'create view' statement so no need
    # to do anything fancy.
  
    push @output, join("\n\n", @comments, $view->sql(),);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions