diff --git a/lib/dml/database_column_info.php b/lib/dml/database_column_info.php index b6198838689..4aee79aa35e 100644 --- a/lib/dml/database_column_info.php +++ b/lib/dml/database_column_info.php @@ -1,5 +1,4 @@ . - /** * Database column information. * - * @package core - * @category dml - * @subpackage dml + * @package core_dml * @copyright 2008 Petr Skoda (http://skodak.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -34,10 +30,9 @@ defined('MOODLE_INTERNAL') || die(); * It is based on the adodb library's ADOFieldObject object. * 'column' does mean 'the field' here. * - * @package core - * @category dml - * @copyright 2008 Petr Skoda (http://skodak.org) - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package core_dml + * @copyright 2008 Petr Skoda (http://skodak.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class database_column_info { /** diff --git a/lib/dml/moodle_database.php b/lib/dml/moodle_database.php index faf097e074c..48a992c73eb 100644 --- a/lib/dml/moodle_database.php +++ b/lib/dml/moodle_database.php @@ -14,24 +14,19 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . - /** * Abstract database driver class. * - * @package core - * @category dml - * @subpackage dml - * @copyright 2008 Petr Skoda (http://skodak.org) - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package core_dml + * @copyright 2008 Petr Skoda (http://skodak.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->libdir.'/dml/database_column_info.php'); -require_once($CFG->libdir.'/dml/moodle_recordset.php'); -require_once($CFG->libdir.'/dml/moodle_transaction.php'); - -/// GLOBAL CONSTANTS ///////////////////////////////////////////////////////// +require_once(__DIR__.'/database_column_info.php'); +require_once(__DIR__.'/moodle_recordset.php'); +require_once(__DIR__.'/moodle_transaction.php'); /** SQL_PARAMS_NAMED - Bitmask, indicates :name type parameters are supported by db backend. */ define('SQL_PARAMS_NAMED', 1); @@ -61,8 +56,7 @@ define('SQL_QUERY_AUX', 5); * Abstract class representing moodle database interface. * @link http://docs.moodle.org/dev/DML_functions * - * @package core - * @category dml + * @package core_dml * @copyright 2008 Petr Skoda (http://skodak.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -89,7 +83,7 @@ abstract class moodle_database { /** @var string Prefix added to table names. */ protected $prefix; - /** @var array Database or driver specific options, such as sockets or TCPIP db connections. */ + /** @var array Database or driver specific options, such as sockets or TCP/IP db connections. */ protected $dboptions; /** @var bool True means non-moodle external database used.*/ @@ -324,7 +318,7 @@ abstract class moodle_database { $backtrace = $lowesttransaction->get_backtrace(); if (defined('PHPUNIT_TEST') and PHPUNIT_TEST) { - //no need to log sudden exits in our PHPunit test cases + //no need to log sudden exits in our PHPUnit test cases } else { error_log('Potential coding error - active database transaction detected when disposing database:'."\n".format_backtrace($backtrace, true)); } @@ -422,7 +416,7 @@ abstract class moodle_database { /** * This logs the last query based on 'logall', 'logslow' and 'logerrors' options configured via $CFG->dboptions . - * @param string $error or false if not error + * @param string|bool $error or false if not error * @return void */ public function query_log($error=false) { @@ -463,7 +457,7 @@ abstract class moodle_database { /** * Returns database server info array - * @return array Array containing 'description' and 'version' atleast. + * @return array Array containing 'description' and 'version' at least. */ public abstract function get_server_info(); @@ -687,6 +681,7 @@ abstract class moodle_database { * Internal private utitlity function used to fix parameters. * Used with {@link preg_replace_callback()} * @param array $match Refer to preg_replace_callback usage for description. + * @return string */ private function _fix_sql_params_dollar_callback($match) { $this->fix_sql_params_i++; @@ -697,6 +692,7 @@ abstract class moodle_database { * Detects object parameters and throws exception if found * @param mixed $value * @return void + * @throws coding_exception if object detected */ protected function detect_objects($value) { if (is_object($value)) { @@ -723,7 +719,7 @@ abstract class moodle_database { $params[$key] = is_bool($value) ? (int)$value : $value; } - // NICOLAS C: Fixed regexp for negative backwards lookahead of double colons. Thanks for Sam Marshall's help + // NICOLAS C: Fixed regexp for negative backwards look-ahead of double colons. Thanks for Sam Marshall's help $named_count = preg_match_all('/(?is_transaction_started()) { @@ -2232,7 +2223,6 @@ abstract class moodle_database { $this->force_rollback = false; } -// session locking /** * Is session lock supported in this driver? * @return bool @@ -2261,7 +2251,6 @@ abstract class moodle_database { public function release_session_lock($rowid) { } -// performance and logging /** * Returns the number of reads done by this database. * @return int Number of reads. diff --git a/lib/dml/moodle_recordset.php b/lib/dml/moodle_recordset.php index d1e7005120a..975b253d79e 100644 --- a/lib/dml/moodle_recordset.php +++ b/lib/dml/moodle_recordset.php @@ -1,5 +1,4 @@ . - /** * Abstract recordset. * - * @package core - * @category dml - * @subpackage dml + * @package core_dml * @copyright 2008 Petr Skoda (http://skodak.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/lib/dml/moodle_temptables.php b/lib/dml/moodle_temptables.php index c89348ae1da..19f0c20ce78 100644 --- a/lib/dml/moodle_temptables.php +++ b/lib/dml/moodle_temptables.php @@ -1,5 +1,4 @@ . - /** * Delegated database transaction support. * - * @package core - * @category dml - * @subpackage dml + * @package core_dml * @copyright 2009 Petr Skoda (http://skodak.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -31,9 +27,7 @@ defined('MOODLE_INTERNAL') || die(); /** * Delegated transaction class. * - * @package core - * @category dml - * @subpackage dml + * @package core_dml * @copyright 2009 Petr Skoda (http://skodak.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -110,4 +104,4 @@ class moodle_transaction { } $this->database->rollback_delegated_transaction($this, $e); } -} \ No newline at end of file +} diff --git a/lib/dml/mssql_native_moodle_database.php b/lib/dml/mssql_native_moodle_database.php index 5ae728e86c6..7d134d2fc61 100644 --- a/lib/dml/mssql_native_moodle_database.php +++ b/lib/dml/mssql_native_moodle_database.php @@ -1,5 +1,4 @@ . - /** * Native mssql class representing moodle database interface. * - * @package core - * @subpackage dml_driver + * @package core_dml * @copyright 2009 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->libdir.'/dml/moodle_database.php'); -require_once($CFG->libdir.'/dml/mssql_native_moodle_recordset.php'); -require_once($CFG->libdir.'/dml/mssql_native_moodle_temptables.php'); +require_once(__DIR__.'/moodle_database.php'); +require_once(__DIR__.'/mssql_native_moodle_recordset.php'); +require_once(__DIR__.'/mssql_native_moodle_temptables.php'); /** * Native mssql class representing moodle database interface. * - * @package core - * @subpackage dml_driver + * @package core_dml * @copyright 2009 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -515,7 +511,7 @@ class mssql_native_moodle_database extends moodle_database { protected function normalise_value($column, $value) { $this->detect_objects($value); - if (is_bool($value)) { /// Always, convert boolean to int + if (is_bool($value)) { // Always, convert boolean to int $value = (int)$value; } // And continue processing because text columns with numeric info need special handling below @@ -619,7 +615,7 @@ class mssql_native_moodle_database extends moodle_database { if (empty($params)) { return $sql; } - /// ok, we have verified sql statement with ? and correct number of params + // ok, we have verified sql statement with ? and correct number of params $parts = explode('?', $sql); $return = array_shift($parts); foreach ($params as $param) { @@ -1039,7 +1035,7 @@ class mssql_native_moodle_database extends moodle_database { // convert params to ? types list($select, $params, $type) = $this->fix_sql_params($select, $params); - /// Get column metadata + // Get column metadata $columns = $this->get_columns($table); $column = $columns[$newfield]; @@ -1094,8 +1090,6 @@ class mssql_native_moodle_database extends moodle_database { return true; } -/// SQL helper functions - public function sql_cast_char2int($fieldname, $text=false) { if (!$text) { return ' CAST(' . $fieldname . ' AS INT) '; @@ -1251,8 +1245,6 @@ s only returning name of SQL substring function, it now requires all parameters. } } -/// session locking - public function session_lock_supported() { return true; } @@ -1315,8 +1307,6 @@ s only returning name of SQL substring function, it now requires all parameters. $this->free_result($result); } -/// transactions - /** * Driver specific start of real database transaction, * this can not be used directly in code. diff --git a/lib/dml/mssql_native_moodle_recordset.php b/lib/dml/mssql_native_moodle_recordset.php index d383d31860b..2c7b7110fbd 100644 --- a/lib/dml/mssql_native_moodle_recordset.php +++ b/lib/dml/mssql_native_moodle_recordset.php @@ -1,5 +1,4 @@ libdir.'/dml/moodle_recordset.php'); +require_once(__DIR__.'/moodle_recordset.php'); class mssql_native_moodle_recordset extends moodle_recordset { @@ -54,7 +52,7 @@ class mssql_native_moodle_recordset extends moodle_recordset { } public function key() { - /// return first column value as key + // return first column value as key if (!$this->current) { return false; } diff --git a/lib/dml/mssql_native_moodle_temptables.php b/lib/dml/mssql_native_moodle_temptables.php index 9242059978b..df04cca1d03 100644 --- a/lib/dml/mssql_native_moodle_temptables.php +++ b/lib/dml/mssql_native_moodle_temptables.php @@ -1,5 +1,4 @@ libdir.'/dml/moodle_temptables.php'); +require_once(__DIR__.'/moodle_temptables.php'); class mssql_native_moodle_temptables extends moodle_temptables { @@ -50,5 +48,4 @@ class mssql_native_moodle_temptables extends moodle_temptables { // TODO: throw exception if exists: if ($this->is_temptable... $this->temptables[$tablename] = '#' . $this->prefix . $tablename; } - } diff --git a/lib/dml/mysqli_native_moodle_database.php b/lib/dml/mysqli_native_moodle_database.php index 535eca61fe8..93311bd5fd4 100644 --- a/lib/dml/mysqli_native_moodle_database.php +++ b/lib/dml/mysqli_native_moodle_database.php @@ -1,5 +1,4 @@ . - /** * Native mysqli class representing moodle database interface. * - * @package core - * @subpackage dml_driver + * @package core_dml * @copyright 2008 Petr Skoda (http://skodak.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->libdir.'/dml/moodle_database.php'); -require_once($CFG->libdir.'/dml/mysqli_native_moodle_recordset.php'); -require_once($CFG->libdir.'/dml/mysqli_native_moodle_temptables.php'); +require_once(__DIR__.'/moodle_database.php'); +require_once(__DIR__.'/mysqli_native_moodle_recordset.php'); +require_once(__DIR__.'/mysqli_native_moodle_temptables.php'); /** * Native mysqli class representing moodle database interface. * - * @package core - * @subpackage dml_driver + * @package core_dml * @copyright 2008 Petr Skoda (http://skodak.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -77,7 +73,7 @@ class mysqli_native_moodle_database extends moodle_database { $dbport = 3306; } ob_start(); - $conn = new mysqli($dbhost, $dbuser, $dbpass, '', $dbport, $dbsocket); /// Connect without db + $conn = new mysqli($dbhost, $dbuser, $dbpass, '', $dbport, $dbsocket); // Connect without db $dberr = ob_get_contents(); ob_end_clean(); $errorno = @$conn->connect_errno; @@ -324,7 +320,7 @@ class mysqli_native_moodle_database extends moodle_database { $this->query_end($result); } - // Connection stabilished and configured, going to instantiate the temptables controller + // Connection stabilised and configured, going to instantiate the temptables controller $this->temptables = new mysqli_native_moodle_temptables($this); return true; @@ -736,7 +732,7 @@ class mysqli_native_moodle_database extends moodle_database { if (empty($params)) { return $sql; } - /// ok, we have verified sql statement with ? and correct number of params + // ok, we have verified sql statement with ? and correct number of params $parts = explode('?', $sql); $return = array_shift($parts); foreach ($params as $param) { @@ -1264,7 +1260,6 @@ class mysqli_native_moodle_database extends moodle_database { return ' CAST(' . $fieldname . ' AS SIGNED) '; } -/// session locking public function session_lock_supported() { return true; } @@ -1273,7 +1268,7 @@ class mysqli_native_moodle_database extends moodle_database { * Obtain session lock * @param int $rowid id of the row with session record * @param int $timeout max allowed time to wait for the lock in seconds - * @return bool success + * @return void */ public function get_session_lock($rowid, $timeout) { parent::get_session_lock($rowid, $timeout); @@ -1309,7 +1304,6 @@ class mysqli_native_moodle_database extends moodle_database { } } -/// transactions /** * Are transactions supported? * It is not responsible to run productions servers diff --git a/lib/dml/mysqli_native_moodle_recordset.php b/lib/dml/mysqli_native_moodle_recordset.php index e8dc5bce994..230ef8c6edc 100644 --- a/lib/dml/mysqli_native_moodle_recordset.php +++ b/lib/dml/mysqli_native_moodle_recordset.php @@ -1,5 +1,4 @@ . - /** * Mysqli specific recordset. * - * @package core - * @subpackage dml_driver + * @package core_dml * @copyright 2008 Petr Skoda (http://skodak.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->libdir.'/dml/moodle_recordset.php'); +require_once(__DIR__.'/moodle_recordset.php'); /** * Mysqli specific moodle recordset class @@ -63,7 +60,7 @@ class mysqli_native_moodle_recordset extends moodle_recordset { } public function key() { - /// return first column value as key + // return first column value as key if (!$this->current) { return false; } diff --git a/lib/dml/mysqli_native_moodle_temptables.php b/lib/dml/mysqli_native_moodle_temptables.php index 0ad5132328f..4d777be009b 100644 --- a/lib/dml/mysqli_native_moodle_temptables.php +++ b/lib/dml/mysqli_native_moodle_temptables.php @@ -1,5 +1,4 @@ libdir.'/dml/moodle_temptables.php'); +require_once(__DIR__.'/moodle_temptables.php'); class mysqli_native_moodle_temptables extends moodle_temptables { - /// I love these classes :-P + // I love these classes :-P } diff --git a/lib/dml/oci_native_moodle_database.php b/lib/dml/oci_native_moodle_database.php index 08df721afd2..b62ac9baddc 100644 --- a/lib/dml/oci_native_moodle_database.php +++ b/lib/dml/oci_native_moodle_database.php @@ -1,5 +1,4 @@ . - /** * Native oci class representing moodle database interface. * - * @package core - * @subpackage dml_driver + * @package core_dml * @copyright 2008 Petr Skoda (http://skodak.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->libdir.'/dml/moodle_database.php'); -require_once($CFG->libdir.'/dml/oci_native_moodle_recordset.php'); -require_once($CFG->libdir.'/dml/oci_native_moodle_temptables.php'); +require_once(__DIR__.'/moodle_database.php'); +require_once(__DIR__.'/oci_native_moodle_recordset.php'); +require_once(__DIR__.'/oci_native_moodle_temptables.php'); /** * Native oci class representing moodle database interface. @@ -37,8 +34,7 @@ require_once($CFG->libdir.'/dml/oci_native_moodle_temptables.php'); * One complete reference for PHP + OCI: * http://www.oracle.com/technology/tech/php/underground-php-oracle-manual.html * - * @package core - * @subpackage dml_driver + * @package core_dml * @copyright 2008 Petr Skoda (http://skodak.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -809,7 +805,7 @@ class oci_native_moodle_database extends moodle_database { // of empties will need to use the sql_empty() and sql_isempty() helper functions. // MDL-17491. - // If the field ins't VARCHAR or CLOB, skip + // If the field isn't VARCHAR or CLOB, skip if ($column->meta_type != 'C' and $column->meta_type != 'X') { return $value; } @@ -835,7 +831,7 @@ class oci_native_moodle_database extends moodle_database { return '0'; // Transform 0 to '0' that evaluates the same for PHP } else if ($value === '') { - return ' '; // Transform '' to ' ' that DONT'T EVALUATE THE SAME + return ' '; // Transform '' to ' ' that DON'T EVALUATE THE SAME // (we'll transform back again on get_records_XXX functions and others)!! } @@ -1449,7 +1445,6 @@ class oci_native_moodle_database extends moodle_database { return ' FROM dual'; } -// Bitwise operations protected function bitwise_supported() { if (isset($this->bitwise_supported)) { // Use cached value if available return $this->bitwise_supported; @@ -1551,11 +1546,11 @@ class oci_native_moodle_database extends moodle_database { } } - // NOTE: Oracle concat implementation isn't ANSI compliant when using NULLs (the result of - // any concatenation with NULL must return NULL) because of his inability to differentiate - // NULLs and empty strings. So this function will cause some tests to fail. Hopefully - // it's only a side case and it won't affect normal concatenation operations in Moodle. public function sql_concat() { + // NOTE: Oracle concat implementation isn't ANSI compliant when using NULLs (the result of + // any concatenation with NULL must return NULL) because of his inability to differentiate + // NULLs and empty strings. So this function will cause some tests to fail. Hopefully + // it's only a side case and it won't affect normal concatenation operations in Moodle. $arr = func_get_args(); $s = implode(' || ', $arr); if ($s === '') { @@ -1604,7 +1599,6 @@ class oci_native_moodle_database extends moodle_database { return 'dbms_lob.substr(' . $fieldname . ', ' . $numchars . ',1)'; } -/// session locking public function session_lock_supported() { if (isset($this->dblocks_supported)) { // Use cached value if available return $this->dblocks_supported; @@ -1629,7 +1623,7 @@ class oci_native_moodle_database extends moodle_database { * Obtain session lock * @param int $rowid id of the row with session record * @param int $timeout max allowed time to wait for the lock in seconds - * @return bool success + * @return void */ public function get_session_lock($rowid, $timeout) { if (!$this->session_lock_supported()) { @@ -1668,7 +1662,6 @@ class oci_native_moodle_database extends moodle_database { oci_free_statement($stmt); } -/// transactions /** * Driver specific start of real database transaction, * this can not be used directly in code. diff --git a/lib/dml/oci_native_moodle_package.sql b/lib/dml/oci_native_moodle_package.sql index 042c6106645..2585f713d08 100644 --- a/lib/dml/oci_native_moodle_package.sql +++ b/lib/dml/oci_native_moodle_package.sql @@ -14,8 +14,7 @@ -- along with Moodle. If not, see . /** - * @package core - * @subpackage dml_driver + * @package core_dml * @copyright 2009 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @version 20091010 (plz, keep this updated for easier reference) diff --git a/lib/dml/oci_native_moodle_recordset.php b/lib/dml/oci_native_moodle_recordset.php index 4d8694a54b1..e21e2310542 100644 --- a/lib/dml/oci_native_moodle_recordset.php +++ b/lib/dml/oci_native_moodle_recordset.php @@ -1,5 +1,4 @@ . - /** * Oracle specific recordset. * - * @package core - * @subpackage dml_driver + * @package core_dml * @copyright 2008 Petr Skoda (http://skodak.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->libdir.'/dml/moodle_recordset.php'); +require_once(__DIR__.'/moodle_recordset.php'); class oci_native_moodle_recordset extends moodle_recordset { @@ -57,7 +54,7 @@ class oci_native_moodle_recordset extends moodle_recordset { } public function key() { - /// return first column value as key + // return first column value as key if (!$this->current) { return false; } diff --git a/lib/dml/oci_native_moodle_temptables.php b/lib/dml/oci_native_moodle_temptables.php index 1343d06dfe6..3b7fd3f7dd5 100644 --- a/lib/dml/oci_native_moodle_temptables.php +++ b/lib/dml/oci_native_moodle_temptables.php @@ -1,5 +1,4 @@ libdir.'/dml/moodle_temptables.php'); +require_once(__DIR__.'/moodle_temptables.php'); class oci_native_moodle_temptables extends moodle_temptables { - protected $unique_session_id; // To store unique_session_id. Needed for temp tables unique naming (upto 24cc) - protected $counter; // To get incrementally different temptable names on each add_temptable() request + /** @var int To store unique_session_id. Needed for temp tables unique naming (upto 24cc) */ + protected $unique_session_id; // + /** @var int To get incrementally different temptable names on each add_temptable() request */ + protected $counter; /** * Creates new moodle_temptables instance @@ -50,7 +50,7 @@ class oci_native_moodle_temptables extends moodle_temptables { /** * Add one temptable to the store. * - * Overriden because OCI only support global temptables, so we need to change completely the name, based + * Overridden because OCI only support global temptables, so we need to change completely the name, based * in unique session identifier, to get local-like temp tables support * tables before the prefix. * diff --git a/lib/dml/pdo_moodle_database.php b/lib/dml/pdo_moodle_database.php index 8b090a49161..4aae9ce6ed6 100644 --- a/lib/dml/pdo_moodle_database.php +++ b/lib/dml/pdo_moodle_database.php @@ -1,5 +1,4 @@ . - /** * Experimental pdo database class * - * @package core - * @subpackage dml_driver + * @package core_dml * @copyright 2008 Andrei Bautu * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->libdir.'/dml/moodle_database.php'); -require_once($CFG->libdir.'/dml/pdo_moodle_recordset.php'); +require_once(__DIR__.'/moodle_database.php'); +require_once(__DIR__.'/pdo_moodle_recordset.php'); /** * Experimental pdo database class * - * @package core - * @subpackage dml_driver + * @package core_dml * @copyright 2008 Andrei Bautu * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -102,7 +98,7 @@ abstract class pdo_moodle_database extends moodle_database { } protected function configure_dbconnection() { - ///TODO: not needed preconfigure_dbconnection() stuff for PDO drivers? + //TODO: not needed preconfigure_dbconnection() stuff for PDO drivers? } /** diff --git a/lib/dml/pdo_moodle_recordset.php b/lib/dml/pdo_moodle_recordset.php index 803416f590c..673d91f30b1 100644 --- a/lib/dml/pdo_moodle_recordset.php +++ b/lib/dml/pdo_moodle_recordset.php @@ -1,5 +1,4 @@ . - /** * Experimental pdo recordset * - * @package core - * @subpackage dml_driver + * @package core_dml * @copyright 2008 Andrei Bautu * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->libdir.'/dml/moodle_recordset.php'); +require_once(__DIR__.'/moodle_recordset.php'); /** * Experimental pdo recordset * - * @package core - * @subpackage dml_driver + * @package core_dml * @copyright 2008 Andrei Bautu * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -64,7 +60,7 @@ class pdo_moodle_recordset extends moodle_recordset { } public function key() { - /// return first column value as key + // return first column value as key if (!$this->current) { return false; } diff --git a/lib/dml/pgsql_native_moodle_database.php b/lib/dml/pgsql_native_moodle_database.php index 57a007a9cd7..c883aed83e2 100644 --- a/lib/dml/pgsql_native_moodle_database.php +++ b/lib/dml/pgsql_native_moodle_database.php @@ -1,5 +1,4 @@ . - /** * Native pgsql class representing moodle database interface. * - * @package core - * @subpackage dml_driver + * @package core_dml * @copyright 2008 Petr Skoda (http://skodak.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->libdir.'/dml/moodle_database.php'); -require_once($CFG->libdir.'/dml/pgsql_native_moodle_recordset.php'); -require_once($CFG->libdir.'/dml/pgsql_native_moodle_temptables.php'); +require_once(__DIR__.'/moodle_database.php'); +require_once(__DIR__.'/pgsql_native_moodle_recordset.php'); +require_once(__DIR__.'/pgsql_native_moodle_temptables.php'); /** * Native pgsql class representing moodle database interface. * - * @package core - * @subpackage dml_driver + * @package core_dml * @copyright 2008 Petr Skoda (http://skodak.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -566,7 +562,7 @@ class pgsql_native_moodle_database extends moodle_database { * @return bool */ public function setup_is_unicodedb() { - /// Get PostgreSQL server_encoding value + // Get PostgreSQL server_encoding value $sql = "SHOW server_encoding"; $this->query_start($sql, null, SQL_QUERY_AUX); $result = pg_query($this->pgsql, $sql); @@ -1044,13 +1040,13 @@ class pgsql_native_moodle_database extends moodle_database { list($select, $params, $type) = $this->fix_sql_params($select, $params); $i = count($params)+1; - /// Get column metadata + // Get column metadata $columns = $this->get_columns($table); $column = $columns[$newfield]; $normalised_value = $this->normalise_value($column, $newvalue); if (is_array($normalised_value) && array_key_exists('blob', $normalised_value)) { - /// Update BYTEA and return + // Update BYTEA and return $normalised_value = pg_escape_bytea($this->pgsql, $normalised_value['blob']); $sql = "UPDATE {$this->prefix}$table SET $newfield = '$normalised_value'::bytea $select"; $this->query_start($sql, NULL, SQL_QUERY_UPDATE); @@ -1152,7 +1148,7 @@ class pgsql_native_moodle_database extends moodle_database { return " '' "; } // Add always empty string element so integer-exclusive concats - // will work without needing to cast each element explicity + // will work without needing to cast each element explicitly return " '' || $s "; } @@ -1175,7 +1171,6 @@ class pgsql_native_moodle_database extends moodle_database { return $positivematch ? '~*' : '!~*'; } -/// session locking public function session_lock_supported() { return true; } @@ -1252,7 +1247,6 @@ class pgsql_native_moodle_database extends moodle_database { } } -/// transactions /** * Driver specific start of real database transaction, * this can not be used directly in code. diff --git a/lib/dml/pgsql_native_moodle_recordset.php b/lib/dml/pgsql_native_moodle_recordset.php index 6d00d157f56..76fe53ea01f 100644 --- a/lib/dml/pgsql_native_moodle_recordset.php +++ b/lib/dml/pgsql_native_moodle_recordset.php @@ -1,5 +1,4 @@ . - /** * Native postgresql recordset. * - * @package core - * @subpackage dml_driver + * @package core_dml * @copyright 2008 Petr Skoda (http://skodak.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->libdir.'/dml/moodle_recordset.php'); +require_once(__DIR__.'/moodle_recordset.php'); /** * pgsql specific moodle recordset class * - * @package core - * @subpackage dml_driver + * @package core_dml * @copyright 2008 Petr Skoda (http://skodak.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -82,7 +78,7 @@ class pgsql_native_moodle_recordset extends moodle_recordset { } public function key() { - /// return first column value as key + // return first column value as key if (!$this->current) { return false; } diff --git a/lib/dml/pgsql_native_moodle_temptables.php b/lib/dml/pgsql_native_moodle_temptables.php index 4227da15cf9..cd87ef2e27c 100644 --- a/lib/dml/pgsql_native_moodle_temptables.php +++ b/lib/dml/pgsql_native_moodle_temptables.php @@ -1,5 +1,4 @@ libdir.'/dml/moodle_temptables.php'); +require_once(__DIR__.'/moodle_temptables.php'); class pgsql_native_moodle_temptables extends moodle_temptables { // I love these classes :-P diff --git a/lib/dml/sqlite3_pdo_moodle_database.php b/lib/dml/sqlite3_pdo_moodle_database.php index c52b2f1916a..e7410a5d50d 100644 --- a/lib/dml/sqlite3_pdo_moodle_database.php +++ b/lib/dml/sqlite3_pdo_moodle_database.php @@ -1,5 +1,4 @@ . - /** * Experimental pdo database class. * - * @package core - * @subpackage dml_driver + * @package core_dml * @copyright 2008 Andrei Bautu * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->libdir.'/dml/pdo_moodle_database.php'); +require_once(__DIR__.'/pdo_moodle_database.php'); /** * Experimental pdo database class * - * @package core - * @subpackage dml_driver + * @package core_dml * @copyright 2008 Andrei Bautu * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/lib/dml/sqlsrv_native_moodle_database.php b/lib/dml/sqlsrv_native_moodle_database.php index 90ec10479e5..168c68234c0 100644 --- a/lib/dml/sqlsrv_native_moodle_database.php +++ b/lib/dml/sqlsrv_native_moodle_database.php @@ -1,5 +1,4 @@ libdir.'/dml/moodle_database.php'); -require_once($CFG->libdir.'/dml/sqlsrv_native_moodle_recordset.php'); -require_once($CFG->libdir.'/dml/sqlsrv_native_moodle_temptables.php'); +require_once(__DIR__.'/moodle_database.php'); +require_once(__DIR__.'/sqlsrv_native_moodle_recordset.php'); +require_once(__DIR__.'/sqlsrv_native_moodle_temptables.php'); /** * Native sqlsrv class representing moodle database interface. * - * @package core - * @subpackage dml_driver + * @package core_dml * @copyright 2009 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later */ @@ -331,29 +328,32 @@ class sqlsrv_native_moodle_database extends moodle_database { return $errorMessage; } - /*** - * Bound variables *are* supported. Until I can get it to work, emulate the bindings - * The challenge/problem/bug is that although they work, doing a SELECT SCOPE_IDENTITY() - * doesn't return a value (no result set) - */ - /** * Prepare the query binding and do the actual query. * * @param string $sql The sql statement - * @param mixed $params array of params for binding. If NULL, they are ignored. - * @param mixed $sql_query_type - Type of operation - * @param mixed $free_result - Default true, transaction query will be freed. - * @param mixed $scrollable - Default false, to use for quickly seeking to target records + * @param array $params array of params for binding. If NULL, they are ignored. + * @param int $sql_query_type - Type of operation + * @param bool $free_result - Default true, transaction query will be freed. + * @param bool $scrollable - Default false, to use for quickly seeking to target records + * @return resource|bool result */ private function do_query($sql, $params, $sql_query_type, $free_result = true, $scrollable = false) { list($sql, $params, $type) = $this->fix_sql_params($sql, $params); + /* + * Bound variables *are* supported. Until I can get it to work, emulate the bindings + * The challenge/problem/bug is that although they work, doing a SELECT SCOPE_IDENTITY() + * doesn't return a value (no result set) + * + * -- somebody from MS + */ + $sql = $this->emulate_bound_params($sql, $params); $this->query_start($sql, $params, $sql_query_type); if (!$scrollable) { // Only supporting next row $result = sqlsrv_query($this->sqlsrv, $sql); - } else { // Suporting absolute/relative rows + } else { // Supporting absolute/relative rows $result = sqlsrv_query($this->sqlsrv, $sql, array(), array('Scrollable' => SQLSRV_CURSOR_STATIC)); } @@ -575,7 +575,7 @@ class sqlsrv_native_moodle_database extends moodle_database { protected function normalise_value($column, $value) { $this->detect_objects($value); - if (is_bool($value)) { /// Always, convert boolean to int + if (is_bool($value)) { // Always, convert boolean to int $value = (int)$value; } // And continue processing because text columns with numeric info need special handling below @@ -585,9 +585,9 @@ class sqlsrv_native_moodle_database extends moodle_database { $value = unpack('H*hex', $value); // we leave it as array, so emulate_bound_params() can detect it } // easily and "bind" the param ok. - } else if ($column->meta_type == 'X') { // sqlsrv doesn't cast from int to text, so if text column + } else if ($column->meta_type == 'X') { // sqlsrv doesn't cast from int to text, so if text column if (is_numeric($value)) { // and is numeric value then cast to string - $value = array('numstr' => (string)$value); // and put into array, so emulate_bound_params() will know how + $value = array('numstr' => (string)$value); // and put into array, so emulate_bound_params() will know how } // to "bind" the param ok, avoiding reverse conversion to number } else if ($value === '') { @@ -602,6 +602,7 @@ class sqlsrv_native_moodle_database extends moodle_database { * Selectively call sqlsrv_free_stmt(), avoiding some warnings without using the horrible @ * * @param sqlsrv_resource $resource resource to be freed if possible + * @return bool */ private function free_result($resource) { if (!is_bool($resource)) { // true/false resources cannot be freed @@ -688,7 +689,6 @@ class sqlsrv_native_moodle_database extends moodle_database { return null; } - /** * Workaround for SQL*Server Native driver similar to MSSQL driver for * consistent behavior. @@ -698,7 +698,7 @@ class sqlsrv_native_moodle_database extends moodle_database { if (empty($params)) { return $sql; } - /// ok, we have verified sql statement with ? and correct number of params + // ok, we have verified sql statement with ? and correct number of params $parts = explode('?', $sql); $return = array_shift($parts); foreach ($params as $param) { @@ -1099,7 +1099,7 @@ class sqlsrv_native_moodle_database extends moodle_database { // convert params to ? types list($select, $params, $type) = $this->fix_sql_params($select, $params); - /// Get column metadata + // Get column metadata $columns = $this->get_columns($table); $column = $columns[$newfield]; @@ -1141,8 +1141,6 @@ class sqlsrv_native_moodle_database extends moodle_database { } - /// SQL helper functions - public function sql_cast_char2int($fieldname, $text = false) { if (!$text) { return ' CAST(' . $fieldname . ' AS INT) '; @@ -1300,8 +1298,6 @@ class sqlsrv_native_moodle_database extends moodle_database { } } - /// session locking - public function session_lock_supported() { return true; } @@ -1310,7 +1306,7 @@ class sqlsrv_native_moodle_database extends moodle_database { * Obtain session lock * @param int $rowid id of the row with session record * @param int $timeout max allowed time to wait for the lock in seconds - * @return bool success + * @return void */ public function get_session_lock($rowid, $timeout) { if (!$this->session_lock_supported()) { @@ -1361,14 +1357,6 @@ class sqlsrv_native_moodle_database extends moodle_database { $this->free_result($result); } - - /// transactions - - // NOTE: - // TODO -- should these be wrapped in query start/end? They arn't a query - // but information and error capture is nice. msk - - /** * Driver specific start of real database transaction, * this can not be used directly in code. diff --git a/lib/dml/sqlsrv_native_moodle_recordset.php b/lib/dml/sqlsrv_native_moodle_recordset.php index 1f9965506cb..6ca88aad323 100644 --- a/lib/dml/sqlsrv_native_moodle_recordset.php +++ b/lib/dml/sqlsrv_native_moodle_recordset.php @@ -1,5 +1,4 @@ libdir.'/dml/moodle_recordset.php'); +require_once(__DIR__.'/moodle_recordset.php'); class sqlsrv_native_moodle_recordset extends moodle_recordset { @@ -55,7 +53,7 @@ class sqlsrv_native_moodle_recordset extends moodle_recordset { } public function key() { - /// return first column value as key + // return first column value as key if (!$this->current) { return false; } diff --git a/lib/dml/sqlsrv_native_moodle_temptables.php b/lib/dml/sqlsrv_native_moodle_temptables.php index fe860346586..2d9cc62b9c7 100644 --- a/lib/dml/sqlsrv_native_moodle_temptables.php +++ b/lib/dml/sqlsrv_native_moodle_temptables.php @@ -1,5 +1,4 @@ libdir.'/dml/mssql_native_moodle_temptables.php'); +require_once(__DIR__.'/mssql_native_moodle_temptables.php'); -/*** +/** * This class is not specific to the SQL Server Native Driver but rather * to the family of Microsoft SQL Servers. * - * @package core - * @subpackage dml_driver + * @package core_dml * @copyright 2009 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later */ diff --git a/lib/dml/tests/dml_test.php b/lib/dml/tests/dml_test.php index 410c7ffef3b..4993d3596bb 100644 --- a/lib/dml/tests/dml_test.php +++ b/lib/dml/tests/dml_test.php @@ -17,8 +17,7 @@ /** * DML layer tests * - * @package core - * @subpackage dml + * @package core_dml * @category phpunit * @copyright 2008 Nicolas Connault * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later @@ -63,8 +62,6 @@ class dml_testcase extends database_driver_testcase { return $debuginfo; } - // NOTE: please keep order of test methods here matching the order of moodle_database class methods - function test_diagnose() { $DB = $this->tdb; $result = $DB->diagnose(); @@ -1090,7 +1087,7 @@ class dml_testcase extends database_driver_testcase { $this->assertEquals(3, $counter); $rs->close(); - $rs = $DB->get_recordset_list($tablename, 'course',array()); /// Must return 0 rows without conditions. MDL-17645 + $rs = $DB->get_recordset_list($tablename, 'course',array()); // Must return 0 rows without conditions. MDL-17645 $counter = 0; foreach ($rs as $record) { @@ -1316,7 +1313,7 @@ class dml_testcase extends database_driver_testcase { $this->assertEquals(2, next($records)->id); $this->assertEquals(4, next($records)->id); - $this->assertSame(array(), $records = $DB->get_records_list($tablename, 'course', array())); /// Must return 0 rows without conditions. MDL-17645 + $this->assertSame(array(), $records = $DB->get_records_list($tablename, 'course', array())); // Must return 0 rows without conditions. MDL-17645 $this->assertEquals(0, count($records)); // note: delegate limits testing to test_get_records_sql() @@ -3070,7 +3067,7 @@ class dml_testcase extends database_driver_testcase { $this->assertTrue($DB->delete_records_list($tablename, 'course', array(2, 3))); $this->assertEquals(1, $DB->count_records($tablename)); - $this->assertTrue($DB->delete_records_list($tablename, 'course', array())); /// Must delete 0 rows without conditions. MDL-17645 + $this->assertTrue($DB->delete_records_list($tablename, 'course', array())); // Must delete 0 rows without conditions. MDL-17645 $this->assertEquals(1, $DB->count_records($tablename)); } @@ -3560,13 +3557,13 @@ class dml_testcase extends database_driver_testcase { function test_coalesce() { $DB = $this->tdb; - // Testing not-null ocurrences, return 1st + // Testing not-null occurrences, return 1st $sql = "SELECT COALESCE('returnthis', 'orthis', 'orwhynotthis') AS test" . $DB->sql_null_from_clause(); $this->assertEquals('returnthis', $DB->get_field_sql($sql, array())); $sql = "SELECT COALESCE(:paramvalue, 'orthis', 'orwhynotthis') AS test" . $DB->sql_null_from_clause(); $this->assertEquals('returnthis', $DB->get_field_sql($sql, array('paramvalue' => 'returnthis'))); - // Testing null ocurrences, return 2nd + // Testing null occurrences, return 2nd $sql = "SELECT COALESCE(null, 'returnthis', 'orthis') AS test" . $DB->sql_null_from_clause(); $this->assertEquals('returnthis', $DB->get_field_sql($sql, array())); $sql = "SELECT COALESCE(:paramvalue, 'returnthis', 'orthis') AS test" . $DB->sql_null_from_clause(); @@ -3574,7 +3571,7 @@ class dml_testcase extends database_driver_testcase { $sql = "SELECT COALESCE(null, :paramvalue, 'orthis') AS test" . $DB->sql_null_from_clause(); $this->assertEquals('returnthis', $DB->get_field_sql($sql, array('paramvalue' => 'returnthis'))); - // Testing null ocurrences, return 3rd + // Testing null occurrences, return 3rd $sql = "SELECT COALESCE(null, null, 'returnthis') AS test" . $DB->sql_null_from_clause(); $this->assertEquals('returnthis', $DB->get_field_sql($sql, array())); $sql = "SELECT COALESCE(null, :paramvalue, 'returnthis') AS test" . $DB->sql_null_from_clause(); @@ -3582,7 +3579,7 @@ class dml_testcase extends database_driver_testcase { $sql = "SELECT COALESCE(null, null, :paramvalue) AS test" . $DB->sql_null_from_clause(); $this->assertEquals('returnthis', $DB->get_field_sql($sql, array('paramvalue' => 'returnthis'))); - // Testing all null ocurrences, return null + // Testing all null occurrences, return null // Note: under mssql, if all elements are nulls, at least one must be a "typed" null, hence // we cannot test this in a cross-db way easily, so next 2 tests are using // different queries depending of the DB family @@ -3603,7 +3600,7 @@ class dml_testcase extends database_driver_testcase { $DB = $this->tdb; $dbman = $DB->get_manager(); - /// Testing all sort of values + // Testing all sort of values $sql = "SELECT ".$DB->sql_concat("?", "?", "?")." AS fullname ". $DB->sql_null_from_clause(); // string, some unicode chars $params = array('name', 'áéíóú', 'name3'); @@ -3621,7 +3618,7 @@ class dml_testcase extends database_driver_testcase { $params = array(123.45, null, 'test'); $this->assertNull($DB->get_field_sql($sql, $params), 'ANSI behaviour: Concatenating NULL must return NULL - But in Oracle :-(. [%s]'); // Concatenate NULL with anything result = NULL - /// Testing fieldnames + values and also integer fieldnames + // Testing fieldnames + values and also integer fieldnames $table = $this->get_test_table(); $tablename = $table->getName(); @@ -4328,7 +4325,7 @@ class dml_testcase extends database_driver_testcase { $DB2 = moodle_database::get_driver_instance($cfg->dbtype, $cfg->dblibrary); $DB2->connect($cfg->dbhost, $cfg->dbuser, $cfg->dbpass, $cfg->dbname, $cfg->prefix, $cfg->dboptions); - // Testing that acquiring a lock efectively locks + // Testing that acquiring a lock effectively locks // Get a session lock on connection1 $rowid = rand(100, 200); $timeout = 1; @@ -4337,14 +4334,14 @@ class dml_testcase extends database_driver_testcase { // Try to get the same session lock on connection2 try { $DB2->get_session_lock($rowid, $timeout); - $DB2->release_session_lock($rowid); // Should not be excuted, but here for safety + $DB2->release_session_lock($rowid); // Should not be executed, but here for safety $this->fail('An Exception is missing, expected due to session lock acquired.'); } catch (exception $e) { $this->assertTrue($e instanceof dml_sessionwait_exception); $DB->release_session_lock($rowid); // Release lock on connection1 } - // Testing that releasing a lock efectively frees + // Testing that releasing a lock effectively frees // Get a session lock on connection1 $rowid = rand(100, 200); $timeout = 1; @@ -4613,7 +4610,7 @@ class moodle_database_for_testing extends moodle_database { /** - * Dumb test class with toString() returrning 1. + * Dumb test class with toString() returning 1. */ class dml_test_object_one { public function __toString() {