From: Rob Kinyon Date: Fri, 3 Apr 2009 18:11:18 +0000 (-0400) Subject: Changed SelectComponent and TableJoin into Expression and added Alias. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FSQL-Abstract-2.0-ish.git;a=commitdiff_plain;h=662b716d50f233a948efa00a844a90298b356761 Changed SelectComponent and TableJoin into Expression and added Alias. --- diff --git a/lib/SQL/Abstract/Manual/Examples.pod b/lib/SQL/Abstract/Manual/Examples.pod index 52b4500..a98e890 100644 --- a/lib/SQL/Abstract/Manual/Examples.pod +++ b/lib/SQL/Abstract/Manual/Examples.pod @@ -20,12 +20,9 @@ one. The SQL used is from the MySQL dialect. ast_version => 0.0001, select => [ { - type => 'SelectComponent', - value => { - type => 'Value', - subtype => 'Number', - value => 1, - }, + type => 'Value', + subtype => 'Number', + value => 1, }, ], } @@ -37,19 +34,16 @@ one. The SQL used is from the MySQL dialect. ast_version => 0.0001, select => [ { - type => 'SelectComponent', + type => 'Alias', value => { type => 'Function', function => 'NOW', }, - as => { - type => 'Identifier', - element1 => 'time', - }, + as => 'time', }, ], tables => { - type => 'TableIdentifier', + type => 'Alias', value => { type => 'Identifier', element1 => 'dual', @@ -65,12 +59,9 @@ one. The SQL used is from the MySQL dialect. ast_version => 0.0001, select => [ { - type => 'SelectComponent', - value => { - type => 'Value', - subtype => 'Number', - value => 1, - }, + type => 'Value', + subtype => 'Number', + value => 1, }, ], tables => { @@ -78,18 +69,12 @@ one. The SQL used is from the MySQL dialect. op => 'LEFT OUTER', args => [ { - type => 'TableIdentifier', - value => { - type => 'Identifier', - element1 => 'foo', - }, + type => 'Identifier', + element1 => 'foo', }, { - type => 'TableIdentifier', - value => { - type => 'Identifier', - element1 => 'bar', - }, + type => 'Identifier', + element1 => 'bar', }, ], on => { @@ -118,19 +103,13 @@ one. The SQL used is from the MySQL dialect. ast_version => 0.0001, select => [ { - type => 'SelectComponent', - value => { - type => 'Identifier', - element1 => '*', - }, + type => 'Identifier', + element1 => '*', }, ], tables => { - type => 'TableIdentifier', - value => { - type => 'Identifier', - element1 => 'foo', - }, + type => 'Identifier', + element1 => 'foo', }, where => { type => 'Operator', @@ -156,25 +135,19 @@ one. The SQL used is from the MySQL dialect. ast_version => 0.0001, select => [ { - type => 'SelectComponent', - value => { - type => 'Operator', - op => 'COUNT', - args => [ - { - type => 'Identifier', - element1 => '*', - }, - ], - }, + type => 'Operator', + op => 'COUNT', + args => [ + { + type => 'Identifier', + element1 => '*', + }, + ], }, ], tables => { - type => 'TableIdentifier', - value => { - type => 'Identifier', - element1 => 'foo', - }, + type => 'Identifier', + element1 => 'foo', }, where => { type => 'Operator', @@ -242,31 +215,25 @@ one. The SQL used is from the MySQL dialect. ast_version => 0.0001, select => [ { - type => 'SelectComponent', - value => { - type => 'Operator', - op => 'COUNT', - args => [ - { - type => 'Operator', - op => 'DISTINCT', - args => [ - { - type => 'Identifier', - element1 => '*', - }, - ], - }, - ], - }, + type => 'Operator', + op => 'COUNT', + args => [ + { + type => 'Operator', + op => 'DISTINCT', + args => [ + { + type => 'Identifier', + element1 => '*', + }, + ], + }, + ], }, ], tables => { - type => 'TableIdentifier', - value => { - type => 'Identifier', - element1 => 'foo', - }, + type => 'Identifier', + element1 => 'foo', }, where => { type => 'Operator', @@ -334,33 +301,21 @@ one. The SQL used is from the MySQL dialect. ast_version => 0.0001, select => [ { - type => 'SelectComponent', - value => { - type => 'Identifier', - element1 => 'foo', - }, + type => 'Identifier', + element1 => 'foo', }, { - type => 'SelectComponent', - value => { - type => 'Identifier', - elements => 'bar', - }, + type => 'Identifier', + elements => 'bar', }, { - type => 'SelectComponent', - value => { - type => 'Identifier', - element1 => 'baz', - }, + type => 'Identifier', + element1 => 'baz', }, ], tables => { - type => 'TableIdentifier', - value => { - type => 'Identifier', - element1 => 'foo', - }, + type => 'Identifier', + element1 => 'foo', }, orderby => [ { @@ -414,11 +369,8 @@ one. The SQL used is from the MySQL dialect. type => 'update', ast_version => 0.0001, tables => { - type => 'TableIdentifier', - value => { - type => 'Identifier', - element1 => 'foo', - }, + type => 'Identifier', + element1 => 'foo', }, set => [ { @@ -442,11 +394,8 @@ one. The SQL used is from the MySQL dialect. type => 'insert', ast_version => 0.0001, tables => { - type => 'TableIdentifier', - value => { - type => 'Identifier', - element1 => 'foo', - }, + type => 'Identifier', + element1 => 'foo', }, columns => [ { @@ -478,11 +427,8 @@ one. The SQL used is from the MySQL dialect. type => 'delete', ast_version => 0.0001, tables => { - type => 'TableIdentifier', - value => { - type => 'Identifier', - element1 => 'foo', - }, + type => 'Identifier', + element1 => 'foo', }, where => { type => 'Operator', diff --git a/lib/SQL/Abstract/Manual/Specification.pod b/lib/SQL/Abstract/Manual/Specification.pod index 950e0ec..ce616b7 100644 --- a/lib/SQL/Abstract/Manual/Specification.pod +++ b/lib/SQL/Abstract/Manual/Specification.pod @@ -292,6 +292,19 @@ impossible. Subqueries, when expressed in SQL, must be bounded by parentheses. +=head3 Alias + +An Alias is any place where the construct "X as Y" appears. While the "as Y" is +often optional, the AST will make it required. + +The hash will be structured as follows: + + { + type => 'Alias', + value => Expression, + as => String, + } + =head3 Expression An Expression can be any one of the following: @@ -306,6 +319,8 @@ An Expression can be any one of the following: =item * Subquery +=item * Alias + =back An Expression is a meta-syntactic unit. An "Expression" unit will never appear @@ -389,18 +404,7 @@ The expected clauses are (name and structure): This corresponds to the SELECT clause of a SELECT statement. -A select clause unit is an array of one or more SelectComponent units. - -The hash for a SelectComponent unit is composed as follows: - - { - type => 'SelectComponent', - value => Expression, - as => String, - } - -The 'as' component is optional. Visitors may choose to make it required in -certain situations. +A select clause unit is an array of one or more Expressions. =head3 tables @@ -413,26 +417,7 @@ The tables clause has several RDBMS-specific variations. The AST will support all of them and it is up to the Visitor object constructing the actual SQL to validate and/or use what is provided as appropriate. -A TableJoin is a junction of the following elements: - -=over 4 - -=item * TableIdentifier - -=item * Operator - -=back - -The hash for a TableIdentifier will be composed as follows: - - # TableIdentifier - { - type => 'TableIdentifier', - value => Expression, - as => String, - } - -The value should be either an Identifier or a SubQuery. +A tables clause is an Expression. The hash for an Operator within a tables clause will be composed as follows: @@ -577,6 +562,12 @@ Both the start_with and order_siblings clauses are optional. =item * sproc unit +=item * UNION, UNION ALL, and MINUS + +=item * INSERT INTO SELECT ... + +=item * INSERT INTO
SET ... + =back =head1 AUTHORS