mirror of
https://github.com/dg/dibi.git
synced 2025-08-08 07:06:52 +02:00
PdoDriver: improved detection of query result [Closes #279]
This commit is contained in:
@@ -104,23 +104,14 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
*/
|
*/
|
||||||
public function query($sql)
|
public function query($sql)
|
||||||
{
|
{
|
||||||
// must detect if SQL returns result set or num of affected rows
|
$res = $this->connection->query($sql);
|
||||||
$cmd = strtoupper(substr(ltrim($sql), 0, 6));
|
if ($res) {
|
||||||
static $list = ['UPDATE' => 1, 'DELETE' => 1, 'INSERT' => 1, 'REPLAC' => 1];
|
$this->affectedRows = $res->rowCount();
|
||||||
$this->affectedRows = false;
|
return $res->columnCount() ? $this->createResultDriver($res) : null;
|
||||||
|
|
||||||
if (isset($list[$cmd])) {
|
|
||||||
$this->affectedRows = $this->connection->exec($sql);
|
|
||||||
if ($this->affectedRows !== false) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$res = $this->connection->query($sql);
|
|
||||||
if ($res) {
|
|
||||||
return $this->createResultDriver($res);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->affectedRows = false;
|
||||||
|
|
||||||
list($sqlState, $code, $message) = $this->connection->errorInfo();
|
list($sqlState, $code, $message) = $this->connection->errorInfo();
|
||||||
$message = "SQLSTATE[$sqlState]: $message";
|
$message = "SQLSTATE[$sqlState]: $message";
|
||||||
switch ($this->driverName) {
|
switch ($this->driverName) {
|
||||||
|
Reference in New Issue
Block a user