1 package SQL::Abstract::Reference;
8 SQL::Abstract::Reference - Reference documentation for L<SQL::Abstract>
12 =head2 Expression (expr)
14 The DWIM structure that's passed to most methods by default is referred to
15 as expression syntax. If you see a variable with C<expr> in the name, or a
16 comment before a code block saying C<# expr>, this is what's being described.
18 =head2 Abstract Query Tree (aqt)
20 The explicit structure that an expression is converted into before it's
21 rendered into SQL is referred to as an abstract query tree. If you see a
22 variable with C<aqt> in the name, or a comment before a code block saying
23 C<# aqt>#, this is what's being described.
25 =head2 SQL and Bind Values (query)
27 The final result of L<SQL::Abstract> rendering is generally an SQL statement
28 plus bind values for passing to DBI, ala:
30 my ($sql, @bind) = $sqla->some_method(@args);
31 my @hashes = @{$dbh->do($sql, { Slice => {} }, @bind)};
33 If you see a comment before a code block saying C<# query>, the SQL + bind
34 array is what's being described.
38 An AQT node consists of a hashref with a single key, whose name is C<-type>
39 where 'type' is the node type, and whose value is the data for the node.
44 { -literal => [ 'SPANG(?, ?)', 1, 27 ] }
60 { -ident => [ 'foo', 'bar' ] }
69 { -bind => [ 'colname', 'value' ] }
79 -row => [ { -bind => [ 'r', 1 ] }, { -ident => [ 'clown', 'car' ] } ]
90 -func => [ 'foo', { -ident => [ 'bar' ] }, { -bind => [ undef, 7 ] } ]
103 '=', { -ident => [ 'bomb', 'status' ] },
104 { -value => 'unexploded' },
114 { -op => [ 'not', { -ident => 'explosive' } ] }
120 Postfix unop: (is_null, is_not_null, asc, desc)
123 { -op => [ 'is_null', { -ident => [ 'bobby' ] } ] }
133 [ 'and', { -ident => 'x' }, { -ident => 'y' }, { -ident => 'z' } ]
144 'in', { -ident => 'card' }, { -bind => [ 'card', 3 ] },
145 { -bind => [ 'card', 'J' ] },
152 BETWEEN (and NOT BETWEEN):
156 'between', { -ident => 'pints' }, { -bind => [ 'pints', 2 ] },
157 { -bind => [ 'pints', 4 ] },
161 ( pints BETWEEN ? AND ? )
164 Comma (use -row for parens):
167 { -op => [ ',', { -literal => [ 1 ] }, { -literal => [ 2 ] } ] }
177 { -row => [ { -bind => [ undef, 1 ] }, { -bind => [ undef, 2 ] } ] }
186 { -row => [ { -literal => [ 1 ] }, { -literal => [ 2 ] } ] },
187 { -row => [ { -literal => [ 3 ] }, { -literal => [ 4 ] } ] },
191 VALUES (1, 2), (3, 4)
194 =head2 statement types
196 AQT node types are also provided for C<select>, C<insert>, C<update> and
197 C<delete>. These types are handled by the clauses system as discussed later.
201 The simplest expression is just an AQT node:
204 { -ident => [ 'foo', 'bar' ] }
207 { -ident => [ 'foo', 'bar' ] }
213 However, even in the case of an AQT node, the node value will be expanded if
214 an expander has been registered for that node type:
217 { -ident => 'foo.bar' }
220 { -ident => [ 'foo', 'bar' ] }