MDL-15094 protected adodb used instead of protected db - we will be able to search for obsoleted $db easier now

This commit is contained in:
skodak 2008-06-15 11:41:02 +00:00
parent 1aef51b8e3
commit 6db04f1124
5 changed files with 76 additions and 76 deletions

View File

@ -9,7 +9,7 @@ require_once($CFG->libdir.'/dml/adodb_moodle_recordset.php');
*/
abstract class adodb_moodle_database extends moodle_database {
protected $db;
protected $adodb;
/**
* Returns localised database type name
@ -59,18 +59,18 @@ abstract class adodb_moodle_database extends moodle_database {
require_once($CFG->libdir.'/adodb/adodb.inc.php');
$this->db = ADONewConnection($this->get_dbtype());
$this->adodb = ADONewConnection($this->get_dbtype());
// See MDL-6760 for why this is necessary. In Moodle 1.8, once we start using NULLs properly,
// we probably want to change this value to ''.
$this->db->null2null = 'A long random string that will never, ever match something we want to insert into the database, I hope. \'';
$this->adodb->null2null = 'A long random string that will never, ever match something we want to insert into the database, I hope. \'';
if (!isset($this->dbpersist) or !empty($this->dbpersist)) { // Use persistent connection (default)
if (!$this->db->PConnect($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname)) {
if (!$this->adodb->PConnect($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname)) {
return false;
}
} else { // Use single connection
if (!$this->db->Connect($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname)) {
if (!$this->adodb->Connect($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname)) {
return false;
}
}
@ -89,8 +89,8 @@ abstract class adodb_moodle_database extends moodle_database {
* Do NOT use connect() again, create a new instance if needed.
*/
public function dispose() {
if ($this->db) {
$this->db->Close();
if ($this->adodb) {
$this->adodb->Close();
}
parent::dispose();
}
@ -101,7 +101,7 @@ abstract class adodb_moodle_database extends moodle_database {
* @return array
*/
public function get_server_info() {
return $this->db->ServerInfo();
return $this->adodb->ServerInfo();
}
/**
@ -109,7 +109,7 @@ abstract class adodb_moodle_database extends moodle_database {
* @return array of table names in lowercase and without prefix
*/
public function get_tables() {
$metatables = $this->db->MetaTables();
$metatables = $this->adodb->MetaTables();
$tables = array();
foreach ($metatables as $table) {
$table = strtolower($table);
@ -126,7 +126,7 @@ abstract class adodb_moodle_database extends moodle_database {
* @return array of arrays
*/
public function get_indexes($table) {
if (!$indexes = $this->db->MetaIndexes($this->prefix.$table)) {
if (!$indexes = $this->adodb->MetaIndexes($this->prefix.$table)) {
return array();
}
$indexes = array_change_key_case($indexes, CASE_LOWER);
@ -145,7 +145,7 @@ abstract class adodb_moodle_database extends moodle_database {
return $this->columns[$table];
}
if (!$columns = $this->db->MetaColumns($this->prefix.$table)) {
if (!$columns = $this->adodb->MetaColumns($this->prefix.$table)) {
return array();
}
@ -153,7 +153,7 @@ abstract class adodb_moodle_database extends moodle_database {
foreach ($columns as $column) {
// colum names must be lowercase
$column->meta_type = substr($this->db->MetaType($column), 0 ,1); // only 1 character
$column->meta_type = substr($this->adodb->MetaType($column), 0 ,1); // only 1 character
if (!empty($column->enums)) {
// hack: fix the 'quotes' surrounding the values itroduced by adodb
foreach ($column->enums as $key=>$value) {
@ -169,7 +169,7 @@ abstract class adodb_moodle_database extends moodle_database {
}
public function get_last_error() {
return $this->db->ErrorMsg();
return $this->adodb->ErrorMsg();
}
/**
@ -177,7 +177,7 @@ abstract class adodb_moodle_database extends moodle_database {
* @param bool $state
*/
public function set_debug($state) {
$this->db->debug = $state;
$this->adodb->debug = $state;
}
/**
@ -185,7 +185,7 @@ abstract class adodb_moodle_database extends moodle_database {
* @return bool $state
*/
public function get_debug() {
return $this->db->debug;
return $this->adodb->debug;
}
/**
@ -203,7 +203,7 @@ abstract class adodb_moodle_database extends moodle_database {
* @return bool success
*/
public function change_database_structure($sql) {
if ($rs = $this->db->Execute($sql)) {
if ($rs = $this->adodb->Execute($sql)) {
$result = true;
} else {
$result = false;
@ -230,7 +230,7 @@ abstract class adodb_moodle_database extends moodle_database {
return false;
}
if ($rs = $this->db->Execute($sql, $params)) {
if ($rs = $this->adodb->Execute($sql, $params)) {
$result = true;
$rs->Close();
} else {
@ -265,14 +265,14 @@ abstract class adodb_moodle_database extends moodle_database {
$sql = "INSERT INTO {$this->prefix}$table ($fields) VALUES($qms)";
if (!$rs = $this->db->Execute($sql, $params)) {
if (!$rs = $this->adodb->Execute($sql, $params)) {
$this->report_error($sql, $params);
return false;
}
if (!$returnid) {
return true;
}
if ($id = $this->db->Insert_ID()) {
if ($id = $this->adodb->Insert_ID()) {
return (int)$id;
}
return false;
@ -309,7 +309,7 @@ abstract class adodb_moodle_database extends moodle_database {
$sets = implode(',', $sets);
$sql = "UPDATE {$this->prefix}$table SET $sets WHERE id=?";
if (!$rs = $this->db->Execute($sql, $params)) {
if (!$rs = $this->adodb->Execute($sql, $params)) {
$this->report_error($sql, $params);
return false;
}
@ -333,7 +333,7 @@ abstract class adodb_moodle_database extends moodle_database {
list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
$result = false;
if ($rs = $this->db->Execute($sql, $params)) {
if ($rs = $this->adodb->Execute($sql, $params)) {
$result = true;
$rs->Close();
} else {
@ -363,9 +363,9 @@ abstract class adodb_moodle_database extends moodle_database {
///Special case, 0 must be -1 for ADOdb
$limitfrom = empty($limitfrom) ? -1 : $limitfrom;
$limitnum = empty($limitnum) ? -1 : $limitnum;
$rs = $this->db->SelectLimit($sql, $limitnum, $limitfrom, $params);
$rs = $this->adodb->SelectLimit($sql, $limitnum, $limitfrom, $params);
} else {
$rs = $this->db->Execute($sql, $params);
$rs = $this->adodb->Execute($sql, $params);
}
if (!$rs) {
$this->report_error($sql, $params);
@ -398,9 +398,9 @@ abstract class adodb_moodle_database extends moodle_database {
///Special case, 0 must be -1 for ADOdb
$limitfrom = empty($limitfrom) ? -1 : $limitfrom;
$limitnum = empty($limitnum) ? -1 : $limitnum;
$rs = $this->db->SelectLimit($sql, $limitnum, $limitfrom, $params);
$rs = $this->adodb->SelectLimit($sql, $limitnum, $limitfrom, $params);
} else {
$rs = $this->db->Execute($sql, $params);
$rs = $this->adodb->Execute($sql, $params);
}
if (!$rs) {
$this->report_error($sql, $params);
@ -420,7 +420,7 @@ abstract class adodb_moodle_database extends moodle_database {
*/
public function get_fieldset_sql($sql, array $params=null) {
list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
if (!$rs = $this->db->Execute($sql, $params)) {
if (!$rs = $this->adodb->Execute($sql, $params)) {
$this->report_error($sql, $params);
return false;
}
@ -473,12 +473,12 @@ abstract class adodb_moodle_database extends moodle_database {
}
public function sql_substr() {
return $this->db->substr;
return $this->adodb->substr;
}
public function sql_concat() {
$args = func_get_args();
return call_user_func_array(array($this->db, 'Concat'), $args);
return call_user_func_array(array($this->adodb, 'Concat'), $args);
}
public function sql_concat_join($separator="' '", $elements=array()) {
@ -489,21 +489,21 @@ abstract class adodb_moodle_database extends moodle_database {
for ($n=count($elements)-1; $n > 0 ; $n--) {
array_splice($elements, $n, 0, $separator);
}
return call_user_func_array(array($this->db, 'Concat'), $elements);
return call_user_func_array(array($this->adodb, 'Concat'), $elements);
}
public function begin_sql() {
$this->db->BeginTrans();
$this->adodb->BeginTrans();
return true;
}
public function commit_sql() {
$this->db->CommitTrans();
$this->adodb->CommitTrans();
return true;
}
public function rollback_sql() {
$this->db->RollbackTrans();
$this->adodb->RollbackTrans();
return true;
}
@ -525,7 +525,7 @@ abstract class adodb_moodle_database extends moodle_database {
} else if (is_numeric($param)) {
$return .= $param;
} else {
$param = $this->db->qstr($param);
$param = $this->adodb->qstr($param);
$return .= "$param";
}
$return .= strtok('?');

View File

@ -40,14 +40,14 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
}
protected function configure_dbconnection() {
$this->db->SetFetchMode(ADODB_FETCH_ASSOC);
$this->adodb->SetFetchMode(ADODB_FETCH_ASSOC);
/// No need to set charset. It must be specified in the driver conf
/// Allow quoted identifiers
$this->db->Execute('SET QUOTED_IDENTIFIER ON');
$this->adodb->Execute('SET QUOTED_IDENTIFIER ON');
/// Force ANSI nulls so the NULL check was done by IS NULL and NOT IS NULL
/// instead of equal(=) and distinct(<>) simbols
$this->db->Execute('SET ANSI_NULLS ON');
$this->adodb->Execute('SET ANSI_NULLS ON');
return true;
}
@ -192,7 +192,7 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
}
foreach ($blobs as $key=>$value) {
if (!$this->db->UpdateBlob($this->prefix.$table, $key, $value, "id = {$dataobject->id}")) {
if (!$this->adodb->UpdateBlob($this->prefix.$table, $key, $value, "id = {$dataobject->id}")) {
return false;
}
}
@ -223,7 +223,7 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
if ($column->meta_type == 'B') { /// If the column is a BLOB (IMAGE)
/// Update BLOB column and return
$select = $this->emulate_bound_params($select, $params); // adodb does not use bound parameters for blob updates :-(
return $this->db->UpdateBlob($this->prefix.$table, $newfield, $newvalue, $select);
return $this->adodb->UpdateBlob($this->prefix.$table, $newfield, $newvalue, $select);
}
/// Arrived here, normal update (without BLOBs)
@ -243,7 +243,7 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
}
$sql = "UPDATE {$this->prefix}$table SET $newfield WHERE $select";
if (!$rs = $this->db->Execute($sql, $params)) {
if (!$rs = $this->adodb->Execute($sql, $params)) {
$this->report_error($sql, $params);
return false;
}
@ -309,7 +309,7 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
foreach ($blobs as $key=>$value) {
if (!$this->db->UpdateBlob($this->prefix.$table, $key, $value, "id = $id")) {
if (!$this->adodb->UpdateBlob($this->prefix.$table, $key, $value, "id = $id")) {
return false;
}
}

View File

@ -19,10 +19,10 @@ class mysqli_adodb_moodle_database extends adodb_moodle_database {
* @return bool success
*/
public function create_database($dbhost, $dbuser, $dbpass, $dbname) {
$this->db->database = ''; // reset database name cached by ADODB. Trick from MDL-9609
if ($this->db->Connect($dbhost, $dbuser, $dbpass)) { /// Try to connect without DB
if ($this->db->Execute("CREATE DATABASE $dbname DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci")) {
$this->db->Disconnect();
$this->adodb->database = ''; // reset database name cached by ADODB. Trick from MDL-9609
if ($this->adodb->Connect($dbhost, $dbuser, $dbpass)) { /// Try to connect without DB
if ($this->adodb->Execute("CREATE DATABASE $dbname DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci")) {
$this->adodb->Disconnect();
return true;
} else {
return false;
@ -49,8 +49,8 @@ class mysqli_adodb_moodle_database extends adodb_moodle_database {
}
protected function configure_dbconnection() {
$this->db->SetFetchMode(ADODB_FETCH_ASSOC);
$this->db->Execute("SET NAMES 'utf8'");
$this->adodb->SetFetchMode(ADODB_FETCH_ASSOC);
$this->adodb->Execute("SET NAMES 'utf8'");
return true;
}
@ -94,7 +94,7 @@ class mysqli_adodb_moodle_database extends adodb_moodle_database {
* @return bool true if db in unicode mode
*/
function setup_is_unicodedb() {
$rs = $this->db->Execute("SHOW LOCAL VARIABLES LIKE 'character_set_database'");
$rs = $this->adodb->Execute("SHOW LOCAL VARIABLES LIKE 'character_set_database'");
if ($rs && !$rs->EOF) {
$records = $rs->GetAssoc(true);
$encoding = $records['character_set_database']['Value'];
@ -111,9 +111,9 @@ class mysqli_adodb_moodle_database extends adodb_moodle_database {
*/
public function change_db_encoding() {
// try forcing utf8 collation, if mysql db and no tables present
if (!$this->db->Metatables()) {
if (!$this->adodb->Metatables()) {
$SQL = 'ALTER DATABASE '.$this->dbname.' CHARACTER SET utf8';
$this->db->Execute($SQL);
$this->adodb->Execute($SQL);
if ($this->setup_is_unicodedb()) {
$this->configure_dbconnection();
return true;
@ -242,7 +242,7 @@ class mysqli_adodb_moodle_database extends adodb_moodle_database {
}
$sql = "UPDATE {$this->prefix}$table SET $newfield $select";
if (!$rs = $this->db->Execute($sql, $params)) {
if (!$rs = $this->adodb->Execute($sql, $params)) {
$this->report_error($sql, $params);
return false;
}

View File

@ -50,13 +50,13 @@ class oci8po_adodb_moodle_database extends adodb_moodle_database {
}
protected function configure_dbconnection() {
$this->db->SetFetchMode(ADODB_FETCH_ASSOC);
$this->adodb->SetFetchMode(ADODB_FETCH_ASSOC);
/// No need to set charset. It must be specified by the NLS_LANG env. variable
/// Now set the decimal separator to DOT, Moodle & PHP will always send floats to
/// DB using DOTS. Manually introduced floats (if using other characters) must be
/// converted back to DOTs (like gradebook does)
$this->db->Execute("ALTER SESSION SET NLS_NUMERIC_CHARACTERS='.,'");
$this->adodb->Execute("ALTER SESSION SET NLS_NUMERIC_CHARACTERS='.,'");
return true;
}
@ -107,7 +107,7 @@ class oci8po_adodb_moodle_database extends adodb_moodle_database {
* @return bool true if db in unicode mode
*/
function setup_is_unicodedb() {
$rs = $this->db->Execute("SELECT parameter, value FROM nls_database_parameters where parameter = 'NLS_CHARACTERSET'");
$rs = $this->adodb->Execute("SELECT parameter, value FROM nls_database_parameters where parameter = 'NLS_CHARACTERSET'");
if ($rs && !$rs->EOF) {
$encoding = $rs->fields['value'];
if (strtoupper($encoding) == 'AL32UTF8') {
@ -267,13 +267,13 @@ class oci8po_adodb_moodle_database extends adodb_moodle_database {
}
foreach ($blobs as $key=>$value) {
if (!$this->db->UpdateBlob($this->prefix.$table, $key, $value, "id = {$dataobject->id}")) {
if (!$this->adodb->UpdateBlob($this->prefix.$table, $key, $value, "id = {$dataobject->id}")) {
return false;
}
}
foreach ($clobs as $key=>$value) {
if (!$this->db->UpdateClob($this->prefix.$table, $key, $value, "id = {$dataobject->id}")) {
if (!$this->adodb->UpdateClob($this->prefix.$table, $key, $value, "id = {$dataobject->id}")) {
return false;
}
}
@ -350,13 +350,13 @@ class oci8po_adodb_moodle_database extends adodb_moodle_database {
}
foreach ($blobs as $key=>$value) {
if (!$this->db->UpdateBlob($this->prefix.$table, $key, $value, "id = $id")) {
if (!$this->adodb->UpdateBlob($this->prefix.$table, $key, $value, "id = $id")) {
return false;
}
}
foreach ($clobs as $key=>$value) {
if (!$this->db->UpdateClob($this->prefix.$table, $key, $value, "id = $id")) {
if (!$this->adodb->UpdateClob($this->prefix.$table, $key, $value, "id = $id")) {
return false;
}
}
@ -391,13 +391,13 @@ class oci8po_adodb_moodle_database extends adodb_moodle_database {
if ($column->meta_type == 'B') { /// If the column is a BLOB
/// Update BLOB column and return
$select = $this->emulate_bound_params($select, $params); // adodb does not use bound parameters for blob updates :-(
return $this->db->UpdateBlob($this->prefix.$table, $newfield, $newvalue, $select);
return $this->adodb->UpdateBlob($this->prefix.$table, $newfield, $newvalue, $select);
}
if ($column->meta_type == 'X' && strlen($newvalue) > 4000) { /// If the column is a CLOB with lenght > 4000
/// Update BLOB column and return
$select = $this->emulate_bound_params($select, $params); // adodb does not use bound parameters for blob updates :-(
return $this->db->UpdateClob($this->prefix.$table, $newfield, $newvalue, $select);
return $this->adodb->UpdateClob($this->prefix.$table, $newfield, $newvalue, $select);
}
/// Arrived here, normal update (without BLOBs)
@ -417,7 +417,7 @@ class oci8po_adodb_moodle_database extends adodb_moodle_database {
}
$sql = "UPDATE {$this->prefix}$table SET $newfield WHERE $select";
if (!$rs = $this->db->Execute($sql, $params)) {
if (!$rs = $this->adodb->Execute($sql, $params)) {
$this->report_error($sql, $params);
return false;
}
@ -449,7 +449,7 @@ class oci8po_adodb_moodle_database extends adodb_moodle_database {
$generator->setPrefix($this->getPrefix());
$seqname = $generator->getNameForObject($table, 'id', 'seq');
}
if ($nextval = $this->db->GenID($seqname)) {
if ($nextval = $this->adodb->GenID($seqname)) {
$params['id'] = (int)$nextval;
}
}
@ -478,7 +478,7 @@ class oci8po_adodb_moodle_database extends adodb_moodle_database {
$sql = "INSERT INTO {$this->prefix}$table ($fields) VALUES($qms)";
if (!$rs = $this->db->Execute($sql, $params)) {
if (!$rs = $this->adodb->Execute($sql, $params)) {
$this->report_error($sql, $params);
return false;
}

View File

@ -36,8 +36,8 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
}
protected function configure_dbconnection() {
$this->db->SetFetchMode(ADODB_FETCH_ASSOC);
$this->db->Execute("SET NAMES 'utf8'");
$this->adodb->SetFetchMode(ADODB_FETCH_ASSOC);
$this->adodb->Execute("SET NAMES 'utf8'");
return true;
}
@ -105,7 +105,7 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
return $this->columns[$table];
}
if (!$columns = $this->db->MetaColumns($this->prefix.$table)) {
if (!$columns = $this->adodb->MetaColumns($this->prefix.$table)) {
return array();
}
@ -113,7 +113,7 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
foreach ($columns as $column) {
// colum names must be lowercase
$column->meta_type = substr($this->db->MetaType($column), 0 ,1); // only 1 character
$column->meta_type = substr($this->adodb->MetaType($column), 0 ,1); // only 1 character
if ($column->has_default) {
if ($pos = strpos($column->default_value, '::')) {
if (strpos($column->default_value, "'") === 0) {
@ -139,7 +139,7 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
*/
function setup_is_unicodedb() {
/// Get PostgreSQL server_encoding value
$rs = $this->db->Execute("SHOW server_encoding");
$rs = $this->adodb->Execute("SHOW server_encoding");
if ($rs && !$rs->EOF) {
$encoding = $rs->fields['server_encoding'];
if (strtoupper($encoding) == 'UNICODE' || strtoupper($encoding) == 'UTF8') {
@ -171,7 +171,7 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
unset($params['id']);
if ($returnid) {
$seqname = "{$this->prefix}{$table}_id_seq";
if ($nextval = $this->db->GenID($seqname)) {
if ($nextval = $this->adodb->GenID($seqname)) {
$params['id'] = (int)$nextval;
}
}
@ -186,7 +186,7 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
$sql = "INSERT INTO {$this->prefix}$table ($fields) VALUES($qms)";
if (!$rs = $this->db->Execute($sql, $params)) {
if (!$rs = $this->adodb->Execute($sql, $params)) {
$this->report_error($sql, $params);
return false;
}
@ -197,11 +197,11 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
return (int)$params['id'];
}
$oid = $this->db->Insert_ID();
$oid = $this->adodb->Insert_ID();
// try to get the primary key based on id
$sql = "SELECT id FROM {$this->prefix}$table WHERE oid = $oid";
if ( ($rs = $this->db->Execute($sql))
if ( ($rs = $this->adodb->Execute($sql))
&& ($rs->RecordCount() == 1) ) {
trigger_error("Retrieved id using oid on table $table because we could not find the sequence.");
return (integer)reset($rs->fields);
@ -271,7 +271,7 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
}
foreach ($blobs as $key=>$value) {
if (!$this->db->UpdateBlob($this->prefix.$table, $key, $value, "id = $id", 'BLOB')) { // adodb does not use bound parameters for blob updates :-(
if (!$this->adodb->UpdateBlob($this->prefix.$table, $key, $value, "id = $id", 'BLOB')) { // adodb does not use bound parameters for blob updates :-(
return false;
}
}
@ -340,7 +340,7 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
}
foreach ($blobs as $key=>$value) {
if (!$this->db->UpdateBlob($this->prefix.$table, $key, $value, "id = $id", 'BLOB')) { // adodb does not use bound parameters for blob updates :-(
if (!$this->adodb->UpdateBlob($this->prefix.$table, $key, $value, "id = $id", 'BLOB')) { // adodb does not use bound parameters for blob updates :-(
return false;
}
}
@ -368,7 +368,7 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
if ($column->meta_type == 'B') {
/// update blobs and return
$select = $this->emulate_bound_params($select, $params); // adodb does not use bound parameters for blob updates :-(
if (!$this->db->UpdateBlob($this->prefix.$table, $newfield, $newvalue, $select, 'BLOB')) {
if (!$this->adodb->UpdateBlob($this->prefix.$table, $newfield, $newvalue, $select, 'BLOB')) {
return false;
}
return true;
@ -395,7 +395,7 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
}
$sql = "UPDATE {$this->prefix}$table SET $newfield $select";
if (!$rs = $this->db->Execute($sql, $params)) {
if (!$rs = $this->adodb->Execute($sql, $params)) {
$this->report_error($sql, $params);
return false;
}
@ -414,7 +414,7 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
if (is_array($args)) {
array_unshift($args , "''");
}
return call_user_func_array(array($this->db, 'Concat'), $args);
return call_user_func_array(array($this->adodb, 'Concat'), $args);
}
public function sql_bitxor($int1, $int2) {