mirror of
https://github.com/processwire/processwire.git
synced 2025-08-12 01:34:31 +02:00
Minor improvements to WireDatabasePDO. Make requests for ft_min_word_len use InnoDB equivalent when InnoDB engine is active.
This commit is contained in:
@@ -73,6 +73,36 @@ class WireDatabasePDO extends Wire implements WireDatabase {
|
|||||||
*/
|
*/
|
||||||
protected $stripMB4 = false;
|
protected $stripMB4 = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lowercase value of $config->dbEngine
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected $engine = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lowercase value of $config->dbCharset
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected $charset = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Substitute variable names according to engine as used by getVariable() method
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected $subVars = array(
|
||||||
|
'myisam' => array(),
|
||||||
|
'innodb' => array(
|
||||||
|
'ft_min_word_len' => 'innodb_ft_min_token_size',
|
||||||
|
'ft_max_word_len' => 'innodb_ft_max_token_size',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PDO connection settings
|
* PDO connection settings
|
||||||
*
|
*
|
||||||
@@ -177,8 +207,10 @@ class WireDatabasePDO extends Wire implements WireDatabase {
|
|||||||
public function _init() {
|
public function _init() {
|
||||||
if($this->init || !$this->isWired()) return;
|
if($this->init || !$this->isWired()) return;
|
||||||
$this->init = true;
|
$this->init = true;
|
||||||
$config = $this->wire('config');
|
$config = $this->wire()->config;
|
||||||
$this->stripMB4 = $config->dbStripMB4 && strtolower($config->dbEngine) != 'utf8mb4';
|
$this->stripMB4 = $config->dbStripMB4 && strtolower($config->dbEngine) != 'utf8mb4';
|
||||||
|
$this->engine = strtolower($config->dbEngine);
|
||||||
|
$this->charset = strtolower($config->dbCharset);
|
||||||
$this->queryLogMax = (int) $config->dbQueryLogMax;
|
$this->queryLogMax = (int) $config->dbQueryLogMax;
|
||||||
if($config->debug && $this->pdo) {
|
if($config->debug && $this->pdo) {
|
||||||
// custom PDO statement for debug mode
|
// custom PDO statement for debug mode
|
||||||
@@ -881,11 +913,13 @@ class WireDatabasePDO extends Wire implements WireDatabase {
|
|||||||
* #pw-group-custom
|
* #pw-group-custom
|
||||||
*
|
*
|
||||||
* @param string $name Name of MySQL variable you want to retrieve
|
* @param string $name Name of MySQL variable you want to retrieve
|
||||||
* @param bool $cache Allow use of cached values?
|
* @param bool $cache Allow use of cached values? (default=true)
|
||||||
|
* @param bool $sub Allow substitution of MyISAM variable names to InnoDB equivalents when InnoDB is engine? (default=true)
|
||||||
* @return string|int
|
* @return string|int
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function getVariable($name, $cache = true) {
|
public function getVariable($name, $cache = true, $sub = true) {
|
||||||
|
if($sub && isset($this->subVars[$this->engine][$name])) $name = $this->subVars[$this->engine][$name];
|
||||||
if($cache && isset($this->variableCache[$name])) return $this->variableCache[$name];
|
if($cache && isset($this->variableCache[$name])) return $this->variableCache[$name];
|
||||||
$query = $this->prepare('SHOW VARIABLES WHERE Variable_name=:name');
|
$query = $this->prepare('SHOW VARIABLES WHERE Variable_name=:name');
|
||||||
$query->bindValue(':name', $name);
|
$query->bindValue(':name', $name);
|
||||||
@@ -934,12 +968,9 @@ class WireDatabasePDO extends Wire implements WireDatabase {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function getMaxIndexLength() {
|
public function getMaxIndexLength() {
|
||||||
$config = $this->wire('config');
|
|
||||||
$engine = strtolower($config->dbEngine);
|
|
||||||
$charset = strtolower($config->dbCharset);
|
|
||||||
$max = 250;
|
$max = 250;
|
||||||
if($charset == 'utf8mb4') {
|
if($this->charset === 'utf8mb4') {
|
||||||
if($engine == 'innodb') {
|
if($this->engine === 'innodb') {
|
||||||
$max = 191;
|
$max = 191;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user