1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-04 13:17:58 +02:00

DibiPdoDriver: speed optimization

This commit is contained in:
David Grudl
2010-08-03 00:42:50 +02:00
parent 739994dac6
commit a0a12701e9

View File

@@ -36,6 +36,9 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver
/** @var int|FALSE Affected rows */ /** @var int|FALSE Affected rows */
private $affectedRows = FALSE; private $affectedRows = FALSE;
/** @var string */
private $driverName;
/** /**
@@ -74,6 +77,8 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver
if (!$this->connection) { if (!$this->connection) {
throw new DibiDriverException('Connecting error.'); throw new DibiDriverException('Connecting error.');
} }
$this->driverName = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME);
} }
@@ -99,7 +104,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver
{ {
// must detect if SQL returns result set or num of affected rows // must detect if SQL returns result set or num of affected rows
$cmd = strtoupper(substr(ltrim($sql), 0, 6)); $cmd = strtoupper(substr(ltrim($sql), 0, 6));
$list = array('UPDATE'=>1, 'DELETE'=>1, 'INSERT'=>1, 'REPLAC'=>1); static $list = array('UPDATE'=>1, 'DELETE'=>1, 'INSERT'=>1, 'REPLAC'=>1);
if (isset($list[$cmd])) { if (isset($list[$cmd])) {
$this->resultSet = NULL; $this->resultSet = NULL;
@@ -229,7 +234,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver
return $this->connection->quote($value, PDO::PARAM_LOB); return $this->connection->quote($value, PDO::PARAM_LOB);
case dibi::IDENTIFIER: case dibi::IDENTIFIER:
switch ($this->connection->getAttribute(PDO::ATTR_DRIVER_NAME)) { switch ($this->driverName) {
case 'mysql': case 'mysql':
return '`' . str_replace('`', '``', $value) . '`'; return '`' . str_replace('`', '``', $value) . '`';
@@ -293,7 +298,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver
{ {
if ($limit < 0 && $offset < 1) return; if ($limit < 0 && $offset < 1) return;
switch ($this->connection->getAttribute(PDO::ATTR_DRIVER_NAME)) { switch ($this->driverName) {
case 'mysql': case 'mysql':
$sql .= ' LIMIT ' . ($limit < 0 ? '18446744073709551615' : (int) $limit) $sql .= ' LIMIT ' . ($limit < 0 ? '18446744073709551615' : (int) $limit)
. ($offset > 0 ? ' OFFSET ' . (int) $offset : ''); . ($offset > 0 ? ' OFFSET ' . (int) $offset : '');