public function test_nested_conditions() { $sql = \Sledgehammer\select('*')->from('customers')->where(array('OR', 'bonus = 1', array('AND', 'special = 1', 'age < 12'))); $this->assertSame((string) $sql, 'SELECT * FROM customers WHERE bonus = 1 OR (special = 1 AND age < 12)'); $sql = \Sledgehammer\select('*')->from('customers')->orWhere(array('AND', 'bonus = 1', array('AND', 'special = 1', 'age < 12'))); $this->assertSame((string) $sql, 'SELECT * FROM customers WHERE bonus = 1 AND special = 1 AND age < 12'); $sql = \Sledgehammer\select('*')->from('customers')->where(array('bonus = 1'))->orWhere('special = 1')->andWhere('age < 12'); $this->assertSame((string) $sql, 'SELECT * FROM customers WHERE (bonus = 1 OR special = 1) AND age < 12'); $sql = \Sledgehammer\select('*')->from('customers'); $sql->where = array('AND', array('OR', array('OR', 'a = 1', 'b = 2'), 'c = 3', array('AND', 'd = 4', array('AND', 'e = 5', 'f = 6'), array('OR'), array('g = 7'), array('OR', 'h = 8'), array('OR', 'i = 9', 'j = 10')))); $this->assertSame((string) $sql, 'SELECT * FROM customers WHERE a = 1 OR b = 2 OR c = 3 OR (d = 4 AND e = 5 AND f = 6 AND g = 7 AND h = 8 AND (i = 9 OR j = 10))'); }
/** * @param array $config * * @return DatabaseCollection */ public function all($config) { $sql = \Sledgehammer\select('*')->from($config['table']); return new DatabaseCollection($sql, $config['dbLink']); }
/** * A collection containing fruit entries and a vegetable entry. * * @return DatabaseCollection */ private function getDatabaseCollection() { return new DatabaseCollection(\Sledgehammer\select('*')->from('fruits'), $this->dbLink); }