public function fetch($limit = null, $offset = null) { // クエリのビルド $sql = $this->buildQuery(); // クエリの検索件数を制限する。 if ($limit != null) { $sql .= " LIMIT " . $limit; if ($offset != null) { $sql .= " OFFSET " . $offset; } } // クエリを実行する。 try { $sql = $this->showQuery(); Vizualizer_Logger::writeDebug($sql); $connection = Vizualizer_Database_Factory::conn($this->module); $result = $connection->query($sql); } catch (Exception $e) { Vizualizer_Logger::writeError($sql, $e); throw new Vizualizer_Exception_Database($e); } return new Vizualizer_Query_Select_Result($result); }
public function showQuery($values) { // パラメータを展開 $cols = array(); $vals = array(); $connection = Vizualizer_Database_Factory::conn($this->module); foreach ($values as $key => $value) { if (isset($this->table->{$key})) { $cols[] = $connection->escapeIdentifier($key); $vals[] = "'" . $connection->escape(trim($value)) . "'"; } } $sql = ""; if (!empty($cols)) { // クエリのビルド $sql = $this->getPrefix() . " INTO " . $this->table->_T . "(" . implode(", ", $cols) . ") VALUES (" . implode(", ", $vals) . ")"; } return $sql; }
/** * フィールドを文字列として扱った場合にフィールド名となるようにする。 * * @return string クラスの文字列表現 */ public function __toString() { // DBの接続を取得する。 $connection = Vizualizer_Database_Factory::conn($this->module); // カラム名をエスケープする。 return $this->table . "." . $connection->escapeIdentifier($this->field); }
protected function initialize() { // DBの接続を取得する。 $connection = Vizualizer_Database_Factory::conn($this->module); // 構成されたカラム情報を元に設定値を生成 $this->_B = $this->_T = $this->_C = $connection->escapeIdentifier($this->tableName); $this->_W = $this->_C . ".*"; // テーブル構成のキャッシュがある場合にはキャッシュからテーブル情報を取得 $tableConfigure = Vizualizer_Cache_Factory::create("table_" . $this->tableName); if ($tableConfigure->options == "") { try { // テーブルの定義を取得 $options = $connection->columns($this->_T); } catch (Exception $e) { //$this->install($connection); // テーブルの定義を再取得 $options = $connection->columns($this->_T); } // テーブルの主キーを取得 $keys = $connection->keys($this->_T); // テーブルのインデックスを取得 $indexes = $connection->indexes($this->_T); // テーブルの設定をデータキャッシュに登録する。 $tableConfigure->import(array("options" => $options, "keys" => $keys)); } // カラム情報を設定 $this->_COLUMNS = array(); $this->_FIELDS = array(); foreach ($tableConfigure->options as $option) { $column = new Vizualizer_Plugin_Table_Column($this, $option); $field = $column->field; $this->_COLUMNS[] = $field; $this->_FIELDS[$field] = $column; } // 主キー情報を設定 $this->_PKEYS = array(); if (is_array($tableConfigure->keys)) { foreach ($tableConfigure->keys as $key) { $this->_PKEYS[] = $key; } } }