/** * Retrieve table indexes definition array for create table * * @param Varien_Db_Ddl_Table $table * @return array */ protected function _getIndexesDefinition(Varien_Db_Ddl_Table $table) { $definition = array(); $indexes = $table->getIndexes(); if (!empty($indexes)) { foreach ($indexes as $indexData) { if ($indexData['UNIQUE']) { $indexType = 'UNIQUE'; } else { if (!empty($indexData['TYPE'])) { $indexType = $indexData['TYPE']; } else { $indexType = 'KEY'; } } $columns = array(); foreach ($indexData['COLUMNS'] as $columnData) { $column = $this->quoteIdentifier($columnData['NAME']); if (!empty($columnData['SIZE'])) { $column .= sprintf('(%d)', $columnData['SIZE']); } $columns[] = $column; } $definition[] = sprintf(' %s %s (%s)', $indexType, $this->quoteIdentifier($indexData['INDEX_NAME']), join(', ', $columns)); } } return $definition; }
/** * Retrieve table indexes definition array for create table * * @param Varien_Db_Ddl_Table $table * @return array */ protected function _getIndexesDefinition(Varien_Db_Ddl_Table $table) { $definition = array(); $indexes = $table->getIndexes(); if (!empty($indexes)) { foreach ($indexes as $indexData) { if (!empty($indexData['TYPE'])) { switch ($indexData['TYPE']) { case 'primary': $indexType = 'PRIMARY KEY'; unset($indexData['INDEX_NAME']); break; default: $indexType = strtoupper($indexData['TYPE']); break; } } else { $indexType = 'KEY'; } $columns = array(); foreach ($indexData['COLUMNS'] as $columnData) { $column = $this->quoteIdentifier($columnData['NAME']); if (!empty($columnData['SIZE'])) { $column .= sprintf('(%d)', $columnData['SIZE']); } $columns[] = $column; } $indexName = isset($indexData['INDEX_NAME']) ? $this->quoteIdentifier($indexData['INDEX_NAME']) : ''; $definition[] = sprintf(' %s %s (%s)', $indexType, $indexName, implode(', ', $columns)); } } return $definition; }
/** * Retrieve table indexes definition array for create table * * @param Varien_Db_Ddl_Table $table * @return array */ protected function _getIndexesDefinition(Varien_Db_Ddl_Table $table) { $definition = array(); $indexes = $table->getIndexes(); if (!empty($indexes)) { foreach ($indexes as $indexData) { if (!empty($indexData['TYPE'])) { switch ($indexData['TYPE']) { case 'primary': $indexType = 'PRIMARY KEY'; unset($indexData['INDEX_NAME']); break; default: $indexType = strtoupper($indexData['TYPE']); break; } } else { $indexType = 'KEY'; } $columns = array(); $columnsDefinition = $table->getColumns(); foreach ($indexData['COLUMNS'] as $columnData) { $columnCode = strtoupper($columnData['NAME']); $column = $this->quoteIdentifier($columnData['NAME']); if (!empty($columnData['SIZE'])) { $column .= sprintf('(%d)', $columnData['SIZE']); } else { if (isset($columnsDefinition[$columnCode]['DATA_TYPE']) && in_array($columnsDefinition[$columnCode]['DATA_TYPE'], array(Varien_Db_Ddl_Table::TYPE_BLOB, Varien_Db_Ddl_Table::TYPE_TEXT))) { if (!empty($columnsDefinition[$columnCode]['LENGTH']) && is_numeric($columnsDefinition[$columnCode]['LENGTH'])) { $column .= "({$columnsDefinition[$columnCode]['LENGTH']})"; } else { $column .= '(255)'; } } } $columns[] = $column; } $indexName = isset($indexData['INDEX_NAME']) ? $this->quoteIdentifier($indexData['INDEX_NAME']) : ''; $definition[] = sprintf(' %s %s (%s)', $indexType, $indexName, implode(', ', $columns)); } } return $definition; }