Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add SQL(1) Support #62

Merged
merged 5 commits into from

2 participants

Commits on Apr 12, 2012
  1. @chregu

    SQL(1) Support

    chregu authored
Commits on Apr 13, 2012
  1. @chregu

    remove debug code

    chregu authored
Commits on Apr 14, 2012
  1. @chregu
Commits on Apr 18, 2012
  1. @chregu

    renamed JCR_SQL to SQL

    chregu authored
  2. @chregu
This page is out of date. Refresh to see the latest.
View
22 tests/06_Query/Sql1/QueryBaseCase.php
@@ -0,0 +1,22 @@
+<?php
+namespace PHPCR\Tests\Query\Sql1;
+
+require_once(__DIR__ . '/../../../inc/BaseCase.php');
+require_once(__DIR__ . '/../QueryBaseCase.php');
+
+/**
+ * a base class for all query tests
+ */
+abstract class QueryBaseCase extends \PHPCR\Tests\Query\QueryBaseCase
+{
+ /**
+ * in addition to base stuff, prepare $this->query with a simple select query
+ */
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->query = $this->sharedFixture['qm']->createQuery("SELECT * FROM nt:folder", \PHPCR\Query\QueryInterface::JCR_SQL2);
+ }
+
+}
View
79 tests/06_Query/Sql1/QueryOperationsTest.php
@@ -0,0 +1,79 @@
+<?php
+namespace PHPCR\Tests\Query\Sql1;
+
+require_once('QueryBaseCase.php');
+
+/**
+ * Run non-trivial queries to try out where, the join features and such
+ */
+class QueryOperationsTest extends QueryBaseCase
+{
+ public function testQueryField()
+ {
+ $query = $this->sharedFixture['qm']->createQuery(
+ "SELECT foo FROM nt:unstructured WHERE foo = 'bar'",
+ \PHPCR\Query\QueryInterface::SQL
+ );
+
+ $this->assertInstanceOf('\PHPCR\Query\QueryInterface', $query);
+ $result = $query->execute();
+ $this->assertInstanceOf('\PHPCR\Query\QueryResultInterface', $result);
+ $vals = array();
+ foreach ($result->getNodes() as $node) {
+ $vals[] = $node->getPropertyValue('foo');
+ }
+ $this->assertEquals(array('bar'), $vals);
+
+ $vals = array();
+ foreach ($result->getRows() as $row) {
+ $vals[] = $row->getValue('foo');
+ }
+ $this->assertEquals(array('bar'), $vals);
+ }
+
+ public function testQueryFieldSomenull()
+ {
+ $query = $this->sharedFixture['qm']->createQuery(
+ 'SELECT foo FROM nt:unstructured',
+ \PHPCR\Query\QueryInterface::SQL
+ );
+
+ $this->assertInstanceOf('\PHPCR\Query\QueryInterface', $query);
+ $result = $query->execute();
+ $this->assertInstanceOf('\PHPCR\Query\QueryResultInterface', $result);
+ $vals = array();
+ foreach ($result->getNodes() as $node) {
+ $vals[] = ($node->hasProperty('foo') ? $node->getPropertyValue('foo') : null);
+ }
+ $this->assertContains('bar', $vals);
+ $this->assertEquals(8, count($vals));
+
+ $vals = array();
+ foreach ($result->getRows() as $row) {
+ $vals[] = $row->getValue('foo');
+ }
+ $this->assertContains('bar', $vals);
+ $this->assertEquals(8, count($vals));
+ }
+
+ public function testQueryOrder()
+ {
+ $query = $this->sharedFixture['qm']->createQuery(
+ 'SELECT zeronumber
+ FROM nt:unstructured
+ ORDER BY zeronumber',
+ \PHPCR\Query\QueryInterface::SQL
+ );
+
+ $this->assertInstanceOf('\PHPCR\Query\QueryInterface', $query);
+ $result = $query->execute();
+ $this->assertInstanceOf('\PHPCR\Query\QueryResultInterface', $result);
+ $vals = array();
+ foreach ($result->getRows() as $row) {
+ $vals[] = $row->getValue('zeronumber');
+ }
+ // rows that do not have that field are null. empty is before fields with values
+ $this->assertEquals(array(null, null, null, null, null, null, null, 0), $vals);
+ }
+
+}
Something went wrong with that request. Please try again.