Minahito
minah****@users*****
2006年 8月 17日 (木) 12:44:25 JST
Index: xoops2jp/html/modules/base/admin/class/Legacy_SQLScanner.class.php diff -u xoops2jp/html/modules/base/admin/class/Legacy_SQLScanner.class.php:1.1.2.1 xoops2jp/html/modules/base/admin/class/Legacy_SQLScanner.class.php:1.1.2.2 --- xoops2jp/html/modules/base/admin/class/Legacy_SQLScanner.class.php:1.1.2.1 Mon Aug 14 10:58:52 2006 +++ xoops2jp/html/modules/base/admin/class/Legacy_SQLScanner.class.php Thu Aug 17 12:44:24 2006 @@ -1,43 +1,79 @@ -<?php - -require_once dirname(__FILE__) . "/EasyLex_SQLScanner.class.php"; - -class Legacy_SQLScanner extends EasyLex_SQLScanner -{ - var $mDB_PREFIX = ""; - - function setDB_PREFIX($prefix) - { - $this->mDB_PREFIX = $prefix; - } - - function &getOperations() - { - $ret =& parent::getOperations(); - - foreach ($ret as $op) { - if (count($op) >= 3) { - if ($op[0]->mType == EASYLEX_SQL_LETTER && strtoupper($op[0]->mValue) == 'CREATE' && - $op[1]->mType == EASYLEX_SQL_LETTER && strtoupper($op[1]->mValue) == 'TABLE' && - $op[2]->mType == EASYLEX_SQL_LETTER) { - $op[2]->mValue = $this->mDB_PREFIX . '_' . $op[2]->mValue; - } - if ($op[0]->mType == EASYLEX_SQL_LETTER && strtoupper($op[0]->mValue) == 'ALTER' && - $op[1]->mType == EASYLEX_SQL_LETTER && strtoupper($op[1]->mValue) == 'TABLE' && - $op[2]->mType == EASYLEX_SQL_LETTER) { - $op[2]->mValue = $this->mDB_PREFIX . '_' . $op[2]->mValue; - } - if ($op[0]->mType == EASYLEX_SQL_LETTER && strtoupper($op[0]->mValue) == 'INSERT' && - $op[1]->mType == EASYLEX_SQL_LETTER && strtoupper($op[1]->mValue) == 'INTO' && - $op[2]->mType == EASYLEX_SQL_LETTER) { - $op[2]->mValue = $this->mDB_PREFIX . '_' . $op[2]->mValue; - } - } - } - - return $ret; - } -} - - +<?php + +require_once dirname(__FILE__) . "/EasyLex_SQLScanner.class.php"; + +class Legacy_SQLScanner extends EasyLex_SQLScanner +{ + var $mDB_PREFIX = ""; + + function setDB_PREFIX($prefix) + { + $this->mDB_PREFIX = $prefix; + } + + /** + * Override. + */ + function &getOperations() + { + $t_lines = array(); + $t_tokens = array(); + $depth = 0; + + foreach (array_keys($this->mTokens) as $key) { + if ($this->mTokens[$key]->mType == EASYLEX_SQL_OPEN_PARENTHESIS) { + $depth++; + } + elseif ($this->mTokens[$key]->mType == EASYLEX_SQL_CLOSE_PARENTHESIS) { + $depth--; + } + + $t_tokens[] =& $this->mTokens[$key]; + + if (count($t_tokens) > 1 && $depth == 0) { + if ($this->mTokens[$key]->mType == EASYLEX_SQL_SEMICOLON) { + $t_lines[] =& $t_tokens; + unset($t_tokens); + $t_tokens = array(); + } + elseif ($this->mTokens[$key]->mValue =='CREATE' || $this->mTokens[$key]->mValue =='ALTER' || $this->mTokens[$key]->mValue =='INSERT') { + array_pop($t_tokens); + $t_lines[] =& $t_tokens; + unset($t_tokens); + $t_tokens = array(); + $t_tokens[] =& $this->mTokens[$key]; + } + } + } + + if (count($t_tokens) > 0) { + $t_lines[] =& $t_tokens; + unset($t_tokens); + } + + foreach ($t_lines as $op) { + if (count($op) >= 3) { + if ($op[0]->mType == EASYLEX_SQL_LETTER && strtoupper($op[0]->mValue) == 'CREATE' && + $op[1]->mType == EASYLEX_SQL_LETTER && strtoupper($op[1]->mValue) == 'TABLE' && + $op[2]->mType == EASYLEX_SQL_LETTER) { + $op[2]->mValue = $this->mDB_PREFIX . '_' . $op[2]->mValue; + } + if ($op[0]->mType == EASYLEX_SQL_LETTER && strtoupper($op[0]->mValue) == 'ALTER' && + $op[1]->mType == EASYLEX_SQL_LETTER && strtoupper($op[1]->mValue) == 'TABLE' && + $op[2]->mType == EASYLEX_SQL_LETTER) { + $op[2]->mValue = $this->mDB_PREFIX . '_' . $op[2]->mValue; + } + if ($op[0]->mType == EASYLEX_SQL_LETTER && strtoupper($op[0]->mValue) == 'INSERT' && + $op[1]->mType == EASYLEX_SQL_LETTER && strtoupper($op[1]->mValue) == 'INTO' && + $op[2]->mType == EASYLEX_SQL_LETTER) { + $op[2]->mValue = $this->mDB_PREFIX . '_' . $op[2]->mValue; + } + } + } + + return $t_lines; + } +} + + ?> \ No newline at end of file