Ejemplo n.º 1
0
 public function testValues()
 {
     $db = new Mock_Database($this, array(array('execute', "INSERT INTO table\n(`name`, `state`)\nVALUES\n\t(?, ?),\n\t(?, ?)", array('name1', 'state1', 'name2', 'state2'))));
     $q = new \Snowfire\Database\Query($db);
     $q->insert('table')->values(array(array('name' => 'name1', 'state' => 'state1'), array('name' => 'name2', 'state' => 'state2')))->execute();
     $db->finished();
 }
Ejemplo n.º 2
0
 public function testDelete()
 {
     $db = new Mock_Database($this, array(array('execute', "DELETE FROM table\nWHERE `column` = ?\nLIMIT 1", array('value'))));
     $q = new \Snowfire\Database\Query($db);
     $q->delete('table')->where('column', 'value')->limit(1)->execute();
     $db->finished();
 }
Ejemplo n.º 3
0
 public function testUpdate()
 {
     $db = new Mock_Database($this, array(array('execute', "UPDATE table\nSET `column` = ?, `column2` = ?, `column3` = ?\n" . "WHERE `column` = ?", array('value', 2, 3, 9))));
     $q = new \Snowfire\Database\Query($db);
     $q->update('table')->set('column', 'value')->set(array('column2' => 2, 'column3' => 3))->set(array('column' => 'value'))->where('column', 9)->execute();
     $db->finished();
 }
Ejemplo n.º 4
0
 public function testSelect()
 {
     $db = new Mock_Database($this, array(array('many', "SELECT *\nFROM table", array(), null), array('many', "SELECT `column`\nFROM table", array(), null), array('one', "SELECT DISTINCT *\n" . "FROM table\n" . "LEFT JOIN `table2`\n" . "\tON table2.id = table.foreign_id AND table2.state = ?\n" . "WHERE table.id = ? AND table.id = ?\n" . "GROUP BY `column`\n" . "ORDER BY `created_date` DESC, `id`, `name` COLLATE utf8_swedish_ci DESC\n" . "LIMIT 1", array('ACTIVE', 9, 10), null)));
     $q = new \Snowfire\Database\Query($db);
     // Basic query functionality
     $q->select()->from('table')->execute();
     // Clear query param
     $q->select()->select(null)->select('column')->from('table')->execute();
     // Full select feature test
     $q->select('*', array('distinct' => true))->from('table')->join('table2', 'left')->on('table2.id = table.foreign_id')->on('table2.state', 'ACTIVE')->where('table.id', 8)->where(null)->where('table.id', 9)->where('table.id', 10)->group_by('column')->order_by('created_date', 'desc')->order_by(array('id', array('column' => 'name', 'order' => 'desc', 'collate' => 'utf8_swedish_ci')))->limit(1)->execute();
     $db->finished();
 }