From 3dce78e1252965b5f824f24825eb35fd5fdeb1d3 Mon Sep 17 00:00:00 2001 From: skodak Date: Sun, 15 Jun 2008 11:35:25 +0000 Subject: [PATCH] MDL-15247 lib/dmllib.php is now obsolete --- admin/cron.php | 2 +- admin/report/simpletest/dbtest.php | 4 +- admin/report/simpletest/index.php | 4 +- install.php | 1 - lib/datalib.php | 87 ++++++++++++++- .../{testddllib.php => testddl.php} | 2 +- lib/dml/adodb_moodle_database.php | 2 +- lib/dml/adodb_moodle_recordset.php | 2 +- lib/dml/moodle_database.php | 19 +++- lib/dml/mssql_adodb_moodle_database.php | 2 +- lib/dml/mssql_n_adodb_moodle_database.php | 2 +- lib/dml/mysql_adodb_moodle_database.php | 2 +- lib/dml/mysqli_adodb_moodle_database.php | 2 +- lib/dml/oci8po_adodb_moodle_database.php | 2 +- lib/dml/oci8po_adodb_moodle_recordset.php | 2 +- lib/dml/odbc_mssql_adodb_moodle_database.php | 2 +- lib/dml/pdo_moodle_database.php | 2 +- lib/dml/pdo_moodle_recordset.php | 2 +- lib/dml/postgres7_adodb_moodle_database.php | 2 +- .../{testdmllib.php => testdml.php} | 6 +- lib/dmllib.php | 101 ------------------ lib/setup.php | 1 - 22 files changed, 122 insertions(+), 129 deletions(-) rename lib/ddl/simpletest/{testddllib.php => testddl.php} (99%) rename lib/dml/simpletest/{testdmllib.php => testdml.php} (99%) diff --git a/admin/cron.php b/admin/cron.php index 2e590601278..092e9d10d68 100644 --- a/admin/cron.php +++ b/admin/cron.php @@ -195,7 +195,7 @@ mtrace('Removing expired enrolments ...', ''); // See MDL-8785 $timenow = time(); $somefound = false; - // The preferred way saves memory, dmllib.php + // The preferred way saves memory, datablib // find courses where limited enrolment is enabled $sql = "SELECT ra.roleid, ra.userid, ra.contextid FROM {course} c diff --git a/admin/report/simpletest/dbtest.php b/admin/report/simpletest/dbtest.php index 4361ea296a9..e5ca21a212b 100644 --- a/admin/report/simpletest/dbtest.php +++ b/admin/report/simpletest/dbtest.php @@ -78,8 +78,8 @@ if (!empty($tests)) { // Create the group of tests. $test = new AutoGroupTest(false, true); - $test->addTestFile($CFG->libdir.'/dml/simpletest/testdmllib.php'); - $test->addTestFile($CFG->libdir.'/ddl/simpletest/testddllib.php'); + $test->addTestFile($CFG->libdir.'/dml/simpletest/testdml.php'); + $test->addTestFile($CFG->libdir.'/ddl/simpletest/testddl.php'); // Make the reporter, which is what displays the results. $reporter = new ExHtmlReporter($showpasses); diff --git a/admin/report/simpletest/index.php b/admin/report/simpletest/index.php index b3ce593dd2c..58db632feeb 100644 --- a/admin/report/simpletest/index.php +++ b/admin/report/simpletest/index.php @@ -77,10 +77,10 @@ if (!is_null($path)) { // Add ddl and dml tests if requested if ($rundbtests) { if (!strstr($path, $CFG->libdir . '/ddl')) { - $test->addTestFile($CFG->libdir . '/ddl/simpletest/testddllib.php'); + $test->addTestFile($CFG->libdir . '/ddl/simpletest/testddl.php'); } if (!strstr($path, $CFG->libdir . '/dml')) { - $test->addTestFile($CFG->libdir . '/dml/simpletest/testdmllib.php'); + $test->addTestFile($CFG->libdir . '/dml/simpletest/testdml.php'); } } diff --git a/install.php b/install.php index 63c975e4439..ab7ed08b0b7 100644 --- a/install.php +++ b/install.php @@ -147,7 +147,6 @@ $COURSE->id = 0; require_once($CFG->libdir.'/setuplib.php'); require_once($CFG->libdir.'/weblib.php'); -require_once($CFG->libdir.'/dmllib.php'); require_once($CFG->libdir.'/deprecatedlib.php'); require_once($CFG->libdir.'/moodlelib.php'); require_once($CFG->libdir.'/adminlib.php'); diff --git a/lib/datalib.php b/lib/datalib.php index 04fdd688cb1..8c1d76b3b50 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -11,6 +11,89 @@ * @package moodlecore */ +/** + * Sets up global $DB moodle_database instance + * @return void + */ +function setup_DB() { + global $CFG, $DB; + + if (isset($DB)) { + return; + } + + if (!isset($CFG->dbuser)) { + $CFG->dbuser = ''; + } + + if (!isset($CFG->dbpass)) { + $CFG->dbpass = ''; + } + + if (!isset($CFG->dbname)) { + $CFG->dbname = ''; + } + + if (!isset($CFG->dbpersist)) { + $CFG->dbpersist = false; + } + + if (!isset($CFG->dblibrary)) { + $CFG->dblibrary = 'adodb'; + } + + if (!isset($CFG->dboptions)) { + $CFG->dboptions = array(); + } + + if ($CFG->dblibrary == 'adodb') { + $classname = $CFG->dbtype.'_adodb_moodle_database'; + require_once($CFG->libdir.'/dml/'.$classname.'.php'); + $DB = new $classname(); + + } else { + error('Not implemented db library yet: '.$CFG->dblibrary); + } + + $CFG->dbfamily = $DB->get_dbfamily(); // TODO: BC only for now + + $driverstatus = $DB->driver_installed(); + + if ($driverstatus !== true) { + print_error('dbdriverproblem', 'error', '', $driverstatus); + } + + if (debugging('', DEBUG_ALL)) { + // catch errors + ob_start(); + } else { + $prevdebug = error_reporting(0); + } + if (!$DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->dbpersist, $CFG->prefix, $CFG->dboptions)) { + if (debugging('', DEBUG_ALL)) { + if ($dberr = ob_get_contents()) { + $dberr = '

'.$dberr.'

'; + } + ob_end_clean(); + } else { + $dberr = ''; + } + if (empty($CFG->noemailever) and !empty($CFG->emailconnectionerrorsto)) { + @mail($CFG->emailconnectionerrorsto, + 'WARNING: Database connection error: '.$CFG->wwwroot, + 'Connection error: '.$CFG->wwwroot); + } + print_error('dbconnectionfailed', 'error', '', $dberr); + } + if (debugging('', DEBUG_ALL)) { + ob_end_clean(); + } else { + error_reporting($prevdebug); + } + + return true; +} + /// Some constants define('LASTACCESS_UPDATE_SECS', 60); /// Number of seconds to wait before /// updating lastaccess information in DB. @@ -1867,10 +1950,6 @@ function add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user /** * Store user last access times - called when use enters a course or site * - * Note: we use ADOdb code directly in this function to save some CPU - * cycles here and there. They are simple operations not needing any - * of the postprocessing performed by dmllib.php - * * @param int $courseid, empty means site * @return void */ diff --git a/lib/ddl/simpletest/testddllib.php b/lib/ddl/simpletest/testddl.php similarity index 99% rename from lib/ddl/simpletest/testddllib.php rename to lib/ddl/simpletest/testddl.php index 0002f101a91..99cde3dd0e0 100755 --- a/lib/ddl/simpletest/testddllib.php +++ b/lib/ddl/simpletest/testddl.php @@ -11,7 +11,7 @@ if (!defined('MOODLE_INTERNAL')) { require_once($CFG->libdir . '/adminlib.php'); -class ddllib_test extends UnitTestCase { +class ddl_test extends UnitTestCase { private $tables = array(); private $tdb; diff --git a/lib/dml/adodb_moodle_database.php b/lib/dml/adodb_moodle_database.php index 406c2aba9db..2aeb9d6c488 100644 --- a/lib/dml/adodb_moodle_database.php +++ b/lib/dml/adodb_moodle_database.php @@ -5,7 +5,7 @@ require_once($CFG->libdir.'/dml/adodb_moodle_recordset.php'); /** * Abstract moodle database class - * @package dmlib + * @package dml */ abstract class adodb_moodle_database extends moodle_database { diff --git a/lib/dml/adodb_moodle_recordset.php b/lib/dml/adodb_moodle_recordset.php index 7a55b176260..a9776957cfd 100644 --- a/lib/dml/adodb_moodle_recordset.php +++ b/lib/dml/adodb_moodle_recordset.php @@ -4,7 +4,7 @@ require_once($CFG->libdir.'/dml/moodle_recordset.php'); /** * Adodb basic moodle recordset class - * @package dmlib + * @package dml */ class adodb_moodle_recordset extends moodle_recordset { diff --git a/lib/dml/moodle_database.php b/lib/dml/moodle_database.php index ea277f58346..9fbc12a7873 100644 --- a/lib/dml/moodle_database.php +++ b/lib/dml/moodle_database.php @@ -2,9 +2,26 @@ require_once($CFG->libdir.'/dml/database_column_info.php'); +/// GLOBAL CONSTANTS ///////////////////////////////////////////////////////// + +/** + * Bitmask, indicates only :name type parameters are supported by db backend. + */ +define('SQL_PARAMS_NAMED', 1); + +/** + * Bitmask, indicates only ? type parameters are supported by db backend. + */ +define('SQL_PARAMS_QM', 2); + +/** + * Bitmask, indicates only $1, $2.. type parameters are supported by db backend. + */ +define('SQL_PARAMS_DOLLAR', 4); + /** * Abstract class representing moodle database interface. - * @package dmlib + * @package dml */ abstract class moodle_database { diff --git a/lib/dml/mssql_adodb_moodle_database.php b/lib/dml/mssql_adodb_moodle_database.php index 655a38029b4..2287ae9b6fa 100644 --- a/lib/dml/mssql_adodb_moodle_database.php +++ b/lib/dml/mssql_adodb_moodle_database.php @@ -5,7 +5,7 @@ require_once($CFG->libdir.'/dml/adodb_moodle_database.php'); /** * MSSQL database class using adodb backend - * @package dmlib + * @package dml */ class mssql_adodb_moodle_database extends adodb_moodle_database { /** diff --git a/lib/dml/mssql_n_adodb_moodle_database.php b/lib/dml/mssql_n_adodb_moodle_database.php index e8a7d508fc9..aa26856ea8e 100644 --- a/lib/dml/mssql_n_adodb_moodle_database.php +++ b/lib/dml/mssql_n_adodb_moodle_database.php @@ -6,7 +6,7 @@ require_once($CFG->libdir.'/dml/mssql_adodb_moodle_database.php'); /** * MSSQL_N database class using adodb backend - * @package dmlib + * @package dml */ class mssql_n_adodb_moodle_database extends mssql_adodb_moodle_database { diff --git a/lib/dml/mysql_adodb_moodle_database.php b/lib/dml/mysql_adodb_moodle_database.php index c796537b61f..76ba6081973 100644 --- a/lib/dml/mysql_adodb_moodle_database.php +++ b/lib/dml/mysql_adodb_moodle_database.php @@ -6,7 +6,7 @@ require_once($CFG->libdir.'/dml/mysqli_adodb_moodle_database.php'); /** * Legacy MySQL database class using adodb backend - * @package dmlib + * @package dml */ class mysql_adodb_moodle_database extends mysqli_adodb_moodle_database { diff --git a/lib/dml/mysqli_adodb_moodle_database.php b/lib/dml/mysqli_adodb_moodle_database.php index 80021cc6090..55ba5aa294a 100644 --- a/lib/dml/mysqli_adodb_moodle_database.php +++ b/lib/dml/mysqli_adodb_moodle_database.php @@ -5,7 +5,7 @@ require_once($CFG->libdir.'/dml/adodb_moodle_database.php'); /** * Recommended MySQL database class using adodb backend - * @package dmlib + * @package dml */ class mysqli_adodb_moodle_database extends adodb_moodle_database { diff --git a/lib/dml/oci8po_adodb_moodle_database.php b/lib/dml/oci8po_adodb_moodle_database.php index ecf358fedf7..585cddc2cda 100644 --- a/lib/dml/oci8po_adodb_moodle_database.php +++ b/lib/dml/oci8po_adodb_moodle_database.php @@ -6,7 +6,7 @@ require_once($CFG->libdir.'/dml/oci8po_adodb_moodle_recordset.php'); /** * Oracle database class using adodb backend - * @package dmlib + * @package dml */ class oci8po_adodb_moodle_database extends adodb_moodle_database { diff --git a/lib/dml/oci8po_adodb_moodle_recordset.php b/lib/dml/oci8po_adodb_moodle_recordset.php index 14a58d9a5df..8df89fff799 100644 --- a/lib/dml/oci8po_adodb_moodle_recordset.php +++ b/lib/dml/oci8po_adodb_moodle_recordset.php @@ -4,7 +4,7 @@ require_once($CFG->libdir.'/dml/adodb_moodle_recordset.php'); /** * Oracle moodle recordest with special hacks - * @package dmlib + * @package dml */ class oci8po_adodb_moodle_recordset extends adodb_moodle_recordset { diff --git a/lib/dml/odbc_mssql_adodb_moodle_database.php b/lib/dml/odbc_mssql_adodb_moodle_database.php index c6e9f35d58a..ec72c98bfd8 100644 --- a/lib/dml/odbc_mssql_adodb_moodle_database.php +++ b/lib/dml/odbc_mssql_adodb_moodle_database.php @@ -6,7 +6,7 @@ require_once($CFG->libdir.'/dml/mssql_adodb_moodle_database.php'); /** * Experimenta mssql odbc database class using adodb backend - * @package dmlib + * @package dml */ class odbc_mssql_adodb_moodle_database extends mssql_adodb_moodle_database { diff --git a/lib/dml/pdo_moodle_database.php b/lib/dml/pdo_moodle_database.php index 81497a4a3ae..5f1167ac2b9 100644 --- a/lib/dml/pdo_moodle_database.php +++ b/lib/dml/pdo_moodle_database.php @@ -5,7 +5,7 @@ require_once($CFG->libdir.'/dml/pdo_moodle_recordset.php'); /** * Experimental pdo database class - * @package dmlib + * @package dml */ abstract class pdo_moodle_database extends moodle_database { diff --git a/lib/dml/pdo_moodle_recordset.php b/lib/dml/pdo_moodle_recordset.php index 3bc45d1c72b..fee26e8b44f 100644 --- a/lib/dml/pdo_moodle_recordset.php +++ b/lib/dml/pdo_moodle_recordset.php @@ -4,7 +4,7 @@ require_once($CFG->libdir.'/dml/moodle_recordset.php'); /** * Experimental pdo recordset - * @package dmlib + * @package dml */ class pdo_moodle_recordset extends moodle_recordset { diff --git a/lib/dml/postgres7_adodb_moodle_database.php b/lib/dml/postgres7_adodb_moodle_database.php index c16299df900..ce667ba9f9a 100644 --- a/lib/dml/postgres7_adodb_moodle_database.php +++ b/lib/dml/postgres7_adodb_moodle_database.php @@ -5,7 +5,7 @@ require_once($CFG->libdir.'/dml/adodb_moodle_database.php'); /** * Postgresql database class using adodb backend - * @package dmlib + * @package dml */ class postgres7_adodb_moodle_database extends adodb_moodle_database { diff --git a/lib/dml/simpletest/testdmllib.php b/lib/dml/simpletest/testdml.php similarity index 99% rename from lib/dml/simpletest/testdmllib.php rename to lib/dml/simpletest/testdml.php index 2f1d4099b62..1a68d08aeaf 100755 --- a/lib/dml/simpletest/testdmllib.php +++ b/lib/dml/simpletest/testdml.php @@ -1,14 +1,14 @@ dbuser)) { - $CFG->dbuser = ''; - } - - if (!isset($CFG->dbpass)) { - $CFG->dbpass = ''; - } - - if (!isset($CFG->dbname)) { - $CFG->dbname = ''; - } - - if (!isset($CFG->dbpersist)) { - $CFG->dbpersist = false; - } - - if (!isset($CFG->dblibrary)) { - $CFG->dblibrary = 'adodb'; - } - - if (!isset($CFG->dboptions)) { - $CFG->dboptions = array(); - } - - if ($CFG->dblibrary == 'adodb') { - $classname = $CFG->dbtype.'_adodb_moodle_database'; - require_once($CFG->libdir.'/dml/'.$classname.'.php'); - $DB = new $classname(); - - } else { - error('Not implemented db library yet: '.$CFG->dblibrary); - } - - $CFG->dbfamily = $DB->get_dbfamily(); // TODO: BC only for now - - $driverstatus = $DB->driver_installed(); - - if ($driverstatus !== true) { - print_error('dbdriverproblem', 'error', '', $driverstatus); - } - - if (debugging('', DEBUG_ALL)) { - // catch errors - ob_start(); - } else { - $prevdebug = error_reporting(0); - } - if (!$DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->dbpersist, $CFG->prefix, $CFG->dboptions)) { - if (debugging('', DEBUG_ALL)) { - if ($dberr = ob_get_contents()) { - $dberr = '

'.$dberr.'

'; - } - ob_end_clean(); - } else { - $dberr = ''; - } - if (empty($CFG->noemailever) and !empty($CFG->emailconnectionerrorsto)) { - @mail($CFG->emailconnectionerrorsto, - 'WARNING: Database connection error: '.$CFG->wwwroot, - 'Connection error: '.$CFG->wwwroot); - } - print_error('dbconnectionfailed', 'error', '', $dberr); - } - if (debugging('', DEBUG_ALL)) { - ob_end_clean(); - } else { - error_reporting($prevdebug); - } - - return true; -} - diff --git a/lib/setup.php b/lib/setup.php index a330d570839..c5ba97153c4 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -127,7 +127,6 @@ global $HTTPSPAGEREQUIRED; /// Load up standard libraries require_once($CFG->libdir .'/textlib.class.php'); // Functions to handle multibyte strings require_once($CFG->libdir .'/weblib.php'); // Functions for producing HTML - require_once($CFG->libdir .'/dmllib.php'); // Functions to handle DB data (DML) require_once($CFG->libdir .'/datalib.php'); // Legacy lib with a big-mix of functions. require_once($CFG->libdir .'/accesslib.php'); // Access control functions require_once($CFG->libdir .'/deprecatedlib.php'); // Deprecated functions included for backward compatibility