Ejemplo n.º 1
0
 public function testQuoteIdentifier()
 {
     $this->db->multiQuery("\n            DROP TABLE IF EXISTS `test``_ident`;\n            CREATE TABLE `test``_ident` (\n             `id` int(11) unsigned NOT NULL,\n             `ide``nt` varchar(100) NULL,\n             PRIMARY KEY (`id`)\n            ) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n        ");
     $table = 'test`_ident';
     // test insert
     $insert = ['id' => 1, 'ide`nt' => 'test'];
     $this->db->insert($table, $insert);
     $ident = $this->db->getAssoc('SELECT id, `ide``nt` FROM `test``_ident` WHERE id = 1');
     $this->assertEquals($insert, $ident);
     // test update
     $update = ['ide`nt' => 'pass'];
     $this->db->update($table, $update, ['id' => 1]);
     $ident = $this->db->getAssoc('SELECT `ide``nt` FROM `test``_ident` WHERE id = 1');
     $this->assertEquals($update, $ident);
     $update = ['ide`nt' => 'order'];
     $where = ['ide`nt' => 'pass'];
     $this->db->update($table, $update, $where);
     $ident = $this->db->getAssoc('SELECT `ide``nt` FROM `test``_ident` WHERE id = 1');
     $this->assertEquals($update, $ident);
     // test insertUpdate
     $update = ['id' => 1, 'ide`nt' => 'update'];
     $this->db->insertUpdate($table, $update);
     $ident = $this->db->getAssoc('SELECT id, `ide``nt` FROM `test``_ident` WHERE id = 1');
     $this->assertEquals($update, $ident);
     // test multiInsert
     $insert = [['id' => 2, 'ide`nt' => 'first'], ['id' => 3, 'ide`nt' => 'second']];
     $this->db->multiInsert($table, array_keys($insert[0]), $insert);
     $idents = $this->db->getAll('SELECT id, `ide``nt` FROM `test``_ident` WHERE id > 1');
     $this->assertEquals($insert, $idents);
     // test delete
     $where = ['id' => 2, 'ide`nt' => 'first'];
     $res = $this->db->delete($table, $where);
     $ident = $this->db->getAssoc('SELECT id, `ide``nt` FROM `test``_ident` WHERE id = 2');
     $this->assertNull($ident);
     $this->assertEquals(1, $res);
 }
Ejemplo n.º 2
0
 public function testFetchRow()
 {
     $res = $this->db->query('SELECT code, name FROM test WHERE id = 1')->fetchRow();
     $expect = ['001', 'Cup'];
     $this->assertEquals($expect, $res);
 }
Ejemplo n.º 3
0
 /**
  * @expectedException Exception
  */
 public function testTransactionWrapperInvalidArgument()
 {
     $this->db->transaction('1+1');
 }
Ejemplo n.º 4
0
 protected function getRowCount()
 {
     return $this->db->getOne('SELECT count(*) FROM test');
 }
Ejemplo n.º 5
0
 /**
  * @expectedException Exception
  */
 public function testNotEnoughParams()
 {
     $this->db->prepare('test ? OR ?', 1);
 }