SQL-Translator

 view release on metacpan or  search on metacpan

lib/SQL/Translator/Parser/SQLServer.pm  view on Meta::CPAN

    { $return = 'null' }
   | /default/i SQSTRING
    { $return = $item[2] }
   | /default/i WORD
    { $return = $item[2] }

auto_inc : /identity/i { 1 }

primary_key_constraint : /constraint/i index_name(?) /primary/i /key/i parens_field_list
    {
        $return = {
            supertype => 'constraint',
            name      => $item[2][0],
            type      => 'primary_key',
            fields    => $item[5],
        }
    }

foreign_key_constraint : /constraint/i index_name(?) /foreign/i /key/i parens_field_list /references/i table_name parens_field_list(?) on_delete(?) on_update(?)
    {
        $return = {
            supertype        => 'constraint',
            name             => $item[2][0],
            type             => 'foreign_key',
            fields           => $item[5],
            reference_table  => $item[7],
            reference_fields => $item[8][0],
            on_delete        => $item[9][0],
            on_update        => $item[10][0],
        }
    }

unique_constraint : /constraint/i index_name(?) /unique/i parens_field_list
    {
        $return = {
            supertype => 'constraint',
            type      => 'unique',
            name      => $item[2][0],
            fields    => $item[4],
        }
    }

unique_constraint : /unique/i clustered(?) INDEX(?) index_name(?) on_table(?) parens_field_list field_not_null(?)
    {
        $return = {
            supertype => 'constraint',
            type      => 'unique',
            clustered => $item[2][0],
            name      => $item[4][0],
            table     => $item[5][0],
            fields    => $item[6],
        }
    }

on_delete : /on delete/i reference_option
    { $item[2] }

on_update : /on update/i reference_option
    { $item[2] }

reference_option: /cascade/i
    { $item[1] }
    | /no action/i
    { $item[1] }

clustered : /clustered/i
    { $return = 1 }
    | /nonclustered/i
    { $return = 0 }

INDEX : /index/i

on_table : /on/i table_name
    { $return = $item[2] }

on_system : /on/i /system/i
    { $return = 1 }

index : clustered(?) INDEX index_name(?) on_table(?) parens_field_list END_STATEMENT
    {
        $return = {
            supertype => 'index',
            type      => 'normal',
            clustered => $item[1][0],
            name      => $item[3][0],
            table     => $item[4][0],
            fields    => $item[5],
        }
    }

parens_field_list : '(' field_name(s /,/) ')'
    { $item[2] }

ident : NAME '.' NAME
    { $return = { owner => $item[1], name => $item[3] } }
    | NAME
    { $return = { name  => $item[1] } }

END_STATEMENT : ';'
   | GO

GO : /^go/i

USERNAME : WORD
    | SQSTRING

NAME : WORD
    | DQSTRING
    | BQSTRING

WORD : /[\w#]+/

DIGITS : /\d+/

COMMA : ','

SQSTRING : "'" <skip: ''> /(?:[^']|'')*/ "'"
    { ($return = $item[3]) =~ s/''/'/g }

DQSTRING : '"' <skip: ''> /(?:[^"]|"")+/ '"'
    { ($return = $item[3]) =~ s/""/"/g }



( run in 0.790 second using v1.01-cache-2.11-cpan-5735350b133 )