notify('<strong>' . get_string('error') . '</strong>');
}
- $this->mdb->reset_columns(); // Clear out the cache, just in case changes were made to table structures
-
return $result;
}
}
/// Get list of fields in table
- $this->mdb->reset_columns($tablename); // better reset before testing
- $columns = $this->mdb->get_columns($tablename);
+ $columns = $this->mdb->get_columns($tablename, false);
$exists = array_key_exists($fieldname, $columns);
$fieldname = $xmldb_field->getName();
/// Take a look to field metadata
- $this->mdb->reset_columns($tablename);
-
- $meta = $this->mdb->get_columns($tablename);
+ $meta = $this->mdb->get_columns($tablename, false);
$metac = $meta[$fieldname];
$oldmetatype = $metac->meta_type;
*/
public function getCheckConstraintsFromDB($xmldb_table, $xmldb_field = null) {
- global $db;
-
$tablename = $xmldb_table->getName($xmldb_table);
- $this->mdb->reset_columns($tablename);
-
/// Fetch all the columns in the table
- if (!$columns = $this->mdb->get_columns($tablename)) {
+ if (!$columns = $this->mdb->get_columns($tablename, false)) {
return array();
}
$fieldname = $xmldb_field->getName();
/// Take a look to field metadata
- $meta = $this->mdb->get_columns($xmldb_table->getName());
+ $meta = $this->mdb->get_columns($tablename, false);
$metac = $meta[$fieldname];
$oldmetatype = $metac->meta_type;
$fieldname = $xmldb_field->getName();
/// Take a look to field metadata
- $meta = $this->mdb->get_columns($xmldb_table->getName());
+ $meta = $this->mdb->get_columns($tablename, false);
$metac = $meta[$xmldb_field->getName()];
$oldmetatype = $metac->meta_type;
$oldlength = $metac->max_length;
}
+/**
+ * Returns a list of all site users
+ * Obsolete, just calls get_course_users(SITEID)
+ *
+ * @uses SITEID
+ * @deprecated Use {@link get_course_users()} instead.
+ * @param string $fields A comma separated list of fields to be returned from the chosen table.
+ * @return object|false {@link $USER} records or false if error.
+ */
+function get_site_users($sort='u.lastaccess DESC', $fields='*', $exceptions='') {
+
+ return get_course_users(SITEID, $sort, $exceptions, $fields);
+}
+
/**
* Returns an array of user objects
*
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
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];
}
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();
}
$result = false;
$this->report_error($sql);
}
+ // structure changed, reset columns cache
+ $this->reset_columns();
return $result;
}
// 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;
/**
* 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.
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) {
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];
}
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));
}
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);
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];
}
}
}
- $DB->reset_columns(); // Clear out the cache, just in case changes were made to table structures
-
if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++; };
$rs = $db->Execute($command);
+ $DB->reset_columns(); // Clear out the cache, just in case changes were made to table structures
+
$db->debug = $olddebug;
if ($rs) {