Commit 4295f599 authored by xjm's avatar xjm

Issue #2672088 by joelpittet, daffie, catch, dawehner, mikeytown2: Add static...

Issue #2672088 by joelpittet, daffie, catch, dawehner, mikeytown2: Add static cache to DatabaseConnection ::escapeDatabase(), ::escapeTable(), ::escapeField() and ::escapeAlias()
parent 6f7f400b
......@@ -140,6 +140,20 @@ abstract class Connection {
*/
protected $unprefixedTablesMap = [];
/**
* List of escaped database, table, and field names, keyed by unescaped names.
*
* @var array
*/
protected $escapedNames = [];
/**
* List of escaped aliases names, keyed by unescaped aliases.
*
* @var array
*/
protected $escapedAliases = [];
/**
* Constructs a Connection object.
*
......@@ -925,7 +939,10 @@ public function schema() {
* The sanitized database name.
*/
public function escapeDatabase($database) {
return preg_replace('/[^A-Za-z0-9_.]+/', '', $database);
if (!isset($this->escapedNames[$database])) {
$this->escapedNames[$database] = preg_replace('/[^A-Za-z0-9_.]+/', '', $database);
}
return $this->escapedNames[$database];
}
/**
......@@ -942,7 +959,10 @@ public function escapeDatabase($database) {
* The sanitized table name.
*/
public function escapeTable($table) {
return preg_replace('/[^A-Za-z0-9_.]+/', '', $table);
if (!isset($this->escapedNames[$table])) {
$this->escapedNames[$table] = preg_replace('/[^A-Za-z0-9_.]+/', '', $table);
}
return $this->escapedNames[$table];
}
/**
......@@ -959,7 +979,10 @@ public function escapeTable($table) {
* The sanitized field name.
*/
public function escapeField($field) {
return preg_replace('/[^A-Za-z0-9_.]+/', '', $field);
if (!isset($this->escapedNames[$field])) {
$this->escapedNames[$field] = preg_replace('/[^A-Za-z0-9_.]+/', '', $field);
}
return $this->escapedNames[$field];
}
/**
......@@ -977,7 +1000,10 @@ public function escapeField($field) {
* The sanitized alias name.
*/
public function escapeAlias($field) {
return preg_replace('/[^A-Za-z0-9_]+/', '', $field);
if (!isset($this->escapedAliases[$field])) {
$this->escapedAliases[$field] = preg_replace('/[^A-Za-z0-9_]+/', '', $field);
}
return $this->escapedAliases[$field];
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment