Skip to content

Commit 2d9de78

Browse files
dbulsmith77
authored andcommitted
qom always has a selector name
1 parent 4576947 commit 2d9de78

File tree

5 files changed

+227
-103
lines changed

5 files changed

+227
-103
lines changed

src/PHPCR/Util/QOM/QueryBuilder.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,33 +352,33 @@ public function setColumns(array $columns)
352352
* Identifies a property in the specified or default selector to include in the tabular view of query results.
353353
* Replaces any previously specified columns to be selected if any.
354354
*
355+
* @param string $selectorName
355356
* @param string $propertyName
356357
* @param string $columnName
357-
* @param string $selectorName
358358
*
359359
* @return QueryBuilder This QueryBuilder instance.
360360
*/
361-
public function select($propertyName, $columnName = null, $selectorName = null)
361+
public function select($selectorName, $propertyName, $columnName = null)
362362
{
363363
$this->state = self::STATE_DIRTY;
364-
$this->columns = array($this->qomFactory->column($propertyName, $columnName, $selectorName));
364+
$this->columns = array($this->qomFactory->column($selectorName, $propertyName, $columnName));
365365

366366
return $this;
367367
}
368368

369369
/**
370370
* Adds a property in the specified or default selector to include in the tabular view of query results.
371371
*
372+
* @param string $selectorName
372373
* @param string $propertyName
373374
* @param string $columnName
374-
* @param string $selectorName
375375
*
376376
* @return QueryBuilder This QueryBuilder instance.
377377
*/
378-
public function addSelect($propertyName, $columnName = null, $selectorName = null)
378+
public function addSelect($selectorName, $propertyName, $columnName = null)
379379
{
380380
$this->state = self::STATE_DIRTY;
381-
$this->columns[] = $this->qomFactory->column($propertyName, $columnName, $selectorName);
381+
$this->columns[] = $this->qomFactory->column($selectorName, $propertyName, $columnName);
382382

383383
return $this;
384384
}

src/PHPCR/Util/QOM/Sql2Generator.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public function evalSelector($nodeTypeName, $selectorName = null)
2626
{
2727
$sql2 = $this->addBracketsIfNeeded($nodeTypeName);
2828

29-
$name = $selectorName;
30-
if (! is_null($name)) {
31-
$sql2 .= ' AS ' . $name;
29+
if (! is_null($selectorName) && $nodeTypeName !== $selectorName) {
30+
// if the selector name is the same as the type name, this is implicit for sql2
31+
$sql2 .= ' AS ' . $selectorName;
3232
}
3333

3434
return $sql2;
@@ -344,7 +344,10 @@ public function evalColumn($selectorName, $propertyName = null, $colname = null)
344344
$sql2 .= $this->addBracketsIfNeeded($selectorName) . '.*';
345345
} else {
346346
$sql2 .= $this->evalPropertyValue($propertyName, $selectorName);
347-
$sql2 .= ! is_null($colname) ? ' AS ' . $colname : '';
347+
if (!is_null($colname) && $colname !== $propertyName) {
348+
// if the column name is the same as the property name, this is implicit for sql2
349+
$sql2 .= ' AS ' . $colname;
350+
}
348351
}
349352

350353
return $sql2;

src/PHPCR/Util/QOM/Sql2Scanner.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace PHPCR\Util\QOM;
44

5+
use PHPCR\Query\InvalidQueryException;
6+
57
/**
68
* Split an SQL2 statement into string tokens. Allows lookup and fetching of tokens.
79
*
@@ -104,7 +106,7 @@ public function expectToken($token, $case_insensitive = true)
104106
{
105107
$nextToken = $this->fetchNextToken();
106108
if (! $this->tokenIs($nextToken, $token, $case_insensitive)) {
107-
throw new \Exception("Syntax error: Expected $token, found $nextToken");
109+
throw new InvalidQueryException("Syntax error: Expected '$token', found '$nextToken' in {$this->sql2}");
108110
}
109111
}
110112

0 commit comments

Comments
 (0)