1
0
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:
David Grudl
2009-04-26 15:35:39 +00:00
parent 6589519419
commit 98d43e0815
4 changed files with 29 additions and 7 deletions

View File

@@ -263,8 +263,13 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver
*/
public function applyLimit(&$sql, $limit, $offset)
{
if ($limit < 0 && $offset < 1) return;
$sql .= ' LIMIT ' . $limit . ($offset > 0 ? ' OFFSET ' . (int) $offset : '');
if ($offset > 0) {
// 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()
{
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;
}

View File

@@ -70,7 +70,7 @@ class DibiDataSource extends DibiObject implements IDataSource
if (strpos($sql, ' ') === FALSE) {
$this->sql = $sql; // table name
} else {
$this->sql = '(' . $sql . ') AS t'; // SQL command
$this->sql = '(' . $sql . ') t'; // SQL command
}
$this->connection = $connection;
}

View File

@@ -108,11 +108,17 @@ class DibiProfiler extends DibiObject implements IDibiProfiler
if (($event & $this->filter) === 0) return;
if ($event & self::QUERY) {
try {
$count = $res instanceof DibiResult ? count($res) : '-';
} catch (Exception $e) {
$count = '?';
}
if ($this->useFirebug && !headers_sent()) {
self::$table[] = array(
sprintf('%0.3f', dibi::$elapsedTime * 1000),
trim($sql),
$res instanceof DibiResult ? count($res) : '-',
$count,
$connection->getConfig('driver') . '/' . $connection->getConfig('name')
);
@@ -138,7 +144,7 @@ class DibiProfiler extends DibiObject implements IDibiProfiler
if ($this->file) {
$this->writeFile(
"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-- driver: " . $connection->getConfig('driver') . '/' . $connection->getConfig('name')
. "\n-- " . date('Y-m-d H:i:s')

View File

@@ -210,7 +210,7 @@ final class DibiTranslator extends DibiObject
case 'and':
case 'or': // key=val AND key IS NULL AND ...
if (empty($value)) {
return $this->driver->escape(TRUE, 'b');
return '1=1';
}
foreach ($value as $k => $v) {