mirror of
https://github.com/dg/dibi.git
synced 2025-08-12 00:54:11 +02:00
fixed bug in conditional SQL
This commit is contained in:
@@ -68,7 +68,7 @@ class DibiDataSource extends NObject implements IDataSource
|
||||
public function getIterator($offset = NULL, $limit = NULL, $cols = NULL)
|
||||
{
|
||||
return $this->connection->query('
|
||||
SELECT %n', ($cols === NULL ? '*' : $cols), '
|
||||
SELECT *
|
||||
FROM', $this->sql, '
|
||||
%ofs %lmt', $offset, $limit
|
||||
);
|
||||
|
@@ -139,7 +139,10 @@ final class DibiTranslator extends NObject
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($comment) continue;
|
||||
if ($comment) {
|
||||
$sql[] = '...';
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_array($arg)) {
|
||||
if (is_string(key($arg))) {
|
||||
@@ -168,19 +171,16 @@ final class DibiTranslator extends NObject
|
||||
} // while
|
||||
|
||||
|
||||
if ($comment) $sql[] = "\0";
|
||||
if ($comment) $sql[] = "*/";
|
||||
|
||||
$this->sql = implode(' ', $sql);
|
||||
|
||||
// remove comments
|
||||
// TODO: check !!!
|
||||
$this->sql = preg_replace('#\x00.*?\x00#s', '', $this->sql);
|
||||
$sql = implode(' ', $sql);
|
||||
|
||||
// apply limit
|
||||
if ($this->limit > -1 || $this->offset > 0) {
|
||||
$this->driver->applyLimit($this->sql, $this->limit, $this->offset);
|
||||
$this->driver->applyLimit($sql, $this->limit, $this->offset);
|
||||
}
|
||||
|
||||
$this->sql = $sql;
|
||||
return !$this->hasError;
|
||||
}
|
||||
|
||||
@@ -368,23 +368,24 @@ final class DibiTranslator extends NObject
|
||||
|
||||
if ($mod === 'if') {
|
||||
$this->ifLevel++;
|
||||
if (!$this->comment && !$this->args[$cursor]) {
|
||||
$cursor++;
|
||||
if (!$this->comment && !$this->args[$cursor - 1]) {
|
||||
// open comment
|
||||
$this->ifLevelStart = $this->ifLevel;
|
||||
$this->comment = TRUE;
|
||||
return "/*";
|
||||
}
|
||||
$cursor++;
|
||||
return "\0";
|
||||
return '';
|
||||
|
||||
} elseif ($mod === 'else') {
|
||||
if ($this->ifLevelStart === $this->ifLevel) {
|
||||
$this->ifLevelStart = 0;
|
||||
$this->comment = FALSE;
|
||||
return "\0";
|
||||
return "*/";
|
||||
} elseif (!$this->comment) {
|
||||
$this->ifLevelStart = $this->ifLevel;
|
||||
$this->comment = TRUE;
|
||||
return "\0";
|
||||
return "/*";
|
||||
}
|
||||
|
||||
} elseif ($mod === 'end') {
|
||||
@@ -393,7 +394,7 @@ final class DibiTranslator extends NObject
|
||||
// close comment
|
||||
$this->ifLevelStart = 0;
|
||||
$this->comment = FALSE;
|
||||
return "\0";
|
||||
return "*/";
|
||||
}
|
||||
return '';
|
||||
|
||||
@@ -417,7 +418,7 @@ final class DibiTranslator extends NObject
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->comment) return '';
|
||||
if ($this->comment) return '...';
|
||||
|
||||
if ($matches[1]) // SQL identifiers: `ident`
|
||||
return $this->delimite($matches[1]);
|
||||
|
@@ -39,12 +39,12 @@
|
||||
* Property names are case-sensitive, and they are written in the camelCaps
|
||||
* or PascalCaps.
|
||||
*
|
||||
* Event functionality is provided by declaration using pseudo-keyword 'event'.
|
||||
* Event functionality is provided by declaration of property named 'on{Something}'
|
||||
* Multiple handlers are allowed.
|
||||
* <code>
|
||||
* public $onClick = event; // declaration in class
|
||||
* public $onClick; // declaration in class
|
||||
* $this->onClick[] = 'callback'; // attaching event handler
|
||||
* if (empty($this->onClick)) ... // are there any handler?
|
||||
* if (!empty($this->onClick)) ... // are there any handlers?
|
||||
* $this->onClick($sender, $arg); // raises the event with arguments
|
||||
* </code>
|
||||
*
|
||||
@@ -110,7 +110,6 @@ abstract class NObject
|
||||
$list = $this->$name;
|
||||
if (is_array($list) || $list instanceof Traversable) {
|
||||
foreach ($list as $handler) {
|
||||
if ($handler === '') continue;
|
||||
call_user_func_array($handler, $args);
|
||||
}
|
||||
}
|
||||
@@ -256,15 +255,7 @@ abstract class NObject
|
||||
*/
|
||||
private static function hasEvent($c, $m)
|
||||
{
|
||||
if (strncmp($m, 'on', 2)) return FALSE;
|
||||
|
||||
static $cache;
|
||||
if (!isset($cache[$c])) {
|
||||
// get_class_vars returns ONLY PUBLIC properties
|
||||
// but returns static methods too (nothing doing...)
|
||||
$cache[$c] = get_class_vars($c);
|
||||
}
|
||||
return isset($cache[$c][$m]) && $cache[$c][$m] === '';
|
||||
return preg_match('#^on[A-Z]#', $m) && property_exists($c, $m);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user