Skip to content

qom always has a selector name #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 25, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
],
"require": {
"php": ">=5.3.0",
"phpcr/phpcr": "~2.1.0-beta10",
"phpcr/phpcr": "~2.1.0-RC1",
"symfony/console": "~2.0"
},
"autoload": {
Expand Down
2 changes: 1 addition & 1 deletion src/PHPCR/Util/CND/Scanner/AbstractScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function applyFilters(Token $token)

$token = $filter->filter($token);

if (is_null($token)) {
if (null === $token) {
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/PHPCR/Util/QOM/QomToSql2QueryConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected function convertSameNodeJoinCondition(QOM\SameNodeJoinConditionInterfa
return $this->generator->evalSameNodeJoinCondition(
$condition->getSelector1Name(),
$condition->getSelector2Name(),
! is_null($condition->getSelector2Path()) ? $this->convertPath($condition->getSelector2Path()) : null);
null !== $condition->getSelector2Path() ? $this->convertPath($condition->getSelector2Path()) : null);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/PHPCR/Util/QOM/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,33 +352,33 @@ public function setColumns(array $columns)
* Identifies a property in the specified or default selector to include in the tabular view of query results.
* Replaces any previously specified columns to be selected if any.
*
* @param string $selectorName
* @param string $propertyName
* @param string $columnName
* @param string $selectorName
*
* @return QueryBuilder This QueryBuilder instance.
*/
public function select($propertyName, $columnName = null, $selectorName = null)
public function select($selectorName, $propertyName, $columnName = null)
{
$this->state = self::STATE_DIRTY;
$this->columns = array($this->qomFactory->column($propertyName, $columnName, $selectorName));
$this->columns = array($this->qomFactory->column($selectorName, $propertyName, $columnName));

return $this;
}

/**
* Adds a property in the specified or default selector to include in the tabular view of query results.
*
* @param string $selectorName
* @param string $propertyName
* @param string $columnName
* @param string $selectorName
*
* @return QueryBuilder This QueryBuilder instance.
*/
public function addSelect($propertyName, $columnName = null, $selectorName = null)
public function addSelect($selectorName, $propertyName, $columnName = null)
{
$this->state = self::STATE_DIRTY;
$this->columns[] = $this->qomFactory->column($propertyName, $columnName, $selectorName);
$this->columns[] = $this->qomFactory->column($selectorName, $propertyName, $columnName);

return $this;
}
Expand Down
32 changes: 20 additions & 12 deletions src/PHPCR/Util/QOM/Sql2Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,21 @@ class Sql2Generator extends BaseSqlGenerator
* Selector ::= nodeTypeName ['AS' selectorName]
* nodeTypeName ::= Name
*
* @param string $nodeTypeName The node type of the selector. If it does not contain starting and ending brackets ([]) they will be added automatically
* @param string $selectorName
* @param string $nodeTypeName The node type of the selector. If it
* does not contain starting and ending brackets ([]) they will be
* added automatically.
* @param string|null $selectorName The selector name. If it is different than
* the nodeTypeName, the alias is declared.
*
* @return string
*/
public function evalSelector($nodeTypeName, $selectorName = null)
{
$sql2 = $this->addBracketsIfNeeded($nodeTypeName);

$name = $selectorName;
if (! is_null($name)) {
$sql2 .= ' AS ' . $name;
if (null !== $selectorName && $nodeTypeName !== $selectorName) {
// if the selector name is the same as the type name, this is implicit for sql2
$sql2 .= ' AS ' . $selectorName;
}

return $sql2;
Expand Down Expand Up @@ -112,7 +115,9 @@ public function evalSameNodeJoinCondition($sel1Name, $sel2Name, $sel2Path = null
. $this->addBracketsIfNeeded($sel1Name) . ', '
. $this->addBracketsIfNeeded($sel2Name)
;
$sql2 .= ! is_null($sel2Path) ? ', ' . $sel2Path : '';
if (null !== $sel2Path) {
$sql2 .= ', ' . $sel2Path;
}
$sql2 .= ')';

return $sql2;
Expand Down Expand Up @@ -165,7 +170,7 @@ public function evalDescendantNodeJoinCondition($descendantSelectorName, $ancest
public function evalSameNode($path, $selectorName = null)
{
$sql2 = 'ISSAMENODE(';
$sql2 .= is_null($selectorName) ? $path : $this->addBracketsIfNeeded($selectorName) . ', ' . $path;
$sql2 .= null === $selectorName ? $path : $this->addBracketsIfNeeded($selectorName) . ', ' . $path;
$sql2 .= ')';

return $sql2;
Expand All @@ -180,7 +185,7 @@ public function evalSameNode($path, $selectorName = null)
public function evalChildNode($path, $selectorName = null)
{
$sql2 = 'ISCHILDNODE(';
$sql2 .= is_null($selectorName) ? $path : $this->addBracketsIfNeeded($selectorName) . ', ' . $path;
$sql2 .= null === $selectorName ? $path : $this->addBracketsIfNeeded($selectorName) . ', ' . $path;
$sql2 .= ')';

return $sql2;
Expand All @@ -195,7 +200,7 @@ public function evalChildNode($path, $selectorName = null)
public function evalDescendantNode($path, $selectorName = null)
{
$sql2 = 'ISDESCENDANTNODE(';
$sql2 .= is_null($selectorName) ? $path : $this->addBracketsIfNeeded($selectorName) . ', ' . $path;
$sql2 .= null === $selectorName ? $path : $this->addBracketsIfNeeded($selectorName) . ', ' . $path;
$sql2 .= ')';

return $sql2;
Expand Down Expand Up @@ -289,7 +294,7 @@ public function evalFullTextSearchScore($selectorValue = null)
*/
public function evalPropertyValue($propertyName, $selectorName = null)
{
$sql2 = ! is_null($selectorName) ? $this->addBracketsIfNeeded($selectorName) . '.' : '';
$sql2 = null !== $selectorName ? $this->addBracketsIfNeeded($selectorName) . '.' : '';
if (false !== strpos($propertyName, ':')) {
$propertyName = "[$propertyName]";
}
Expand Down Expand Up @@ -340,11 +345,14 @@ public function evalColumns($columns)
public function evalColumn($selectorName, $propertyName = null, $colname = null)
{
$sql2 = '';
if (! is_null($selectorName) && is_null($propertyName) && is_null($colname)) {
if (null !== $selectorName && null === $propertyName && null === $colname) {
$sql2 .= $this->addBracketsIfNeeded($selectorName) . '.*';
} else {
$sql2 .= $this->evalPropertyValue($propertyName, $selectorName);
$sql2 .= ! is_null($colname) ? ' AS ' . $colname : '';
if (null !== $colname && $colname !== $propertyName) {
// if the column name is the same as the property name, this is implicit for sql2
$sql2 .= ' AS ' . $colname;
}
}

return $sql2;
Expand Down
4 changes: 3 additions & 1 deletion src/PHPCR/Util/QOM/Sql2Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace PHPCR\Util\QOM;

use PHPCR\Query\InvalidQueryException;

/**
* Split an SQL2 statement into string tokens. Allows lookup and fetching of tokens.
*
Expand Down Expand Up @@ -104,7 +106,7 @@ public function expectToken($token, $case_insensitive = true)
{
$nextToken = $this->fetchNextToken();
if (! $this->tokenIs($nextToken, $token, $case_insensitive)) {
throw new \Exception("Syntax error: Expected $token, found $nextToken");
throw new InvalidQueryException("Syntax error: Expected '$token', found '$nextToken' in {$this->sql2}");
}
}

Expand Down
Loading