当前位置: 首页>>代码示例>>PHP>>正文


PHP Statement::setQuery方法代码示例

本文整理汇总了PHP中Statement::setQuery方法的典型用法代码示例。如果您正苦于以下问题:PHP Statement::setQuery方法的具体用法?PHP Statement::setQuery怎么用?PHP Statement::setQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Statement的用法示例。


在下文中一共展示了Statement::setQuery方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getDiameter

 /**
  * Get the <a href="http://en.wikipedia.org/wiki/Eccentricity_%28graph_theory%29">diameter</a> of a graph.
  *
  * This will throw if the list cannot be fetched from the server
  * This does not support 'batchsize', 'limit' and 'count'.<br><br>
  *
  * @throws Exception
  *
  * @param mixed      $graph        - graph name as a string or instance of Graph
  *
  * @param bool|array $options      - an array of optional parameters:
  * <ul><br>
  * <li><b>direction</b> - The direction of the edges as a string.
  * Possible values are *outbound*, *inbound* and *any* (default).</li>
  *	<li><b>algorithm</b> - The algorithm to calculate the shortest paths. If both start and end vertex examples are empty
  * <a href="http://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm">Floyd-Warshall</a> is used, otherwise the
  * default is <a "href=http://en.wikipedia.org/wiki/Dijkstra's_algorithm">Dijkstra</a>.
  * <li><b>weight</b> - The name of the attribute of the edges containing the length as a string.
  * <li><b>defaultWeight</b> - Only used with the option *weight*. If an edge does not have the attribute named as
  * defined in option *weight* this default.
  * </ul>
  *
  *
  * @return double
  */
 public function getDiameter($graph, $options = array())
 {
     if ($graph instanceof Graph) {
         $graph = $graph->getKey();
     }
     $options['objectType'] = 'figure';
     $data = array_merge($options, $this->getCursorOptions($options));
     $statement = new Statement($this->getConnection(), array("query" => ''));
     $statement->setResultType($options['objectType']);
     $aql = "RETURN GRAPH_DIAMETER(@graphName, @options) ";
     if (isset($options['direction'])) {
         if ($options['direction'] === "in") {
             $options['direction'] = "inbound";
         }
         if ($options['direction'] === "out") {
             $options['direction'] = "outbound";
         }
     }
     $statement->bind('graphName', $graph);
     $statement->bind('options', $options);
     $statement->setQuery($aql);
     $a = $statement->execute()->getAll();
     return $a[0];
 }
开发者ID:TomSearch,项目名称:arangodb-php-docs,代码行数:49,代码来源:GraphHandler.php

示例2: testImportFromStringUsingDocumentsUsingResultset

    /**
     * test for import of documents by giving an array of documents
     */
    public function testImportFromStringUsingDocumentsUsingResultset()
    {
        if (isCluster($this->connection)) {
            // don't execute this test in a cluster
            return;
        }
        $collectionHandler = $this->collectionHandler;
        $data = '[{ "firstName" : "Joe", "lastName" : "Public", "age" : 42, "gender" : "male", "_key" : "test1"},
{ "firstName" : "Jane", "lastName" : "Doe", "age" : 31, "gender" : "female", "_key" : "test2"}]';
        $result = $collectionHandler->import('importCollection_01_arango_unittests', $data, $options = array('createCollection' => true, 'type' => 'array'));
        $this->assertTrue($result['error'] === false && $result['created'] == 2);
        $statement = new Statement($this->connection, array("query" => '', "count" => true, "batchSize" => 1000, "sanitize" => true));
        $query = 'FOR u IN `importCollection_01_arango_unittests` SORT u._id ASC RETURN u';
        $statement->setQuery($query);
        $cursor = $statement->execute();
        $resultingDocument = null;
        foreach ($cursor as $key => $value) {
            $resultingDocument[$key] = $value;
        }
        $this->assertTrue($resultingDocument[0]->getKey() == 'test1' && $resultingDocument[0]->firstName == 'Joe', 'Document returned did not contain expected data.');
        $this->assertTrue($resultingDocument[1]->getKey() == 'test2' && $resultingDocument[1]->firstName == 'Jane', 'Document returned did not contain expected data.');
        $this->assertTrue(count($resultingDocument) == 2, 'Should be 2, was: ' . count($resultingDocument));
    }
开发者ID:vinigomescunha,项目名称:ArangoDB-Ajax-PHP-Example,代码行数:26,代码来源:CollectionExtendedTest.php

示例3: testCreateMixedBatchWithPartIds

 public function testCreateMixedBatchWithPartIds()
 {
     $edgeCollection = $this->edgeCollection;
     $batch = new Batch($this->connection);
     $this->assertInstanceOf('\\triagens\\ArangoDb\\Batch', $batch);
     // Create collection
     $connection = $this->connection;
     $collection = new Collection();
     $collectionHandler = new CollectionHandler($connection);
     $name = 'ArangoDB_PHP_TestSuite_TestCollection_02';
     $collection->setName($name);
     $batch->nextBatchPartId('testCollection1');
     $response = $collectionHandler->add($collection);
     $this->assertTrue(is_numeric($response), 'Did not return a fake numeric id!');
     $batch->process();
     $resultingCollectionId = $batch->getProcessedPartResponse('testCollection1');
     $testCollection1Part = $batch->getPart('testCollection1');
     $this->assertTrue($testCollection1Part->getHttpCode() == 200, 'Did not return an HttpCode 200!');
     $resultingCollection = $collectionHandler->get($batch->getProcessedPartResponse('testCollection1'));
     $resultingAttribute = $resultingCollection->getName();
     $this->assertTrue($name === $resultingAttribute, 'The created collection name and resulting collection name do not match!');
     $this->assertEquals(Collection::getDefaultType(), $resultingCollection->getType());
     $batch = new Batch($this->connection);
     // Create documents
     $documentHandler = $this->documentHandler;
     $batch->nextBatchPartId('doc1');
     $document = Document::createFromArray(array('someAttribute' => 'someValue', 'someOtherAttribute' => 'someOtherValue'));
     $documentId = $documentHandler->add($resultingCollectionId, $document);
     $this->assertTrue(is_numeric($documentId), 'Did not return a fake numeric id!');
     for ($i = 0; $i <= 10; ++$i) {
         $document = Document::createFromArray(array('someAttribute' => 'someValue' . $i, 'someOtherAttribute' => 'someOtherValue2' . $i));
         $documentId = $documentHandler->add($resultingCollectionId, $document);
     }
     $this->assertTrue(is_numeric($documentId), 'Did not return a fake numeric id!');
     $batch->process();
     // try getting processed response through batchpart
     $testDocument1PartResponse = $batch->getPart('doc1')->getProcessedResponse();
     // try getting it from batch
     $testDocument2PartResponse = $batch->getProcessedPartResponse(1);
     $batch = new Batch($this->connection);
     $docId1 = explode('/', $testDocument1PartResponse);
     $docId2 = explode('/', $testDocument2PartResponse);
     $documentHandler->getById($resultingCollectionId, $docId1[1]);
     $documentHandler->getById($resultingCollectionId, $docId2[1]);
     $batch->process();
     $document1 = $batch->getProcessedPartResponse(0);
     $document2 = $batch->getProcessedPartResponse(1);
     $batch = new Batch($this->connection);
     // test edge creation
     $edgeDocument = new Edge();
     $edgeDocumentHandler = new EdgeHandler($connection);
     $edgeDocument->set('label', 'knows');
     $edgeDocumentHandler->saveEdge($edgeCollection->getName(), $document1->getHandle(), $document2->getHandle(), $edgeDocument);
     $batch->process();
     $edge = $batch->getProcessedPartResponse(0);
     $this->assertFalse(is_a($edge, 'triagens\\ArangoDb\\HttpResponse'), 'Edge batch creation did return an error: ' . print_r($edge, true));
     $this->assertTrue($edge == !'', 'Edge batch creation did return empty string: ' . print_r($edge, true));
     $batch = new Batch($this->connection);
     $document = new Document();
     $documentHandler = new DocumentHandler($connection);
     $document->someAttribute = 'someValue';
     $documentHandler->add($resultingCollection->getId(), $document);
     // set the next batchpart id
     $batch->nextBatchPartId('myBatchPart');
     // set cursor options for the next batchpart
     $batch->nextBatchPartCursorOptions(array("sanitize" => true));
     // set batchsize to 10, so we can test if an additional http request is done when we getAll() a bit later
     $statement = new Statement($connection, array("query" => '', "count" => true, "batchSize" => 10, "sanitize" => true));
     $statement->setQuery('FOR a IN `ArangoDB_PHP_TestSuite_TestCollection_02` RETURN a');
     $statement->execute();
     $documentHandler->removeById($resultingCollectionId, $docId1[1]);
     $documentHandler->removeById($resultingCollectionId, $docId2[1]);
     $batch->nextBatchPartId('docsAfterRemoval');
     $collectionHandler->getAllIds($resultingCollectionId);
     $batch->process();
     $stmtCursor = $batch->getProcessedPartResponse('myBatchPart');
     $this->assertTrue(count($stmtCursor->getAll()) == 13, 'At the time of statement execution there should be 13 documents found! Found: ' . count($stmtCursor->getAll()));
     // This fails but we'll just make a note because such a query is not needed to be batched.
     // $docsAfterRemoval=$batch->getProcessedPartResponse('docsAfterRemoval');
     // $this->assertTrue(count($docsAfterRemoval) == 1, 'At the time of statement execution there should be 3 documents found! Found: '.count($stmtCursor->getAll()));
     // Get previously created collection and delete it, from inside a batch
     $batch = new Batch($this->connection);
     $collectionHandler->delete($resultingCollectionId);
     $batch->process();
 }
开发者ID:vinigomescunha,项目名称:ArangoDB-Ajax-PHP-Example,代码行数:85,代码来源:BatchTest.php

示例4: testValidateStatement

 /**
  * Test if the validate function works
  */
 public function testValidateStatement()
 {
     $connection = $this->connection;
     $collection = $this->collection;
     $document = new Document();
     $documentHandler = new DocumentHandler($connection);
     $document->someAttribute = 'someValue';
     $documentHandler->add($collection->getId(), $document);
     $statement = new Statement($connection, array("query" => '', "count" => true, "batchSize" => 1000, "_sanitize" => true));
     $statement->setQuery('FOR a IN `ArangoDB_PHP_TestSuite_TestCollection_01` RETURN a');
     $result = $statement->validate();
     $this->assertArrayHasKey('bindVars', $result, "result-array does not contain plan !");
 }
开发者ID:vinigomescunha,项目名称:ArangoDB-Ajax-PHP-Example,代码行数:16,代码来源:StatementTest.php

示例5: testCreateAndDeleteEdgeWithWrongEncoding

 /**
  * Try to create and delete an edge with wrong encoding
  * We expect an exception here:
  *
  * @expectedException \triagens\ArangoDb\ClientException
  */
 public function testCreateAndDeleteEdgeWithWrongEncoding()
 {
     $connection = $this->connection;
     $this->collection;
     $edgeCollection = $this->edgeCollection;
     $this->collectionHandler;
     $document1 = new Document();
     $document2 = new Document();
     $documentHandler = new DocumentHandler($connection);
     $edgeDocument = new Edge();
     $edgeDocumentHandler = new EdgeHandler($connection);
     $document1->someAttribute = 'someValue1';
     $document2->someAttribute = 'someValue2';
     $documentHandler->add('ArangoDBPHPTestSuiteTestCollection01', $document1);
     $documentHandler->add('ArangoDBPHPTestSuiteTestCollection01', $document2);
     $documentHandle1 = $document1->getHandle();
     $documentHandle2 = $document2->getHandle();
     $isoValue = iconv("UTF-8", "ISO-8859-1//TRANSLIT", "knowsü");
     $edgeDocument->set('label', $isoValue);
     $edgeDocumentId = $edgeDocumentHandler->saveEdge($edgeCollection->getId(), $documentHandle1, $documentHandle2, $edgeDocument);
     //        $resultingDocument = $documentHandler->get($edgeCollection->getId(), $edgeDocumentId);
     $resultingEdge = $edgeDocumentHandler->get($edgeCollection->getId(), $edgeDocumentId);
     $resultingAttribute = $resultingEdge->label;
     $this->assertTrue($resultingAttribute === 'knows', 'Attribute set on the Edge is different from the one retrieved!');
     $edgesQuery1Result = $edgeDocumentHandler->edges($edgeCollection->getId(), $documentHandle1, 'out');
     $this->assertEquals(2, count($edgesQuery1Result));
     $statement = new Statement($connection, array("query" => '', "count" => true, "batchSize" => 1000, "sanitize" => true));
     $statement->setQuery('FOR p IN PATHS(ArangoDBPHPTestSuiteTestCollection01, ArangoDBPHPTestSuiteTestEdgeCollection01, "outbound")  RETURN p');
     $cursor = $statement->execute();
     $result = $cursor->current();
     $this->assertInstanceOf('triagens\\ArangoDb\\Document', $result, "IN PATHS statement did not return a document object!");
     $resultingEdge->set('label', 'knows not');
     $documentHandler->update($resultingEdge);
     $resultingEdge = $edgeDocumentHandler->get($edgeCollection->getId(), $edgeDocumentId);
     $resultingAttribute = $resultingEdge->label;
     $this->assertTrue($resultingAttribute === 'knows not', 'Attribute "knows not" set on the Edge is different from the one retrieved (' . $resultingAttribute . ')!');
     $documentHandler->delete($document1);
     $documentHandler->delete($document2);
     // On ArangoDB 1.0 deleting a vertex doesn't delete the associated edge. Caution!
     $edgeDocumentHandler->delete($resultingEdge);
 }
开发者ID:vinigomescunha,项目名称:ArangoDB-Ajax-PHP-Example,代码行数:47,代码来源:EdgeBasicTest.php


注:本文中的Statement::setQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。