mirror of
https://github.com/dg/dibi.git
synced 2025-08-07 06:36:44 +02:00
- Oracle driver: implemented applyLimit() & getTables()
- DibiDataSource: removed key word AS - DibiProfiler: fixed bug with unbuffered queries - DibiTranslator: empty %and generates '1=1'
This commit is contained in:
@@ -263,8 +263,13 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver
|
|||||||
*/
|
*/
|
||||||
public function applyLimit(&$sql, $limit, $offset)
|
public function applyLimit(&$sql, $limit, $offset)
|
||||||
{
|
{
|
||||||
if ($limit < 0 && $offset < 1) return;
|
if ($offset > 0) {
|
||||||
$sql .= ' LIMIT ' . $limit . ($offset > 0 ? ' OFFSET ' . (int) $offset : '');
|
// see http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html
|
||||||
|
$sql = 'SELECT * FROM (SELECT t.*, ROWNUM AS __rnum FROM (' . $sql . ') t ' . ($limit >= 0 ? 'WHERE ROWNUM <= ' . ((int) $offset + (int) $limit) : '') . ') WHERE __rnum > '. (int) $offset;
|
||||||
|
|
||||||
|
} elseif ($limit >= 0) {
|
||||||
|
$sql = 'SELECT * FROM (' . $sql . ') WHERE ROWNUM <= ' . (int) $limit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -363,7 +368,18 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver
|
|||||||
*/
|
*/
|
||||||
public function getTables()
|
public function getTables()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException;
|
$this->query('SELECT * FROM cat');
|
||||||
|
$res = array();
|
||||||
|
while ($row = $this->fetch(FALSE)) {
|
||||||
|
if ($row[1] === 'TABLE' || $row[1] === 'VIEW') {
|
||||||
|
$res[] = array(
|
||||||
|
'name' => $row[0],
|
||||||
|
'view' => $row[1] === 'VIEW',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->free();
|
||||||
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -70,7 +70,7 @@ class DibiDataSource extends DibiObject implements IDataSource
|
|||||||
if (strpos($sql, ' ') === FALSE) {
|
if (strpos($sql, ' ') === FALSE) {
|
||||||
$this->sql = $sql; // table name
|
$this->sql = $sql; // table name
|
||||||
} else {
|
} else {
|
||||||
$this->sql = '(' . $sql . ') AS t'; // SQL command
|
$this->sql = '(' . $sql . ') t'; // SQL command
|
||||||
}
|
}
|
||||||
$this->connection = $connection;
|
$this->connection = $connection;
|
||||||
}
|
}
|
||||||
|
@@ -108,11 +108,17 @@ class DibiProfiler extends DibiObject implements IDibiProfiler
|
|||||||
if (($event & $this->filter) === 0) return;
|
if (($event & $this->filter) === 0) return;
|
||||||
|
|
||||||
if ($event & self::QUERY) {
|
if ($event & self::QUERY) {
|
||||||
|
try {
|
||||||
|
$count = $res instanceof DibiResult ? count($res) : '-';
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$count = '?';
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->useFirebug && !headers_sent()) {
|
if ($this->useFirebug && !headers_sent()) {
|
||||||
self::$table[] = array(
|
self::$table[] = array(
|
||||||
sprintf('%0.3f', dibi::$elapsedTime * 1000),
|
sprintf('%0.3f', dibi::$elapsedTime * 1000),
|
||||||
trim($sql),
|
trim($sql),
|
||||||
$res instanceof DibiResult ? count($res) : '-',
|
$count,
|
||||||
$connection->getConfig('driver') . '/' . $connection->getConfig('name')
|
$connection->getConfig('driver') . '/' . $connection->getConfig('name')
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -138,7 +144,7 @@ class DibiProfiler extends DibiObject implements IDibiProfiler
|
|||||||
if ($this->file) {
|
if ($this->file) {
|
||||||
$this->writeFile(
|
$this->writeFile(
|
||||||
"OK: " . $sql
|
"OK: " . $sql
|
||||||
. ($res instanceof DibiResult ? ";\n-- rows: " . count($res) : '')
|
. ($res instanceof DibiResult ? ";\n-- rows: " . $count : '')
|
||||||
. "\n-- takes: " . sprintf('%0.3f', dibi::$elapsedTime * 1000) . ' ms'
|
. "\n-- takes: " . sprintf('%0.3f', dibi::$elapsedTime * 1000) . ' ms'
|
||||||
. "\n-- driver: " . $connection->getConfig('driver') . '/' . $connection->getConfig('name')
|
. "\n-- driver: " . $connection->getConfig('driver') . '/' . $connection->getConfig('name')
|
||||||
. "\n-- " . date('Y-m-d H:i:s')
|
. "\n-- " . date('Y-m-d H:i:s')
|
||||||
|
@@ -210,7 +210,7 @@ final class DibiTranslator extends DibiObject
|
|||||||
case 'and':
|
case 'and':
|
||||||
case 'or': // key=val AND key IS NULL AND ...
|
case 'or': // key=val AND key IS NULL AND ...
|
||||||
if (empty($value)) {
|
if (empty($value)) {
|
||||||
return $this->driver->escape(TRUE, 'b');
|
return '1=1';
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($value as $k => $v) {
|
foreach ($value as $k => $v) {
|
||||||
|
Reference in New Issue
Block a user