Permalink
Browse files

MDL-39389 add databasemeta cache to pdo_sqlite

Done in a separate commit, coz this driver is not
truly supported, but considering it as a reference
for people developing drivers... it's better to
have it supporting the databasemeta cache.
  • Loading branch information...
1 parent 9043466 commit f33d4784fec1b1779f1028740fff423639c0f725 @stronk7 stronk7 committed Apr 28, 2013
Showing with 16 additions and 6 deletions.
  1. +16 −6 lib/dml/sqlite3_pdo_moodle_database.php
@@ -197,9 +197,17 @@ public function get_indexes($table) {
* @return array array of database_column_info objects indexed with column names
*/
public function get_columns($table, $usecache=true) {
- if ($usecache and isset($this->columns[$table])) {
- return $this->columns[$table];
+
+ if ($usecache) {
+ $properties = array('dbfamily' => $this->get_dbfamily(), 'settings' => $this->get_settings_hash());
+ $cache = cache::make('core', 'databasemeta', $properties);
+ if ($data = $cache->get($table)) {
+ return $data;
+ }
}
+
+ $structure = array();
+
// get table's CREATE TABLE command (we'll need it for autoincrement fields)
$sql = 'SELECT sql FROM sqlite_master WHERE type="table" AND tbl_name="'.$this->prefix.$table.'"';
if ($this->debug) {
@@ -211,7 +219,6 @@ public function get_columns($table, $usecache=true) {
}
$createsql = $createsql['sql'];
- $columns = array();
$sql = 'PRAGMA table_info("'. $this->prefix.$table.'")';
if ($this->debug) {
$this->debug_query($sql);
@@ -287,11 +294,14 @@ public function get_columns($table, $usecache=true) {
// trim extra quotes from text default values
$columninfo['default_value'] = substr($columninfo['default_value'], 1, -1);
}
- $columns[$columninfo['name']] = new database_column_info($columninfo);
+ $structure[$columninfo['name']] = new database_column_info($columninfo);
+ }
+
+ if ($usecache) {
+ $result = $cache->set($table, $structure);
}
- $this->columns[$table] = $columns;
- return $columns;
+ return $structure;
}
/**

0 comments on commit f33d478

Please sign in to comment.