public function testAssemble() { $clause = new SetClause(); $eq = new EqualPredicate(); $eq->setField('one')->setExpression((new StringExpression())->setValue('val')); $clause->addPredicate($eq); $this->assertEquals('SET one = "val"', QueryAssembler::stringify($clause)); $inc = new EqualPredicate(); $inc->setField('two')->setExpression(IncrementExpression::create('two', 5)); $clause->addPredicate($inc); $this->assertEquals('SET one = "val", two = two + 5', QueryAssembler::stringify($clause)); }
public function testAssemble() { $statement = QueryBuilder::insertInto('tbl'); $this->assertEquals('INSERT INTO tbl ()', QueryAssembler::stringify($statement)); $statement = QueryBuilder::insertInto('tbl', 'field'); $this->assertEquals('INSERT INTO tbl (field)', QueryAssembler::stringify($statement)); $statement->insertInto('tbl', FieldExpression::create('id'), 'name'); $this->assertEquals('INSERT INTO tbl (id, name)', QueryAssembler::stringify($statement)); $statement->values(null, ValueExpression::create('Test')); $this->assertEquals('INSERT INTO tbl (id, name) ' . 'VALUES (NULL, "Test")', QueryAssembler::stringify($statement)); $statement->values('row2v1', 'row2v2'); $this->assertEquals('INSERT INTO tbl (id, name) ' . 'VALUES (NULL, "Test"), ("row2v1", "row2v2")', QueryAssembler::stringify($statement)); $statement = QueryBuilder::insertInto('tbl', 'field1', 'field2')->values('value1', 'value2')->onDuplicateKeyUpdate('field1', IncrementExpression::create('field2', 1)); $assembler = new QueryAssembler($statement); $this->assertEquals('INSERT INTO tbl (field1, field2) VALUES (?, ?) ON DUPLICATE KEY UPDATE field1 = field2 + ?', $assembler->getQuery()); $this->assertEquals(['value1', 'value2', 1], $assembler->getParameters()); }
protected function _getCounterValue(QlDao $dao, $field, $value) { $newValue = $dao->{$field}; if ($newValue instanceof Counter) { if ($newValue->isIncrement()) { $value = IncrementExpression::create($field, $newValue->getIncrement()); } elseif ($newValue->isDecrement()) { $value = DecrementExpression::create($field, $newValue->getDecrement()); } elseif ($newValue->isFixedValue()) { $value = NumericExpression::create($newValue->calculated()); } } return $value; }