diff options
Diffstat (limited to 'lib/db')
-rw-r--r-- | lib/db/connection.php | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/lib/db/connection.php b/lib/db/connection.php index 7d56452678c..763251c1903 100644 --- a/lib/db/connection.php +++ b/lib/db/connection.php @@ -17,6 +17,9 @@ class Connection extends \Doctrine\DBAL\Connection { protected $adapter; + protected $preparedQueries = array(); + protected $cachingQueryStatementEnabled = true; + /** * Initializes a new instance of the Connection class. * @@ -47,9 +50,19 @@ class Connection extends \Doctrine\DBAL\Connection { */ public function prepare( $statement, $limit=null, $offset=null ) { $statement = $this->replaceTablePrefix($statement); - // TODO: limit & offset - // TODO: prepared statement cache - return parent::prepare($statement); + if (!is_null($limit) && $limit != -1) { + // TODO: limit & offset + } else { + if (isset($this->preparedQueries[$statement]) && $this->cachingQueryStatementEnabled) { + return $this->preparedQueries[$statement]; + } + } + $rawQuery = $statement; + $result = parent::prepare($statement); + if ((is_null($limit) || $limit == -1) && $this->cachingQueryStatementEnabled) { + $this->preparedQueries[$rawQuery] = $result; + } + return $result; } /** @@ -120,4 +133,13 @@ class Connection extends \Doctrine\DBAL\Connection { public function replaceTablePrefix($statement) { return str_replace( '*PREFIX*', $this->table_prefix, $statement ); } + + public function enableQueryStatementCaching() { + $this->cachingQueryStatementEnabled = true; + } + + public function disableQueryStatementCaching() { + $this->cachingQueryStatementEnabled = false; + $this->preparedQueries = array(); + } } |