1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-16 20:41:27 +02:00

toMySQL() added keyname to index if available

getIndex() now supports also the INDEX keyword
This commit is contained in:
Achim Ennenbach
2018-06-15 19:05:15 +02:00
parent eeaa9b22a8
commit e1920c740a

View File

@@ -641,7 +641,10 @@ class db_verify
// print_a($data); // print_a($data);
if($data['type']) if($data['type'])
{ {
return $data['type']." (".$data['field'].");"; //return $data['type']." (".$data['field'].");";
// Check if index keyname exists and add backticks
$keyname = (!empty($data['keyname']) ? " `".$data['keyname']."`" : "");
return $data['type'] . $keyname . " (" . $data['field'] . ");";
} }
else else
{ {
@@ -919,9 +922,15 @@ 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|FOREIGN))?[\s]*?KEY (?: ?`?([\w]*)`?)[\s]* ?(?:\([\s]?([\w\s,`]*[\s]?)`?\))?,?/i"; // $regex = "/(?:(PRIMARY|UNIQUE|FULLTEXT|FOREIGN))?[\s]*?KEY (?: ?`?([\w]*)`?)[\s]* ?(?:\([\s]?([\w\s,`]*[\s]?)`?\))?,?/i";
$regex = "/(?:(PRIMARY|UNIQUE|FULLTEXT|FOREIGN))?[\s]*?(INDEX|KEY) (?: ?`?([\w]*)`?)[\s]* ?(?:\([\s]?([\w\s,`]*[\s]?)`?\))?,?/i";
preg_match_all($regex,$data,$m); preg_match_all($regex,$data,$m);
if (count($m) > 0)
{
unset($m[2]);
$m = array_combine(range(0, count($m)-1), array_values($m));
}
$ret = array(); $ret = array();
if($print) if($print)
@@ -933,6 +942,7 @@ class db_verify
$fieldReplace = array("`"," "); $fieldReplace = array("`"," ");
foreach($m[3] as $k=>$val) foreach($m[3] as $k=>$val)
{ {
if(!$val) continue; if(!$val) continue;