Moodle  2.2.1
http://www.collinsharper.com
moodle_database Class Reference
Inheritance diagram for moodle_database:

Public Member Functions

 __construct ($external=false)
 __destruct ()
 driver_installed ()
 get_prefix ()
 get_dbfamily ()
 get_name ()
 get_configuration_help ()
 get_configuration_hints ()
 export_dbconfig ()
 diagnose ()
 connect ($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null)
 create_database ($dbhost, $dbuser, $dbpass, $dbname, array $dboptions=null)
 dispose ()
 query_log ($error=false)
 get_server_info ()
 get_last_error ()
 get_in_or_equal ($items, $type=SQL_PARAMS_QM, $prefix='param', $equal=true, $onemptyitems=false)
 fix_sql_params ($sql, array $params=null)
 get_tables ($usecache=true)
 get_indexes ($table)
 get_columns ($table, $usecache=true)
 reset_caches ()
 get_manager ()
 change_db_encoding ()
 setup_is_unicodedb ()
 set_debug ($state)
 get_debug ()
 set_logging ($state)
 change_database_structure ($sql)
 execute ($sql, array $params=null)
 get_recordset ($table, array $conditions=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0)
 get_recordset_list ($table, $field, array $values, $sort='', $fields='*', $limitfrom=0, $limitnum=0)
 get_recordset_select ($table, $select, array $params=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0)
 get_recordset_sql ($sql, array $params=null, $limitfrom=0, $limitnum=0)
 get_records ($table, array $conditions=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0)
 get_records_list ($table, $field, array $values, $sort='', $fields='*', $limitfrom=0, $limitnum=0)
 get_records_select ($table, $select, array $params=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0)
 get_records_sql ($sql, array $params=null, $limitfrom=0, $limitnum=0)
 get_records_menu ($table, array $conditions=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0)
 get_records_select_menu ($table, $select, array $params=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0)
 get_records_sql_menu ($sql, array $params=null, $limitfrom=0, $limitnum=0)
 get_record ($table, array $conditions, $fields='*', $strictness=IGNORE_MISSING)
 get_record_select ($table, $select, array $params=null, $fields='*', $strictness=IGNORE_MISSING)
 get_record_sql ($sql, array $params=null, $strictness=IGNORE_MISSING)
 get_field ($table, $return, array $conditions, $strictness=IGNORE_MISSING)
 get_field_select ($table, $return, $select, array $params=null, $strictness=IGNORE_MISSING)
 get_field_sql ($sql, array $params=null, $strictness=IGNORE_MISSING)
 get_fieldset_select ($table, $return, $select, array $params=null)
 get_fieldset_sql ($sql, array $params=null)
 insert_record_raw ($table, $params, $returnid=true, $bulk=false, $customsequence=false)
 insert_record ($table, $dataobject, $returnid=true, $bulk=false)
 import_record ($table, $dataobject)
 update_record_raw ($table, $params, $bulk=false)
 update_record ($table, $dataobject, $bulk=false)
 set_field ($table, $newfield, $newvalue, array $conditions=null)
 set_field_select ($table, $newfield, $newvalue, $select, array $params=null)
 count_records ($table, array $conditions=null)
 count_records_select ($table, $select, array $params=null, $countitem="COUNT('x')")
 count_records_sql ($sql, array $params=null)
 record_exists ($table, array $conditions)
 record_exists_select ($table, $select, array $params=null)
 record_exists_sql ($sql, array $params=null)
 delete_records ($table, array $conditions=null)
 delete_records_list ($table, $field, array $values)
 delete_records_select ($table, $select, array $params=null)
 sql_null_from_clause ()
 sql constructs
 sql_bitand ($int1, $int2)
 sql_bitnot ($int1)
 sql_bitor ($int1, $int2)
 sql_bitxor ($int1, $int2)
 sql_modulo ($int1, $int2)
 sql_ceil ($fieldname)
 sql_cast_char2int ($fieldname, $text=false)
 sql_cast_char2real ($fieldname, $text=false)
 sql_cast_2signed ($fieldname)
 sql_compare_text ($fieldname, $numchars=32)
 sql_like ($fieldname, $param, $casesensitive=true, $accentsensitive=true, $notlike=false, $escapechar= '\\')
 sql_like_escape ($text, $escapechar= '\\')
 sql_ilike ()
 sql_concat ()
 sql_concat_join ($separator="' '", $elements=array())
 sql_fullname ($first='firstname', $last='lastname')
 sql_order_by_text ($fieldname, $numchars=32)
 sql_length ($fieldname)
 sql_substr ($expr, $start, $length=false)
 sql_position ($needle, $haystack)
 sql_empty ()
 sql_isempty ($tablename, $fieldname, $nullablefield, $textfield)
 sql_isnotempty ($tablename, $fieldname, $nullablefield, $textfield)
 sql_regex_supported ()
 sql_regex ($positivematch=true)
 is_transaction_started ()
 transactions_forbidden ()
 start_delegated_transaction ()
 commit_delegated_transaction (moodle_transaction $transaction)
 rollback_delegated_transaction (moodle_transaction $transaction, Exception $e)
 force_transaction_rollback ()
 session_lock_supported ()
 session locking
 get_session_lock ($rowid, $timeout)
 release_session_lock ($rowid)
 perf_get_reads ()
 performance and logging
 perf_get_writes ()
 perf_get_queries ()

Static Public Member Functions

static get_driver_instance ($type, $library, $external=false)

Protected Member Functions

 get_dbtype ()
 get_dblibrary ()
 store_settings ($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null)
 query_start ($sql, array $params=null, $type, $extrainfo=null)
 query_end ($result)
 allowed_param_types ()
 print_debug ($sql, array $params=null, $obj=null)
 where_clause ($table, array $conditions=null)
 where_clause_list ($field, array $values)
 fix_table_names ($sql)
 normalise_value ($column, $value)
 transactions_supported ()
 transactions
 begin_transaction ()
 commit_transaction ()
 rollback_transaction ()

Protected Attributes

 $database_manager
 $temptables
 $columns = array()
 $tables = null
 $dbhost
 $dbuser
 $dbpass
 $dbname
 $prefix
 $dboptions
 $external
 $reads = 0
 $writes = 0
 $debug = 0
 $last_sql
 $last_params
 $last_type
 $last_extrainfo
 $last_time
 $used_for_db_sessions = false

Detailed Description

Abstract class representing moodle database interface.

Definition at line 64 of file moodle_database.php.


Constructor & Destructor Documentation

__construct ( external = false)

Constructor - instantiates the database, specifying if it's external (connect to other systems) or no (Moodle DB) note this has effect to decide if prefix checks must be performed or no

Parameters:
booltrue means external database used

Reimplemented in sqlsrv_native_moodle_database, and pdo_moodle_database.

Definition at line 132 of file moodle_database.php.

Destructor - cleans up and flushes everything needed.

Definition at line 139 of file moodle_database.php.

Here is the call graph for this function:


Member Function Documentation

allowed_param_types ( ) [abstract, protected]

Returns supported query parameter types

Returns:
int bitmask

Reimplemented in moodle_database_for_testing, mysqli_native_moodle_database, oci_native_moodle_database, mssql_native_moodle_database, sqlsrv_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

Here is the caller graph for this function:

begin_transaction ( ) [abstract, protected]

Driver specific start of real database transaction, this can not be used directly in code.

Returns:
void

Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, mysqli_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

Here is the caller graph for this function:

change_database_structure ( sql) [abstract]

Do NOT use in code, to be used by database_manager only!

Parameters:
string$sqlquery
Returns:
bool true
Exceptions:
dml_exceptionif error

Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mysqli_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

Attempt to change db encoding toUTF-8 if possible

Returns:
bool success

Definition at line 887 of file moodle_database.php.

Indicates delegated transaction finished successfully. The real database transaction is committed only if all delegated transactions committed.

Returns:
void

Definition at line 2097 of file moodle_database.php.

Here is the call graph for this function:

commit_transaction ( ) [abstract, protected]

Driver specific commit of real database transaction, this can not be used directly in code.

Returns:
void

Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, mysqli_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

Here is the caller graph for this function:

connect ( dbhost,
dbuser,
dbpass,
dbname,
prefix,
array dboptions = null 
) [abstract]

Connect to db Must be called before other methods.

Parameters:
string$dbhost
string$dbuser
string$dbpass
string$dbname
mixed$prefixstring means moodle db prefix, false used for external databases where prefix not used
array$dboptionsdriver specific options
Returns:
bool true
Exceptions:
dml_connection_exceptionif error

Reimplemented in moodle_database_for_testing, mysqli_native_moodle_database, oci_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

count_records ( table,
array conditions = null 
)

Count the records in a table where all the given conditions met.

Parameters:
string$tableThe table to query.
array$conditionsoptional array $fieldname=>requestedvalue with AND in between
Returns:
int The count of records returned from the specified criteria.
Exceptions:
dml_exceptionif error

Definition at line 1507 of file moodle_database.php.

Here is the call graph for this function:

count_records_select ( table,
select,
array params = null,
countitem = "COUNT('x')" 
)

Count the records in a table which match a particular WHERE clause.

Parameters:
string$tableThe database table to be checked against.
string$selectA fragment of SQL to be used in a WHERE clause in the SQL call.
array$paramsarray of sql parameters
string$countitemThe count string to be used in the SQL call. Default is COUNT('x').
Returns:
int The count of records returned from the specified criteria.
Exceptions:
dml_exceptionif error

Definition at line 1522 of file moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

count_records_sql ( sql,
array params = null 
)

Get the result of a SQL SELECT COUNT(...) query.

Given a query that counts rows, return that count. (In fact, given any query, return the first field of the first record returned. However, this method should only be used for the intended purpose.) If an error occurs, 0 is returned.

Parameters:
string$sqlThe SQL string you wish to be executed.
array$paramsarray of sql parameters
Returns:
int the count
Exceptions:
dml_exceptionif error

Definition at line 1542 of file moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

create_database ( dbhost,
dbuser,
dbpass,
dbname,
array dboptions = null 
)

Attempt to create the database

Parameters:
string$dbhost
string$dbuser
string$dbpass
string$dbname
Returns:
bool success

Reimplemented in sqlite3_pdo_moodle_database, and mysqli_native_moodle_database.

Definition at line 294 of file moodle_database.php.

delete_records ( table,
array conditions = null 
)

Delete the records from a table where all the given conditions met. If conditions not specified, table is truncated.

Parameters:
string$tablethe table to delete from.
array$conditionsoptional array $fieldname=>requestedvalue with AND in between
Returns:
bool true.
Exceptions:
dml_exceptionif error

Reimplemented in sqlite3_pdo_moodle_database.

Definition at line 1609 of file moodle_database.php.

Here is the call graph for this function:

delete_records_list ( table,
field,
array values 
)

Delete the records from a table where one field match one list of values.

Parameters:
string$tablethe table to delete from.
string$fieldThe field to search
array$valuesarray of values
Returns:
bool true.
Exceptions:
dml_exceptionif error

Definition at line 1628 of file moodle_database.php.

Here is the call graph for this function:

delete_records_select ( table,
select,
array params = null 
) [abstract]

Delete one or more records from a table which match a particular WHERE clause.

Parameters:
string$tableThe database table to be checked against.
string$selectA fragment of SQL to be used in a where clause in the SQL call (used to define the selection criteria).
array$paramsarray of sql parameters
Returns:
bool true.
Exceptions:
dml_exceptionif error

Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mysqli_native_moodle_database, pgsql_native_moodle_database, mssql_native_moodle_database, and pdo_moodle_database.

Here is the caller graph for this function:

diagnose ( )

Diagnose database and tables, this function is used to verify database and driver settings, db engine types, etc.

Returns:
string null means everything ok, string means problem found.

Reimplemented in mysqli_native_moodle_database, and oci_native_moodle_database.

Definition at line 248 of file moodle_database.php.

dispose ( )

Close database connection and release all resources and memory (especially circular memory references). Do NOT use connect() again, create a new instance if needed.

Returns:
void

Reimplemented in mysqli_native_moodle_database, oci_native_moodle_database, mssql_native_moodle_database, sqlsrv_native_moodle_database, and pgsql_native_moodle_database.

Definition at line 304 of file moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

driver_installed ( ) [abstract]

Detects if all needed PHP stuff installed. Note: can be used before connect()

Returns:
mixed true if ok, string if something

Reimplemented in moodle_database_for_testing, mysqli_native_moodle_database, oci_native_moodle_database, sqlsrv_native_moodle_database, pgsql_native_moodle_database, mssql_native_moodle_database, and sqlite3_pdo_moodle_database.

Here is the caller graph for this function:

execute ( sql,
array params = null 
) [abstract]

Execute general sql query. Should be used only when no other method suitable. Do NOT use this to make changes in db structure, use database_manager::execute_sql() instead!

Parameters:
string$sqlquery
array$paramsquery parameters
Returns:
bool true
Exceptions:
dml_exceptionif error

Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mysqli_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

Here is the caller graph for this function:

Returns db related part of config.php

Returns:
object

Definition at line 226 of file moodle_database.php.

Here is the call graph for this function:

fix_sql_params ( sql,
array params = null 
)

Normalizes sql query parameters and verifies parameters.

Parameters:
string$sqlquery or part of it
array$paramsquery parameters
Returns:
array (sql, params, type of params)

Definition at line 677 of file moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

fix_table_names ( sql) [protected]

Converts short table name {tablename} to real table name

Parameters:
stringsql
Returns:
string sql

Reimplemented in oci_native_moodle_database, mssql_native_moodle_database, and sqlsrv_native_moodle_database.

Definition at line 661 of file moodle_database.php.

Here is the caller graph for this function:

Force rollback of all delegated transaction. Does not trow any exceptions and does not log anything.

This method should be used only from default exception handlers and other core code.

Returns:
void

Definition at line 2188 of file moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_columns ( table,
usecache = true 
) [abstract]

Returns detailed information about columns in table. This information is cached internally.

Parameters:
string$tablename
bool$usecache
Returns:
array of database_column_info objects indexed with column names

Reimplemented in moodle_database_for_testing, sqlsrv_native_moodle_database, oci_native_moodle_database, mysqli_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and sqlite3_pdo_moodle_database.

Here is the caller graph for this function:

get_dbfamily ( ) [abstract]

Returns database family type - describes SQL dialect Note: can be used before connect()

Returns:
string db family name (mysql, postgres, mssql, oracle, etc.)

Reimplemented in moodle_database_for_testing, mysqli_native_moodle_database, sqlsrv_native_moodle_database, oci_native_moodle_database, pgsql_native_moodle_database, mssql_native_moodle_database, and sqlite3_pdo_moodle_database.

Here is the caller graph for this function:

get_dblibrary ( ) [abstract, protected]

Returns general database library name Note: can be used before connect()

Returns:
string db type pdo, native

Reimplemented in moodle_database_for_testing, mysqli_native_moodle_database, pdo_moodle_database, sqlsrv_native_moodle_database, oci_native_moodle_database, pgsql_native_moodle_database, and mssql_native_moodle_database.

Here is the caller graph for this function:

get_dbtype ( ) [abstract, protected]

Returns more specific database driver type Note: can be used before connect()

Returns:
string db type mysqli, pgsql, oci, mssql, sqlsrv

Reimplemented in moodle_database_for_testing, mysqli_native_moodle_database, sqlsrv_native_moodle_database, oci_native_moodle_database, pgsql_native_moodle_database, mssql_native_moodle_database, and sqlite3_pdo_moodle_database.

Here is the caller graph for this function:

get_debug ( )

Returns debug status

Returns:
bool $state

Reimplemented in moodle_database_for_testing.

Definition at line 912 of file moodle_database.php.

Here is the caller graph for this function:

static get_driver_instance ( type,
library,
external = false 
) [static]

Loads and returns a database instance with the specified type and library.

Parameters:
string$typedatabase type of the driver (mysqli, pgsql, mssql, sqldrv, oci, etc.)
string$librarydatabase library of the driver (native, pdo, etc.)
boolean$externaltrue if this is an external database
Returns:
moodle_database driver object or null if error

Definition at line 166 of file moodle_database.php.

Here is the caller graph for this function:

get_field ( table,
return,
array conditions,
strictness = IGNORE_MISSING 
)

Get a single field value from a table record where all the given conditions met.

Parameters:
string$tablethe table to query.
string$returnthe field to return the value of.
array$conditionsoptional array $fieldname=>requestedvalue with AND in between
int$strictnessIGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); MUST_EXIST means throw exception if no record or multiple records found
Returns:
mixed the specified value false if not found
Exceptions:
dml_exceptionif error

Definition at line 1328 of file moodle_database.php.

Here is the call graph for this function:

get_field_select ( table,
return,
select,
array params = null,
strictness = IGNORE_MISSING 
)

Get a single field value from a table record which match a particular WHERE clause.

Parameters:
string$tablethe table to query.
string$returnthe field to return the value of.
string$selectA fragment of SQL to be used in a where clause returning one row with one column
array$paramsarray of sql parameters
int$strictnessIGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); MUST_EXIST means throw exception if no record or multiple records found
Returns:
mixed the specified value false if not found
Exceptions:
dml_exceptionif error

Definition at line 1346 of file moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_field_sql ( sql,
array params = null,
strictness = IGNORE_MISSING 
)

Get a single field value (first field) using a SQL statement.

Parameters:
string$tablethe table to query.
string$returnthe field to return the value of.
string$sqlThe SQL query returning one row with one column
array$paramsarray of sql parameters
int$strictnessIGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); MUST_EXIST means throw exception if no record or multiple records found
Returns:
mixed the specified value false if not found
Exceptions:
dml_exceptionif error

Definition at line 1371 of file moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_fieldset_select ( table,
return,
select,
array params = null 
)

Selects records and return values of chosen field as an array which match a particular WHERE clause.

Parameters:
string$tablethe table to query.
string$returnthe field we are intered in
string$selectA fragment of SQL to be used in a where clause in the SQL call.
array$paramsarray of sql parameters
Returns:
array of values
Exceptions:
dml_exceptionif error

Definition at line 1390 of file moodle_database.php.

Here is the call graph for this function:

get_fieldset_sql ( sql,
array params = null 
) [abstract]

Selects records and return values (first field) as an array using a SQL statement.

Parameters:
string$sqlThe SQL query
array$paramsarray of sql parameters
Returns:
array of values
Exceptions:
dml_exceptionif error

Reimplemented in moodle_database_for_testing, oci_native_moodle_database, mysqli_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

Here is the caller graph for this function:

get_in_or_equal ( items,
type = SQL_PARAMS_QM,
prefix = 'param',
equal = true,
onemptyitems = false 
)

Constructs IN() or = sql fragment

Parameters:
mixed$itemssingle or array of values
int$typebound param type SQL_PARAMS_QM or SQL_PARAMS_NAMED
string$prefixnamed parameter placeholder prefix (unique counter value is appended to each parameter name)
bool$equaltrue means equal, false not equal
mixed$onemptyitemsdefines the behavior when the array of items is empty. Defaults to false, meaning throw exceptions. Other values will become part of the returned SQL fragment.
Returns:
array - $sql and $params

Definition at line 591 of file moodle_database.php.

get_last_error ( ) [abstract]

Returns last error reported by database engine.

Returns:
string error message

Reimplemented in moodle_database_for_testing, mysqli_native_moodle_database, oci_native_moodle_database, mssql_native_moodle_database, sqlsrv_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

Here is the caller graph for this function:

Returns sql generator used for db manipulation. Used mostly in upgrade.php scripts.

Returns:
database_manager instance

Definition at line 868 of file moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Returns database table prefix Note: can be used before connect()

Returns:
string database table prefix

Definition at line 155 of file moodle_database.php.

get_record ( table,
array conditions,
fields = '*',
strictness = IGNORE_MISSING 
)

Get a single database record as an object where all the given conditions met.

Parameters:
string$tableThe table to select from.
array$conditionsoptional array $fieldname=>requestedvalue with AND in between
string$fieldsA comma separated list of fields to be returned from the chosen table.
int$strictnessIGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); MUST_EXIST means throw exception if no record or multiple records found
Returns:
mixed a fieldset object containing the first matching record, false or exception if error not found depending on mode
Exceptions:
dml_exceptionif error

Definition at line 1247 of file moodle_database.php.

Here is the call graph for this function:

get_record_select ( table,
select,
array params = null,
fields = '*',
strictness = IGNORE_MISSING 
)

Get a single database record as an object which match a particular WHERE clause.

Parameters:
string$tableThe database table to be checked against.
string$selectA fragment of SQL to be used in a where clause in the SQL call.
array$paramsarray of sql parameters
int$strictnessIGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); MUST_EXIST means throw exception if no record or multiple records found
Returns:
mixed a fieldset object containing the first matching record, false or exception if error not found depending on mode
Exceptions:
dml_exceptionif error

Definition at line 1264 of file moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_record_sql ( sql,
array params = null,
strictness = IGNORE_MISSING 
)

Get a single database record as an object using a SQL statement.

The SQL statement should normally only return one record. It is recommended to use get_records_sql() if more matches possible!

Parameters:
string$sqlThe SQL string you wish to be executed, should normally only return one record.
array$paramsarray of sql parameters
int$strictnessIGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); MUST_EXIST means throw exception if no record or multiple records found
Returns:
mixed a fieldset object containing the first matching record, false or exception if error not found depending on mode
Exceptions:
dml_exceptionif error

Reimplemented in oci_native_moodle_database.

Definition at line 1290 of file moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_records ( table,
array conditions = null,
sort = '',
fields = '*',
limitfrom = 0,
limitnum = 0 
)

Get a number of records as an array of objects where all the given conditions met.

If the query succeeds and returns at least one record, the return value is an array of objects, one object for each record found. The array key is the value from the first column of the result set. The object associated with that key has a member variable for each column of the results.

Parameters:
string$tablethe table to query.
array$conditionsoptional array $fieldname=>requestedvalue with AND in between
string$sortan order to sort the results in (optional, a valid SQL ORDER BY parameter).
string$fieldsa comma separated list of fields to return (optional, by default all fields are returned). The first field will be used as key for the array so must be a unique field such as 'id'.
int$limitfromreturn a subset of records, starting at this point (optional, required if $limitnum is set).
int$limitnumreturn a subset comprising this many records (optional, required if $limitfrom is set).
Returns:
array of objects indexed by first column
Exceptions:
dml_exceptionif error

Definition at line 1076 of file moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_records_list ( table,
field,
array values,
sort = '',
fields = '*',
limitfrom = 0,
limitnum = 0 
)

Get a number of records as an array of objects where one field match one list of values.

Return value as for

See also:
function get_records.
Parameters:
string$tableThe database table to be checked against.
string$fieldThe field to search
string$valuesarray of values
string$sortSort order (as valid SQL sort parameter)
string$fieldsA comma separated list of fields to be returned from the chosen table. If specified, the first field should be a unique one such as 'id' since it will be used as a key in the associative array.
Returns:
array of objects indexed by first column
Exceptions:
dml_exceptionif error

Definition at line 1096 of file moodle_database.php.

Here is the call graph for this function:

get_records_menu ( table,
array conditions = null,
sort = '',
fields = '*',
limitfrom = 0,
limitnum = 0 
)

Get the first two columns from a number of records as an associative array where all the given conditions met.

Arguments as for

See also:
function get_recordset.

If no errors occur the return value is an associative whose keys come from the first field of each record, and whose values are the corresponding second fields. False is returned if an error occurs.

Parameters:
string$tablethe table to query.
array$conditionsoptional array $fieldname=>requestedvalue with AND in between
string$sortan order to sort the results in (optional, a valid SQL ORDER BY parameter).
string$fieldsa comma separated list of fields to return - the number of fields should be 2!
int$limitfromreturn a subset of records, starting at this point (optional, required if $limitnum is set).
int$limitnumreturn a subset comprising this many records (optional, required if $limitfrom is set).
Returns:
array an associative array
Exceptions:
dml_exceptionif error

Definition at line 1167 of file moodle_database.php.

Here is the call graph for this function:

get_records_select ( table,
select,
array params = null,
sort = '',
fields = '*',
limitfrom = 0,
limitnum = 0 
)

Get a number of records as an array of objects which match a particular WHERE clause.

Return value as for

See also:
function get_records.
Parameters:
string$tablethe table to query.
string$selectA fragment of SQL to be used in a where clause in the SQL call.
array$paramsarray of sql parameters
string$sortan order to sort the results in (optional, a valid SQL ORDER BY parameter).
string$fieldsa comma separated list of fields to return (optional, by default all fields are returned). The first field will be used as key for the array so must be a unique field such as 'id'.
int$limitfromreturn a subset of records, starting at this point (optional, required if $limitnum is set).
int$limitnumreturn a subset comprising this many records (optional, required if $limitfrom is set).
Returns:
array of objects indexed by first column
Exceptions:
dml_exceptionif error

Definition at line 1122 of file moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_records_select_menu ( table,
select,
array params = null,
sort = '',
fields = '*',
limitfrom = 0,
limitnum = 0 
)

Get the first two columns from a number of records as an associative array which match a particular WHERE clause.

Arguments as for

See also:
function get_recordset_select. Return value as for
function get_records_menu.
Parameters:
string$tableThe database table to be checked against.
string$selectA fragment of SQL to be used in a where clause in the SQL call.
array$paramsarray of sql parameters
string$sortSort order (optional) - a valid SQL order parameter
string$fieldsA comma separated list of fields to be returned from the chosen table - the number of fields should be 2!
int$limitfromreturn a subset of records, starting at this point (optional, required if $limitnum is set).
int$limitnumreturn a subset comprising this many records (optional, required if $limitfrom is set).
Returns:
array an associative array
Exceptions:
dml_exceptionif error

Definition at line 1196 of file moodle_database.php.

Here is the call graph for this function:

get_records_sql ( sql,
array params = null,
limitfrom = 0,
limitnum = 0 
) [abstract]

Get a number of records as an array of objects using a SQL statement.

Return value as for

See also:
function get_records.
Parameters:
string$sqlthe SQL select query to execute. The first column of this SELECT statement must be a unique value (usually the 'id' field), as it will be used as the key of the returned array.
array$paramsarray of sql parameters
int$limitfromreturn a subset of records, starting at this point (optional, required if $limitnum is set).
int$limitnumreturn a subset comprising this many records (optional, required if $limitfrom is set).
Returns:
array of objects indexed by first column
Exceptions:
dml_exceptionif error

Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mysqli_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

Here is the caller graph for this function:

get_records_sql_menu ( sql,
array params = null,
limitfrom = 0,
limitnum = 0 
)

Get the first two columns from a number of records as an associative array using a SQL statement.

Arguments as for

See also:
function get_recordset_sql. Return value as for
function get_records_menu.
Parameters:
string$sqlThe SQL string you wish to be executed.
array$paramsarray of sql parameters
int$limitfromreturn a subset of records, starting at this point (optional, required if $limitnum is set).
int$limitnumreturn a subset comprising this many records (optional, required if $limitfrom is set).
Returns:
array an associative array
Exceptions:
dml_exceptionif error

Definition at line 1222 of file moodle_database.php.

Here is the call graph for this function:

get_recordset ( table,
array conditions = null,
sort = '',
fields = '*',
limitfrom = 0,
limitnum = 0 
)

Get a number of records as a moodle_recordset where all the given conditions met.

Selects records from the table $table.

If specified, only records meeting $conditions.

If specified, the results will be sorted as specified by $sort. This is added to the SQL as "ORDER BY $sort". Example values of $sort might be "time ASC" or "time DESC".

If $fields is specified, only those fields are returned.

Since this method is a little less readable, use of it should be restricted to code where it's possible there might be large datasets being returned. For known small datasets use get_records - it leads to simpler code.

If you only want some of the records, specify $limitfrom and $limitnum. The query will skip the first $limitfrom records (according to the sort order) and then return the next $limitnum records. If either of $limitfrom or $limitnum is specified, both must be present.

The return value is a moodle_recordset if the query succeeds. If an error occurs, false is returned.

Parameters:
string$tablethe table to query.
array$conditionsoptional array $fieldname=>requestedvalue with AND in between
string$sortan order to sort the results in (optional, a valid SQL ORDER BY parameter).
string$fieldsa comma separated list of fields to return (optional, by default all fields are returned).
int$limitfromreturn a subset of records, starting at this point (optional, required if $limitnum is set).
int$limitnumreturn a subset comprising this many records (optional, required if $limitfrom is set).
Returns:
moodle_recordset instance
Exceptions:
dml_exceptionif error

Definition at line 977 of file moodle_database.php.

Here is the call graph for this function:

get_recordset_list ( table,
field,
array values,
sort = '',
fields = '*',
limitfrom = 0,
limitnum = 0 
)

Get a number of records as a moodle_recordset where one field match one list of values.

Only records where $field takes one of the values $values are returned. $values must be an array of values.

Other arguments and the return type as for

See also:
function get_recordset.
Parameters:
string$tablethe table to query.
string$fielda field to check (optional).
array$valuesarray of values the field must have
string$sortan order to sort the results in (optional, a valid SQL ORDER BY parameter).
string$fieldsa comma separated list of fields to return (optional, by default all fields are returned).
int$limitfromreturn a subset of records, starting at this point (optional, required if $limitnum is set).
int$limitnumreturn a subset comprising this many records (optional, required if $limitfrom is set).
Returns:
moodle_recordset instance
Exceptions:
dml_exceptionif error

Fake condition, won't return rows ever. MDL-17645

Definition at line 1000 of file moodle_database.php.

Here is the call graph for this function:

get_recordset_select ( table,
select,
array params = null,
sort = '',
fields = '*',
limitfrom = 0,
limitnum = 0 
)

Get a number of records as a moodle_recordset which match a particular WHERE clause.

If given, $select is used as the SELECT parameter in the SQL query, otherwise all records from the table are returned.

Other arguments and the return type as for

See also:
function get_recordset.
Parameters:
string$tablethe table to query.
string$selectA fragment of SQL to be used in a where clause in the SQL call.
array$paramsarray of sql parameters
string$sortan order to sort the results in (optional, a valid SQL ORDER BY parameter).
string$fieldsa comma separated list of fields to return (optional, by default all fields are returned).
int$limitfromreturn a subset of records, starting at this point (optional, required if $limitnum is set).
int$limitnumreturn a subset comprising this many records (optional, required if $limitfrom is set).
Returns:
moodle_recordset instance
Exceptions:
dml_exceptionif error

Definition at line 1027 of file moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_recordset_sql ( sql,
array params = null,
limitfrom = 0,
limitnum = 0 
) [abstract]

Get a number of records as a moodle_recordset using a SQL statement.

Since this method is a little less readable, use of it should be restricted to code where it's possible there might be large datasets being returned. For known small datasets use get_records_sql - it leads to simpler code.

The return type is as for

See also:
function get_recordset.
Parameters:
string$sqlthe SQL select query to execute.
array$paramsarray of sql parameters
int$limitfromreturn a subset of records, starting at this point (optional, required if $limitnum is set).
int$limitnumreturn a subset comprising this many records (optional, required if $limitfrom is set).
Returns:
moodle_recordset instance
Exceptions:
dml_exceptionif error

Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mysqli_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

Here is the caller graph for this function:

get_session_lock ( rowid,
timeout 
)

Obtain session lock

Parameters:
int$rowidid of the row with session record
int$timeoutmax allowed time to wait for the lock in seconds
Returns:
bool success

Reimplemented in oci_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, mysqli_native_moodle_database, and pgsql_native_moodle_database.

Definition at line 2217 of file moodle_database.php.

get_tables ( usecache = true) [abstract]

Return tables in database WITHOUT current prefix

Returns:
array of table names in lowercase and without prefix

Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mysqli_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and sqlite3_pdo_moodle_database.

import_record ( table,
dataobject 
) [abstract]

Import a record into a table, id field is required. Safety checks are NOT carried out. Lobs are supported.

Parameters:
string$tablename of database table to be inserted into
object$dataobjectA data object with values for one or more fields in the record
Returns:
bool true
Exceptions:
dml_exceptionif error

Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mysqli_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

insert_record ( table,
dataobject,
returnid = true,
bulk = false 
) [abstract]

Insert a record into a table and return the "id" field if required.

Some conversions and safety checks are carried out. Lobs are supported. If the return ID isn't required, then this just reports success as true/false. $data is an object containing needed data

Parameters:
string$tableThe database table to be inserted into
object$dataA data object with values for one or more fields in the record
bool$returnidShould the id of the newly created record entry be returned? If this option is not requested then true/false is returned.
Returns:
bool|int true or new id
Exceptions:
dml_exceptionif error

Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mysqli_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

Here is the caller graph for this function:

insert_record_raw ( table,
params,
returnid = true,
bulk = false,
customsequence = false 
) [abstract]

Insert new record into database, as fast as possible, no safety checks, lobs not supported.

Parameters:
string$tablename
mixed$paramsdata record as object or array
bool$returnitreturn it of inserted record
bool$bulktrue means repeated inserts expected
bool$customsequencetrue if 'id' included in $params, disables $returnid
Returns:
bool|int true or new id
Exceptions:
dml_exceptionif error

Reimplemented in moodle_database_for_testing, oci_native_moodle_database, mysqli_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

Returns true if transaction in progress

Returns:
bool

Definition at line 2043 of file moodle_database.php.

Here is the caller graph for this function:

normalise_value ( column,
value 
) [abstract, protected]

Normalise values based in RDBMS dependencies (booleans, LOBs...)

Parameters:
database_column_info$columncolumn metadata corresponding with the value we are going to normalise
mixed$valuevalue we are going to normalise
Returns:
mixed the normalised value

Reimplemented in moodle_database_for_testing, oci_native_moodle_database, mysqli_native_moodle_database, sqlsrv_native_moodle_database, pgsql_native_moodle_database, mssql_native_moodle_database, and sqlite3_pdo_moodle_database.

Returns number of queries done by this database

Returns:
int

Definition at line 2250 of file moodle_database.php.

performance and logging

Returns number of reads done by this database

Returns:
int

Definition at line 2234 of file moodle_database.php.

Returns number of writes done by this database

Returns:
int

Definition at line 2242 of file moodle_database.php.

print_debug ( sql,
array params = null,
obj = null 
) [protected]

Print sql debug info

Parameters:
string$sqlquery which caused problems
array$paramsoptional query parameters
mixed$objoptional library specific object
Returns:
void

Definition at line 470 of file moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

query_end ( result) [protected]

Called immediately after each db query.

Parameters:
mixeddb specific result
Returns:
void

Reimplemented in mssql_native_moodle_database, sqlsrv_native_moodle_database, and pgsql_native_moodle_database.

Definition at line 370 of file moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

query_log ( error = false)

Log last database query if requested

Parameters:
mixedstring error or false if not error
Returns:
void

Definition at line 409 of file moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

query_start ( sql,
array params = null,
type,
extrainfo = null 
) [protected]

Called before each db query.

Parameters:
string$sql
arrayarray of parameters
int$typetype of query
mixed$extrainfodriver specific extra information
Returns:
void

Reimplemented in pdo_moodle_database, oci_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, and pgsql_native_moodle_database.

Definition at line 341 of file moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

record_exists ( table,
array conditions 
)

Test whether a record exists in a table where all the given conditions met.

The record to test is specified by giving up to three fields that must equal the corresponding values.

Parameters:
string$tableThe table to check.
array$conditionsoptional array $fieldname=>requestedvalue with AND in between
Returns:
bool true if a matching record exists, else false.
Exceptions:
dml_exceptionif error

Definition at line 1561 of file moodle_database.php.

Here is the call graph for this function:

record_exists_select ( table,
select,
array params = null 
)

Test whether any records exists in a table which match a particular WHERE clause.

Parameters:
string$tableThe database table to be checked against.
string$selectA fragment of SQL to be used in a WHERE clause in the SQL call.
array$paramsarray of sql parameters
Returns:
bool true if a matching record exists, else false.
Exceptions:
dml_exceptionif error

Definition at line 1575 of file moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

record_exists_sql ( sql,
array params = null 
)

Test whether a SQL SELECT statement returns any records.

This function returns true if the SQL statement executes without any errors and returns at least one record.

Parameters:
string$sqlThe SQL statement to execute.
array$paramsarray of sql parameters
Returns:
bool true if the SQL executes without errors and returns at least one record.
Exceptions:
dml_exceptionif error

Definition at line 1593 of file moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

release_session_lock ( rowid)

Release session lock

Parameters:
int$rowidid of the row with session record
Returns:
bool success

Reimplemented in oci_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, mysqli_native_moodle_database, and pgsql_native_moodle_database.

Definition at line 2226 of file moodle_database.php.

Reset internal column details cache

Parameters:
string$table- empty means all, or one if name of table given
Returns:
void

Definition at line 858 of file moodle_database.php.

Here is the caller graph for this function:

rollback_delegated_transaction ( moodle_transaction transaction,
Exception $  e 
)

Call when delegated transaction failed, this rolls back all delegated transactions up to the top most level.

In many cases you do not need to call this method manually, because all open delegated transactions are rolled back automatically if exceptions not caught.

Parameters:
moodle_transaction$transaction
Exception$eexception that caused the problem
Returns:
void - does not return, exception is rethrown

Definition at line 2144 of file moodle_database.php.

Here is the call graph for this function:

rollback_transaction ( ) [abstract, protected]

Driver specific abort of real database transaction, this can not be used directly in code.

Returns:
void

Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, mysqli_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

Here is the caller graph for this function:

session locking

Is session lock supported in this driver?

Returns:
bool

Reimplemented in oci_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, mysqli_native_moodle_database, and pgsql_native_moodle_database.

Definition at line 2207 of file moodle_database.php.

set_debug ( state)

Enable/disable very detailed debugging

Parameters:
bool$state
Returns:
void

Reimplemented in moodle_database_for_testing.

Definition at line 904 of file moodle_database.php.

set_field ( table,
newfield,
newvalue,
array conditions = null 
)

Set a single field in every table record where all the given conditions met.

Parameters:
string$tableThe database table to be checked against.
string$newfieldthe field to set.
string$newvaluethe value to set the field to.
array$conditionsoptional array $fieldname=>requestedvalue with AND in between
Returns:
bool true
Exceptions:
dml_exceptionif error

Definition at line 1480 of file moodle_database.php.

Here is the call graph for this function:

set_field_select ( table,
newfield,
newvalue,
select,
array params = null 
) [abstract]

Set a single field in every table record which match a particular WHERE clause.

Parameters:
string$tableThe database table to be checked against.
string$newfieldthe field to set.
string$newvaluethe value to set the field to.
string$selectA fragment of SQL to be used in a where clause in the SQL call.
array$paramsarray of sql parameters
Returns:
bool true
Exceptions:
dml_exceptionif error

Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mysqli_native_moodle_database, pgsql_native_moodle_database, mssql_native_moodle_database, and pdo_moodle_database.

Here is the caller graph for this function:

set_logging ( state)

Enable/disable detailed sql logging

Parameters:
bool$state

Reimplemented in moodle_database_for_testing.

Definition at line 920 of file moodle_database.php.

Is db in unicode mode?

Returns:
bool

Reimplemented in oci_native_moodle_database, mysqli_native_moodle_database, and pgsql_native_moodle_database.

Definition at line 895 of file moodle_database.php.

sql_bitand ( int1,
int2 
)

Returns the SQL text to be used in order to perform one bitwise AND operation between 2 integers.

NOTE: The SQL result is a number and can not be used directly in SQL condition, please compare it to some number to get a bool!!

Parameters:
int$int1first integer in the operation
int$int2second integer in the operation
Returns:
string the piece of SQL code to be used in your statement

Reimplemented in oci_native_moodle_database.

Definition at line 1673 of file moodle_database.php.

sql_bitnot ( int1)

Returns the SQL text to be used in order to perform one bitwise NOT operation with 1 integer.

Parameters:
int$int1integer in the operation
Returns:
string the piece of SQL code to be used in your statement.

Reimplemented in oci_native_moodle_database.

Definition at line 1684 of file moodle_database.php.

sql_bitor ( int1,
int2 
)

Returns the SQL text to be used in order to perform one bitwise OR operation between 2 integers.

NOTE: The SQL result is a number and can not be used directly in SQL condition, please compare it to some number to get a bool!!

Parameters:
int$int1first integer in the operation
int$int2second integer in the operation
Returns:
string the piece of SQL code to be used in your statement.

Reimplemented in oci_native_moodle_database.

Definition at line 1699 of file moodle_database.php.

sql_bitxor ( int1,
int2 
)

Returns the SQL text to be used in order to perform one bitwise XOR operation between 2 integers.

NOTE: The SQL result is a number and can not be used directly in SQL condition, please compare it to some number to get a bool!!

Parameters:
int$int1first integer in the operation
int$int2second integer in the operation
Returns:
string the piece of SQL code to be used in your statement.

Reimplemented in oci_native_moodle_database, pgsql_native_moodle_database, and sqlite3_pdo_moodle_database.

Definition at line 1714 of file moodle_database.php.

sql_cast_2signed ( fieldname)

Returns the SQL to be used in order to an UNSIGNED INTEGER column to SIGNED.

(Only MySQL needs this. MySQL things that 1 * -1 = 18446744073709551615 if the 1 comes from an unsigned column).

Parameters:
string$fieldnamethe name of the field to be cast
Returns:
string the piece of SQL code to be used in your statement.

Reimplemented in mysqli_native_moodle_database.

Definition at line 1778 of file moodle_database.php.

sql_cast_char2int ( fieldname,
text = false 
)

Returns the SQL to be used in order to CAST one CHAR column to INTEGER.

Be aware that the CHAR column you're trying to cast contains really int values or the RDBMS will throw an error!

Parameters:
string$fieldnamethe name of the field to be casted
bool$textto specify if the original column is one TEXT (CLOB) column (true). Defaults to false.
Returns:
string the piece of SQL code to be used in your statement.

Reimplemented in oci_native_moodle_database, sqlsrv_native_moodle_database, pgsql_native_moodle_database, mysqli_native_moodle_database, and mssql_native_moodle_database.

Definition at line 1751 of file moodle_database.php.

sql_cast_char2real ( fieldname,
text = false 
)

Returns the SQL to be used in order to CAST one CHAR column to REAL number.

Be aware that the CHAR column you're trying to cast contains really numbers or the RDBMS will throw an error!

Parameters:
string$fieldnamethe name of the field to be casted
bool$textto specify if the original column is one TEXT (CLOB) column (true). Defaults to false.
Returns:
string the piece of SQL code to be used in your statement.

Reimplemented in oci_native_moodle_database, sqlsrv_native_moodle_database, pgsql_native_moodle_database, mysqli_native_moodle_database, and mssql_native_moodle_database.

Definition at line 1765 of file moodle_database.php.

sql_ceil ( fieldname)

Returns the correct CEIL expression applied to fieldname.

Parameters:
string$fieldnamethe field (or expression) we are going to ceil
Returns:
string the piece of SQL code to be used in your ceiling statement Most DB use CEIL(), hence it's the default.

Reimplemented in sqlsrv_native_moodle_database, and mssql_native_moodle_database.

Definition at line 1737 of file moodle_database.php.

sql_compare_text ( fieldname,
numchars = 32 
)

Returns the SQL text to be used to compare one TEXT (clob) column with one varchar column, because some RDBMS doesn't support such direct comparisons.

Parameters:
string$fieldnamethe name of the TEXT field we need to order by
int$numcharsof chars to use for the ordering (defaults to 32)
Returns:
string the piece of SQL code to be used in your statement.

Definition at line 1791 of file moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

sql_concat ( ) [abstract]

Returns the proper SQL to do CONCAT between the elements passed Can take many parameters

This function accepts variable number of string parameters.

Returns:
string

Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, mysqli_native_moodle_database, pgsql_native_moodle_database, pdo_moodle_database, and sqlite3_pdo_moodle_database.

Here is the caller graph for this function:

sql_concat_join ( separator = "' '",
elements = array() 
) [abstract]

Returns the proper SQL to do CONCAT between the elements passed with a given separator

Parameters:
string$separator
array$elements
Returns:
string

Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, mysqli_native_moodle_database, pgsql_native_moodle_database, pdo_moodle_database, and sqlite3_pdo_moodle_database.

sql_empty ( )

Returns the empty string char used by every supported DB. To be used when we are searching for that values in our queries. Only Oracle uses this for now (will be out, once we migrate to proper NULLs if that days arrives)

Returns:
string

Reimplemented in oci_native_moodle_database.

Definition at line 1939 of file moodle_database.php.

sql_fullname ( first = 'firstname',
last = 'lastname' 
)

Returns the proper SQL (for the dbms in use) to concatenate $firstname and $lastname TODO: Does this really need to be here? Eloy 20070727. TODO: we definitely do not! (skodak)

Parameters:
string$firstUser's first name
string$lastUser's last name
Returns:
string

Definition at line 1871 of file moodle_database.php.

Here is the call graph for this function:

sql_ilike ( )

Returns the proper SQL to do LIKE in a case-insensitive way.

Note the LIKE are case sensitive for Oracle. Oracle 10g is required to use the case insensitive search using regexp_like() or NLS_COMP=LINGUISTIC :-( See http://docs.moodle.org/en/XMLDB_Problems#Case-insensitive_searches

Deprecated:
Returns:
string

Reimplemented in pgsql_native_moodle_database.

Definition at line 1837 of file moodle_database.php.

Here is the call graph for this function:

sql_isempty ( tablename,
fieldname,
nullablefield,
textfield 
)

Returns the proper SQL to know if one field is empty.

Note that the function behavior strongly relies on the parameters passed describing the field so, please, be accurate when specifying them.

Also, note that this function is not suitable to look for fields having NULL contents at all. It's all for empty values!

This function should be applied in all the places where conditions of the type:

... AND fieldname = '';

are being used. Final result should be:

... AND ' . sql_isempty('tablename', 'fieldname', true/false, true/false);

(see parameters description below)

Parameters:
string$tablenamename of the table (without prefix). Not used for now but can be necessary in the future if we want to use some introspection using meta information against the DB. /// TODO ///
string$fieldnamename of the field we are going to check
boolean$nullablefieldto specify if the field us nullable (true) or no (false) in the DB
boolean$textfieldto specify if it is a text (also called clob) field (true) or a varchar one (false)
Returns:
string the sql code to be added to check for empty values

Reimplemented in oci_native_moodle_database, sqlsrv_native_moodle_database, and mssql_native_moodle_database.

Definition at line 1972 of file moodle_database.php.

Here is the caller graph for this function:

sql_isnotempty ( tablename,
fieldname,
nullablefield,
textfield 
)

Returns the proper SQL to know if one field is not empty.

Note that the function behavior strongly relies on the parameters passed describing the field so, please, be accurate when specifying them.

This function should be applied in all the places where conditions of the type:

... AND fieldname != '';

are being used. Final result should be:

... AND ' . sql_isnotempty('tablename', 'fieldname', true/false, true/false);

(see parameters description below)

Parameters:
string$tablenamename of the table (without prefix). Not used for now but can be necessary in the future if we want to use some introspection using meta information against the DB. /// TODO ///
string$fieldnamename of the field we are going to check
boolean$nullablefieldto specify if the field us nullable (true) or no (false) in the DB
boolean$textfieldto specify if it is a text (also called clob) field (true) or a varchar one (false)
Returns:
string the sql code to be added to check for non empty values

Definition at line 2002 of file moodle_database.php.

Here is the call graph for this function:

sql_length ( fieldname)

Returns the SQL text to be used to calculate the length in characters of one expression.

Parameters:
string$fieldnameor expression to calculate its length in characters.
Returns:
string the piece of SQL code to be used in the statement.

Reimplemented in sqlsrv_native_moodle_database, mssql_native_moodle_database, and mysqli_native_moodle_database.

Definition at line 1895 of file moodle_database.php.

sql_like ( fieldname,
param,
casesensitive = true,
accentsensitive = true,
notlike = false,
escapechar = '\\' 
)

Returns 'LIKE' part of a query.

Parameters:
string$fieldnameusually name of the table column
string$paramusually bound query parameter (?, :named)
bool$casesensitiveuse case sensitive search
bool$accensensitiveuse accent sensitive search (not all databases support accent insensitive)
bool$notliketrue means "NOT LIKE"
string$escapecharescape char for '' and '_'
Returns:
string SQL code fragment

Reimplemented in oci_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, mysqli_native_moodle_database, and pgsql_native_moodle_database.

Definition at line 1806 of file moodle_database.php.

Here is the call graph for this function:

sql_like_escape ( text,
escapechar = '\\' 
)

Escape sql LIKE special characters.

Parameters:
string$text
string$escapechar
Returns:
string

Definition at line 1821 of file moodle_database.php.

sql_modulo ( int1,
int2 
)

Returns the SQL text to be used in order to perform module '' operation - remainder after division

Parameters:
int$int1first integer in the operation
int$int2second integer in the operation
Returns:
string the piece of SQL code to be used in your statement.

Reimplemented in oci_native_moodle_database.

Definition at line 1726 of file moodle_database.php.

sql constructs

Returns the FROM clause required by some DBs in all SELECT statements.

To be used in queries not having FROM clause to provide cross_db Most DBs don't need it, hence the default is ''

Returns:
string

Reimplemented in oci_native_moodle_database.

Definition at line 1658 of file moodle_database.php.

sql_order_by_text ( fieldname,
numchars = 32 
)

Returns the SQL text to be used to order by one TEXT (clob) column, because some RDBMS doesn't support direct ordering of such fields.

Note that the use or queries being ordered by TEXT columns must be minimised, because it's really slooooooow.

Parameters:
string$fieldnamethe name of the TEXT field we need to order by
string$numcharsof chars to use for the ordering (defaults to 32)
Returns:
string the piece of SQL code to be used in your statement.

Reimplemented in oci_native_moodle_database, sqlsrv_native_moodle_database, and mssql_native_moodle_database.

Definition at line 1886 of file moodle_database.php.

Here is the caller graph for this function:

sql_position ( needle,
haystack 
)

Returns the SQL for returning searching one string for the location of another. Note, there is no guarantee which order $needle, $haystack will be in the resulting SQL, so when using this method, and both arguments contain placeholders, you should use named placeholders.

Parameters:
string$needlethe SQL expression that will be searched for.
string$haystackthe SQL expression that will be searched in.
Returns:
string the required SQL

Reimplemented in oci_native_moodle_database, sqlsrv_native_moodle_database, and mssql_native_moodle_database.

Definition at line 1928 of file moodle_database.php.

sql_regex ( positivematch = true)

Return regex positive or negative match sql

Parameters:
bool$positivematch
Returns:
string or empty if not supported

Reimplemented in mysqli_native_moodle_database, and pgsql_native_moodle_database.

Definition at line 2019 of file moodle_database.php.

Does this driver suppoer regex syntax when searching

Returns:
bool

Reimplemented in mysqli_native_moodle_database, and pgsql_native_moodle_database.

Definition at line 2010 of file moodle_database.php.

sql_substr ( expr,
start,
length = false 
)

Returns the proper substr() SQL text used to extract substrings from DB NOTE: this was originally returning only function name

Parameters:
string$exprsome string field, no aggregates
mixed$startinteger or expression evaluating to int (1 based value; first char has index 1)
mixed$lengthoptional integer or expression evaluating to int
Returns:
string sql fragment

Reimplemented in moodle_database_for_testing, sqlsrv_native_moodle_database, and mssql_native_moodle_database.

Definition at line 1908 of file moodle_database.php.

On DBs that support it, switch to transaction mode and begin a transaction you'll need to ensure you call allow_commit() on the returned object or your changes *will* be lost.

this is _very_ useful for massive updates

Delegated database transactions can be nested, but only one actual database transaction is used for the outer-most delegated transaction. This method returns a transaction object which you should keep until the end of the delegated transaction. The actual database transaction will only be committed if all the nested delegated transactions commit successfully. If any part of the transaction rolls back then the whole thing is rolled back.

Returns:
moodle_transaction

Definition at line 2075 of file moodle_database.php.

Here is the call graph for this function:

store_settings ( dbhost,
dbuser,
dbpass,
dbname,
prefix,
array dboptions = null 
) [protected]

Store various database settings

Parameters:
string$dbhost
string$dbuser
string$dbpass
string$dbname
mixed$prefixstring means moodle db prefix, false used for external databases where prefix not used
array$dboptionsdriver specific options
Returns:
void

Definition at line 276 of file moodle_database.php.

Here is the caller graph for this function:

Throws exception if transaction in progress. This test does not force rollback of active transactions.

Returns:
void

Definition at line 2052 of file moodle_database.php.

Here is the call graph for this function:

transactions_supported ( ) [protected]

transactions

Are transactions supported? It is not responsible to run productions servers on databases without transaction support ;-)

Override in driver if needed.

Returns:
bool

Reimplemented in mysqli_native_moodle_database.

Definition at line 2034 of file moodle_database.php.

update_record ( table,
dataobject,
bulk = false 
) [abstract]

Update a record in a table

$dataobject is an object containing needed data Relies on $dataobject having a variable "id" to specify the record to update

Parameters:
string$tableThe database table to be checked against.
object$dataobjectAn object with contents equal to fieldname=>fieldvalue. Must have an entry for 'id' to map to the table specified.
booltrue means repeated updates expected
Returns:
bool true
Exceptions:
dml_exceptionif error

Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mysqli_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

update_record_raw ( table,
params,
bulk = false 
) [abstract]

Update record in database, as fast as possible, no safety checks, lobs not supported.

Parameters:
string$tablename
mixed$paramsdata record as object or array
booltrue means repeated updates expected
Returns:
bool true
Exceptions:
dml_exceptionif error

Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mysqli_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

where_clause ( table,
array conditions = null 
) [protected]

Returns SQL WHERE conditions.

Parameters:
string$table- the table name that these conditions will be validated against.
arrayconditions - must not contain numeric indexes
Returns:
array sql part and params

Definition at line 497 of file moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

where_clause_list ( field,
array values 
) [protected]

Returns SQL WHERE conditions for the ..._list methods.

Parameters:
string$fieldthe name of a field.
array$valuesthe values field might take.
Returns:
array sql part and params

Definition at line 562 of file moodle_database.php.

Here is the caller graph for this function:


Field Documentation

$columns = array() [protected]

Definition at line 71 of file moodle_database.php.

$database_manager [protected]

Definition at line 67 of file moodle_database.php.

$dbhost [protected]

Definition at line 77 of file moodle_database.php.

$dbname [protected]

Definition at line 83 of file moodle_database.php.

$dboptions [protected]

Definition at line 88 of file moodle_database.php.

$dbpass [protected]

Definition at line 81 of file moodle_database.php.

$dbuser [protected]

Definition at line 79 of file moodle_database.php.

$debug = 0 [protected]

Definition at line 99 of file moodle_database.php.

$external [protected]

Definition at line 91 of file moodle_database.php.

$last_extrainfo [protected]

Definition at line 108 of file moodle_database.php.

$last_params [protected]

Definition at line 104 of file moodle_database.php.

$last_sql [protected]

Definition at line 102 of file moodle_database.php.

$last_time [protected]

Definition at line 110 of file moodle_database.php.

$last_type [protected]

Definition at line 106 of file moodle_database.php.

$prefix [protected]

Reimplemented in moodle_database_for_testing.

Definition at line 85 of file moodle_database.php.

$reads = 0 [protected]

Definition at line 94 of file moodle_database.php.

$tables = null [protected]

Definition at line 73 of file moodle_database.php.

$temptables [protected]

Reimplemented in sqlsrv_native_moodle_database.

Definition at line 69 of file moodle_database.php.

$used_for_db_sessions = false [protected]

Definition at line 115 of file moodle_database.php.

$writes = 0 [protected]

Definition at line 96 of file moodle_database.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations