コード例 #1
0
 public function setTable($field)
 {
     if ($field === null || $field instanceof IExpression) {
         $this->_table = $field;
     } else {
         $this->_table = TableExpression::create($field);
     }
     return $this;
 }
コード例 #2
0
ファイル: JoinClause.php プロジェクト: packaged/querybuilder
 public function getTable()
 {
     if ($this->_table instanceof TableExpression) {
         return $this->_table;
     } elseif (is_scalar($this->_table)) {
         return TableExpression::create($this->_table);
     }
     return $this->_table;
 }
コード例 #3
0
 public function testCreate()
 {
     $class = new FinalJoinTrait();
     $class->addClause((new FromClause())->setTable('tbl'));
     $class->join(TableExpression::create('tbl2'), 'email');
     $this->assertEquals("FROM tbl INNER JOIN tbl2 ON tbl.email = tbl2.email", QueryAssembler::stringify($class));
     $class->join('tbl3', 'user', 'user_id');
     $this->assertEquals('FROM tbl INNER JOIN tbl2 ON tbl.email = tbl2.email ' . 'INNER JOIN tbl3 ON tbl.user = tbl3.user_id', QueryAssembler::stringify($class));
     $class->joinWithPredicates(TableSelectExpression::createWithAlias('tbl4', 't4'), EqualPredicate::create(FieldExpression::createWithTable('email', 'tbl2'), FieldExpression::createWithTable('email', 't4')));
     $this->assertEquals('FROM tbl INNER JOIN tbl2 ON tbl.email = tbl2.email ' . 'INNER JOIN tbl3 ON tbl.user = tbl3.user_id ' . 'INNER JOIN tbl4 AS t4 ON tbl2.email = t4.email', QueryAssembler::stringify($class));
 }
コード例 #4
0
 public function testAssemble()
 {
     $sel1 = TableSelectExpression::create('table_one');
     $this->assertEquals('`table_one`', MySQLAssembler::stringify($sel1));
     $sel1->setAlias('t1');
     $this->assertEquals('`table_one` AS `t1`', MySQLAssembler::stringify($sel1));
     $sel2 = new TableSelectExpression();
     $sel2->setTable('table_two');
     $this->assertEquals('table_two', QueryAssembler::stringify($sel2));
     $sel2->setAlias('t2');
     $this->assertEquals('table_two AS t2', QueryAssembler::stringify($sel2));
     $sel3 = TableSelectExpression::createWithAlias(TableExpression::create('table_three'), 't3');
     $this->assertEquals('`table_three` AS `t3`', MySQLAssembler::stringify($sel3));
 }
コード例 #5
0
ファイル: TableTrait.php プロジェクト: packaged/querybuilder
 public function getTable()
 {
     if ($this->_table instanceof TableExpression) {
         return $this->_table;
     } else {
         if ($this->_table instanceof TableSelectExpression) {
             if ($this->_table->getAlias()) {
                 return TableExpression::create($this->_table->getAlias());
             } else {
                 /** @var TableExpression $tbl */
                 $tbl = $this->_table->getTable();
                 return TableExpression::create($tbl->getTableName());
             }
         } else {
             if ($this->_table !== null) {
                 return TableExpression::create($this->_table);
             }
         }
     }
     return $this->_table;
 }
コード例 #6
0
 public function testTableExpression()
 {
     $this->assertEquals('"testTable"', CqlAssembler::stringify(TableExpression::create('testTable')));
 }
コード例 #7
0
 public function testAssembler()
 {
     $assembler = new QueryAssembler(QueryBuilder::insertInto(TableExpression::create('tbl'), 'field')->values('value'));
     $this->assertEquals('INSERT INTO tbl (field) VALUES (?)', $assembler->getQuery());
 }
コード例 #8
0
 public function assembleTableExpression(TableExpression $expr)
 {
     return $this->escapeField($expr->getTableName());
 }
コード例 #9
0
 public function testTableName()
 {
     $this->assertEquals('`mytable`.`myfield`', MySQLAssembler::stringify(FieldExpression::createWithTable('myfield', 'mytable')));
     $this->assertEquals('`mytable`', MySQLAssembler::stringify(TableExpression::create('mytable')));
 }