public function testIsInsert() { $this->assertTrue(\r8\DB\Link::isInsert("INSERT INTO table SET field = 1")); $this->assertTrue(\r8\DB\Link::isInsert("INSERT INTO table VALUES (1, 2)")); $this->assertTrue(\r8\DB\Link::isInsert(" \n\t INSERT INTO table SET field = 1")); $this->assertTrue(\r8\DB\Link::isInsert("insert into table set field = 1")); $this->assertFalse(\r8\DB\Link::isInsert("INSERTER")); $this->assertFalse(\r8\DB\Link::isInsert("SELECT * FROM table")); $this->assertFalse(\r8\DB\Link::isInsert("UPDATE table SET field = 1")); }
/** * Runs a query and returns the result * * @param String $query The query to run * @param Integer $flags Any boolean flags to set * @returns \r8\iface\DB\Result Returns a result object */ public function query($query, $flags = 0) { $query = (string) $query; if (\r8\DB\Link::isSelect($query)) { if (empty($this->queue)) { $result = new \r8\DB\BlackHole\Result(); } else { $result = array_shift($this->queue); } return new \r8\DB\Result\Read($result, $query); } else { if (\r8\DB\Link::isInsert($query)) { return new \r8\DB\Result\Write(1, ++$this->insertID, $query); } else { return new \r8\DB\Result\Write(0, null, $query); } } }