From f2ed3f05a71b7403e05a2cde8f427cc032f42ae8 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sun, 25 Jul 2010 12:57:24 +0000 Subject: [PATCH] MDL-21249 improved php docs and adding direct access prevention in dml --- lib/dml/database_column_info.php | 6 ++-- lib/dml/moodle_database.php | 6 ++-- lib/dml/moodle_recordset.php | 6 ++-- lib/dml/moodle_temptables.php | 9 ++--- lib/dml/moodle_transaction.php | 6 ++-- lib/dml/mssql_native_moodle_database.php | 6 ++-- lib/dml/mssql_native_moodle_recordset.php | 6 ++-- lib/dml/mssql_native_moodle_temptables.php | 6 ++-- lib/dml/mysqli_native_moodle_database.php | 6 ++-- lib/dml/mysqli_native_moodle_recordset.php | 6 ++-- lib/dml/mysqli_native_moodle_temptables.php | 6 ++-- lib/dml/oci_native_moodle_database.php | 6 ++-- lib/dml/oci_native_moodle_recordset.php | 6 ++-- lib/dml/oci_native_moodle_temptables.php | 6 ++-- lib/dml/pdo_moodle_database.php | 6 ++-- lib/dml/pdo_moodle_recordset.php | 6 ++-- lib/dml/pgsql_native_moodle_database.php | 6 ++-- lib/dml/pgsql_native_moodle_recordset.php | 6 ++-- lib/dml/pgsql_native_moodle_temptables.php | 6 ++-- lib/dml/sqlite3_pdo_moodle_database.php | 6 ++-- lib/dml/sqlsrv_native_moodle_database.php | 40 +++++++++++---------- lib/dml/sqlsrv_native_moodle_recordset.php | 16 +++++---- lib/dml/sqlsrv_native_moodle_temptables.php | 20 ++++++----- 23 files changed, 122 insertions(+), 77 deletions(-) diff --git a/lib/dml/database_column_info.php b/lib/dml/database_column_info.php index 9e7fd102bda..6e8001af034 100644 --- a/lib/dml/database_column_info.php +++ b/lib/dml/database_column_info.php @@ -19,12 +19,14 @@ /** * Database column information. * - * @package moodlecore - * @subpackage DML + * @package code + * @subpackage 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(); + /** * Detail database field information. * Based on ADOFieldObject. diff --git a/lib/dml/moodle_database.php b/lib/dml/moodle_database.php index 49e75ec640b..4eeae79da49 100644 --- a/lib/dml/moodle_database.php +++ b/lib/dml/moodle_database.php @@ -19,12 +19,14 @@ /** * Abstract database driver class. * - * @package moodlecore - * @subpackage DML + * @package code + * @subpackage 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'); diff --git a/lib/dml/moodle_recordset.php b/lib/dml/moodle_recordset.php index 63bb95390bc..3714719e8df 100644 --- a/lib/dml/moodle_recordset.php +++ b/lib/dml/moodle_recordset.php @@ -19,12 +19,14 @@ /** * Abstract recordset. * - * @package moodlecore - * @subpackage DML + * @package code + * @subpackage 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(); + /** * Abstract class for resultsets returned from database functions. * This is a simple Iterator with needed recorset closing support. diff --git a/lib/dml/moodle_temptables.php b/lib/dml/moodle_temptables.php index cca2d56d6f1..0fe35f7b039 100644 --- a/lib/dml/moodle_temptables.php +++ b/lib/dml/moodle_temptables.php @@ -33,15 +33,16 @@ * of doing temporary tables support 100% cross-db and transparent within the DB API. * * Only drivers needing it will use this store. Neither moodle_database (abstract) or - * databases like postgres need this, because they don't lack any temp functionality.ยบ:w - + * databases like postgres need this, because they don't lack any temp functionality. * - * @package moodlecore - * @subpackage DML + * @package code + * @subpackage 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(); + class moodle_temptables { protected $mdb; // circular reference, to be able to use DB facilities here if needed diff --git a/lib/dml/moodle_transaction.php b/lib/dml/moodle_transaction.php index 3e630842cfa..319a95ecf98 100644 --- a/lib/dml/moodle_transaction.php +++ b/lib/dml/moodle_transaction.php @@ -19,12 +19,14 @@ /** * Delegated database transaction support. * - * @package moodlecore - * @subpackage DML + * @package code + * @subpackage dml * @copyright 2009 Petr Skoda (http://skodak.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** * Delegated transaction class. */ diff --git a/lib/dml/mssql_native_moodle_database.php b/lib/dml/mssql_native_moodle_database.php index d5197a64da7..c5ea1b5b0cf 100644 --- a/lib/dml/mssql_native_moodle_database.php +++ b/lib/dml/mssql_native_moodle_database.php @@ -19,12 +19,14 @@ /** * Native mssql class representing moodle database interface. * - * @package moodlecore - * @subpackage DML + * @package code + * @subpackage 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'); diff --git a/lib/dml/mssql_native_moodle_recordset.php b/lib/dml/mssql_native_moodle_recordset.php index e897d4b63c0..38bfc0a01a0 100644 --- a/lib/dml/mssql_native_moodle_recordset.php +++ b/lib/dml/mssql_native_moodle_recordset.php @@ -18,12 +18,14 @@ /** * MSSQL specific recordset. * - * @package moodlecore - * @subpackage DML + * @package code + * @subpackage 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_recordset.php'); class mssql_native_moodle_recordset extends moodle_recordset { diff --git a/lib/dml/mssql_native_moodle_temptables.php b/lib/dml/mssql_native_moodle_temptables.php index 0af51cde713..d1418e6f26f 100644 --- a/lib/dml/mssql_native_moodle_temptables.php +++ b/lib/dml/mssql_native_moodle_temptables.php @@ -20,12 +20,14 @@ * are named differently than normal tables. Also used to be able to retrieve * temp table names included in the get_tables() method of the DB. * - * @package moodlecore - * @subpackage DML + * @package code + * @subpackage 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_temptables.php'); class mssql_native_moodle_temptables extends moodle_temptables { diff --git a/lib/dml/mysqli_native_moodle_database.php b/lib/dml/mysqli_native_moodle_database.php index ab3990fe881..65d90e38976 100644 --- a/lib/dml/mysqli_native_moodle_database.php +++ b/lib/dml/mysqli_native_moodle_database.php @@ -19,12 +19,14 @@ /** * Native mysqli class representing moodle database interface. * - * @package moodlecore - * @subpackage DML + * @package code + * @subpackage 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'); diff --git a/lib/dml/mysqli_native_moodle_recordset.php b/lib/dml/mysqli_native_moodle_recordset.php index 9e1e6e55cab..0df8808aec2 100644 --- a/lib/dml/mysqli_native_moodle_recordset.php +++ b/lib/dml/mysqli_native_moodle_recordset.php @@ -19,12 +19,14 @@ /** * Mysqli specific recordset. * - * @package moodlecore - * @subpackage DML + * @package code + * @subpackage 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'); /** diff --git a/lib/dml/mysqli_native_moodle_temptables.php b/lib/dml/mysqli_native_moodle_temptables.php index 045b9d75d9a..cbedf637393 100644 --- a/lib/dml/mysqli_native_moodle_temptables.php +++ b/lib/dml/mysqli_native_moodle_temptables.php @@ -20,12 +20,14 @@ * are named differently than normal tables. Also used to be able to retrieve * temp table names included in the get_tables() method of the DB. * - * @package moodlecore - * @subpackage DML + * @package code + * @subpackage 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_temptables.php'); class mysqli_native_moodle_temptables extends moodle_temptables { diff --git a/lib/dml/oci_native_moodle_database.php b/lib/dml/oci_native_moodle_database.php index 56bec443041..75a3677411e 100644 --- a/lib/dml/oci_native_moodle_database.php +++ b/lib/dml/oci_native_moodle_database.php @@ -19,12 +19,14 @@ /** * Native oci class representing moodle database interface. * - * @package moodlecore - * @subpackage DML + * @package code + * @subpackage 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'); diff --git a/lib/dml/oci_native_moodle_recordset.php b/lib/dml/oci_native_moodle_recordset.php index 172a926d2da..1434c260d66 100644 --- a/lib/dml/oci_native_moodle_recordset.php +++ b/lib/dml/oci_native_moodle_recordset.php @@ -19,12 +19,14 @@ /** * Oracle specific recordset. * - * @package moodlecore - * @subpackage DML + * @package code + * @subpackage 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'); class oci_native_moodle_recordset extends moodle_recordset { diff --git a/lib/dml/oci_native_moodle_temptables.php b/lib/dml/oci_native_moodle_temptables.php index a9f5fadc249..4ce8211854f 100644 --- a/lib/dml/oci_native_moodle_temptables.php +++ b/lib/dml/oci_native_moodle_temptables.php @@ -22,12 +22,14 @@ * Also used to be able to retrieve temp table names included in the get_tables() * method of the DB. * - * @package moodlecore - * @subpackage DML + * @package code + * @subpackage 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_temptables.php'); class oci_native_moodle_temptables extends moodle_temptables { diff --git a/lib/dml/pdo_moodle_database.php b/lib/dml/pdo_moodle_database.php index 1f6214dabcc..8bcaecb0149 100644 --- a/lib/dml/pdo_moodle_database.php +++ b/lib/dml/pdo_moodle_database.php @@ -19,12 +19,14 @@ /** * Experimental pdo database class * - * @package moodlecore - * @subpackage DML + * @package code + * @subpackage 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'); diff --git a/lib/dml/pdo_moodle_recordset.php b/lib/dml/pdo_moodle_recordset.php index 7d038af36d3..4848da7b797 100644 --- a/lib/dml/pdo_moodle_recordset.php +++ b/lib/dml/pdo_moodle_recordset.php @@ -19,12 +19,14 @@ /** * Experimental pdo recordset * - * @package moodlecore - * @subpackage DML + * @package code + * @subpackage 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'); /** diff --git a/lib/dml/pgsql_native_moodle_database.php b/lib/dml/pgsql_native_moodle_database.php index cd5ddf2a5f6..7b8218b37f5 100644 --- a/lib/dml/pgsql_native_moodle_database.php +++ b/lib/dml/pgsql_native_moodle_database.php @@ -19,12 +19,14 @@ /** * Native pgsql class representing moodle database interface. * - * @package moodlecore - * @subpackage DML + * @package code + * @subpackage 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'); diff --git a/lib/dml/pgsql_native_moodle_recordset.php b/lib/dml/pgsql_native_moodle_recordset.php index 41093740e0c..a2640f6812b 100644 --- a/lib/dml/pgsql_native_moodle_recordset.php +++ b/lib/dml/pgsql_native_moodle_recordset.php @@ -19,12 +19,14 @@ /** * Native postgresql recordset. * - * @package moodlecore - * @subpackage DML + * @package code + * @subpackage 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'); /** diff --git a/lib/dml/pgsql_native_moodle_temptables.php b/lib/dml/pgsql_native_moodle_temptables.php index 82900fff262..0ced452267f 100644 --- a/lib/dml/pgsql_native_moodle_temptables.php +++ b/lib/dml/pgsql_native_moodle_temptables.php @@ -20,12 +20,14 @@ * are named differently than normal tables. Also used to be able to retrieve * temp table names included in the get_tables() method of the DB. * - * @package moodlecore - * @subpackage DML + * @package code + * @subpackage dml * @copyright 2010 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_temptables.php'); class pgsql_native_moodle_temptables extends moodle_temptables { diff --git a/lib/dml/sqlite3_pdo_moodle_database.php b/lib/dml/sqlite3_pdo_moodle_database.php index 8aab36eee74..47070bc0d1a 100644 --- a/lib/dml/sqlite3_pdo_moodle_database.php +++ b/lib/dml/sqlite3_pdo_moodle_database.php @@ -19,12 +19,14 @@ /** * Experimental pdo database class. * - * @package moodlecore - * @subpackage DML + * @package code + * @subpackage 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'); /** diff --git a/lib/dml/sqlsrv_native_moodle_database.php b/lib/dml/sqlsrv_native_moodle_database.php index 640584624b5..6f58e62880a 100644 --- a/lib/dml/sqlsrv_native_moodle_database.php +++ b/lib/dml/sqlsrv_native_moodle_database.php @@ -16,13 +16,15 @@ // along with Moodle. If not, see . /** -* Native sqlsrv class representing moodle database interface. -* -* @package moodlecore -* @subpackage DML -* @copyright 2009 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} -* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later -*/ + * Native sqlsrv class representing moodle database interface. + * + * @package code + * @subpackage dml + * @copyright 2009 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later + */ + +defined('MOODLE_INTERNAL') || die(); require_once($CFG->libdir.'/dml/moodle_database.php'); require_once($CFG->libdir.'/dml/sqlsrv_native_moodle_recordset.php'); @@ -47,7 +49,7 @@ class sqlsrv_native_moodle_database extends moodle_database { } /** - * Setup the driver configuration. As a TODO, might want to put some levele of debugging to + * Setup the driver configuration. As a TODO, might want to put some level of debugging to * see / log more info, warnings, errors. } @@ -58,8 +60,8 @@ class sqlsrv_native_moodle_database extends moodle_database { */ public function driver_installed() { // use 'function_exists()' rather than 'extension_loaded()' because - // the name used by 'extension_loaded()' is case specific! The extention - // therefor *could be* mixed case and hence not found. + // the name used by 'extension_loaded()' is case specific! The extension + // therefore *could be* mixed case and hence not found. if (!function_exists('sqlsrv_num_rows')) { return get_string('sqlsrvextensionisnotpresentinphp', 'install'); } @@ -342,14 +344,14 @@ class sqlsrv_native_moodle_database extends moodle_database { /*** * Bound variables *are* supported. Until I can get it to work, emulate the bindings - * The challenge/problem/bug is that allthough they work, doing a SELECT SCOPE_IDENTITY() - * doesnt return a value (no result set) + * 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 statment + * @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. @@ -469,7 +471,7 @@ class sqlsrv_native_moodle_database extends moodle_database { } /** - * Returns datailed information about columns in table. This information is cached internally. + * Returns detailed 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 @@ -786,7 +788,7 @@ class sqlsrv_native_moodle_database extends moodle_database { } /** - * Preform a emulation for LIMIT(offset, limit) + * Perform a emulation for LIMIT(offset, limit) * * @param mixed $sql * @param mixed $offset @@ -804,7 +806,7 @@ class sqlsrv_native_moodle_database extends moodle_database { $sql1 = preg_replace('/^([\s(])*SELECT( DISTINCT | ALL)?(?!\s*TOP\s*\()/i', "\\1SELECT\\2 TOP $limit", $sql); } else { - // Only apply TOP clause if we have any limitnum (limitfrom offset is hadled later) + // Only apply TOP clause if we have any limitnum (limitfrom offset is handled later) if ($limit < 1) { $limit = "9223372036854775806"; // MAX BIGINT -1 } @@ -1248,8 +1250,8 @@ class sqlsrv_native_moodle_database extends moodle_database { * NOTE: this was originally returning only function name * * @param string $expr some string field, no aggregates - * @param mixed $start integer or expresion evaluating to int - * @param mixed $length optional integer or expresion evaluating to int + * @param mixed $start integer or expression evaluating to int + * @param mixed $length optional integer or expression evaluating to int * @return string sql fragment */ public function sql_substr($expr, $start, $length = false) { @@ -1303,7 +1305,7 @@ class sqlsrv_native_moodle_database extends moodle_database { /// transactions // NOTE: - // TODO -- should these be wrapped in query start/end? They arnt a query + // TODO -- should these be wrapped in query start/end? They arn't a query // but information and error capture is nice. msk diff --git a/lib/dml/sqlsrv_native_moodle_recordset.php b/lib/dml/sqlsrv_native_moodle_recordset.php index cf0d1a2d10d..bfa5ac90ab4 100644 --- a/lib/dml/sqlsrv_native_moodle_recordset.php +++ b/lib/dml/sqlsrv_native_moodle_recordset.php @@ -16,13 +16,15 @@ // along with Moodle. If not, see . /** -* sqlsrv specific recorset. -* -* @package moodlecore -* @subpackage DML -* @copyright 2009 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} -* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later -*/ + * sqlsrv specific recorset. + * + * @package code + * @subpackage dml + * @copyright 2009 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later + */ + +defined('MOODLE_INTERNAL') || die(); require_once($CFG->libdir.'/dml/moodle_recordset.php'); diff --git a/lib/dml/sqlsrv_native_moodle_temptables.php b/lib/dml/sqlsrv_native_moodle_temptables.php index 992e8b40dbe..6043f5b7626 100644 --- a/lib/dml/sqlsrv_native_moodle_temptables.php +++ b/lib/dml/sqlsrv_native_moodle_temptables.php @@ -16,15 +16,17 @@ // along with Moodle. If not, see . /** -* sqlsrv specific temptables store. Needed because temporary tables -* are named diferently than normal tables. Also used to be able to retrieve -* temp table names included in the get_tables() method od the DB. -* -* @package moodlecore -* @subpackage DML -* @copyright 2009 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} -* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later -*/ + * sqlsrv specific temptables store. Needed because temporary tables + * are named differently than normal tables. Also used to be able to retrieve + * temp table names included in the get_tables() method of the DB. + * + * @package code + * @subpackage dml + * @copyright 2009 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later + */ + +defined('MOODLE_INTERNAL') || die(); require_once($CFG->libdir.'/dml/mssql_native_moodle_temptables.php');