Skip to content

Commit 6847ede

Browse files
committed
Fixed edge case for getPathForDescendantQuery
- e.g. $qomf->descendantNode("/") now works - Some other random fixes - Fixed typo in DocBlocks - Command doctrine:phpcr:query - Display language when executing query via (I was wondering why my query wasn't working, it was being executed as JCR_SQL2 and not SQL) - Display query execution time
1 parent a34967d commit 6847ede

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

src/PHPCR/Util/Console/Command/QueryCommand.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,20 @@ protected function execute(InputInterface $input, OutputInterface $output)
5858
$query->setOffset($offset);
5959
}
6060

61+
$output->writeln(sprintf('<info>Executing, language:</info> %s', $query->getLanguage()));
62+
63+
$start = microtime(true);
6164
$result = $query->execute();
65+
$elapsed = microtime(true) - $start;
66+
6267
$output->writeln("Results:\n");
6368
foreach ($result as $i => $row) {
6469
$output->writeln("\n".($i+1).'. Row (Path: '. $row->getPath() .', Score: '. $row->getScore() .'):');
6570
foreach ($row as $column => $value) {
6671
$output->writeln("$column: $value");
6772
}
6873
}
74+
$output->writeln(sprintf('<info>%.2f seconds</info>', $elapsed));
6975

7076
return 0;
7177
}

src/PHPCR/Util/QOM/QueryBuilder.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ public function getSource()
412412
*
413413
* @return QueryBuilder This QueryBuilder instance.
414414
*
415-
* @trows RuntimeException if there is not an existing source.
415+
* @throws RuntimeException if there is not an existing source.
416416
*/
417417
public function join(SourceInterface $rightSource, JoinConditionInterface $joinCondition)
418418
{
@@ -427,7 +427,7 @@ public function join(SourceInterface $rightSource, JoinConditionInterface $joinC
427427
*
428428
* @return QueryBuilder This QueryBuilder instance.
429429
*
430-
* @trows RuntimeException if there is not an existing source.
430+
* @throws RuntimeException if there is not an existing source.
431431
*/
432432
public function innerJoin(SourceInterface $rightSource, JoinConditionInterface $joinCondition)
433433
{
@@ -442,7 +442,7 @@ public function innerJoin(SourceInterface $rightSource, JoinConditionInterface $
442442
*
443443
* @return QueryBuilder This QueryBuilder instance.
444444
*
445-
* @trows RuntimeException if there is not an existing source.
445+
* @throws RuntimeException if there is not an existing source.
446446
*/
447447
public function leftJoin(SourceInterface $rightSource, JoinConditionInterface $joinCondition)
448448
{
@@ -457,7 +457,7 @@ public function leftJoin(SourceInterface $rightSource, JoinConditionInterface $j
457457
*
458458
* @return QueryBuilder This QueryBuilder instance.
459459
*
460-
* @trows RuntimeException if there is not an existing source.
460+
* @throws RuntimeException if there is not an existing source.
461461
*/
462462
public function rightJoin(SourceInterface $rightSource, JoinConditionInterface $joinCondition)
463463
{
@@ -473,7 +473,7 @@ public function rightJoin(SourceInterface $rightSource, JoinConditionInterface $
473473
*
474474
* @return QueryBuilder This QueryBuilder instance.
475475
*
476-
* @trows RuntimeException if there is not an existing source.
476+
* @throws RuntimeException if there is not an existing source.
477477
*/
478478
public function joinWithType(SourceInterface $rightSource, $joinType, JoinConditionInterface $joinCondition)
479479
{

src/PHPCR/Util/QOM/Sql1Generator.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ public function evalSelector($nodeTypeName, $selectorName = null)
2626

2727
protected function getPathForDescendantQuery($path)
2828
{
29-
$path = trim($path,"\"'/");
30-
$sql1 = "/" . str_replace("/","[%]/",$path) ;
31-
$sql1 .= "[%]/%";
29+
if ($path == '/') {
30+
$sql1 = '/%';
31+
} else {
32+
$path = trim($path,"\"'/");
33+
$sql1 = "/" . str_replace("/","[%]/",$path) ;
34+
$sql1 .= "[%]/%";
35+
}
3236

3337
return $sql1;
3438
}

tests/PHPCR/Tests/Util/QOM/Sql1GeneratorTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,18 @@ public function testDoubleLiteral()
4545

4646
public function testChildNode()
4747
{
48+
$literal = $this->generator->evalChildNode("/");
49+
$this->assertSame("jcr:path LIKE '/%' AND NOT jcr:path LIKE '/%/%'", $literal);
50+
4851
$literal = $this->generator->evalChildNode("/foo/bar/baz");
4952
$this->assertSame("jcr:path LIKE '/foo[%]/bar[%]/baz[%]/%' AND NOT jcr:path LIKE '/foo[%]/bar[%]/baz[%]/%/%'", $literal);
5053
}
5154

5255
public function testDescendantNode()
5356
{
57+
$literal = $this->generator->evalDescendantNode("/");
58+
$this->assertSame("jcr:path LIKE '/%'", $literal);
59+
5460
$literal = $this->generator->evalDescendantNode("/foo/bar/baz");
5561
$this->assertSame("jcr:path LIKE '/foo[%]/bar[%]/baz[%]/%'", $literal);
5662
}

0 commit comments

Comments
 (0)