public function testIsSelect() { $this->assertTrue(\r8\DB\Link::isSelect("SELECT * FROM table")); $this->assertTrue(\r8\DB\Link::isSelect(" SELECT * FROM table")); $this->assertTrue(\r8\DB\Link::isSelect(" \r \n \t SELECT * FROM table")); $this->assertTrue(\r8\DB\Link::isSelect(" ( SELECT * FROM table )")); $this->assertTrue(\r8\DB\Link::isSelect("(((SELECT * FROM table)))")); $this->assertTrue(\r8\DB\Link::isSelect(" ( ( ( SELECT * FROM table)))")); $this->assertTrue(\r8\DB\Link::isSelect("EXPLAIN SELECT * FROM table")); $this->assertTrue(\r8\DB\Link::isSelect("( (EXPLAIN SELECT * FROM table))")); $this->assertTrue(\r8\DB\Link::isSelect("( ( EXPLAIN \n \t SELECT * FROM table))")); $this->assertFalse(\r8\DB\Link::isSelect("UPDATE table SET field = 1")); $this->assertFalse(\r8\DB\Link::isSelect("INSERT INTO table SET field = 1")); }
/** * Execute a query and return a result object * * @param String $query The query to execute * @return \r8\iface\DB\Adapter\Result */ public function query($query) { if (!isset($this->link)) { $this->connect(); } $result = $this->link->query($query); if ($result === FALSE) { throw new \r8\Exception\DB\Query($query, $this->link->error, $this->link->errno); } if (\r8\DB\Link::isSelect($query)) { return new \r8\DB\Result\Read(new \r8\DB\MySQLi\Result($result), $query); } else { return new \r8\DB\Result\Write($this->link->affected_rows, $this->link->insert_id, $query); } }
/** * 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); } } }
/** * Execute a query and return a result object * * @param String $query The query to execute * @return \r8\iface\DB\Adapter\Result */ public function query($query) { if (!isset($this->link)) { $this->connect(); } $error = null; $result = @sqlite_query($this->link, $query, SQLITE_ASSOC, $error); if ($result === FALSE) { $code = sqlite_last_error($this->link); throw new \r8\Exception\DB\Query($query, sqlite_error_string($code) . ": " . $error, $code); } if (\r8\DB\Link::isSelect($query)) { return new \r8\DB\Result\Read(new \r8\DB\SQLite\Result($result), $query); } else { return new \r8\DB\Result\Write(sqlite_changes($this->link), sqlite_last_insert_rowid($this->link), $query); } }