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

Public Member Functions

 __construct ($external=false)
 driver_installed ()
 get_dbfamily ()
 get_name ()
 get_configuration_help ()
 get_configuration_hints ()
 connect ($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null)
 dispose ()
 get_server_info ()
 get_last_error ()
 get_tables ($usecache=true)
 get_indexes ($table)
 get_columns ($table, $usecache=true)
 change_database_structure ($sql)
 execute ($sql, array $params=null)
 get_recordset_sql ($sql, array $params=null, $limitfrom=0, $limitnum=0)
 get_records_sql ($sql, array $params=null, $limitfrom=0, $limitnum=0)
 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_select ($table, $newfield, $newvalue, $select, array $params=null)
 delete_records_select ($table, $select, array $params=null)
 sql_cast_char2int ($fieldname, $text=false)
 SQL helper functions.
 sql_cast_char2real ($fieldname, $text=false)
 sql_ceil ($fieldname)
 sql_like ($fieldname, $param, $casesensitive=true, $accentsensitive=true, $notlike=false, $escapechar= '\\')
 sql_concat ()
 sql_concat_join ($separator="' '", $elements=array())
 sql_isempty ($tablename, $fieldname, $nullablefield, $textfield)
 sql_length ($fieldname)
 sql_order_by_text ($fieldname, $numchars=32)
 sql_position ($needle, $haystack)
 sql_substr ($expr, $start, $length=false)
 session_lock_supported ()
 session locking
 get_session_lock ($rowid, $timeout)
 release_session_lock ($rowid)

Protected Member Functions

 get_dbtype ()
 get_dblibrary ()
 query_start ($sql, array $params=null, $type, $extrainfo=null)
 query_end ($result)
 is_min_version ($version)
 fix_table_names ($sql)
 allowed_param_types ()
 normalise_value ($column, $value)
 build_native_bound_params (array $params=null)
 emulate_bound_params ($sql, array $params=null)
 create_recordset ($result)
 get_collation ()
 begin_transaction ()
 transactions
 commit_transaction ()
 rollback_transaction ()

Protected Attributes

 $sqlsrv = null
 $last_error_reporting
 $temptables
 $collation

Detailed Description

Native sqlsrv class representing moodle database interface.

Definition at line 36 of file sqlsrv_native_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 from moodle_database.

Definition at line 48 of file sqlsrv_native_moodle_database.php.


Member Function Documentation

allowed_param_types ( ) [protected]

Returns supported query parameter types

Returns:
int bitmask

Reimplemented from moodle_database.

Definition at line 312 of file sqlsrv_native_moodle_database.php.

begin_transaction ( ) [protected]

transactions

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

Returns:
void

Reimplemented from moodle_database.

Definition at line 1357 of file sqlsrv_native_moodle_database.php.

Here is the call graph for this function:

build_native_bound_params ( array params = null) [protected]

Prepare the array of params for native binding

Definition at line 683 of file sqlsrv_native_moodle_database.php.

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

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

Reimplemented from moodle_database.

Definition at line 670 of file sqlsrv_native_moodle_database.php.

Here is the call graph for this function:

commit_transaction ( ) [protected]

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

Returns:
void

Reimplemented from moodle_database.

Definition at line 1368 of file sqlsrv_native_moodle_database.php.

Here is the call graph for this function:

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

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 from moodle_database.

Definition at line 139 of file sqlsrv_native_moodle_database.php.

Here is the call graph for this function:

create_recordset ( result) [protected]

Create a record set and initialize with first row

Parameters:
mixed$result
Returns:
sqlsrv_native_moodle_recordset

Definition at line 787 of file sqlsrv_native_moodle_database.php.

Here is the caller graph for this function:

delete_records_select ( table,
select,
array params = null 
)

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 from moodle_database.

Definition at line 1110 of file sqlsrv_native_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.

Reimplemented from moodle_database.

Definition at line 225 of file sqlsrv_native_moodle_database.php.

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

Returns:
mixed true if ok, string if something

Reimplemented from moodle_database.

Definition at line 57 of file sqlsrv_native_moodle_database.php.

Here is the caller graph for this function:

emulate_bound_params ( sql,
array params = null 
) [protected]

Workaround for SQL*Server Native driver similar to MSSQL driver for consistent behavior.

ok, we have verified sql statement with ? and correct number of params

Definition at line 693 of file sqlsrv_native_moodle_database.php.

Here is the call graph for this function:

execute ( sql,
array params = null 
)

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 from moodle_database.

Definition at line 733 of file sqlsrv_native_moodle_database.php.

fix_table_names ( sql) [protected]

Override: Converts short table name {tablename} to real table name supporting temp tables (#) if detected

Parameters:
stringsql
Returns:
string sql

Reimplemented from moodle_database.

Definition at line 293 of file sqlsrv_native_moodle_database.php.

get_collation ( ) [protected]

Definition at line 1146 of file sqlsrv_native_moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_columns ( table,
usecache = true 
)

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

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

Reimplemented from moodle_database.

Definition at line 475 of file sqlsrv_native_moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Returns localised database configuration help. Note: can be used before connect()

Returns:
string

Reimplemented from moodle_database.

Definition at line 108 of file sqlsrv_native_moodle_database.php.

Returns localised database description Note: can be used before connect()

Returns:
string

Reimplemented from moodle_database.

Definition at line 117 of file sqlsrv_native_moodle_database.php.

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

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

Reimplemented from moodle_database.

Definition at line 72 of file sqlsrv_native_moodle_database.php.

get_dblibrary ( ) [protected]

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

Returns:
string db type pdo, native

Reimplemented from moodle_database.

Definition at line 90 of file sqlsrv_native_moodle_database.php.

get_dbtype ( ) [protected]

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

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

Reimplemented from moodle_database.

Definition at line 81 of file sqlsrv_native_moodle_database.php.

get_fieldset_sql ( sql,
array params = null 
)

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 from moodle_database.

Definition at line 833 of file sqlsrv_native_moodle_database.php.

Here is the call graph for this function:

get_indexes ( table)

Return table indexes - everything lowercased

Returns:
array of arrays

Reimplemented from moodle_database.

Definition at line 416 of file sqlsrv_native_moodle_database.php.

Here is the call graph for this function:

Returns last error reported by database engine.

Returns:
string error message

Reimplemented from moodle_database.

Definition at line 320 of file sqlsrv_native_moodle_database.php.

Here is the caller graph for this function:

get_name ( )

Returns localised database type name Note: can be used before connect()

Returns:
string

Reimplemented from moodle_database.

Definition at line 99 of file sqlsrv_native_moodle_database.php.

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.

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, or empty array if no records were found
Exceptions:
dml_exceptionif error

Reimplemented from moodle_database.

Definition at line 805 of file sqlsrv_native_moodle_database.php.

Here is the call graph for this function:

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

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 from moodle_database.

Definition at line 757 of file sqlsrv_native_moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Returns database server info array

Returns:
array

Reimplemented from moodle_database.

Definition at line 259 of file sqlsrv_native_moodle_database.php.

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 from moodle_database.

Definition at line 1295 of file sqlsrv_native_moodle_database.php.

Here is the call graph for this function:

get_tables ( usecache = true)

Return tables in database WITHOUT current prefix

Returns:
array of table names in lowercase and without prefix

Reimplemented from moodle_database.

Definition at line 381 of file sqlsrv_native_moodle_database.php.

Here is the call graph for this function:

import_record ( table,
dataobject 
)

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 from moodle_database.

Definition at line 971 of file sqlsrv_native_moodle_database.php.

Here is the call graph for this function:

insert_record ( table,
dataobject,
returnid = true,
bulk = false 
)

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 from moodle_database.

Definition at line 942 of file sqlsrv_native_moodle_database.php.

Here is the call graph for this function:

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.

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 from moodle_database.

Definition at line 857 of file sqlsrv_native_moodle_database.php.

Here is the caller graph for this function:

is_min_version ( version) [protected]

Get the minimum SQL allowed

Parameters:
mixed$version
Returns:
mixed

Definition at line 280 of file sqlsrv_native_moodle_database.php.

Here is the call graph for this function:

normalise_value ( column,
value 
) [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

Always, convert boolean to int

Reimplemented from moodle_database.

Definition at line 574 of file sqlsrv_native_moodle_database.php.

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 from moodle_database.

Definition at line 251 of file sqlsrv_native_moodle_database.php.

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 from moodle_database.

Definition at line 242 of file sqlsrv_native_moodle_database.php.

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 from moodle_database.

Definition at line 1330 of file sqlsrv_native_moodle_database.php.

Here is the call graph for this function:

rollback_transaction ( ) [protected]

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

Returns:
void

Reimplemented from moodle_database.

Definition at line 1379 of file sqlsrv_native_moodle_database.php.

Here is the call graph for this function:

session locking

Reimplemented from moodle_database.

Definition at line 1285 of file sqlsrv_native_moodle_database.php.

Here is the caller graph for this function:

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

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

Get column metadata

Reimplemented from moodle_database.

Definition at line 1070 of file sqlsrv_native_moodle_database.php.

Here is the call graph for this function:

sql_cast_char2int ( fieldname,
text = false 
)

SQL helper functions.

Reimplemented from moodle_database.

Definition at line 1126 of file sqlsrv_native_moodle_database.php.

Here is the call graph for this function:

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 from moodle_database.

Definition at line 1134 of file sqlsrv_native_moodle_database.php.

Here is the call graph for this function:

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 from moodle_database.

Definition at line 1142 of file sqlsrv_native_moodle_database.php.

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 from moodle_database.

Definition at line 1207 of file sqlsrv_native_moodle_database.php.

sql_concat_join ( separator = "' '",
elements = array() 
)

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

Parameters:
string$separator
array$elements
Returns:
string

Reimplemented from moodle_database.

Definition at line 1221 of file sqlsrv_native_moodle_database.php.

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 from moodle_database.

Definition at line 1233 of file sqlsrv_native_moodle_database.php.

sql_length ( fieldname)

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

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

Reimplemented from moodle_database.

Definition at line 1246 of file sqlsrv_native_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 from moodle_database.

Definition at line 1185 of file sqlsrv_native_moodle_database.php.

Here is the call graph for this function:

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 from moodle_database.

Definition at line 1250 of file sqlsrv_native_moodle_database.php.

sql_position ( needle,
haystack 
)

Returns the SQL for returning searching one string for the location of another.

Reimplemented from moodle_database.

Definition at line 1257 of file sqlsrv_native_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
mixed$lengthoptional integer or expression evaluating to int
Returns:
string sql fragment

Reimplemented from moodle_database.

Definition at line 1270 of file sqlsrv_native_moodle_database.php.

update_record ( table,
dataobject,
bulk = false 
)

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 from moodle_database.

Definition at line 1042 of file sqlsrv_native_moodle_database.php.

Here is the call graph for this function:

update_record_raw ( table,
params,
bulk = false 
)

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 from moodle_database.

Definition at line 1000 of file sqlsrv_native_moodle_database.php.

Here is the caller graph for this function:


Field Documentation

$collation [protected]

Definition at line 41 of file sqlsrv_native_moodle_database.php.

$last_error_reporting [protected]

Definition at line 39 of file sqlsrv_native_moodle_database.php.

$sqlsrv = null [protected]

Definition at line 38 of file sqlsrv_native_moodle_database.php.

$temptables [protected]

Reimplemented from moodle_database.

Definition at line 40 of file sqlsrv_native_moodle_database.php.


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