public function query($type, $sql, $as_object = false, array $params = NULL) { $result = preg_match('/^\\s*(SET|EXPLAIN|PRAGMA|SELECT\\s*FOUND_ROWS|SELECT|INSERT|UPDATE|REPLACE|DELETE|ALTER|CREATE|DROP\\s*INDEX|DROP|SHOW|DESCRIBE|DESC|TRUNCATE|OPTIMIZE|CHECK|ANALYZE)/i', $sql, $match); if ($result) { $query_type = strtolower($match[1]); switch ($query_type) { case 'pragma': break; case 'set': $pattern = '/^\\s*SET\\s*FOREIGN_KEY_CHECKS\\s*=\\s*(0|1)\\s*/im'; if (preg_match($pattern, $sql, $match)) { $sql = 'PRAGMA foreign_keys = ' . $match[1]; } break; case 'show': $sql = $this->handle_show_tables($sql); $sql = $this->handle_show_create($sql); $sql = $this->handle_show_columns($sql); $sql = $this->handle_show_index($sql); break; case 'create': $engine = new Kohana_Database_PDO_SQLite_Create(); $sql = join(";\n", $engine->rewrite_query($sql)); break; case 'alter': $engine = new Kohana_Database_PDO_SQLite_Alter(); $re_query = NULL; $rewritten_query = $engine->rewrite_query($sql, $query_type); if (is_array($rewritten_query) && array_key_exists('recursion', $rewritten_query)) { $re_query = $rewritten_query['recursion']; unset($rewritten_query['recursion']); $rewritten_query[] = $re_query; } $sql = join(";\n", $rewritten_query); break; default: $sql = preg_replace(array('/NOW\\(\\)/im', '/CURDATE\\(\\)\\s+(\\+|-)\\s+INTERVAL\\s+([0-9]+)\\s+(DAY|WEEK|MONTH|YEAR)/im', '/CURDATE\\(\\)/im'), array("DATETIME('now')", "DATE('now','\$1\$2 \$3')", "DATE('now')"), $sql); $sql = preg_replace_callback('/([1-9])+\\s+WEEK/im', create_function('$matches', 'return ($matches[1] * 7) . " DAY";'), $sql); break; } } try { $result = parent::query($type, $sql, $as_object, $params); } catch (Database_Exception $e) { throw new Kohana_Kohana_Exception('Problem in executing query. Error was: :message', array(':message' => $e->getMessage())); } return $result; }
public function query($type, $sql, $as_object) { $result = parent::query($type, $sql, $as_object); FirePHP_Profiler::instance()->query($result, $type, $sql); return $result; }