mirror of
https://github.com/e107inc/e107.git
synced 2025-08-01 20:30:39 +02:00
Fixed #2909 - SQL Index validation issue.
This commit is contained in:
@@ -447,7 +447,8 @@ class db_verify
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -926,29 +927,38 @@ class db_verify
|
|||||||
function getIndex($data, $print = false)
|
function getIndex($data, $print = false)
|
||||||
{
|
{
|
||||||
// $regex = "/(?:(PRIMARY|UNIQUE|FULLTEXT))?[\s]*?KEY (?: ?`?([\w]*)`?)[\s]* ?(?:\([\s]?`?([\w,]*[\s]?)`?\))?,?/i";
|
// $regex = "/(?:(PRIMARY|UNIQUE|FULLTEXT))?[\s]*?KEY (?: ?`?([\w]*)`?)[\s]* ?(?:\([\s]?`?([\w,]*[\s]?)`?\))?,?/i";
|
||||||
$regex = "/(?:(PRIMARY|UNIQUE|FULLTEXT))?[\s]*?KEY (?: ?`?([\w]*)`?)[\s]* ?(?:\([\s]?([\w\s,`]*[\s]?)`?\))?,?/i";
|
$regex = "/(?:(PRIMARY|UNIQUE|FULLTEXT|FOREIGN))?[\s]*?KEY (?: ?`?([\w]*)`?)[\s]* ?(?:\([\s]?([\w\s,`]*[\s]?)`?\))?,?/i";
|
||||||
preg_match_all($regex,$data,$m);
|
preg_match_all($regex,$data,$m);
|
||||||
|
|
||||||
$ret = array();
|
$ret = array();
|
||||||
|
|
||||||
if($print) var_dump($regex, $m);
|
if($print)
|
||||||
|
{
|
||||||
|
e107::getDebug()->log($m);
|
||||||
|
}
|
||||||
|
|
||||||
// Standard Detection Method.
|
// Standard Detection Method.
|
||||||
|
|
||||||
|
$fieldReplace = array("`"," ");
|
||||||
|
|
||||||
foreach($m[3] as $k=>$val)
|
foreach($m[3] as $k=>$val)
|
||||||
{
|
{
|
||||||
if(!$val) continue;
|
if(!$val) continue;
|
||||||
$val = str_replace("`","",$val);
|
$val = str_replace("`","",$val);
|
||||||
$ret[$val] = array(
|
|
||||||
|
$key = !empty($m[2][$k]) ? $m[2][$k] : $val;
|
||||||
|
|
||||||
|
$ret[$key] = array(
|
||||||
'type' => strtoupper($m[1][$k]),
|
'type' => strtoupper($m[1][$k]),
|
||||||
'keyname' => (vartrue($m[2][$k])) ? str_replace("`","",$m[2][$k]) : str_replace("`","",$m[3][$k]),
|
'keyname' => (!empty($m[2][$k])) ? str_replace("`","",$m[2][$k]) : str_replace("`","",$m[3][$k]),
|
||||||
'field' => str_replace("`","",$m[3][$k])
|
'field' => str_replace($fieldReplace,"",$m[3][$k])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Alternate Index detection method.
|
//Alternate Index detection method.
|
||||||
// eg. `table_id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
|
// eg. `table_id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
|
||||||
|
|
||||||
$regex = "/`?([\w]*)`? .*((?:AUTO_INCREMENT))\s?(PRIMARY|UNIQUE|FULLTEXT)\s?KEY\s?,/i";
|
$regex = "/`?([\w]*)`? .*((?:AUTO_INCREMENT))\s?(PRIMARY|UNIQUE|FULLTEXT|FOREIGN)\s?KEY\s?,/i";
|
||||||
preg_match_all($regex,$data,$m);
|
preg_match_all($regex,$data,$m);
|
||||||
|
|
||||||
foreach($m[1] as $k=>$val)
|
foreach($m[1] as $k=>$val)
|
||||||
@@ -958,10 +968,15 @@ class db_verify
|
|||||||
$ret[$val] = array(
|
$ret[$val] = array(
|
||||||
'type' => strtoupper($m[3][$k]),
|
'type' => strtoupper($m[3][$k]),
|
||||||
'keyname' => $m[1][$k],
|
'keyname' => $m[1][$k],
|
||||||
'field' => str_replace("`","",$m[1][$k])
|
'field' => str_replace($fieldReplace,"",$m[1][$k])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($print)
|
||||||
|
{
|
||||||
|
e107::getDebug()->log($ret);
|
||||||
|
}
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user