Browse Source

Santize table names to prevent conllisions with MySQL reserved words. Fixes #25.

master
Tom Lingham 9 years ago
parent
commit
7c840af2f6
  1. 19
      src/SearchDrivers/BaseSearchDriver.php

19
src/SearchDrivers/BaseSearchDriver.php

@ -139,16 +139,31 @@ abstract class BaseSearchDriver implements SearchDriverInterface
foreach ($searchFields as $searchField) {
if (strpos($searchField, '::')) {
$concatString = str_replace('::', ", ' ', ", $searchField);
$concatString = implode(', ', array_map( [$this, 'sanitizeColumnName'] , explode('::', $searchField)));
$query[] = $this->buildSelectCriteria("CONCAT({$concatString})");
} else {
$query[] = $this->buildSelectCriteria($searchField);
$query[] = $this->buildSelectCriteria($this->sanitizeColumnName($searchField));
}
}
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
*

Loading…
Cancel
Save