本文整理汇总了PHP中Expression::minus方法的典型用法代码示例。如果您正苦于以下问题:PHP Expression::minus方法的具体用法?PHP Expression::minus怎么用?PHP Expression::minus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Expression
的用法示例。
在下文中一共展示了Expression::minus方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGroupBy
public function testGroupBy()
{
$query = OQL::select('from TestUser');
$criteria = Criteria::create(TestUser::dao());
$this->assertCriteria($query->addGroupBy(OQL::groupBy('id')), $criteria->addProjection(Projection::group('id')));
$this->assertCriteria($query->addGroupBy(OQL::groupBy('-name')), $criteria->addProjection(Projection::group(Expression::minus('name'))));
$this->assertEquals(OQL::groupBy('id, name')->toProjection(), Projection::chain()->add(Projection::group('id'))->add(Projection::group('name')));
$this->assertEquals(OQL::groupBy('id + 2')->toProjection(), Projection::chain()->add(Projection::group(Expression::add('id', 2))));
$this->assertEquals(OQL::groupBy('id > 2')->toProjection(), Projection::chain()->add(Projection::group(Expression::gt('id', 2))));
$this->assertEquals(OQL::groupBy('$1')->bindNext('id')->toProjection(), Projection::chain()->add(Projection::group('id')));
$this->assertEquals(OQL::groupBy('$1, $2 + 3')->bindNext('name')->bindNext('id')->toProjection(), Projection::chain()->add(Projection::group('name'))->add(Projection::group(Expression::add('id', 3))));
}
示例2: testBaseSqlGeneration
public function testBaseSqlGeneration()
{
$dialect = ImaginaryDialect::me();
$pgDialect = $this->getDbByType('PgSQL')->getDialect();
$this->assertRegExp('/^\\(a (AND|and) b\\)$/', Expression::expAnd('a', 'b')->toDialectString($dialect));
$this->assertRegExp('/^\\(a (OR|or) b\\)$/', Expression::expOr('a', 'b')->toDialectString($dialect));
$this->assertEquals(Expression::eq('a', 'b')->toDialectString($dialect), '(a = b)');
$some = IdentifiableObject::wrap(123);
$this->assertEquals(Expression::eqId('a', $some)->toDialectString($dialect), '(a = 123)');
$this->assertEquals(Expression::notEq('a', 'b')->toDialectString($dialect), '(a != b)');
$this->assertEquals(Expression::gt('a', 'b')->toDialectString($dialect), '(a > b)');
$this->assertEquals(Expression::gtEq('a', 'b')->toDialectString($dialect), '(a >= b)');
$this->assertEquals(Expression::lt('a', 'b')->toDialectString($dialect), '(a < b)');
$this->assertEquals(Expression::ltEq('a', 'b')->toDialectString($dialect), '(a <= b)');
$this->assertRegExp('/^\\(a ((IS NOT NULL)|(is not null)) *\\)$/', Expression::notNull('a')->toDialectString($dialect));
$this->assertRegExp('/^\\(a ((IS NULL)|(is null)) *\\)$/', Expression::isNull('a')->toDialectString($dialect));
$this->assertRegExp('/^\\(a ((IS TRUE)|(is true)) *\\)$/', Expression::isTrue('a')->toDialectString($dialect));
$this->assertRegExp('/^\\(a ((IS FALSE)|(is false)) *\\)$/', Expression::isFalse('a')->toDialectString($dialect));
$this->assertRegExp('/^\\(a (LIKE|like) b\\)$/', Expression::like('a', 'b')->toDialectString($dialect));
$this->assertRegExp('/^\\(a ((NOT LIKE)|(not like)) b\\)$/', Expression::notLike('a', 'b')->toDialectString($dialect));
$this->assertRegExp('/^\\(a (ILIKE|ilike) b\\)$/', Expression::ilike('a', 'b')->toDialectString($dialect));
$this->assertRegExp('/^\\(a ((NOT ILIKE)|(not like)) b\\)$/', Expression::notIlike('a', 'b')->toDialectString($dialect));
$this->assertRegExp('/^\\(a ((SIMILAR TO)|(similar to)) b\\)$/', Expression::similar('a', 'b')->toDialectString($dialect));
$this->assertRegExp('/^\\(a ((NOT SIMILAR TO)|(not similar to)) b\\)$/', Expression::notSimilar('a', 'b')->toDialectString($dialect));
$this->assertEquals('(lower(a) = b)', Expression::eqLower('a', 'b')->toDialectString($dialect));
$this->assertEquals('(lower(a) = lower(b))', Expression::eqLower(new DBValue('a'), new DBValue('b'))->toDialectString($dialect));
$this->assertEquals('(lower(\'a\') = lower(\'b\'))', Expression::eqLower(new DBValue('a'), new DBValue('b'))->toDialectString($pgDialect));
$this->assertEquals('(lower(\'a\') = lower("b"))', Expression::eqLower(new DBValue('a'), new DBField('b'))->toDialectString($pgDialect));
$this->assertEquals('(lower("a") = lower(\'b\'))', Expression::eqLower(new DBField('a'), new DBValue('b'))->toDialectString($pgDialect));
$this->assertRegExp('/^\\(a (BETWEEN|between) b (AND|and) c\\)$/', Expression::between('a', 'b', 'c')->toDialectString($dialect));
$this->assertEquals('(a = 123)', Expression::in('a', 123)->toDialectString($dialect));
$this->assertEquals('(a = 123)', Expression::in('a', array(123))->toDialectString($dialect));
$this->assertRegExp('/^\\(a (in|IN) \\(123, 456\\)\\)$/', Expression::in('a', array(123, 456))->toDialectString($dialect));
$this->assertEquals('(a != 123)', Expression::notIn('a', 123)->toDialectString($dialect));
$this->assertEquals('(a != 123)', Expression::notIn('a', array(123))->toDialectString($dialect));
$this->assertRegExp('/^\\(a ((not in)|(NOT IN)) \\(123, 456\\)\\)$/', Expression::notIn('a', array(123, 456))->toDialectString($dialect));
$this->assertEquals('(a + b)', Expression::add('a', 'b')->toDialectString($dialect));
$this->assertEquals('(a - b)', Expression::sub('a', 'b')->toDialectString($dialect));
$this->assertEquals('(a * b)', Expression::mul('a', 'b')->toDialectString($dialect));
$this->assertEquals('(a / b)', Expression::div('a', 'b')->toDialectString($dialect));
$this->assertRegExp('/^\\(a (between|BETWEEN) b (and|AND) c\\)$/', Expression::between('a', 'b', 'c')->toDialectString($dialect));
$this->assertEquals('(-1 IS NULL)', Expression::isNull(-1)->toDialectString($dialect));
$this->assertEquals('(NOT a)', Expression::not('a')->toDialectString($dialect));
$this->assertEquals('(- a)', Expression::minus('a')->toDialectString($dialect));
try {
Expression::eq('id', null)->toDialectString($dialect);
$this->fail();
} catch (WrongArgumentException $e) {
//it's Ok
}
}
示例3: testHaving
public function testHaving()
{
$this->assertCriteria('from TestUser having (2 + -id --1) / 2 = id', Criteria::create(TestUser::dao())->setProjection(Projection::having(Expression::eq(Expression::div(Expression::sub(Expression::add(2, Expression::minus('id')), -1), 2), 'id'))), array(1 => 'id'))->assertCriteria('from TestUser having (id = 1) != ((1 = id) = (id >= 2))', Criteria::create(TestUser::dao())->setProjection(Projection::having(Expression::notEq(Expression::eq('id', 1), Expression::eq(Expression::eq(1, 'id'), Expression::gtEq('id', 2))))))->assertCriteria('from TestUser having $1 = 1', Criteria::create(TestUser::dao())->setProjection(Projection::having(Expression::eq(SQLFunction::create('count', 'id'), 1))), array(1 => SQLFunction::create('count', 'id')));
}