1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-10 00:37:02 +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:
Ryan Cramer
2020-06-12 12:50:32 -04:00
parent 8239e0b11e
commit 602ac0e1a5

View File

@@ -73,6 +73,36 @@ class WireDatabasePDO extends Wire implements WireDatabase {
*/
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
*
@@ -82,7 +112,7 @@ class WireDatabasePDO extends Wire implements WireDatabase {
'user' => '',
'pass' => '',
'options' => '',
);
);
/**
* Cached values from getVariable method
@@ -177,8 +207,10 @@ class WireDatabasePDO extends Wire implements WireDatabase {
public function _init() {
if($this->init || !$this->isWired()) return;
$this->init = true;
$config = $this->wire('config');
$config = $this->wire()->config;
$this->stripMB4 = $config->dbStripMB4 && strtolower($config->dbEngine) != 'utf8mb4';
$this->engine = strtolower($config->dbEngine);
$this->charset = strtolower($config->dbCharset);
$this->queryLogMax = (int) $config->dbQueryLogMax;
if($config->debug && $this->pdo) {
// custom PDO statement for debug mode
@@ -881,11 +913,13 @@ class WireDatabasePDO extends Wire implements WireDatabase {
* #pw-group-custom
*
* @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
*
*/
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];
$query = $this->prepare('SHOW VARIABLES WHERE Variable_name=:name');
$query->bindValue(':name', $name);
@@ -934,12 +968,9 @@ class WireDatabasePDO extends Wire implements WireDatabase {
*
*/
public function getMaxIndexLength() {
$config = $this->wire('config');
$engine = strtolower($config->dbEngine);
$charset = strtolower($config->dbCharset);
$max = 250;
if($charset == 'utf8mb4') {
if($engine == 'innodb') {
if($this->charset === 'utf8mb4') {
if($this->engine === 'innodb') {
$max = 191;
}
}