Ejemplo n.º 1
0
 /**
  * @return sql_select
  * @param sql_select $query
  * @param string $alias
  */
 public static function excludeDeleted(sql_select $query = null, $alias = null)
 {
     if (null === $query) {
         $query = self::createQuery(get_called_class(), $alias);
     }
     return $query->where(sql::expr(($alias ? $alias . '.' : '') . 'deleted', '=', 0));
 }
Ejemplo n.º 2
0
 public function testHaving()
 {
     self::assertEquals("select * from t having (a = 'b')", sql::select(sql::ALL)->from('t')->having(sql::expr('a', '=', 'b'))->toString(Nano::db()));
     self::assertEquals("select * from t having (a = 'b') and (c = 'd')", sql::select(sql::ALL)->from('t')->having(sql::expr('a', '=', 'b'))->having(sql::expr('c', '=', 'd'))->toString(Nano::db()));
     self::assertEquals("select * from t having (a = 'b') or (c = 'd')", sql::select(sql::ALL)->from('t')->having(sql::expr('a', '=', 'b'))->orHaving(sql::expr('c', '=', 'd'))->toString(Nano::db()));
     self::assertEquals("select * from t having custom expr", sql::select(sql::ALL)->from('t')->having(sql::custom('custom expr'))->toString(Nano::db()));
     self::assertEquals("select * from t having custom expr", sql::select(sql::ALL)->from('t')->having('custom expr')->toString(Nano::db()));
 }
Ejemplo n.º 3
0
 public function testNestedExpr()
 {
     $expected = "((a = 'b') and (c = 'd')) or ((e = 'f') and (g = 'h'))";
     $expr = sql::expr(sql::expr('a', '=', 'b')->addAnd('c', '=', 'd'))->addOr(sql::expr('e', '=', 'f')->addAnd('g', '=', 'h'));
     self::assertEquals($expected, $expr->toString(Nano::db()));
 }