PMA\libraries\plugins\export\ExportSql::_makeCreateTableMSSQLCompatible PHP Метод

_makeCreateTableMSSQLCompatible() приватный Метод

Make a create table statement compatible with MSSQL
private _makeCreateTableMSSQLCompatible ( string $create_query ) : string
$create_query string MySQL create table statement
Результат string MSSQL compatible create table statement
    private function _makeCreateTableMSSQLCompatible($create_query)
    {
        // In MSSQL
        // 1. No 'IF NOT EXISTS' in CREATE TABLE
        // 2. DATE field doesn't exists, we will use DATETIME instead
        // 3. UNSIGNED attribute doesn't exist
        // 4. No length on INT, TINYINT, SMALLINT, BIGINT and no precision on
        //    FLOAT fields
        // 5. No KEY and INDEX inside CREATE TABLE
        // 6. DOUBLE field doesn't exists, we will use FLOAT instead
        $create_query = preg_replace("/^CREATE TABLE IF NOT EXISTS/", 'CREATE TABLE', $create_query);
        // first we need  to replace all lines ended with '" DATE ...,\n'
        // last preg_replace preserve us from situation with date text
        // inside DEFAULT field value
        $create_query = preg_replace("/\" date DEFAULT NULL(,)?\n/", '" datetime DEFAULT NULL$1' . "\n", $create_query);
        $create_query = preg_replace("/\" date NOT NULL(,)?\n/", '" datetime NOT NULL$1' . "\n", $create_query);
        $create_query = preg_replace('/" date NOT NULL DEFAULT \'([^\'])/', '" datetime NOT NULL DEFAULT \'$1', $create_query);
        // next we need to replace all lines ended with ') UNSIGNED ...,'
        // last preg_replace preserve us from situation with unsigned text
        // inside DEFAULT field value
        $create_query = preg_replace("/\\) unsigned NOT NULL(,)?\n/", ') NOT NULL$1' . "\n", $create_query);
        $create_query = preg_replace("/\\) unsigned DEFAULT NULL(,)?\n/", ') DEFAULT NULL$1' . "\n", $create_query);
        $create_query = preg_replace('/\\) unsigned NOT NULL DEFAULT \'([^\'])/', ') NOT NULL DEFAULT \'$1', $create_query);
        // we need to replace all lines ended with
        // '" INT|TINYINT([0-9]{1,}) ...,' last preg_replace preserve us
        // from situation with int([0-9]{1,}) text inside DEFAULT field
        // value
        $create_query = preg_replace('/" (int|tinyint|smallint|bigint)\\([0-9]+\\) DEFAULT NULL(,)?\\n/', '" $1 DEFAULT NULL$2' . "\n", $create_query);
        $create_query = preg_replace('/" (int|tinyint|smallint|bigint)\\([0-9]+\\) NOT NULL(,)?\\n/', '" $1 NOT NULL$2' . "\n", $create_query);
        $create_query = preg_replace('/" (int|tinyint|smallint|bigint)\\([0-9]+\\) NOT NULL DEFAULT \'([^\'])/', '" $1 NOT NULL DEFAULT \'$2', $create_query);
        // we need to replace all lines ended with
        // '" FLOAT|DOUBLE([0-9,]{1,}) ...,'
        // last preg_replace preserve us from situation with
        // float([0-9,]{1,}) text inside DEFAULT field value
        $create_query = preg_replace('/" (float|double)(\\([0-9]+,[0-9,]+\\))? DEFAULT NULL(,)?\\n/', '" float DEFAULT NULL$3' . "\n", $create_query);
        $create_query = preg_replace('/" (float|double)(\\([0-9,]+,[0-9,]+\\))? NOT NULL(,)?\\n/', '" float NOT NULL$3' . "\n", $create_query);
        $create_query = preg_replace('/" (float|double)(\\([0-9,]+,[0-9,]+\\))? NOT NULL DEFAULT \'([^\'])/', '" float NOT NULL DEFAULT \'$3', $create_query);
        // @todo remove indexes from CREATE TABLE
        return $create_query;
    }