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); }
public function setUp() { $options = (include __DIR__ . '/../config.php'); $this->db = new Database($options); $this->db->multiQuery("\n DROP TABLE IF EXISTS `test`;\n CREATE TABLE `test` (\n `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n `code` char(15) NOT NULL,\n `name` varchar(200) NOT NULL,\n `price` decimal(10,2) unsigned DEFAULT NULL,\n `order` int(11) unsigned DEFAULT 0,\n PRIMARY KEY (`id`),\n KEY `code` (`code`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\n INSERT INTO test (id, code, name, price)\n VALUES\n (1, '001', 'Cup', 20.00),\n (2, '002', 'Plate', 30.50)\n "); }
/** * @expectedException Exception */ public function testMultiQueryExceptionOnErrorInSecondQuery() { $this->db->multiQuery("\n INSERT INTO test (code, name)\n VALUES ('003', 'Cup2');\n INSERT INTO test2 (code, name)\n VALUES ('004', 'Plate2')\n "); }