コード例 #1
0
ファイル: Mysql.php プロジェクト: energylab/gacela
 public function loadConnection()
 {
     if (!$this->_conn) {
         parent::loadConnection();
         $this->_columns = \Gacela\Gacela::instance()->cacheMetaData($this->_config->schema . '_columns');
         if (!$this->_columns) {
             $sql = "SELECT *\n\t\t\t\t\t\tFROM information_schema.COLUMNS\n\t\t\t\t\t\tWHERE TABLE_SCHEMA = DATABASE()";
             $this->_columns = $this->query($sql)->fetchAll(\PDO::FETCH_OBJ);
             \Gacela\Gacela::instance()->cacheMetaData($this->_config->schema . '_columns', $this->_columns);
         }
     }
     // Moved out of __construct to allow for lazy loading of config data
     $this->_relationships = \Gacela\Gacela::instance()->cacheMetaData($this->_config->schema . '_relationships');
     if (!$this->_relationships) {
         $fk = 'fk' . static::$_separator . '%' . static::$_separator . '%';
         $sql = "\n\t\t\t\tSELECT\n\t\t\t\t\tTABLE_NAME AS keyTable,\n\t\t\t\t\tGROUP_CONCAT(COLUMN_NAME) AS keyColumns,\n\t\t\t\t\tREFERENCED_TABLE_NAME AS refTable,\n\t\t\t\t\tGROUP_CONCAT(REFERENCED_COLUMN_NAME) AS refColumns,\n\t\t\t\t\tCONSTRAINT_NAME AS constraintName\n\t\t\t\tFROM information_schema.key_column_usage\n\t\t\t\tWHERE TABLE_SCHEMA = DATABASE()\n\t\t\t\tAND CONSTRAINT_NAME LIKE '{$fk}'\n\t\t\t\tAND REFERENCED_TABLE_NAME IS NOT NULL\n\t\t\t\tGROUP BY constraintName\n\t\t\t\t";
         $this->_relationships = $this->query($sql)->fetchAll(\PDO::FETCH_OBJ);
         \Gacela\Gacela::instance()->cacheMetaData($this->_config->schema . '_relationships', $this->_relationships);
     }
 }