Santize table names to prevent conllisions with MySQL reserved words. Fixes #25.
This commit is contained in:
@ -30,6 +30,6 @@ class StudlyCaseMatcher extends BaseMatcher
|
|||||||
|
|
||||||
public function buildQueryString($column, $searchString)
|
public function buildQueryString($column, $searchString)
|
||||||
{
|
{
|
||||||
return "IF( CHAR_LENGTH( TRIM($column)) = CHAR_LENGTH( REPLACE( TRIM($column), ' ', '')) AND $column {$this->operator} '{$this->formatSearchString($searchString)}', {$this->multiplier}, 0)";
|
return "IF( CHAR_LENGTH( TRIM( $column )) = CHAR_LENGTH( REPLACE( TRIM( $column ), ' ', '')) AND $column {$this->operator} '{$this->formatSearchString($searchString)}', {$this->multiplier}, 0)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,16 +139,31 @@ abstract class BaseSearchDriver implements SearchDriverInterface
|
|||||||
|
|
||||||
foreach ($searchFields as $searchField) {
|
foreach ($searchFields as $searchField) {
|
||||||
if (strpos($searchField, '::')) {
|
if (strpos($searchField, '::')) {
|
||||||
$concatString = str_replace('::', ", ' ', ", $searchField);
|
|
||||||
|
$concatString = implode(', ', array_map( [$this, 'sanitizeColumnName'] , explode('::', $searchField)));
|
||||||
|
|
||||||
$query[] = $this->buildSelectCriteria("CONCAT({$concatString})");
|
$query[] = $this->buildSelectCriteria("CONCAT({$concatString})");
|
||||||
} else {
|
} else {
|
||||||
$query[] = $this->buildSelectCriteria($searchField);
|
$query[] = $this->buildSelectCriteria($this->sanitizeColumnName($searchField));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return \DB::raw(implode(' + ', $query).' AS '.$this->relevanceFieldName);
|
return \DB::raw( implode(' + ', $query) . ' AS ' . $this->relevanceFieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sanitize column names to prevent collisions with MySQL reserved words
|
||||||
|
*
|
||||||
|
* @param $name
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function sanitizeColumnName( $name ){
|
||||||
|
$name = trim($name, '` ');
|
||||||
|
return "`${name}`";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param null $searchField
|
* @param null $searchField
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user