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.
This commit is contained in:
Eloy Lafuente (stronk7) 2013-04-28 18:14:17 +02:00
parent 9043466103
commit f33d4784fe

View File

@ -197,9 +197,17 @@ class sqlite3_pdo_moodle_database extends pdo_moodle_database {
* @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 @@ class sqlite3_pdo_moodle_database extends pdo_moodle_database {
}
$createsql = $createsql['sql'];
$columns = array();
$sql = 'PRAGMA table_info("'. $this->prefix.$table.'")';
if ($this->debug) {
$this->debug_query($sql);
@ -287,11 +294,14 @@ class sqlite3_pdo_moodle_database extends pdo_moodle_database {
// 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);
}
$this->columns[$table] = $columns;
return $columns;
if ($usecache) {
$result = $cache->set($table, $structure);
}
return $structure;
}
/**