mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #3328 from tractorcow/pulls/3.2/fix-mysql-segfaults
BUG Remove caching of statements due to risk of instability
This commit is contained in:
commit
7c4294b782
@ -38,47 +38,20 @@ class MySQLiConnector extends DBConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of prepared statements, cached by SQL string
|
* Retrieve a prepared statement for a given SQL string
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $cachedStatements = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Flush all prepared statements
|
|
||||||
*/
|
|
||||||
public function flushStatements() {
|
|
||||||
$this->cachedStatements = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve a prepared statement for a given SQL string, or return an already prepared version if
|
|
||||||
* one exists for the given query
|
|
||||||
*
|
*
|
||||||
* @param string $sql
|
* @param string $sql
|
||||||
* @param boolean &$success
|
* @param boolean &$success
|
||||||
* @return mysqli_stmt
|
* @return mysqli_stmt
|
||||||
*/
|
*/
|
||||||
public function getOrPrepareStatement($sql, &$success) {
|
public function prepareStatement($sql, &$success) {
|
||||||
// Check for cached statement
|
|
||||||
if(!empty($this->cachedStatements[$sql])) {
|
|
||||||
$success = true;
|
|
||||||
return $this->cachedStatements[$sql];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepare statement with arguments
|
// Prepare statement with arguments
|
||||||
$statement = $this->dbConn->stmt_init();
|
$statement = $this->dbConn->stmt_init();
|
||||||
if($success = $statement->prepare($sql)) {
|
$success = $statement->prepare($sql);
|
||||||
// Only cache prepared statement on success
|
|
||||||
$this->cachedStatements[$sql] = $statement;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $statement;
|
return $statement;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function connect($parameters, $selectDB = false) {
|
public function connect($parameters, $selectDB = false) {
|
||||||
$this->flushStatements();
|
|
||||||
|
|
||||||
// Normally $selectDB is set to false by the MySQLDatabase controller, as per convention
|
// Normally $selectDB is set to false by the MySQLDatabase controller, as per convention
|
||||||
$selectedDB = ($selectDB && !empty($parameters['database'])) ? $parameters['database'] : null;
|
$selectedDB = ($selectDB && !empty($parameters['database'])) ? $parameters['database'] : null;
|
||||||
|
|
||||||
@ -248,7 +221,7 @@ class MySQLiConnector extends DBConnector {
|
|||||||
$self = $this;
|
$self = $this;
|
||||||
$lastStatement = $this->benchmarkQuery($sql, function($sql) use($parsedParameters, $blobs, $self) {
|
$lastStatement = $this->benchmarkQuery($sql, function($sql) use($parsedParameters, $blobs, $self) {
|
||||||
|
|
||||||
$statement = $self->getOrPrepareStatement($sql, $success);
|
$statement = $self->prepareStatement($sql, $success);
|
||||||
if(!$success) return $statement;
|
if(!$success) return $statement;
|
||||||
|
|
||||||
$self->bindParameters($statement, $parsedParameters);
|
$self->bindParameters($statement, $parsedParameters);
|
||||||
|
Loading…
Reference in New Issue
Block a user