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

MySQL8 対応 #174

Merged
merged 2 commits into from
Oct 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions data/class/db/dbfactory/SC_DB_DBFactory_MYSQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public function sfChangeMySQL($sql)
$sql = $this->sfChangeTrunc($sql);
// ARRAY_TO_STRINGをGROUP_CONCATに変換する
$sql = $this->sfChangeArrayToString($sql);

// rank に引用符をつける
$sql = $this->sfChangeReservedWords($sql);
return $sql;
}

Expand Down Expand Up @@ -342,6 +343,15 @@ public function sfGetCreateIndexDefinition($table, $name, $definition)
return $definition;
}

/**
* 予約語に引用符を付与する.
*/
public function sfChangeReservedWords($sql)
{
$changesql = preg_replace('/(^|[^\w])RANK([^\w]|$)/i', '$1`RANK`$2', $sql);
return $changesql;
}

/**
* 擬似表を表すSQL文(FROM 句)を取得する
*
Expand All @@ -360,7 +370,11 @@ public function getDummyFromClauseSql()
*/
public function initObjQuery(SC_Query &$objQuery)
{
$objQuery->exec('SET SESSION storage_engine = InnoDB');
if ($objQuery->conn->getConnection()->server_version >= 50705) {
$objQuery->exec('SET SESSION default_storage_engine = InnoDB');
} else {
$objQuery->exec('SET SESSION storage_engine = InnoDB');
}
$objQuery->exec("SET SESSION sql_mode = 'ANSI'");
}
}
13 changes: 11 additions & 2 deletions html/install/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -850,15 +850,24 @@ function lfExecuteSQL($filepath, $arrDsn, $disp_err = true)

// MySQL 用の初期化
// XXX SC_Query を使うようにすれば、この処理は不要となる
if ($arrDsn['phptype'] === 'mysql') {
$objDB->exec('SET SESSION storage_engine = InnoDB');
if ($arrDsn['phptype'] === 'mysqli') {
if ($objDB->getConnection()->server_version >= 50705) {
$objDB->exec('SET SESSION defaut_storage_engine = InnoDB');
} else {
$objDB->exec('SET SESSION storage_engine = InnoDB');
}
$objDB->exec("SET SESSION sql_mode = 'ANSI'");
}

$sql_split = explode(';', $sql);
foreach ($sql_split as $key => $val) {
SC_Utils::sfFlush(true);
if (trim($val) != '') {
if ($arrDsn['phptype'] === 'mysqli') {
// rank は予約語なので MySQL8 から引用符をつけないとエラーになる
$dbFactory = SC_DB_DBFactory_Ex::getInstance($arrDsn['phptype']);
$val = $dbFactory->sfChangeReservedWords($val);
}
$ret = $objDB->query($val);
if (PEAR::isError($ret) && $disp_err) {
$arrErr['all'] = '>> ' . $ret->message . '<br />';
Expand Down