Moodle APIs 4.3
Moodle 4.3.6 (Build: 20240812)
|
Native MariaDB class representing moodle database interface. More...
Public Member Functions | |
change_database_structure ($sql, $tablenames=null) | |
Do NOT use in code, to be used by database_manager only! | |
change_db_encoding () | |
Attempts to change db encoding to UTF-8 encoding if possible. | |
commit_delegated_transaction (moodle_transaction $transaction) | |
Indicates delegated transaction finished successfully. | |
connect ($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null) | |
Connects to the database. | |
convert_table_row_format ($tablename) | |
Converts a table to either 'Compressed' or 'Dynamic' row format. | |
count_records ($table, array $conditions=null) | |
Count the records in a table where all the given conditions met. | |
count_records_select ($table, $select, array $params=null, $countitem="COUNT('x')") | |
Count the records in a table which match a particular WHERE clause. | |
count_records_sql ($sql, array $params=null) | |
Get the result of a SQL SELECT COUNT(...) query. | |
create_database ($dbhost, $dbuser, $dbpass, $dbname, array $dboptions=null) | |
Attempt to create the database. | |
delete_records ($table, array $conditions=null) | |
Delete the records from a table where all the given conditions met. | |
delete_records_list ($table, $field, array $values) | |
Delete the records from a table where one field match one list of values. | |
delete_records_select ($table, $select, array $params=null) | |
Delete one or more records from a table which match a particular WHERE clause. | |
delete_records_subquery (string $table, string $field, string $alias, string $subquery, array $params=[]) | |
Deletes records using a subquery, which is done with a strange DELETE...JOIN syntax in MySQL because it performs very badly with normal subqueries. | |
diagnose () | |
Diagnose database and tables, this function is used to verify database and driver settings, db engine types, etc. | |
dispose () | |
Close database connection and release all resources and memory (especially circular memory references). | |
driver_installed () | |
Detects if all needed PHP stuff installed. | |
execute ($sql, array $params=null) | |
Execute general sql query. | |
export_dbconfig () | |
Returns the db related part of config.php. | |
export_table_recordset ($table) | |
Get all records from a table. | |
fix_sql_params ($sql, array $params=null) | |
Normalizes sql query parameters and verifies parameters. | |
force_transaction_rollback () | |
Force rollback of all delegated transaction. | |
get_columns ($table, $usecache=true) | |
Returns detailed information about columns in table. | |
get_configuration_help () | |
Returns localised database configuration help. | |
get_configuration_hints () | |
Returns the localised database description Note: can be used before connect() | |
get_dbcollation () | |
Returns the current MySQL db collation. | |
get_dbengine () | |
Returns the current MySQL db engine. | |
get_dbfamily () | |
Returns database family type - describes SQL dialect Note: can be used before connect() | |
get_dbvendor () | |
Returns the database vendor. | |
get_debug () | |
Returns debug status. | |
get_field ($table, $return, array $conditions, $strictness=IGNORE_MISSING) | |
Get a single field value from a table record where all the given conditions met. | |
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. | |
get_field_sql ($sql, array $params=null, $strictness=IGNORE_MISSING) | |
Get a single field value (first field) using a SQL statement. | |
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. | |
get_fieldset_sql ($sql, array $params=null) | |
Selects records and return values (first field) as an array using a SQL statement. | |
get_in_or_equal ($items, $type=SQL_PARAMS_QM, $prefix='param', $equal=true, $onemptyitems=false) | |
Constructs 'IN()' or '=' sql fragment. | |
get_indexes ($table) | |
Return table indexes - everything lowercased. | |
get_last_error () | |
Returns last error reported by database engine. | |
get_manager () | |
Returns the sql generator used for db manipulation. | |
get_name () | |
Returns localised database type name Note: can be used before connect() | |
get_prefix () | |
Returns database table prefix Note: can be used before connect() | |
get_record ($table, array $conditions, $fields=' *', $strictness=IGNORE_MISSING) | |
Get a single database record as an object where all the given conditions met. | |
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. | |
get_record_sql ($sql, array $params=null, $strictness=IGNORE_MISSING) | |
Get a single database record as an object using a SQL statement. | |
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. | |
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. | |
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. | |
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. | |
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. | |
get_records_sql ($sql, array $params=null, $limitfrom=0, $limitnum=0) | |
Get a number of records as an array of objects using a SQL statement. | |
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. | |
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. | |
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. | |
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. | |
get_recordset_sql ($sql, array $params=null, $limitfrom=0, $limitnum=0) | |
Get a number of records as a moodle_recordset using a SQL statement. | |
get_row_format ($table=null) | |
Get the row format from the database schema. | |
get_row_format_sql ($engine=null, $collation=null) | |
Determine if the row format should be set to compressed, dynamic, or default. | |
get_server_info () | |
Returns database server info array. | |
get_session_lock ($rowid, $timeout) | |
Obtain session lock. | |
get_tables ($usecache=true) | |
Return tables in database WITHOUT current prefix. | |
get_transaction_start_backtrace () | |
Returns transaction trace for debugging purposes. | |
has_breaking_change_sqlmode () | |
Indicates whether SQL_MODE default value has changed in a not backward compatible way. | |
import_record ($table, $dataobject) | |
Import a record into a table, id field is required. | |
insert_record ($table, $dataobject, $returnid=true, $bulk=false) | |
Insert a record into a table and return the "id" field if required. | |
insert_record_raw ($table, $params, $returnid=true, $bulk=false, $customsequence=false) | |
Insert new record into database, as fast as possible, no safety checks, lobs not supported. | |
insert_records ($table, $dataobjects) | |
Insert multiple records into database as fast as possible. | |
is_compressed_row_format_supported ($cached=true) | |
Is this database compatible with compressed row format? This feature is necessary for support of large number of text columns in InnoDB/XtraDB database. | |
is_file_per_table_enabled () | |
Check the database to see if innodb_file_per_table is on. | |
is_fulltext_search_supported () | |
Does this mariadb instance support fulltext indexes? | |
is_large_prefix_enabled () | |
Check the database to see if innodb_large_prefix is on. | |
is_transaction_started () | |
Returns true if a transaction is in progress. | |
perf_get_queries () | |
Returns the number of queries done by this database. | |
perf_get_queries_time () | |
Time waiting for the database engine to finish running all queries. | |
perf_get_reads () | |
Returns the number of reads done by this database. | |
perf_get_reads_slave () | |
Returns the number of reads before first write done by this database. | |
perf_get_writes () | |
Returns the number of writes done by this database. | |
query_log ($error=false) | |
This logs the last query based on 'logall', 'logslow' and 'logerrors' options configured via $CFG->dboptions . | |
raw_connect (string $dbhost, string $dbuser, string $dbpass, string $dbname, $prefix, array $dboptions=null) | |
Connect to db. | |
record_exists ($table, array $conditions) | |
Test whether a record exists in a table where all the given conditions met. | |
record_exists_select ($table, $select, array $params=null) | |
Test whether any records exists in a table which match a particular WHERE clause. | |
record_exists_sql ($sql, array $params=null) | |
Test whether a SQL SELECT statement returns any records. | |
release_session_lock ($rowid) | |
Releases the session lock. | |
replace_all_text ($table, database_column_info $column, $search, $replace) | |
Replace given text in all rows of column. | |
replace_all_text_supported () | |
Does this driver support tool_replace? | |
reset_caches ($tablenames=null) | |
Resets the internal column details cache. | |
rollback_delegated_transaction (moodle_transaction $transaction, $e) | |
Call when delegated transaction failed, this rolls back all delegated transactions up to the top most level. | |
session_lock_supported () | |
Is session lock supported in this driver? | |
set_debug ($state) | |
Enable/disable very detailed debugging. | |
set_field ($table, $newfield, $newvalue, array $conditions=null) | |
Set a single field in every table record where all the given conditions met. | |
set_field_select ($table, $newfield, $newvalue, $select, array $params=null) | |
Set a single field in every table record which match a particular WHERE clause. | |
set_logging ($state) | |
Enable/disable detailed sql logging. | |
setup_is_unicodedb () | |
Is this database compatible with utf8? | |
sql_bitand ($int1, $int2) | |
Returns the SQL text to be used in order to perform one bitwise AND operation between 2 integers. | |
sql_bitnot ($int1) | |
Returns the SQL text to be used in order to perform one bitwise NOT operation with 1 integer. | |
sql_bitor ($int1, $int2) | |
Returns the SQL text to be used in order to perform one bitwise OR operation between 2 integers. | |
sql_bitxor ($int1, $int2) | |
Returns the SQL text to be used in order to perform one bitwise XOR operation between 2 integers. | |
sql_cast_2signed ($fieldname) | |
Returns the SQL to be used in order to an UNSIGNED INTEGER column to SIGNED. | |
sql_cast_char2int ($fieldname, $text=false) | |
Returns the SQL to be used in order to CAST one CHAR column to INTEGER. | |
sql_cast_char2real ($fieldname, $text=false) | |
Returns the SQL to be used in order to CAST one CHAR column to REAL number. | |
sql_cast_to_char (string $field) | |
Return SQL for casting to char of given field/expression. | |
sql_ceil ($fieldname) | |
Returns the cross db correct CEIL (ceiling) expression applied to fieldname. | |
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. | |
sql_concat () | |
Returns the proper SQL to do CONCAT between the elements passed Can take many parameters. | |
sql_concat_join ($separator="' '", $elements=array()) | |
Returns the proper SQL to do CONCAT between the elements passed with a given separator. | |
sql_empty () | |
This used to return empty string replacement character. | |
sql_equal ($fieldname, $param, $casesensitive=true, $accentsensitive=true, $notequal=false) | |
Returns an equal (=) or not equal (<>) part of a query. | |
sql_fullname ($first='firstname', $last='lastname') | |
Returns the proper SQL (for the dbms in use) to concatenate $firstname and $lastname. | |
sql_group_concat (string $field, string $separator=', ', string $sort='') | |
Return SQL for performing group concatenation on given field/expression. | |
sql_intersect ($selects, $fields) | |
Returns the SQL that allows to find intersection of two or more queries. | |
sql_isempty ($tablename, $fieldname, $nullablefield, $textfield) | |
Returns the proper SQL to know if one field is empty. | |
sql_isnotempty ($tablename, $fieldname, $nullablefield, $textfield) | |
Returns the proper SQL to know if one field is not empty. | |
sql_length ($fieldname) | |
Returns the SQL text to be used to calculate the length in characters of one expression. | |
sql_like ($fieldname, $param, $casesensitive=true, $accentsensitive=true, $notlike=false, $escapechar='\\') | |
Returns 'LIKE' part of a query. | |
sql_like_escape ($text, $escapechar='\\') | |
Escape sql LIKE special characters like '_' or ''. | |
sql_modulo ($int1, $int2) | |
Returns the SQL text to be used in order to perform module '' operation - remainder after division. | |
sql_null_from_clause () | |
Returns the FROM clause required by some DBs in all SELECT statements. | |
sql_order_by_null (string $fieldname, int $sort=SORT_ASC) | |
Returns the SQL text to be used to order by columns, standardising the return pattern of null values across database types to sort nulls first when ascending and last when descending. | |
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. | |
sql_position ($needle, $haystack) | |
Returns the SQL for returning searching one string for the location of another. | |
sql_regex ($positivematch=true, $casesensitive=false) | |
Return regex positive or negative match sql. | |
sql_regex_get_word_beginning_boundary_marker () | |
Returns the word-beginning boundary marker based on MySQL version. | |
sql_regex_get_word_end_boundary_marker () | |
Returns the word-end boundary marker based on MySQL version. | |
sql_regex_supported () | |
Does this driver support regex syntax when searching. | |
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. | |
start_delegated_transaction () | |
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. | |
transactions_forbidden () | |
This is a test that throws an exception if transaction in progress. | |
update_record ($table, $dataobject, $bulk=false) | |
Update a record in a table. | |
update_record_raw ($table, $params, $bulk=false) | |
Update record in database, as fast as possible, no safety checks, lobs not supported. | |
update_temp_table_stats () | |
Analyze the data in temporary tables to force statistics collection after bulk data loads. | |
want_read_slave () | |
Returns whether we want to connect to slave database for read queries. | |
Static Public Member Functions | |
static | get_driver_instance ($type, $library, $external=false) |
Loads and returns a database instance with the specified type and library. | |
Protected Member Functions | |
add_sql_debugging (string $sql) | |
Add an SQL comment to trace all sql calls back to the calling php code. | |
allowed_param_types () | |
Returns supported query parameter types. | |
begin_transaction () | |
Driver specific start of real database transaction, this can not be used directly in code. | |
can_use_readonly (int $type, string $sql) | |
Check if The query qualifies for readonly connection execution Logging queries are exempt, those are write operations that circumvent standard query_start/query_end paths. | |
commit_transaction () | |
Driver specific commit of real database transaction, this can not be used directly in code. | |
create_recordset ($result) | |
detect_objects ($value) | |
Detects object parameters and throws exception if found. | |
emulate_bound_params ($sql, array $params=null) | |
Very ugly hack which emulates bound parameters in queries because prepared statements do not use query cache. | |
fetch_columns (string $table) | |
Fetches detailed information about columns in table. | |
fix_table_name ($tablename) | |
Fixes any table names that clash with reserved words. | |
fix_table_names ($sql) | |
Converts short table name {tablename} to the real prefixed table name in given sql. | |
get_db_handle () | |
Gets db handle currently used with queries. | |
get_dblibrary () | |
Returns general database library name Note: can be used before connect() | |
get_dbtype () | |
Returns more specific database driver type Note: can be used before connect() | |
get_metacache () | |
Handle the creation and caching of the databasemeta information for all databases. | |
get_mysqli_server_info () | |
Returns the version of the MySQL server, as reported by the PHP client connection. | |
get_settings_hash () | |
Returns a hash for the settings used during connection. | |
get_temp_tables_cache () | |
Handle the creation and caching of the temporary tables. | |
get_version_from_db () | |
Returns the version of the MySQL server, as reported by 'SELECT VERSION()' query. | |
has_breaking_change_quoted_defaults () | |
Indicates whether column information retrieved from information_schema.columns has default values quoted or not. | |
insert_chunk ($table, array $chunk, array $columns) | |
Insert records in chunks. | |
is_antelope_file_format_no_more_supported () | |
Tests if the Antelope file format is still supported or it has been removed. | |
normalise_limit_from_num ($limitfrom, $limitnum) | |
Ensures that limit params are numeric and positive integers, to be passed to the database. | |
normalise_value ($column, $value) | |
Normalise values based in RDBMS dependencies (booleans, LOBs...) | |
print_debug ($sql, array $params=null, $obj=null) | |
Prints sql debug info. | |
print_debug_time () | |
Prints the time a query took to run. | |
query_end ($result) | |
This should be called immediately after each db query. | |
query_log_allow () | |
Restore old logging behavior. | |
query_log_prevent () | |
Disable logging temporarily. | |
query_start ($sql, ?array $params, $type, $extrainfo=null) | |
This should be called before each db query. | |
query_time () | |
Returns the time elapsed since the query started. | |
rollback_transaction () | |
Driver specific abort of real database transaction, this can not be used directly in code. | |
set_db_handle ($dbh) | |
Sets db handle to be used with subsequent queries. | |
should_db_version_be_read_from_db () | |
Returns whether $CFG->dboptions['versionfromdb'] has been set to boolean true . | |
store_settings ($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null) | |
Store various database settings. | |
transactions_supported () | |
It is time to require transactions everywhere. | |
where_clause ($table, array $conditions=null) | |
Returns the SQL WHERE conditions. | |
where_clause_list ($field, array $values) | |
Returns SQL WHERE conditions for the ..._list group of methods. | |
Protected Attributes | |
bool | $compressedrowformatsupported = null |
is compressed row format supported cache | |
database_manager | $database_manager |
db manager which allows db structure modifications. | |
string | $dbhost |
db host name. | |
string | $dbname |
db name. | |
array | $dboptions |
Database or driver specific options, such as sockets or TCP/IP db connections. | |
string | $dbpass |
db host password. | |
string | $dbuser |
db host user. | |
int | $debug = 0 |
Debug level. | |
bool | $disposed |
flag marking database instance as disposed | |
bool | $external |
True means non-moodle external database used. | |
int | $inorequaluniqueindex = 1 |
internal temporary variable used to guarantee unique parameters in each request. | |
string | $last_extrainfo |
Last extra info. | |
array | $last_params |
Last query parameters. | |
string | $last_sql |
Last used query sql. | |
float | $last_time |
Last time in seconds with millisecond precision. | |
int | $last_type |
Last query type. | |
bool | $loggingquery = false |
Flag indicating logging of query in progress. | |
cache_application | $metacache |
for column info | |
cache_request | $metacachetemp |
for column info on temp tables | |
mysqli | $mysqli = null |
$mysqli | |
string | $prefix |
Prefix added to table names. | |
float | $queriestime = 0 |
Time queries took to finish, seconds with microseconds. | |
int | $reads = 0 |
The database reads (performance counter). | |
string | $serverversion = null |
DB server actual version. | |
boolean | $skiplogging = false |
variable use to temporarily disable logging. | |
array | $tables = null |
Cache of table info. | |
moodle_temptables | $temptables |
temptables manager to provide cross-db support for temp tables. | |
array | $transactions = array() |
Array containing open transactions. | |
bool | $used_for_db_sessions = false |
True if the db is used for db sessions. | |
int | $writes = 0 |
The database writes (performance counter). | |
Native MariaDB class representing moodle database interface.
|
protectedinherited |
Add an SQL comment to trace all sql calls back to the calling php code.
string | $sql | Original sql |
string | Instrumented sql |
|
protectedinherited |
Returns supported query parameter types.
int | bitmask of accepted SQL_PARAMS_* |
Reimplemented from moodle_database.
|
protectedinherited |
Driver specific start of real database transaction, this can not be used directly in code.
void |
Reimplemented from moodle_database.
|
protectedinherited |
Check if The query qualifies for readonly connection execution Logging queries are exempt, those are write operations that circumvent standard query_start/query_end paths.
int | $type | type of query |
string | $sql |
bool |
|
inherited |
Do NOT use in code, to be used by database_manager only!
string | array | $sql | query |
array | null | $tablenames | an array of xmldb table names affected by this request. |
bool | true |
ddl_change_structure_exception | A DDL specific exception is thrown for any errors. |
Reimplemented from moodle_database.
|
inherited |
Attempts to change db encoding to UTF-8 encoding if possible.
bool | True is successful. |
|
inherited |
Indicates delegated transaction finished successfully.
The real database transaction is committed only if all delegated transactions committed.
moodle_transaction | $transaction | The transaction to commit |
void |
dml_transaction_exception | Creates and throws transaction related exceptions. |
|
protectedinherited |
Driver specific commit of real database transaction, this can not be used directly in code.
void |
Reimplemented from moodle_database.
|
abstractinherited |
Connects to the database.
Must be called before other methods.
string | $dbhost | The database host. |
string | $dbuser | The database user to connect as. |
string | $dbpass | The password to use when connecting to the database. |
string | $dbname | The name of the database being connected to. |
mixed | $prefix | string means moodle db prefix, false used for external databases where prefix not used |
array | $dboptions | driver specific options |
bool | true |
dml_connection_exception | if error |
Reimplemented in oci_native_moodle_database, pdo_moodle_database, and sqlsrv_native_moodle_database.
|
inherited |
Converts a table to either 'Compressed' or 'Dynamic' row format.
string | $tablename | Name of the table to convert to the new row format. |
|
inherited |
Count the records in a table where all the given conditions met.
string | $table | The table to query. |
array | $conditions | optional array $fieldname=>requestedvalue with AND in between |
int | The count of records returned from the specified criteria. |
dml_exception | A DML specific exception is thrown for any errors. |
|
inherited |
Count the records in a table which match a particular WHERE clause.
string | $table | The database table to be checked against. |
string | $select | A fragment of SQL to be used in a WHERE clause in the SQL call. |
array | $params | array of sql parameters |
string | $countitem | The count string to be used in the SQL call. Default is COUNT('x'). |
int | The count of records returned from the specified criteria. |
dml_exception | A DML specific exception is thrown for any errors. |
|
inherited |
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.
string | $sql | The SQL string you wish to be executed. |
array | $params | array of sql parameters |
int | the count |
dml_exception | A DML specific exception is thrown for any errors. |
|
inherited |
Attempt to create the database.
string | $dbhost | |
string | $dbuser | |
string | $dbpass | |
string | $dbname |
bool | success |
dml_exception | A DML specific exception is thrown for any errors. |
Reimplemented from moodle_database.
|
inherited |
Delete the records from a table where all the given conditions met.
If conditions not specified, table is truncated.
string | $table | the table to delete from. |
array | $conditions | optional array $fieldname=>requestedvalue with AND in between |
bool | true. |
dml_exception | A DML specific exception is thrown for any errors. |
|
inherited |
Delete the records from a table where one field match one list of values.
string | $table | the table to delete from. |
string | $field | The field to search |
array | $values | array of values |
bool | true. |
dml_exception | A DML specific exception is thrown for any errors. |
|
inherited |
Delete one or more records from a table which match a particular WHERE clause.
string | $table | The database table to be checked against. |
string | $select | A fragment of SQL to be used in a where clause in the SQL call (used to define the selection criteria). |
array | $params | array of sql parameters |
bool | true |
dml_exception | A DML specific exception is thrown for any errors. |
Reimplemented from moodle_database.
|
inherited |
Deletes records using a subquery, which is done with a strange DELETE...JOIN syntax in MySQL because it performs very badly with normal subqueries.
string | $table | Table to delete from |
string | $field | Field in table to match |
string | $alias | Name of single column in subquery e.g. 'id' |
string | $subquery | Query that will return values of the field to delete |
array | $params | Parameters for query |
dml_exception | If there is any error |
Reimplemented from moodle_database.
|
protectedinherited |
Detects object parameters and throws exception if found.
mixed | $value |
void |
coding_exception | if object detected |
|
inherited |
Diagnose database and tables, this function is used to verify database and driver settings, db engine types, etc.
string | null means everything ok, string means problem found. |
Reimplemented from moodle_database.
|
inherited |
Close database connection and release all resources and memory (especially circular memory references).
Do NOT use connect() again, create a new instance if needed.
Reimplemented from moodle_database.
|
inherited |
Detects if all needed PHP stuff installed.
Note: can be used before connect()
mixed | true if ok, string if something |
Reimplemented from moodle_database.
|
inherited |
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 methods instead!
string | $sql | query |
array | $params | query parameters |
bool | true |
dml_exception | A DML specific exception is thrown for any errors. |
Reimplemented from moodle_database.
|
inherited |
Returns the db related part of config.php.
stdClass |
|
inherited |
Get all records from a table.
This method works around potential memory problems and may improve performance, this method may block access to table until the recordset is closed.
string | $table | Name of database table. |
moodle_recordset | A moodle_recordset instance functionget_recordset. |
dml_exception | A DML specific exception is thrown for any errors. |
Reimplemented from moodle_database.
|
protectedinherited |
Fetches detailed information about columns in table.
string | $table | name |
database_column_info[] | array of database_column_info objects indexed with column names |
Reimplemented from moodle_database.
|
inherited |
Normalizes sql query parameters and verifies parameters.
string | $sql | The query or part of it. |
array | $params | The query parameters. |
array | (sql, params, type of params) |
|
protectedinherited |
Fixes any table names that clash with reserved words.
string | $tablename | The table name |
string | The fixed table name |
Reimplemented from moodle_database.
|
protectedinherited |
Converts short table name {tablename} to the real prefixed table name in given sql.
string | $sql | The sql to be operated on. |
string | The sql with tablenames being prefixed with $CFG->prefix |
Reimplemented in oci_native_moodle_database, and sqlsrv_native_moodle_database.
|
inherited |
Force rollback of all delegated transaction.
Does not throw any exceptions and does not log anything.
This method should be used only from default exception handlers and other core code.
void |
|
inherited |
Returns detailed information about columns in table.
This information is cached internally.
string | $table | The table's name. |
bool | $usecache | Flag to use internal cacheing. The default is true. |
database_column_info[] | of database_column_info objects indexed with column names |
mariadb_native_moodle_database::get_configuration_help | ( | ) |
Returns localised database configuration help.
Note: can be used before connect()
string |
Reimplemented from mysqli_native_moodle_database.
|
inherited |
Returns the localised database description Note: can be used before connect()
string |
|
protectedinherited |
Gets db handle currently used with queries.
resource |
|
inherited |
Returns the current MySQL db collation.
This is an ugly workaround for MySQL default collation problems.
string | or null MySQL collation name |
|
inherited |
Returns the current MySQL db engine.
This is an ugly workaround for MySQL default engine problems, Moodle is designed to work best on ACID compliant databases with full transaction support. Do not use MyISAM.
string | or null MySQL engine name |
|
inherited |
Returns database family type - describes SQL dialect Note: can be used before connect()
string | db family name (mysql, postgres, mssql, oracle, etc.) |
Reimplemented from moodle_database.
|
protectedinherited |
Returns general database library name Note: can be used before connect()
string | db type pdo, native |
Reimplemented from moodle_database.
|
protected |
Returns more specific database driver type Note: can be used before connect()
string | db type mysqli, pgsql, oci, mssql, sqlsrv |
Reimplemented from mysqli_native_moodle_database.
mariadb_native_moodle_database::get_dbvendor | ( | ) |
Returns the database vendor.
Note: can be used before connect()
string | The db vendor name, usually the same as db family name. |
Reimplemented from moodle_database.
|
inherited |
Returns debug status.
bool\$state |
|
staticinherited |
Loads and returns a database instance with the specified type and library.
The loaded class is within lib/dml directory and of the form: $type.'_'.$library.'_moodle_database'
string | $type | Database driver's type. (eg: mysqli, pgsql, mssql, sqldrv, oci, etc.) |
string | $library | Database driver's library (native, pdo, etc.) |
bool | $external | True if this is an external database. |
moodle_database | driver object or null if error, for example of driver object see mysqli_native_moodle_database |
|
inherited |
Get a single field value from a table record where all the given conditions met.
string | $table | the table to query. |
string | $return | the field to return the value of. |
array | $conditions | optional array $fieldname=>requestedvalue with AND in between |
int | $strictness | IGNORE_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 |
mixed | the specified value false if not found |
dml_exception | A DML specific exception is thrown for any errors. |
|
inherited |
Get a single field value from a table record which match a particular WHERE clause.
string | $table | the table to query. |
string | $return | the field to return the value of. |
string | $select | A fragment of SQL to be used in a where clause returning one row with one column |
array | $params | array of sql parameters |
int | $strictness | IGNORE_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 |
mixed | the specified value false if not found |
dml_exception | A DML specific exception is thrown for any errors. |
|
inherited |
Get a single field value (first field) using a SQL statement.
string | $sql | The SQL query returning one row with one column |
array | $params | array of sql parameters |
int | $strictness | IGNORE_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 |
mixed | the specified value false if not found |
dml_exception | A DML specific exception is thrown for any errors. |
|
inherited |
Selects records and return values of chosen field as an array which match a particular WHERE clause.
string | $table | the table to query. |
string | $return | the field we are intered in |
string | $select | A fragment of SQL to be used in a where clause in the SQL call. |
array | $params | array of sql parameters |
array | of values |
dml_exception | A DML specific exception is thrown for any errors. |
|
inherited |
Selects records and return values (first field) as an array using a SQL statement.
string | $sql | The SQL query |
array | $params | array of sql parameters |
array | of values |
dml_exception | A DML specific exception is thrown for any errors. |
Reimplemented from moodle_database.
|
inherited |
Constructs 'IN()' or '=' sql fragment.
mixed | $items | A single value or array of values for the expression. |
int | $type | Parameter bounding type : SQL_PARAMS_QM or SQL_PARAMS_NAMED. |
string | $prefix | Named parameter placeholder prefix (a unique counter value is appended to each parameter name). |
bool | $equal | True means we want to equate to the constructed expression, false means we don't want to equate to it. |
mixed | $onemptyitems | This defines the behavior when the array of items provided is empty. Defaults to false, meaning throw exceptions. Other values will become part of the returned SQL fragment. |
coding_exception | | dml_exception |
array | A list containing the constructed sql fragment and an array of parameters. |
Reimplemented in oci_native_moodle_database, and pgsql_native_moodle_database.
|
inherited |
Return table indexes - everything lowercased.
string | $table | The table we want to get indexes from. |
array | An associative array of indexes containing 'unique' flag and 'columns' being indexed |
Reimplemented from moodle_database.
|
inherited |
Returns last error reported by database engine.
string | error message |
Reimplemented from moodle_database.
|
inherited |
Returns the sql generator used for db manipulation.
Used mostly in upgrade.php scripts.
database_manager | The instance used to perform ddl operations. |
|
protectedinherited |
Handle the creation and caching of the databasemeta information for all databases.
cache_application | The databasemeta cachestore to complete operations on. |
|
protectedinherited |
Returns the version of the MySQL server, as reported by the PHP client connection.
Wrap $this->mysqli->server_info to improve testing strategy.
string | A string representing the version of the MySQL server that the MySQLi extension is connected to. |
mariadb_native_moodle_database::get_name | ( | ) |
Returns localised database type name Note: can be used before connect()
string |
Reimplemented from mysqli_native_moodle_database.
|
inherited |
Returns database table prefix Note: can be used before connect()
string | The prefix used in the database. |
|
inherited |
Get a single database record as an object where all the given conditions met.
string | $table | The table to select from. |
array | $conditions | optional array $fieldname=>requestedvalue with AND in between |
string | $fields | A comma separated list of fields to be returned from the chosen table. |
int | $strictness | IGNORE_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 we will throw an exception if no record or multiple records found. |
mixed | a fieldset object containing the first matching record, false or exception if error not found depending on mode |
dml_exception | A DML specific exception is thrown for any errors. |
|
inherited |
Get a single database record as an object which match a particular WHERE clause.
string | $table | The database table to be checked against. |
string | $select | A fragment of SQL to be used in a where clause in the SQL call. |
array | $params | array of sql parameters |
string | $fields | A comma separated list of fields to be returned from the chosen table. |
int | $strictness | IGNORE_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 |
stdClass|false | a fieldset object containing the first matching record, false or exception if error not found depending on mode |
dml_exception | A DML specific exception is thrown for any errors. |
|
inherited |
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!
string | $sql | The SQL string you wish to be executed, should normally only return one record. |
array | $params | array of sql parameters |
int | $strictness | IGNORE_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 |
mixed | a fieldset object containing the first matching record, false or exception if error not found depending on mode |
dml_exception | A DML specific exception is thrown for any errors. |
Reimplemented in oci_native_moodle_database.
|
inherited |
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.
string | $table | the table to query. |
array | $conditions | optional array $fieldname=>requestedvalue with AND in between |
string | $sort | an order to sort the results in (optional, a valid SQL ORDER BY parameter). |
string | $fields | a 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 | $limitfrom | return a subset of records, starting at this point (optional). |
int | $limitnum | return a subset comprising this many records in total (optional, required if $limitfrom is set). |
array | An array of Objects indexed by first column. |
dml_exception | A DML specific exception is thrown for any errors. |
|
inherited |
Get a number of records as an array of objects where one field match one list of values.
Return value is like functionget_records.
string | $table | The database table to be checked against. |
string | $field | The field to search |
array | $values | An array of values |
string | $sort | Sort order (as valid SQL sort parameter) |
string | $fields | A 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. |
int | $limitfrom | return a subset of records, starting at this point (optional). |
int | $limitnum | return a subset comprising this many records in total (optional). |
array | An array of objects indexed by first column |
dml_exception | A DML specific exception is thrown for any errors. |
|
inherited |
Get the first two columns from a number of records as an associative array where all the given conditions met.
Arguments are like functionget_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.
string | $table | the table to query. |
array | $conditions | optional array $fieldname=>requestedvalue with AND in between |
string | $sort | an order to sort the results in (optional, a valid SQL ORDER BY parameter). |
string | $fields | a comma separated list of fields to return - the number of fields should be 2! |
int | $limitfrom | return a subset of records, starting at this point (optional). |
int | $limitnum | return a subset comprising this many records (optional, required if $limitfrom is set). |
array | an associative array |
dml_exception | A DML specific exception is thrown for any errors. |
|
inherited |
Get a number of records as an array of objects which match a particular WHERE clause.
Return value is like functionget_records.
string | $table | The table to query. |
string | $select | A fragment of SQL to be used in a where clause in the SQL call. |
array | $params | An array of sql parameters |
string | $sort | An order to sort the results in (optional, a valid SQL ORDER BY parameter). |
string | $fields | A 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 | $limitfrom | return a subset of records, starting at this point (optional). |
int | $limitnum | return a subset comprising this many records in total (optional, required if $limitfrom is set). |
array | of objects indexed by first column |
dml_exception | A DML specific exception is thrown for any errors. |
|
inherited |
Get the first two columns from a number of records as an associative array which match a particular WHERE clause.
Arguments are like functionget_recordset_select. Return value is like functionget_records_menu.
string | $table | The database table to be checked against. |
string | $select | A fragment of SQL to be used in a where clause in the SQL call. |
array | $params | array of sql parameters |
string | $sort | Sort order (optional) - a valid SQL order parameter |
string | $fields | A comma separated list of fields to be returned from the chosen table - the number of fields should be 2! |
int | $limitfrom | return a subset of records, starting at this point (optional). |
int | $limitnum | return a subset comprising this many records (optional, required if $limitfrom is set). |
array | an associative array |
dml_exception | A DML specific exception is thrown for any errors. |
|
inherited |
Get a number of records as an array of objects using a SQL statement.
Return value is like:
string | $sql | the 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 | $params | array of sql parameters |
int | $limitfrom | return a subset of records, starting at this point (optional, required if $limitnum is set). |
int | $limitnum | return a subset comprising this many records (optional, required if $limitfrom is set). |
array | of objects, or empty array if no records were found |
dml_exception | A DML specific exception is thrown for any errors. |
Reimplemented from moodle_database.
|
inherited |
Get the first two columns from a number of records as an associative array using a SQL statement.
Arguments are like functionget_recordset_sql. Return value is like functionget_records_menu.
string | $sql | The SQL string you wish to be executed. |
array | $params | array of sql parameters |
int | $limitfrom | return a subset of records, starting at this point (optional). |
int | $limitnum | return a subset comprising this many records (optional, required if $limitfrom is set). |
array | an associative array |
dml_exception | A DML specific exception is thrown for any errors. |
|
inherited |
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.
string | $table | the table to query. |
array | $conditions | optional array $fieldname=>requestedvalue with AND in between |
string | $sort | an order to sort the results in (optional, a valid SQL ORDER BY parameter). |
string | $fields | a comma separated list of fields to return (optional, by default all fields are returned). |
int | $limitfrom | return a subset of records, starting at this point (optional). |
int | $limitnum | return a subset comprising this many records (optional, required if $limitfrom is set). |
moodle_recordset | A moodle_recordset instance |
dml_exception | A DML specific exception is thrown for any errors. |
|
inherited |
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 are like functionget_recordset.
string | $table | the table to query. |
string | $field | a field to check (optional). |
array | $values | array of values the field must have |
string | $sort | an order to sort the results in (optional, a valid SQL ORDER BY parameter). |
string | $fields | a comma separated list of fields to return (optional, by default all fields are returned). |
int | $limitfrom | return a subset of records, starting at this point (optional). |
int | $limitnum | return a subset comprising this many records (optional, required if $limitfrom is set). |
moodle_recordset | A moodle_recordset instance. |
dml_exception | A DML specific exception is thrown for any errors. |
|
inherited |
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 are like functionget_recordset.
string | $table | the table to query. |
string | $select | A fragment of SQL to be used in a where clause in the SQL call. |
array | $params | array of sql parameters |
string | $sort | an order to sort the results in (optional, a valid SQL ORDER BY parameter). |
string | $fields | a comma separated list of fields to return (optional, by default all fields are returned). |
int | $limitfrom | return a subset of records, starting at this point (optional). |
int | $limitnum | return a subset comprising this many records (optional, required if $limitfrom is set). |
moodle_recordset | A moodle_recordset instance. |
dml_exception | A DML specific exception is thrown for any errors. |
|
inherited |
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 like:
string | $sql | the SQL select query to execute. |
array | $params | array of sql parameters |
int | $limitfrom | return a subset of records, starting at this point (optional, required if $limitnum is set). |
int | $limitnum | return a subset comprising this many records (optional, required if $limitfrom is set). |
moodle_recordset | instance |
dml_exception | A DML specific exception is thrown for any errors. |
Reimplemented from moodle_database.
|
inherited |
Get the row format from the database schema.
string | $table |
string | row_format name or null if not known or table does not exist. |
|
inherited |
Determine if the row format should be set to compressed, dynamic, or default.
Terrible kludge. If we're using utf8mb4 AND we're using InnoDB, we need to specify row format to be either dynamic or compressed (default is compact) in order to allow for bigger indexes (MySQL errors #1709 and #1071).
string | $engine | The database engine being used. Will be looked up if not supplied. |
string | $collation | The database collation to use. Will look up the current collation if not supplied. |
string | An sql fragment to add to sql statements. |
|
inherited |
Returns database server info array.
array | Array containing 'description' and 'version' info. |
dml_read_exception | If the execution of 'SELECT VERSION()' query will fail. |
Reimplemented from moodle_database.
|
inherited |
Obtain session lock.
int | $rowid | id of the row with session record |
int | $timeout | max allowed time to wait for the lock in seconds |
void |
Reimplemented from moodle_database.
|
protectedinherited |
Returns a hash for the settings used during connection.
If not already requested it is generated and stored in a private property.
string |
|
inherited |
Return tables in database WITHOUT current prefix.
bool | $usecache | if true, returns list of cached tables. |
array | of table names in lowercase and without prefix |
Reimplemented from moodle_database.
|
protectedinherited |
Handle the creation and caching of the temporary tables.
cache_application | The temp_tables cachestore to complete operations on. |
|
inherited |
Returns transaction trace for debugging purposes.
to be used by core only
array | or null if not in transaction. |
|
protectedinherited |
Returns the version of the MySQL server, as reported by 'SELECT VERSION()' query.
string | A string that indicates the MySQL server version. |
dml_read_exception | If the execution of 'SELECT VERSION()' query will fail. |
|
protected |
Indicates whether column information retrieved from information_schema.columns
has default values quoted or not.
boolean | True when default values are quoted (breaking change); otherwise, false. |
Reimplemented from mysqli_native_moodle_database.
mariadb_native_moodle_database::has_breaking_change_sqlmode | ( | ) |
Indicates whether SQL_MODE default value has changed in a not backward compatible way.
boolean | True when SQL_MODE breaks BC; otherwise, false. |
Reimplemented from mysqli_native_moodle_database.
|
inherited |
Import a record into a table, id field is required.
Safety checks are NOT carried out. Lobs are supported.
string | $table | name of database table to be inserted into |
object | $dataobject | A data object with values for one or more fields in the record |
bool | true |
dml_exception | A DML specific exception is thrown for any errors. |
Reimplemented from moodle_database.
|
protectedinherited |
Insert records in chunks.
Note: can be used only from insert_records().
string | $table | |
array | $chunk | |
database_column_info[] | $columns |
|
inherited |
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
string | $table | The database table to be inserted into |
object | array | $dataobject | A data object with values for one or more fields in the record |
bool | $returnid | Should the id of the newly created record entry be returned? If this option is not requested then true/false is returned. |
bool|int | true or new id |
dml_exception | A DML specific exception is thrown for any errors. |
Reimplemented from moodle_database.
|
inherited |
Insert new record into database, as fast as possible, no safety checks, lobs not supported.
string | $table | name |
mixed | $params | data record as object or array |
bool | $returnit | return it of inserted record |
bool | $bulk | true means repeated inserts expected |
bool | $customsequence | true if 'id' included in $params, disables $returnid |
bool|int | true or new id |
dml_exception | A DML specific exception is thrown for any errors. |
Reimplemented from moodle_database.
|
inherited |
Insert multiple records into database as fast as possible.
Order of inserts is maintained, but the operation is not atomic, use transactions if necessary.
This method is intended for inserting of large number of small objects, do not use for huge objects with text or binary fields.
string | $table | The database table to be inserted into |
array | Traversable | $dataobjects | list of objects to be inserted, must be compatible with foreach |
void | does not return new record ids |
coding_exception | if data objects have different structure |
dml_exception | A DML specific exception is thrown for any errors. |
Reimplemented from moodle_database.
|
protectedinherited |
Tests if the Antelope file format is still supported or it has been removed.
When removed, only Barracuda file format is supported, given the XtraDB/InnoDB engine.
bool | True if the Antelope file format has been removed; otherwise, false. |
|
inherited |
Is this database compatible with compressed row format? This feature is necessary for support of large number of text columns in InnoDB/XtraDB database.
bool | $cached | use cached result |
bool | true if table can be created or changed to compressed row format. |
|
inherited |
Check the database to see if innodb_file_per_table is on.
bool | True if on otherwise false. |
mariadb_native_moodle_database::is_fulltext_search_supported | ( | ) |
Does this mariadb instance support fulltext indexes?
bool |
Reimplemented from mysqli_native_moodle_database.
|
inherited |
Check the database to see if innodb_large_prefix is on.
bool | True if on otherwise false. |
|
inherited |
Returns true if a transaction is in progress.
bool |
|
protectedinherited |
Ensures that limit params are numeric and positive integers, to be passed to the database.
We explicitly treat null, '' and -1 as 0 in order to provide compatibility with how limit values have been passed historically.
int | $limitfrom | Where to start results from |
int | $limitnum | How many results to return |
array | Normalised limit params in array($limitfrom, $limitnum) |
|
protectedinherited |
Normalise values based in RDBMS dependencies (booleans, LOBs...)
database_column_info | $column | column metadata corresponding with the value we are going to normalise |
mixed | $value | value we are going to normalise |
mixed | the normalised value |
Reimplemented from moodle_database.
|
inherited |
Returns the number of queries done by this database.
int | Number of queries. |
|
inherited |
Time waiting for the database engine to finish running all queries.
float | Number of seconds with microseconds |
|
inherited |
Returns the number of reads done by this database.
int | Number of reads. |
|
inherited |
Returns the number of reads before first write done by this database.
int | Number of reads. |
|
inherited |
Returns the number of writes done by this database.
int | Number of writes. |
|
protectedinherited |
Prints sql debug info.
string | $sql | The query which is being debugged. |
array | $params | The query parameters. (optional) |
mixed | $obj | The library specific object. (optional) |
void |
|
protectedinherited |
Prints the time a query took to run.
void |
|
protectedinherited |
This should be called immediately after each db query.
It does a clean up of resources. It also throws exceptions if the sql that ran produced errors.
mixed | $result | The db specific result obtained from running a query. |
void |
Reimplemented in pgsql_native_moodle_database, and sqlsrv_native_moodle_database.
|
inherited |
This logs the last query based on 'logall', 'logslow' and 'logerrors' options configured via $CFG->dboptions .
string | bool | $error | or false if not error |
void |
|
protectedinherited |
This should be called before each db query.
string | $sql | The query string. |
array | null | $params | An array of parameters. |
int | $type | The type of query ( SQL_QUERY_SELECT | SQL_QUERY_AUX_READONLY | SQL_QUERY_AUX | SQL_QUERY_INSERT | SQL_QUERY_UPDATE | SQL_QUERY_STRUCTURE ). |
mixed | $extrainfo | This is here for any driver specific extra information. |
void |
Reimplemented in oci_native_moodle_database, pdo_moodle_database, pgsql_native_moodle_database, and sqlsrv_native_moodle_database.
|
protectedinherited |
Returns the time elapsed since the query started.
float | Seconds with microseconds |
|
inherited |
Connect to db.
string | $dbhost | The database host. |
string | $dbuser | The database username. |
string | $dbpass | The database username's password. |
string | $dbname | The name of the database being connected to.e |
mixed | $prefix | string means moodle db prefix, false used for external databases where prefix not used |
array | $dboptions | driver specific options |
bool | success |
moodle_exception | |
dml_connection_exception | if error |
|
inherited |
Test whether a record exists in a table where all the given conditions met.
string | $table | The table to check. |
array | $conditions | optional array $fieldname=>requestedvalue with AND in between |
bool | true if a matching record exists, else false. |
dml_exception | A DML specific exception is thrown for any errors. |
|
inherited |
Test whether any records exists in a table which match a particular WHERE clause.
string | $table | The database table to be checked against. |
string | $select | A fragment of SQL to be used in a WHERE clause in the SQL call. |
array | $params | array of sql parameters |
bool | true if a matching record exists, else false. |
dml_exception | A DML specific exception is thrown for any errors. |
|
inherited |
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.
string | $sql | The SQL statement to execute. |
array | $params | array of sql parameters |
bool | true if the SQL executes without errors and returns at least one record. |
dml_exception | A DML specific exception is thrown for any errors. |
|
inherited |
Releases the session lock.
int | $rowid | The id of the row with session record. |
void |
dml_exception | A DML specific exception is thrown for any errors. |
Reimplemented from moodle_database.
|
inherited |
Replace given text in all rows of column.
string | $table | name of the table |
database_column_info | $column | |
string | $search | |
string | $replace |
|
inherited |
Does this driver support tool_replace?
bool |
Reimplemented from moodle_database.
|
inherited |
Resets the internal column details cache.
array | null | $tablenames | an array of xmldb table names affected by this request. |
void |
|
inherited |
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.
moodle_transaction | $transaction | An instance of a moodle_transaction. |
Exception | Throwable | $e | The related exception/throwable to this transaction rollback. |
void | This does not return, instead the exception passed in will be rethrown. |
|
protectedinherited |
Driver specific abort of real database transaction, this can not be used directly in code.
void |
Reimplemented from moodle_database.
|
inherited |
|
protectedinherited |
Sets db handle to be used with subsequent queries.
resource | $dbh |
void |
|
inherited |
Enable/disable very detailed debugging.
bool | $state |
void |
|
inherited |
Set a single field in every table record where all the given conditions met.
string | $table | The database table to be checked against. |
string | $newfield | the field to set. |
mixed | $newvalue | the value to set the field to. |
array | $conditions | optional array $fieldname=>requestedvalue with AND in between |
bool | true |
dml_exception | A DML specific exception is thrown for any errors. |
|
inherited |
Set a single field in every table record which match a particular WHERE clause.
string | $table | The database table to be checked against. |
string | $newfield | the field to set. |
string | $newvalue | the value to set the field to. |
string | $select | A fragment of SQL to be used in a where clause in the SQL call. |
array | $params | array of sql parameters |
bool | true |
dml_exception | A DML specific exception is thrown for any errors. |
Reimplemented from moodle_database.
|
inherited |
Enable/disable detailed sql logging.
|
inherited |
|
protectedinherited |
Returns whether $CFG->dboptions['versionfromdb'] has been set to boolean true
.
bool | True if $CFG->dboptions['versionfromdb'] has been set to boolean true . Otherwise, false . |
|
inherited |
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!!
string | $int1 | SQL for the first integer in the operation. |
string | $int2 | SQL for the second integer in the operation. |
string | The piece of SQL code to be used in your statement. |
Reimplemented in oci_native_moodle_database.
|
inherited |
Returns the SQL text to be used in order to perform one bitwise NOT operation with 1 integer.
int | $int1 | The operand integer in the operation. |
string | The piece of SQL code to be used in your statement. |
Reimplemented in oci_native_moodle_database.
|
inherited |
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!!
int | $int1 | The first operand integer in the operation. |
int | $int2 | The second operand integer in the operation. |
string | The piece of SQL code to be used in your statement. |
Reimplemented in oci_native_moodle_database.
|
inherited |
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!!
int | $int1 | The first operand integer in the operation. |
int | $int2 | The second operand integer in the operation. |
string | The piece of SQL code to be used in your statement. |
Reimplemented in oci_native_moodle_database, and pgsql_native_moodle_database.
|
inherited |
Returns the SQL to be used in order to an UNSIGNED INTEGER column to SIGNED.
string | $fieldname | The name of the field to be cast |
string | The piece of SQL code to be used in your statement. |
Reimplemented from moodle_database.
|
inherited |
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!
string | $fieldname | The name of the field to be casted. |
bool | $text | Specifies if the original column is one TEXT (CLOB) column (true). Defaults to false. |
string | The piece of SQL code to be used in your statement. |
Reimplemented from moodle_database.
|
inherited |
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!
string | $fieldname | The name of the field to be casted. |
bool | $text | Specifies if the original column is one TEXT (CLOB) column (true). Defaults to false. |
string | The piece of SQL code to be used in your statement. |
Reimplemented from moodle_database.
|
inherited |
Return SQL for casting to char of given field/expression.
Default implementation performs implicit cast using concatenation with an empty string
string | $field | Table field or SQL expression to be cast |
string |
Reimplemented in oci_native_moodle_database, pgsql_native_moodle_database, and sqlsrv_native_moodle_database.
|
inherited |
Returns the cross db correct CEIL (ceiling) expression applied to fieldname.
note: Most DBs use CEIL(), hence it's the default here.
string | $fieldname | The field (or expression) we are going to ceil. |
string | The piece of SQL code to be used in your ceiling statement. |
Reimplemented in sqlsrv_native_moodle_database.
|
inherited |
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.
string | $fieldname | The name of the TEXT field we need to order by |
int | $numchars | Number of chars to use for the ordering (defaults to 32). |
string | The piece of SQL code to be used in your statement. |
|
inherited |
Returns the proper SQL to do CONCAT between the elements passed Can take many parameters.
string | $str,... | 1 or more fields/strings to concat |
string | The concat sql |
Reimplemented from moodle_database.
|
inherited |
Returns the proper SQL to do CONCAT between the elements passed with a given separator.
string | $separator | The string to use as the separator |
array | $elements | An array of items to concatenate |
string | The concat SQL |
Reimplemented from moodle_database.
|
inherited |
This used to return empty string replacement character.
string | An empty string. |
|
inherited |
Returns an equal (=) or not equal (<>) part of a query.
Note the use of this method may lead to slower queries (full scans) so use it only when needed and against already reduced data sets.
string | $fieldname | Usually the name of the table column. |
string | $param | Usually the bound query parameter (?, :named). |
bool | $casesensitive | Use case sensitive search when set to true (default). |
bool | $accentsensitive | Use accent sensitive search when set to true (default). (not all databases support accent insensitive) |
bool | $notequal | True means not equal (<>) |
string | The SQL code fragment. |
Reimplemented from moodle_database.
|
inherited |
|
inherited |
Return SQL for performing group concatenation on given field/expression.
string | $field | |
string | $separator | |
string | $sort |
string |
Reimplemented from moodle_database.
|
inherited |
Returns the SQL that allows to find intersection of two or more queries.
array | $selects | array of SQL select queries, each of them only returns fields with the names from $fields |
string | $fields | comma-separated list of fields |
string | SQL query that will return only values that are present in each of selects |
Reimplemented from moodle_database.
|
inherited |
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 for text fields should be:
... AND ' . sql_isempty('tablename', 'fieldname', true/false, true);
and for varchar fields result should be:
... AND fieldname = :empty; "; $params['empty'] = '';
(see parameters description below)
string | $tablename | Name 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 | $fieldname | Name of the field we are going to check |
bool | $nullablefield | For specifying if the field is nullable (true) or no (false) in the DB. |
bool | $textfield | For specifying if it is a text (also called clob) field (true) or a varchar one (false) |
string | the sql code to be added to check for empty values |
Reimplemented in oci_native_moodle_database, and sqlsrv_native_moodle_database.
|
inherited |
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 for text fields should be:
... AND ' . sql_isnotempty('tablename', 'fieldname', true/false, true/false);
and for varchar fields result should be:
... AND fieldname != :empty; "; $params['empty'] = '';
(see parameters description below)
string | $tablename | Name of the table (without prefix). This is not used for now but can be necessary in the future if we want to use some introspection using meta information against the DB. |
string | $fieldname | The name of the field we are going to check. |
bool | $nullablefield | Specifies if the field is nullable (true) or not (false) in the DB. |
bool | $textfield | Specifies if it is a text (also called clob) field (true) or a varchar one (false). |
string | The sql code to be added to check for non empty values. |
|
inherited |
Returns the SQL text to be used to calculate the length in characters of one expression.
string | fieldname or expression to calculate its length in characters. |
string | the piece of SQL code to be used in the statement. |
Reimplemented from moodle_database.
|
inherited |
Returns 'LIKE' part of a query.
Note that mysql does not support $casesensitive = true and $accentsensitive = false. More information in http://bugs.mysql.com/bug.php?id=19567.
string | $fieldname | usually name of the table column |
string | $param | usually bound query parameter (?, :named) |
bool | $casesensitive | use case sensitive search |
bool | $accensensitive | use accent sensitive search (ignored if $casesensitive is true) |
bool | $notlike | true means "NOT LIKE" |
string | $escapechar | escape char for '' and '_' |
string | SQL code fragment |
Reimplemented from moodle_database.
|
inherited |
Escape sql LIKE special characters like '_' or ''.
string | $text | The string containing characters needing escaping. |
string | $escapechar | The desired escape character, defaults to '::::'. |
string | The escaped sql LIKE string. |
Reimplemented in sqlsrv_native_moodle_database.
|
inherited |
Returns the SQL text to be used in order to perform module '' operation - remainder after division.
int | $int1 | The first operand integer in the operation. |
int | $int2 | The second operand integer in the operation. |
string | The piece of SQL code to be used in your statement. |
Reimplemented in oci_native_moodle_database.
|
inherited |
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 ''
string |
Reimplemented in oci_native_moodle_database.
|
inherited |
Returns the SQL text to be used to order by columns, standardising the return pattern of null values across database types to sort nulls first when ascending and last when descending.
string | $fieldname | The name of the field we need to sort by. |
int | $sort | An order to sort the results in. |
string | The piece of SQL code to be used in your statement. |
Reimplemented in oci_native_moodle_database, and pgsql_native_moodle_database.
|
inherited |
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.
string | $fieldname | The name of the TEXT field we need to order by. |
int | $numchars | The number of chars to use for the ordering (defaults to 32). |
string | The piece of SQL code to be used in your statement. |
Reimplemented in oci_native_moodle_database, and sqlsrv_native_moodle_database.
|
inherited |
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.
string | $needle | the SQL expression that will be searched for. |
string | $haystack | the SQL expression that will be searched in. |
string | The required searching SQL part. |
Reimplemented in oci_native_moodle_database, and sqlsrv_native_moodle_database.
|
inherited |
Return regex positive or negative match sql.
bool | $positivematch | |
bool | $casesensitive |
string | or empty if not supported |
Reimplemented from moodle_database.
|
inherited |
Returns the word-beginning boundary marker based on MySQL version.
string | The word-beginning boundary marker. |
Reimplemented from moodle_database.
|
inherited |
Returns the word-end boundary marker based on MySQL version.
string | The word-end boundary marker. |
Reimplemented from moodle_database.
|
inherited |
Does this driver support regex syntax when searching.
Reimplemented from moodle_database.
|
inherited |
Returns the proper substr() SQL text used to extract substrings from DB NOTE: this was originally returning only function name.
string | $expr | Some string field, no aggregates. |
mixed | $start | Integer or expression evaluating to integer (1 based value; first char has index 1) |
mixed | $length | Optional integer or expression evaluating to integer. |
string | The sql substring extraction fragment. |
Reimplemented in sqlsrv_native_moodle_database.
|
inherited |
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.
moodle_transaction |
|
protectedinherited |
Store various database settings.
string | $dbhost | The database host. |
string | $dbuser | The database user to connect as. |
string | $dbpass | The password to use when connecting to the database. |
string | $dbname | The name of the database being connected to. |
mixed | $prefix | string means moodle db prefix, false used for external databases where prefix not used |
array | $dboptions | driver specific options |
void |
|
inherited |
This is a test that throws an exception if transaction in progress.
This test does not force rollback of active transactions.
void |
dml_transaction_exception | if stansaction active |
|
protected |
It is time to require transactions everywhere.
MyISAM is NOT supported!
bool |
Reimplemented from mysqli_native_moodle_database.
|
inherited |
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
string | $table | The database table to be checked against. |
stdClass | array | $dataobject | An object with contents equal to fieldname=>fieldvalue. Must have an entry for 'id' to map to the table specified. |
bool | true means repeated updates expected |
bool | true |
dml_exception | A DML specific exception is thrown for any errors. |
Reimplemented from moodle_database.
|
inherited |
Update record in database, as fast as possible, no safety checks, lobs not supported.
string | $table | name |
stdClass | array | $params | data record as object or array |
bool | true means repeated updates expected |
bool | true |
dml_exception | A DML specific exception is thrown for any errors. |
Reimplemented from moodle_database.
|
inherited |
Analyze the data in temporary tables to force statistics collection after bulk data loads.
void |
|
inherited |
Returns whether we want to connect to slave database for read queries.
bool | Want read only connection |
|
protectedinherited |
Returns the SQL WHERE conditions.
string | $table | The table name that these conditions will be validated against. |
array | $conditions | The conditions to build the where clause. (must not contain numeric indexes) |
dml_exception |
array | An array list containing sql 'where' part and 'params'. |
|
protectedinherited |
Returns SQL WHERE conditions for the ..._list group of methods.
string | $field | the name of a field. |
array | $values | the values field might take. |
array | An array containing sql 'where' part and 'params' |
|
protectedinherited |
internal temporary variable used to guarantee unique parameters in each request.
Its used by get_in_or_equal().
|
protectedinherited |
Flag indicating logging of query in progress.
This helps prevent infinite loops.