Beispiel #1
0
 /**
  * Test not DDL query inside transaction
  *
  * @dataProvider sqlQueryProvider
  */
 public function testCheckNotDdlTransaction($query)
 {
     try {
         $this->_mockAdapter->query($query);
     } catch (\Exception $e) {
         $this->assertNotContains($e->getMessage(), AdapterInterface::ERROR_DDL_MESSAGE);
     }
     $select = new Select($this->_mockAdapter);
     $select->from('user');
     try {
         $this->_mockAdapter->query($select);
     } catch (\Exception $e) {
         $this->assertNotContains($e->getMessage(), AdapterInterface::ERROR_DDL_MESSAGE);
     }
 }
Beispiel #2
0
 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());
 }
Beispiel #3
0
 /**
  * Db tree constructor
  *
  * $fields = array(
  *      \Magento\Framework\Data\Tree\Db::ID_FIELD       => string,
  *      \Magento\Framework\Data\Tree\Db::PARENT_FIELD   => string,
  *      \Magento\Framework\Data\Tree\Db::LEVEL_FIELD    => string
  *      \Magento\Framework\Data\Tree\Db::ORDER_FIELD    => string
  * )
  *
  * @param \Magento\Framework\DB\Adapter\AdapterInterface $connection
  * @param string $table
  * @param array $fields
  * @throws \Exception
  */
 public function __construct(\Magento\Framework\DB\Adapter\AdapterInterface $connection, $table, $fields)
 {
     parent::__construct();
     if (!$connection) {
         throw new \Exception('Wrong "$connection" parametr');
     }
     $this->_conn = $connection;
     $this->_table = $table;
     if (!isset($fields[self::ID_FIELD]) || !isset($fields[self::PARENT_FIELD]) || !isset($fields[self::LEVEL_FIELD]) || !isset($fields[self::ORDER_FIELD])) {
         throw new \Exception('"$fields" tree configuratin array');
     }
     $this->_idField = $fields[self::ID_FIELD];
     $this->_parentField = $fields[self::PARENT_FIELD];
     $this->_levelField = $fields[self::LEVEL_FIELD];
     $this->_orderField = $fields[self::ORDER_FIELD];
     $this->_select = $this->_conn->select();
     $this->_select->from($this->_table, array_values($fields));
 }
 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());
 }
Beispiel #5
0
 /**
  * @param string|int $nodeId
  * @return Node
  */
 public function getNode($nodeId)
 {
     $dbSelect = new Select($this->_db);
     $dbSelect->from($this->_table)->where($this->_table . '.' . $this->_id . ' >= :id');
     $this->_addExtTablesToSelect($dbSelect);
     $data = [];
     $data['id'] = $nodeId;
     $data = $this->_db->fetchRow($dbSelect, $data);
     return new Node($data, $this->getKeys());
 }