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


PHP Select::assemble方法代码示例

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


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

示例1: testWhere

 public function testWhere()
 {
     $select = new Select($this->_getConnectionMockWithMockedQuote(1, "'5'"));
     $select->from('test')->where('field = ?', 5);
     $this->assertEquals("SELECT `test`.* FROM `test` WHERE (field = '5')", $select->assemble());
     $select = new Select($this->_getConnectionMockWithMockedQuote(1, "''"));
     $select->from('test')->where('field = ?');
     $this->assertEquals("SELECT `test`.* FROM `test` WHERE (field = '')", $select->assemble());
     $select = new Select($this->_getConnectionMockWithMockedQuote(1, "'%?%'"));
     $select->from('test')->where('field LIKE ?', '%value?%');
     $this->assertEquals("SELECT `test`.* FROM `test` WHERE (field LIKE '%?%')", $select->assemble());
     $select = new Select($this->_getConnectionMockWithMockedQuote(0));
     $select->from('test')->where("field LIKE '%value?%'", null, Select::TYPE_CONDITION);
     $this->assertEquals("SELECT `test`.* FROM `test` WHERE (field LIKE '%value?%')", $select->assemble());
     $select = new Select($this->_getConnectionMockWithMockedQuote(1, "'1', '2', '4', '8'"));
     $select->from('test')->where("id IN (?)", [1, 2, 4, 8]);
     $this->assertEquals("SELECT `test`.* FROM `test` WHERE (id IN ('1', '2', '4', '8'))", $select->assemble());
 }
开发者ID:IlyaGluschenko,项目名称:test001,代码行数:18,代码来源:SelectTest.php

示例2: testWhere

 public function testWhere()
 {
     $quote = new \Magento\Framework\DB\Platform\Quote();
     $renderer = new \Magento\Framework\DB\Select\SelectRenderer(['distinct' => ['renderer' => new \Magento\Framework\DB\Select\DistinctRenderer(), 'sort' => 100, 'part' => 'distinct'], 'columns' => ['renderer' => new \Magento\Framework\DB\Select\ColumnsRenderer($quote), 'sort' => 200, 'part' => 'columns'], 'union' => ['renderer' => new \Magento\Framework\DB\Select\UnionRenderer(), 'sort' => 300, 'part' => 'union'], 'from' => ['renderer' => new \Magento\Framework\DB\Select\FromRenderer($quote), 'sort' => 400, 'part' => 'from'], 'where' => ['renderer' => new \Magento\Framework\DB\Select\WhereRenderer(), 'sort' => 500, 'part' => 'where'], 'group' => ['renderer' => new \Magento\Framework\DB\Select\GroupRenderer($quote), 'sort' => 600, 'part' => 'group'], 'having' => ['renderer' => new \Magento\Framework\DB\Select\HavingRenderer(), 'sort' => 700, 'part' => 'having'], 'order' => ['renderer' => new \Magento\Framework\DB\Select\OrderRenderer($quote), 'sort' => 800, 'part' => 'order'], 'limit' => ['renderer' => new \Magento\Framework\DB\Select\LimitRenderer(), 'sort' => 900, 'part' => 'limitcount'], 'for_update' => ['renderer' => new \Magento\Framework\DB\Select\ForUpdateRenderer(), 'sort' => 1000, 'part' => 'forupdate']]);
     $select = new Select($this->_getConnectionMockWithMockedQuote(1, "'5'"), $renderer);
     $select->from('test')->where('field = ?', 5);
     $this->assertEquals("SELECT `test`.* FROM `test` WHERE (field = '5')", $select->assemble());
     $select = new Select($this->_getConnectionMockWithMockedQuote(1, "''"), $renderer);
     $select->from('test')->where('field = ?');
     $this->assertEquals("SELECT `test`.* FROM `test` WHERE (field = '')", $select->assemble());
     $select = new Select($this->_getConnectionMockWithMockedQuote(1, "'%?%'"), $renderer);
     $select->from('test')->where('field LIKE ?', '%value?%');
     $this->assertEquals("SELECT `test`.* FROM `test` WHERE (field LIKE '%?%')", $select->assemble());
     $select = new Select($this->_getConnectionMockWithMockedQuote(0), $renderer);
     $select->from('test')->where("field LIKE '%value?%'", null, Select::TYPE_CONDITION);
     $this->assertEquals("SELECT `test`.* FROM `test` WHERE (field LIKE '%value?%')", $select->assemble());
     $select = new Select($this->_getConnectionMockWithMockedQuote(1, "'1', '2', '4', '8'"), $renderer);
     $select->from('test')->where("id IN (?)", [1, 2, 4, 8]);
     $this->assertEquals("SELECT `test`.* FROM `test` WHERE (id IN ('1', '2', '4', '8'))", $select->assemble());
 }
开发者ID:dragonsword007008,项目名称:magento2,代码行数:20,代码来源:SelectTest.php

示例3: exists

 /**
  * Add EXISTS clause
  *
  * @param  Select $select
  * @param  string           $joinCondition
  * @param   bool            $isExists
  * @return $this
  */
 public function exists($select, $joinCondition, $isExists = true)
 {
     if ($isExists) {
         $exists = 'EXISTS (%s)';
     } else {
         $exists = 'NOT EXISTS (%s)';
     }
     $select->reset(self::COLUMNS)->columns([new \Zend_Db_Expr('1')])->where($joinCondition);
     $exists = sprintf($exists, $select->assemble());
     $this->where($exists);
     return $this;
 }
开发者ID:tingyeeh,项目名称:magento2,代码行数:20,代码来源:Select.php

示例4: insertFromSelect

 /**
  * Get insert from Select object query
  *
  * @param Select $select
  * @param string $table     insert into table
  * @param array $fields
  * @param int|false $mode
  * @return string
  */
 public function insertFromSelect(Select $select, $table, array $fields = array(), $mode = false)
 {
     $query = 'INSERT';
     if ($mode == self::INSERT_IGNORE) {
         $query .= ' IGNORE';
     }
     $query = sprintf('%s INTO %s', $query, $this->quoteIdentifier($table));
     if ($fields) {
         $columns = array_map(array($this, 'quoteIdentifier'), $fields);
         $query = sprintf('%s (%s)', $query, join(', ', $columns));
     }
     $query = sprintf('%s %s', $query, $select->assemble());
     if ($mode == self::INSERT_ON_DUPLICATE) {
         if (!$fields) {
             $describe = $this->describeTable($table);
             foreach ($describe as $column) {
                 if ($column['PRIMARY'] === false) {
                     $fields[] = $column['COLUMN_NAME'];
                 }
             }
         }
         $update = array();
         foreach ($fields as $field) {
             $update[] = sprintf('%1$s = VALUES(%1$s)', $this->quoteIdentifier($field));
         }
         if ($update) {
             $query = sprintf('%s ON DUPLICATE KEY UPDATE %s', $query, join(', ', $update));
         }
     }
     return $query;
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:40,代码来源:Mysql.php


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