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


PHP DataQuery::query方法代码示例

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


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

示例1: testApplyReplationDeepInheretence

 public function testApplyReplationDeepInheretence()
 {
     //test has_one relation
     $newDQ = new DataQuery('DataQueryTest_E');
     //apply a relation to a relation from an ancestor class
     $newDQ->applyRelation('TestA');
     $this->assertTrue($newDQ->query()->isJoinedTo('DataQueryTest_C'));
     $this->assertContains('"DataQueryTest_A"."ID" = "DataQueryTest_C"."TestAID"', $newDQ->sql($params));
     //test many_many relation
     //test many_many with separate inheritance
     $newDQ = new DataQuery('DataQueryTest_C');
     $baseDBTable = ClassInfo::baseDataClass('DataQueryTest_C');
     $newDQ->applyRelation('ManyTestAs');
     //check we are "joined" to the DataObject's table (there is no distinction between FROM or JOIN clauses)
     $this->assertTrue($newDQ->query()->isJoinedTo($baseDBTable));
     //check we are explicitly selecting "FROM" the DO's table
     $this->assertContains("FROM \"{$baseDBTable}\"", $newDQ->sql());
     //test many_many with shared inheritance
     $newDQ = new DataQuery('DataQueryTest_E');
     $baseDBTable = ClassInfo::baseDataClass('DataQueryTest_E');
     //check we are "joined" to the DataObject's table (there is no distinction between FROM or JOIN clauses)
     $this->assertTrue($newDQ->query()->isJoinedTo($baseDBTable));
     //check we are explicitly selecting "FROM" the DO's table
     $this->assertContains("FROM \"{$baseDBTable}\"", $newDQ->sql(), 'The FROM clause is missing from the query');
     $newDQ->applyRelation('ManyTestGs');
     //confirm we are still joined to the base table
     $this->assertTrue($newDQ->query()->isJoinedTo($baseDBTable));
     //double check it is the "FROM" clause
     $this->assertContains("FROM \"{$baseDBTable}\"", $newDQ->sql(), 'The FROM clause has been removed from the query');
     //another (potentially less crude check) for checking "FROM" clause
     $fromTables = $newDQ->query()->getFrom();
     $this->assertEquals('"' . $baseDBTable . '"', $fromTables[$baseDBTable]);
 }
开发者ID:aaronleslie,项目名称:aaronunix,代码行数:33,代码来源:DataQueryTest.php

示例2: testApplyReplationDeepInheretence

 public function testApplyReplationDeepInheretence()
 {
     $newDQ = new DataQuery('DataQueryTest_E');
     //apply a relation to a relation from an ancestor class
     $newDQ->applyRelation('TestA');
     $this->assertTrue($newDQ->query()->isJoinedTo('DataQueryTest_C'));
     $this->assertContains('"DataQueryTest_A"."ID" = "DataQueryTest_C"."TestAID"', $newDQ->sql($params));
 }
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:8,代码来源:DataQueryTest.php

示例3: toArray

 /**
  * Return an array of the actual items that this DataList contains at this stage.
  * This is when the query is actually executed.
  *
  * @return array
  */
 public function toArray()
 {
     $query = $this->dataQuery->query();
     $rows = $query->execute();
     $results = array();
     foreach ($rows as $row) {
         $results[] = $this->createDataObject($row);
     }
     return $results;
 }
开发者ID:assertchris,项目名称:silverstripe-framework,代码行数:16,代码来源:DataList.php

示例4: loadLazyFields

 /**
  * Loads all the stub fields than an initial lazy load didn't load fully.
  *
  * @param tableClass Base table to load the values from. Others are joined as required.
  */
 protected function loadLazyFields($tableClass = null)
 {
     // Smarter way to work out the tableClass? Should the functionality in toMap and getField be moved into here?
     if (!$tableClass) {
         $tableClass = $this->ClassName;
     }
     $dataQuery = new DataQuery($tableClass);
     // TableField sets the record ID to "new" on new row data, so don't try doing anything in that case
     if (!is_numeric($this->record['ID'])) {
         return false;
     }
     $dataQuery->where("\"{$tableClass}\".\"ID\" = {$this->record['ID']}")->limit(1);
     $columns = array();
     // Add SQL for fields, both simple & multi-value
     // TODO: This is copy & pasted from buildSQL(), it could be moved into a method
     $databaseFields = self::database_fields($tableClass);
     if ($databaseFields) {
         foreach ($databaseFields as $k => $v) {
             if (!isset($this->record[$k]) || $this->record[$k] === null) {
                 $columns[] = $k;
             }
         }
     }
     if ($columns) {
         $query = $dataQuery->query();
         // eh?
         $this->extend('augmentSQL', $query, $dataQuery);
         $dataQuery->setQueriedColumns($columns);
         $newData = $dataQuery->execute()->record();
         // Load the data into record
         if ($newData) {
             foreach ($newData as $k => $v) {
                 if (in_array($k, $columns)) {
                     $this->record[$k] = $v;
                     $this->original[$k] = $v;
                     unset($this->record[$k . '_Lazy']);
                 }
             }
             // No data means that the query returned nothing; assign 'null' to all the requested fields
         } else {
             foreach ($columns as $k) {
                 $this->record[$k] = null;
                 $this->original[$k] = null;
                 unset($this->record[$k . '_Lazy']);
             }
         }
     }
 }
开发者ID:nomidi,项目名称:sapphire,代码行数:53,代码来源:DataObject.php

示例5: loadLazyFields

 /**
  * Loads all the stub fields that an initial lazy load didn't load fully.
  *
  * @param tableClass Base table to load the values from. Others are joined as required.
  *                   Not specifying a tableClass will load all lazy fields from all tables.
  */
 protected function loadLazyFields($tableClass = null)
 {
     if (!$tableClass) {
         $loaded = array();
         foreach ($this->record as $key => $value) {
             if (strlen($key) > 5 && substr($key, -5) == '_Lazy' && !array_key_exists($value, $loaded)) {
                 $this->loadLazyFields($value);
                 $loaded[$value] = $value;
             }
         }
         return;
     }
     $dataQuery = new DataQuery($tableClass);
     // Reset query parameter context to that of this DataObject
     if ($params = $this->getSourceQueryParams()) {
         foreach ($params as $key => $value) {
             $dataQuery->setQueryParam($key, $value);
         }
     }
     // TableField sets the record ID to "new" on new row data, so don't try doing anything in that case
     if (!is_numeric($this->record['ID'])) {
         return false;
     }
     // Limit query to the current record, unless it has the Versioned extension,
     // in which case it requires special handling through augmentLoadLazyFields()
     if (!$this->hasExtension('Versioned')) {
         $dataQuery->where("\"{$tableClass}\".\"ID\" = {$this->record['ID']}")->limit(1);
     }
     $columns = array();
     // Add SQL for fields, both simple & multi-value
     // TODO: This is copy & pasted from buildSQL(), it could be moved into a method
     $databaseFields = self::database_fields($tableClass);
     if ($databaseFields) {
         foreach ($databaseFields as $k => $v) {
             if (!isset($this->record[$k]) || $this->record[$k] === null) {
                 $columns[] = $k;
             }
         }
     }
     if ($columns) {
         $query = $dataQuery->query();
         $this->extend('augmentLoadLazyFields', $query, $dataQuery, $this);
         $this->extend('augmentSQL', $query, $dataQuery);
         $dataQuery->setQueriedColumns($columns);
         $newData = $dataQuery->execute()->record();
         // Load the data into record
         if ($newData) {
             foreach ($newData as $k => $v) {
                 if (in_array($k, $columns)) {
                     $this->record[$k] = $v;
                     $this->original[$k] = $v;
                     unset($this->record[$k . '_Lazy']);
                 }
             }
             // No data means that the query returned nothing; assign 'null' to all the requested fields
         } else {
             foreach ($columns as $k) {
                 $this->record[$k] = null;
                 $this->original[$k] = null;
                 unset($this->record[$k . '_Lazy']);
             }
         }
     }
 }
开发者ID:vinstah,项目名称:body,代码行数:70,代码来源:DataObject.php


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