/** @var bool Flag used to force rollback of all current transactions. */
private $force_rollback = false;
+ /** @var string MD5 of settings used for connection. Used by MUC as an identifier. */
+ private $settingshash;
+
/**
* @var int internal temporary variable used to fix params. Its used by {@link _fix_sql_params_dollar_callback()}.
*/
$this->dboptions = (array)$dboptions;
}
+ /**
+ * Returns a hash for the settings used during connection.
+ *
+ * If not already requested it is generated and stored in a private property.
+ *
+ * @return string
+ */
+ protected function get_settings_hash() {
+ if (empty($this->settingshash)) {
+ $this->settingshash = md5($this->dbhost . $this->dbuser . $this->prefix);
+ }
+ return $this->settingshash;
+ }
+
/**
* Attempt to create the database
* @param string $dbhost The database host.
public function reset_caches() {
$this->columns = array();
$this->tables = null;
+ // Purge MUC as well
+ $identifiers = array('dbfamily' => $this->get_dbfamily(), 'settings' => $this->get_settings_hash());
+ cache_helper::purge_by_definition('core', 'databasemeta', $identifiers);
}
/**
* @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;
+ }
}
- $this->columns[$table] = array();
+ $structure = array();
$sql = "SELECT column_name, data_type, character_maximum_length, numeric_precision,
numeric_scale, is_nullable, column_type, column_default, column_key, extra
// standard table exists
while ($rawcolumn = $result->fetch_assoc()) {
$info = (object)$this->get_column_info((object)$rawcolumn);
- $this->columns[$table][$info->name] = new database_column_info($info);
+ $structure[$info->name] = new database_column_info($info);
}
$result->close();
}
$info = $this->get_column_info($rawcolumn);
- $this->columns[$table][$info->name] = new database_column_info($info);
+ $structure[$info->name] = new database_column_info($info);
}
$result->close();
}
- return $this->columns[$table];
+ if ($usecache) {
+ $result = $cache->set($table, $structure);
+ }
+
+ return $structure;
}
/**
* @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;
+ }
}
- $this->columns[$table] = array();
+ $structure = array();
$tablename = $this->prefix.$table;
}
- $this->columns[$table][$info->name] = new database_column_info($info);
+ $structure[$info->name] = new database_column_info($info);
}
pg_free_result($result);
- return $this->columns[$table];
+ if ($usecache) {
+ $result = $cache->set($table, $structure);
+ }
+
+ return $structure;
}
/**