@@ -17,18 +17,21 @@ class Sql2Generator extends BaseSqlGenerator
17
17
* Selector ::= nodeTypeName ['AS' selectorName]
18
18
* nodeTypeName ::= Name
19
19
*
20
- * @param string $nodeTypeName The node type of the selector. If it does not contain starting and ending brackets ([]) they will be added automatically
21
- * @param string $selectorName
20
+ * @param string $nodeTypeName The node type of the selector. If it
21
+ * does not contain starting and ending brackets ([]) they will be
22
+ * added automatically.
23
+ * @param string|null $selectorName The selector name. If it is different than
24
+ * the nodeTypeName, the alias is declared.
22
25
*
23
26
* @return string
24
27
*/
25
28
public function evalSelector ($ nodeTypeName , $ selectorName = null )
26
29
{
27
30
$ sql2 = $ this ->addBracketsIfNeeded ($ nodeTypeName );
28
31
29
- $ name = $ selectorName;
30
- if (! is_null ( $ name)) {
31
- $ sql2 .= ' AS ' . $ name ;
32
+ if ( null !== $ selectorName && $ nodeTypeName !== $ selectorName) {
33
+ // if the selector name is the same as the type name, this is implicit for sql2
34
+ $ sql2 .= ' AS ' . $ selectorName ;
32
35
}
33
36
34
37
return $ sql2 ;
@@ -112,7 +115,9 @@ public function evalSameNodeJoinCondition($sel1Name, $sel2Name, $sel2Path = null
112
115
. $ this ->addBracketsIfNeeded ($ sel1Name ) . ', '
113
116
. $ this ->addBracketsIfNeeded ($ sel2Name )
114
117
;
115
- $ sql2 .= ! is_null ($ sel2Path ) ? ', ' . $ sel2Path : '' ;
118
+ if (null !== $ sel2Path ) {
119
+ $ sql2 .= ', ' . $ sel2Path ;
120
+ }
116
121
$ sql2 .= ') ' ;
117
122
118
123
return $ sql2 ;
@@ -165,7 +170,7 @@ public function evalDescendantNodeJoinCondition($descendantSelectorName, $ancest
165
170
public function evalSameNode ($ path , $ selectorName = null )
166
171
{
167
172
$ sql2 = 'ISSAMENODE( ' ;
168
- $ sql2 .= is_null ( $ selectorName) ? $ path : $ this ->addBracketsIfNeeded ($ selectorName ) . ', ' . $ path ;
173
+ $ sql2 .= null === $ selectorName ? $ path : $ this ->addBracketsIfNeeded ($ selectorName ) . ', ' . $ path ;
169
174
$ sql2 .= ') ' ;
170
175
171
176
return $ sql2 ;
@@ -180,7 +185,7 @@ public function evalSameNode($path, $selectorName = null)
180
185
public function evalChildNode ($ path , $ selectorName = null )
181
186
{
182
187
$ sql2 = 'ISCHILDNODE( ' ;
183
- $ sql2 .= is_null ( $ selectorName) ? $ path : $ this ->addBracketsIfNeeded ($ selectorName ) . ', ' . $ path ;
188
+ $ sql2 .= null === $ selectorName ? $ path : $ this ->addBracketsIfNeeded ($ selectorName ) . ', ' . $ path ;
184
189
$ sql2 .= ') ' ;
185
190
186
191
return $ sql2 ;
@@ -195,7 +200,7 @@ public function evalChildNode($path, $selectorName = null)
195
200
public function evalDescendantNode ($ path , $ selectorName = null )
196
201
{
197
202
$ sql2 = 'ISDESCENDANTNODE( ' ;
198
- $ sql2 .= is_null ( $ selectorName) ? $ path : $ this ->addBracketsIfNeeded ($ selectorName ) . ', ' . $ path ;
203
+ $ sql2 .= null === $ selectorName ? $ path : $ this ->addBracketsIfNeeded ($ selectorName ) . ', ' . $ path ;
199
204
$ sql2 .= ') ' ;
200
205
201
206
return $ sql2 ;
@@ -289,7 +294,7 @@ public function evalFullTextSearchScore($selectorValue = null)
289
294
*/
290
295
public function evalPropertyValue ($ propertyName , $ selectorName = null )
291
296
{
292
- $ sql2 = ! is_null ( $ selectorName) ? $ this ->addBracketsIfNeeded ($ selectorName ) . '. ' : '' ;
297
+ $ sql2 = null !== $ selectorName ? $ this ->addBracketsIfNeeded ($ selectorName ) . '. ' : '' ;
293
298
if (false !== strpos ($ propertyName , ': ' )) {
294
299
$ propertyName = "[ $ propertyName] " ;
295
300
}
@@ -340,11 +345,14 @@ public function evalColumns($columns)
340
345
public function evalColumn ($ selectorName , $ propertyName = null , $ colname = null )
341
346
{
342
347
$ sql2 = '' ;
343
- if (! is_null ( $ selectorName) && is_null ( $ propertyName) && is_null ( $ colname) ) {
348
+ if (null !== $ selectorName && null === $ propertyName && null === $ colname ) {
344
349
$ sql2 .= $ this ->addBracketsIfNeeded ($ selectorName ) . '.* ' ;
345
350
} else {
346
351
$ sql2 .= $ this ->evalPropertyValue ($ propertyName , $ selectorName );
347
- $ sql2 .= ! is_null ($ colname ) ? ' AS ' . $ colname : '' ;
352
+ if (null !== $ colname && $ colname !== $ propertyName ) {
353
+ // if the column name is the same as the property name, this is implicit for sql2
354
+ $ sql2 .= ' AS ' . $ colname ;
355
+ }
348
356
}
349
357
350
358
return $ sql2 ;
0 commit comments