/** * Prepare Add INDEX command * * @param string $index * @param array $config * @param boolean $create * - optional use create table mode * @param Db_Object $object * @return string */ protected function _prepareIndex($index, array $config, $create = false) { if (isset($config['primary']) && $config['primary']) { if (!isset($config['columns'][0])) { trigger_error('Invalid index config'); } if ($create) { return "\n" . ' PRIMARY KEY (`' . $config['columns'][0] . '`)'; } else { return "\n" . ' ADD PRIMARY KEY (`' . $config['columns'][0] . '`)'; } } $createType = ''; /* * Set key length for text column index */ foreach ($config['columns'] as &$col) { if ($this->_objectConfig->isText($col)) { $col = '`' . $col . '`(32)'; } else { $col = '`' . $col . '`'; } } unset($col); $str = '`' . $index . '` (' . implode(',', $config['columns']) . ')'; if (isset($config['unique']) && $config['unique']) { $createType = $indexType = 'UNIQUE'; } elseif (isset($config['fulltext']) && $config['fulltext']) { $createType = $indexType = 'FULLTEXT'; } else { $indexType = 'INDEX'; } if ($create) { return "\n" . ' ' . $createType . ' KEY ' . $str; } else { return "\n" . ' ADD ' . $indexType . ' ' . $str; } }