mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-14974 improved columns caching implementation
This commit is contained in:
parent
aa07a81368
commit
a7544e377a
11 changed files with 36 additions and 44 deletions
|
@ -10,7 +10,6 @@ require_once($CFG->libdir.'/dml/adodb_moodle_recordset.php');
|
|||
abstract class adodb_moodle_database extends moodle_database {
|
||||
|
||||
protected $db;
|
||||
protected $columns = array(); // I wish we had a shared memory cache for this :-(
|
||||
|
||||
/**
|
||||
* Returns localised database type name
|
||||
|
@ -137,8 +136,8 @@ abstract class adodb_moodle_database extends moodle_database {
|
|||
return $indexes;
|
||||
}
|
||||
|
||||
public function get_columns($table) {
|
||||
if (isset($this->columns[$table])) {
|
||||
public function get_columns($table, $usecache=true) {
|
||||
if ($usecache and isset($this->columns[$table])) {
|
||||
return $this->columns[$table];
|
||||
}
|
||||
|
||||
|
@ -157,14 +156,6 @@ abstract class adodb_moodle_database extends moodle_database {
|
|||
return $this->columns[$table];
|
||||
}
|
||||
|
||||
public function reset_columns($table=null) {
|
||||
if ($table) {
|
||||
unset($this->columns[$table]);
|
||||
} else {
|
||||
$this->columns[$table] = array();
|
||||
}
|
||||
}
|
||||
|
||||
public function get_last_error() {
|
||||
return $this->db->ErrorMsg();
|
||||
}
|
||||
|
@ -206,6 +197,8 @@ abstract class adodb_moodle_database extends moodle_database {
|
|||
$result = false;
|
||||
$this->report_error($sql);
|
||||
}
|
||||
// structure changed, reset columns cache
|
||||
$this->reset_columns();
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@ abstract class moodle_database {
|
|||
// manipulates the db structure
|
||||
protected $database_manager;
|
||||
|
||||
protected $columns = array(); // I wish we had a shared memory cache for this :-(
|
||||
|
||||
// db connection options
|
||||
protected $dbhost;
|
||||
protected $dbuser;
|
||||
|
@ -319,16 +321,19 @@ abstract class moodle_database {
|
|||
/**
|
||||
* Returns datailed information about columns in table. This information is cached internally.
|
||||
* @param string $table name
|
||||
* @param bool $usecache
|
||||
* @return array array of database_column_info objects indexed with column names
|
||||
*/
|
||||
public abstract function get_columns($table);
|
||||
public abstract function get_columns($table, $usecache=true);
|
||||
|
||||
/**
|
||||
* Reset internal column details cache
|
||||
* @param string $table - empty means all, or one if name of table given
|
||||
* @return void
|
||||
*/
|
||||
public abstract function reset_columns($table=null);
|
||||
public function reset_columns() {
|
||||
$this->columns[] = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns sql generator used for db manipulation.
|
||||
|
|
|
@ -10,7 +10,6 @@ require_once($CFG->libdir.'/dml/pdo_moodle_recordset.php');
|
|||
abstract class pdo_moodle_database extends moodle_database {
|
||||
|
||||
protected $pdb;
|
||||
protected $columns = array(); // I wish we had a shared memory cache for this :-(
|
||||
|
||||
//TODO: This looks incorrect now IMO. Construct should have only external and connect get all the rest of params
|
||||
public function __construct($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null, $external=false) {
|
||||
|
@ -31,8 +30,8 @@ abstract class pdo_moodle_database extends moodle_database {
|
|||
protected function configure_dbconnection() {
|
||||
}
|
||||
|
||||
public function get_columns($table) {
|
||||
if (isset($this->columns[$table])) {
|
||||
public function get_columns($table, $usecache=true) {
|
||||
if ($usecache and isset($this->columns[$table])) {
|
||||
return $this->columns[$table];
|
||||
}
|
||||
|
||||
|
@ -43,15 +42,6 @@ abstract class pdo_moodle_database extends moodle_database {
|
|||
return $this->columns[$table];
|
||||
}
|
||||
|
||||
public function reset_columns($table=null) {
|
||||
if ($table) {
|
||||
unset($this->columns[$table]);
|
||||
} else {
|
||||
$this->columns[$table] = array();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function report_error($sql, $params, $obj) {
|
||||
debugging($e->getMessage() .'<br /><br />'. s($sql));
|
||||
}
|
||||
|
@ -66,7 +56,6 @@ abstract class pdo_moodle_database extends moodle_database {
|
|||
|
||||
public function execute($sql, array $params=null) {
|
||||
try {
|
||||
//$this->reset_columns(); // TODO: do we need to clean the cache here??
|
||||
list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
|
||||
$sth = $this->dbh->prepare($sql);
|
||||
return $sth->execute($params);
|
||||
|
|
|
@ -100,8 +100,8 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
|
|||
return SQL_PARAMS_QM;
|
||||
}
|
||||
|
||||
public function get_columns($table) {
|
||||
if (isset($this->columns[$table])) {
|
||||
public function get_columns($table, $usecache=true) {
|
||||
if ($usecache and isset($this->columns[$table])) {
|
||||
return $this->columns[$table];
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue