示例#1
0
文件: Strict.php 项目: jelito/dibi
 /**
  * Access to undeclared property.
  * @throws \LogicException
  */
 public function __set($name, $value)
 {
     $rc = new ReflectionClass($this);
     $items = array_diff($rc->getProperties(ReflectionProperty::IS_PUBLIC), $rc->getProperties(ReflectionProperty::IS_STATIC));
     $hint = ($t = Helpers::getSuggestion($items, $name)) ? ", did you mean \${$t}?" : '.';
     throw new \LogicException("Attempt to write to undeclared property {$rc->getName()}::\${$name}{$hint}");
 }
示例#2
0
 /** @deprecated */
 public function escape($value, $type)
 {
     trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED);
     return Dibi\Helpers::escape($this, $value, $type);
 }
示例#3
0
 /**
  * Import SQL dump from file.
  * @param  string  filename
  * @return int  count of sql commands
  */
 public function loadFile($file)
 {
     return Helpers::loadFromFile($this, $file);
 }
 /**
  * Filter by date
  * @param  Filter\FilterText $filter
  * @return void
  */
 public function applyFilterText(Filter\FilterText $filter)
 {
     $condition = $filter->getCondition();
     $or = [];
     foreach ($condition as $column => $value) {
         $column = Dibi\Helpers::escape($this->data_source->getConnection()->getDriver(), $column, \dibi::IDENTIFIER);
         if ($filter->isExactSearch()) {
             $this->data_source->where("{$column} = %s", $value);
             continue;
         }
         $or[] = "{$column} LIKE \"%{$value}%\"";
     }
     if (sizeof($or) > 1) {
         $this->data_source->where('(%or)', $or);
     } else {
         $this->data_source->where($or);
     }
 }
示例#5
0
    /**
     * Returns HTML code for custom panel. (Tracy\IBarPanel)
     * @return mixed
     */
    public function getPanel()
    {
        $totalTime = $s = NULL;
        $h = 'htmlSpecialChars';
        foreach ($this->events as $event) {
            $totalTime += $event->time;
            $explain = NULL;
            // EXPLAIN is called here to work SELECT FOUND_ROWS()
            if ($this->explain && $event->type === Event::SELECT) {
                try {
                    $backup = [$event->connection->onEvent, \dibi::$numOfQueries, \dibi::$totalTime];
                    $event->connection->onEvent = NULL;
                    $cmd = is_string($this->explain) ? $this->explain : ($event->connection->getConfig('driver') === 'oracle' ? 'EXPLAIN PLAN FOR' : 'EXPLAIN');
                    $explain = Helpers::dump(@$event->connection->nativeQuery("{$cmd} {$event->sql}"), TRUE);
                } catch (Dibi\Exception $e) {
                }
                list($event->connection->onEvent, \dibi::$numOfQueries, \dibi::$totalTime) = $backup;
            }
            $s .= '<tr><td>' . sprintf('%0.3f', $event->time * 1000);
            if ($explain) {
                static $counter;
                $counter++;
                $s .= "<br /><a href='#tracy-debug-DibiProfiler-row-{$counter}' class='tracy-toggle tracy-collapsed' rel='#tracy-debug-DibiProfiler-row-{$counter}'>explain</a>";
            }
            $s .= '</td><td class="tracy-DibiProfiler-sql">' . Helpers::dump(strlen($event->sql) > self::$maxLength ? substr($event->sql, 0, self::$maxLength) . '...' : $event->sql, TRUE);
            if ($explain) {
                $s .= "<div id='tracy-debug-DibiProfiler-row-{$counter}' class='tracy-collapsed'>{$explain}</div>";
            }
            if ($event->source) {
                $s .= Tracy\Helpers::editorLink($event->source[0], $event->source[1]);
                //->class('tracy-DibiProfiler-source');
            }
            $s .= "</td><td>{$event->count}</td><td>{$h($event->connection->getConfig('driver') . '/' . $event->connection->getConfig('name'))}</td></tr>";
        }
        return empty($this->events) ? '' : '<style> #tracy-debug td.tracy-DibiProfiler-sql { background: white !important }
			#tracy-debug .tracy-DibiProfiler-source { color: #999 !important }
			#tracy-debug tracy-DibiProfiler tr table { margin: 8px 0; max-height: 150px; overflow:auto } </style>
			<h1>Queries: ' . count($this->events) . ($totalTime === NULL ? '' : sprintf(', time: %0.3f ms', $totalTime * 1000)) . '</h1>
			<div class="tracy-inner tracy-DibiProfiler">
			<table>
				<tr><th>Time&nbsp;ms</th><th>SQL Statement</th><th>Rows</th><th>Connection</th></tr>' . $s . '
			</table>
			</div>';
    }
示例#6
0
文件: Column.php 项目: janlanger/dibi
 /**
  * @return string
  */
 public function getType()
 {
     return Dibi\Helpers::getTypeCache()->{$this->info['nativetype']};
 }