Example #1
0
 protected function loadConstraintReferences($table, $schema)
 {
     parent::loadConstraintReferences($table, $schema);
     $p = $this->adapter->getPlatform();
     $isColumns = array(array('RC', 'TABLE_NAME'), array('RC', 'CONSTRAINT_NAME'), array('RC', 'UPDATE_RULE'), array('RC', 'DELETE_RULE'), array('KCU', 'REFERENCED_TABLE_SCHEMA'), array('KCU', 'REFERENCED_TABLE_NAME'), array('KCU', 'REFERENCED_COLUMN_NAME'));
     array_walk($isColumns, function (&$c) use($p) {
         $c = $p->quoteIdentifierChain($c);
     });
     $sql = 'SELECT ' . implode(', ', $isColumns) . 'FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLES')) . 'T' . ' INNER JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'REFERENTIAL_CONSTRAINTS')) . 'RC' . ' ON ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) . '  = ' . $p->quoteIdentifierChain(array('RC', 'CONSTRAINT_SCHEMA')) . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) . '  = ' . $p->quoteIdentifierChain(array('RC', 'TABLE_NAME')) . ' INNER JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'KEY_COLUMN_USAGE')) . 'KCU' . ' ON ' . $p->quoteIdentifierChain(array('RC', 'CONSTRAINT_SCHEMA')) . '  = ' . $p->quoteIdentifierChain(array('KCU', 'TABLE_SCHEMA')) . ' AND ' . $p->quoteIdentifierChain(array('RC', 'TABLE_NAME')) . '  = ' . $p->quoteIdentifierChain(array('KCU', 'TABLE_NAME')) . ' AND ' . $p->quoteIdentifierChain(array('RC', 'CONSTRAINT_NAME')) . '  = ' . $p->quoteIdentifierChain(array('KCU', 'CONSTRAINT_NAME')) . 'WHERE ' . $p->quoteIdentifierChain(array('T', 'TABLE_TYPE')) . ' IN (\'BASE TABLE\', \'VIEW\')';
     if ($schema != self::DEFAULT_SCHEMA) {
         $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) . ' = ' . $p->quoteTrustedValue($schema);
     } else {
         $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) . ' != \'INFORMATION_SCHEMA\'';
     }
     $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE);
     $data = array();
     foreach ($results->toArray() as $row) {
         $data[] = array_change_key_case($row, CASE_LOWER);
     }
     $this->data['constraint_references'][$schema] = $data;
 }