Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Добавить в модуль БД метод получения списка индексов таблицы #112

Open
psnet opened this issue Apr 21, 2015 · 2 comments

Comments

@psnet
Copy link

psnet commented Apr 21, 2015

Добавить метод GetIndexExists($sTable, $sIndexName) для проверки есть ли указанный индекс в таблице.

@psnet
Copy link
Author

psnet commented Apr 21, 2015

UPD:

проверять по имени индекса, а не по имени столбца

@psnet
Copy link
Author

psnet commented May 26, 2015

    /**
     * Существует ли индекс у таблицы
     *
     * @param string $sTableName имя таблицы
     * @param string $sIndexName имя индекса
     * @param array  $aConfig
     * @return bool
     */
    protected function GetIndexExists($sTableName, $sIndexName, $aConfig = null) {
        $sTableName = str_replace('prefix_', Config::Get('db.table.prefix'), $sTableName);
        $sQuery = "SHOW INDEX FROM `{$sTableName}`";
        if ($aRows = $this->GetConnect($aConfig)->select($sQuery)) {
            foreach ($aRows as $aRow) {
                if ($aRow['Key_name'] == $sIndexName) {
                    return true;
                }
            }
        }
        return false;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant