[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/lib/ -> dmllib.php (summary)

(no description)

File Size: 2818 lines (106 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 81 functions

  execute_sql()
  begin_sql()
  commit_sql()
  rollback_sql()
  db_uppercase()
  db_lowercase()
  modify_database()
  record_exists()
  record_exists_select()
  record_exists_sql()
  count_records()
  count_records_select()
  count_records_sql()
  get_record()
  get_record_sql()
  get_record_select()
  get_recordset()
  get_recordset_select()
  get_recordset_list()
  get_recordset_sql()
  recordset_to_array()
  rs_fetch_record()
  rs_next_record()
  rs_fetch_next_record()
  rs_EOF()
  rs_close()
  onespace2empty()
  get_records()
  get_records_select()
  get_records_list()
  get_records_sql()
  recordset_to_menu()
  records_to_menu()
  get_records_menu()
  get_records_select_menu()
  get_records_sql_menu()
  get_field()
  get_field_select()
  get_field_sql()
  get_fieldset_select()
  get_fieldset_sql()
  set_field()
  set_field_select()
  delete_records()
  delete_records_select()
  insert_record()
  update_record()
  sql_paging_limit()
  sql_ilike()
  sql_max()
  sql_fullname()
  sql_concat()
  sql_concat_join()
  sql_isempty()
  sql_isnotempty()
  sql_as()
  sql_empty()
  sql_substr()
  sql_compare_text()
  sql_order_by_text()
  sql_position()
  sql_cast_char2int()
  sql_bitand()
  sql_bitor()
  sql_bitxor()
  sql_bitnot()
  sql_null_from_clause()
  sql_ceil()
  where_clause()
  column_type()
  execute_sql_arr()
  configure_dbconnection()
  oracle_dirty_hack()
  db_detect_lobs()
  db_update_lobs()
  rcache_set()
  rcache_unset()
  rcache_get()
  rcache_getforfill()
  rcache_releaseforfill()
  rcache_unset_table()

Functions
Functions that are not part of a class:

execute_sql($command, $feedback=true)   X-Ref
Execute a given sql command string

Completely general function - it just runs some SQL and reports success.

param: string $command The sql string you wish to be executed.
param: bool $feedback Set this argument to true if the results generated should be printed. Default is true.
return: bool success

begin_sql()   X-Ref
on DBs that support it, switch to transaction mode and begin a transaction
you'll need to ensure you call commit_sql() or your changes *will* be lost.

Now using ADOdb standard transactions. Some day, we should switch to
Smart Transactions (http://phplens.com/adodb/tutorial.smart.transactions.html)
as they autodetect errors and are nestable and easier to write

this is _very_ useful for massive updates

commit_sql()   X-Ref
on DBs that support it, commit the transaction

Now using ADOdb standard transactions. Some day, we should switch to
Smart Transactions (http://phplens.com/adodb/tutorial.smart.transactions.html)
as they autodetect errors and are nestable and easier to write

rollback_sql()   X-Ref
on DBs that support it, rollback the transaction

Now using ADOdb standard transactions. Some day, we should switch to
Smart Transactions (http://phplens.com/adodb/tutorial.smart.transactions.html)
as they autodetect errors and are nestable and easier to write

db_uppercase()   X-Ref
returns db specific uppercase function


db_lowercase()   X-Ref
returns db specific lowercase function


modify_database($sqlfile='', $sqlstring='')   X-Ref
Run an arbitrary sequence of semicolon-delimited SQL commands

Assumes that the input text (file or string) consists of
a number of SQL statements ENDING WITH SEMICOLONS.  The
semicolons MUST be the last character in a line.
Lines that are blank or that start with "#" or "--" (postgres) are ignored.
Only tested with mysql dump files (mysqldump -p -d moodle)

param: string $sqlfile The path where a file with sql commands can be found on the server.
param: string $sqlstring If no path is supplied then a string with semicolon delimited sql
return: bool Returns true if databse was modified successfully.

record_exists($table, $field1='', $value1='', $field2='', $value2='', $field3='', $value3='')   X-Ref
Test whether a record exists in a table where all the given fields match the given values.

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

param: string $table The table to check.
param: string $field1 the first field to check (optional).
param: string $value1 the value field1 must have (requred if field1 is given, else optional).
param: string $field2 the second field to check (optional).
param: string $value2 the value field2 must have (requred if field2 is given, else optional).
param: string $field3 the third field to check (optional).
param: string $value3 the value field3 must have (requred if field3 is given, else optional).
return: bool true if a matching record exists, else false.

record_exists_select($table, $select='')   X-Ref
Test whether any records exists in a table which match a particular WHERE clause.

param: string $table The database table to be checked against.
param: string $select A fragment of SQL to be used in a WHERE clause in the SQL call.
return: bool true if a matching record exists, else false.

record_exists_sql($sql)   X-Ref
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.

param: string $sql The SQL statement to execute.
return: bool true if the SQL executes without errors and returns at least one record.

count_records($table, $field1='', $value1='', $field2='', $value2='', $field3='', $value3='')   X-Ref
Count the records in a table where all the given fields match the given values.

param: string $table The table to query.
param: string $field1 the first field to check (optional).
param: string $value1 the value field1 must have (requred if field1 is given, else optional).
param: string $field2 the second field to check (optional).
param: string $value2 the value field2 must have (requred if field2 is given, else optional).
param: string $field3 the third field to check (optional).
param: string $value3 the value field3 must have (requred if field3 is given, else optional).
return: int The count of records returned from the specified criteria.

count_records_select($table, $select='', $countitem='COUNT(*)   X-Ref
Count the records in a table which match a particular WHERE clause.

param: string $table The database table to be checked against.
param: string $select A fragment of SQL to be used in a WHERE clause in the SQL call.
param: string $countitem The count string to be used in the SQL call. Default is COUNT(*).
return: int The count of records returned from the specified criteria.

count_records_sql($sql)   X-Ref
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 occurrs, 0 is returned.

param: string $sql The SQL string you wish to be executed.
return: int the count. If an error occurrs, 0 is returned.

get_record($table, $field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields='*')   X-Ref
Get a single record as an object

param: string $table The table to select from.
param: string $field1 the first field to check (optional).
param: string $value1 the value field1 must have (requred if field1 is given, else optional).
param: string $field2 the second field to check (optional).
param: string $value2 the value field2 must have (requred if field2 is given, else optional).
param: string $field3 the third field to check (optional).
param: string $value3 the value field3 must have (requred if field3 is given, else optional).
return: mixed a fieldset object containing the first mathcing record, or false if none found.

get_record_sql($sql, $expectmultiple=false, $nolimit=false)   X-Ref
Get a single record as an object using an SQL statement

The SQL statement should normally only return one record. In debug mode
you will get a warning if more record is returned (unless you
set $expectmultiple to true). In non-debug mode, it just returns
the first record.

param: string $sql The SQL string you wish to be executed, should normally only return one record.
param: bool $expectmultiple If the SQL cannot be written to conveniently return just one record,
param: bool $nolimit sometimes appending ' LIMIT 1' to the SQL causes an error. Set this to true
return: Found record as object. False if not found or error

get_record_select($table, $select='', $fields='*')   X-Ref
Gets one record from a table, as an object

param: string $table The database table to be checked against.
param: string $select A fragment of SQL to be used in a where clause in the SQL call.
param: string $fields A comma separated list of fields to be returned from the chosen table.
return: object|false Returns an array of found records (as objects) or false if no records or error occured.

get_recordset($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='')   X-Ref
Get a number of records as an ADODB RecordSet.

Selects records from the table $table.

If specified, only records where the field $field has value $value are retured.

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
mightbe "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 an ADODB RecordSet object
param: string $table the table to query.
param: string $field a field to check (optional).
param: string $value the value the field must have (requred if field1 is given, else optional).
param: string $sort an order to sort the results in (optional, a valid SQL ORDER BY parameter).
param: string $fields a comma separated list of fields to return (optional, by default all fields are returned).
param: int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set).
param: int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set).
return: mixed an ADODB RecordSet object, or false if an error occured.

get_recordset_select($table, $select='', $sort='', $fields='*', $limitfrom='', $limitnum='')   X-Ref
Get a number of records as an ADODB RecordSet.

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

Other arguments and the return type as for @see function get_recordset.

param: string $table the table to query.
param: string $select A fragment of SQL to be used in a where clause in the SQL call.
param: string $sort an order to sort the results in (optional, a valid SQL ORDER BY parameter).
param: string $fields a comma separated list of fields to return (optional, by default all fields are returned).
param: int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set).
param: int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set).
return: mixed an ADODB RecordSet object, or false if an error occured.

get_recordset_list($table, $field='', $values='', $sort='', $fields='*', $limitfrom='', $limitnum='')   X-Ref
Get a number of records as an ADODB RecordSet.

Only records where $field takes one of the values $values are returned.
$values should be a comma-separated list of values, for example "4,5,6,10"
or "'foo','bar','baz'".

Other arguments and the return type as for @see function get_recordset.

param: string $table the table to query.
param: string $field a field to check (optional).
param: string $values comma separated list of values the field must have (requred if field is given, else optional).
param: string $sort an order to sort the results in (optional, a valid SQL ORDER BY parameter).
param: string $fields a comma separated list of fields to return (optional, by default all fields are returned).
param: int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set).
param: int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set).
return: mixed an ADODB RecordSet object, or false if an error occured.

get_recordset_sql($sql, $limitfrom=null, $limitnum=null)   X-Ref
Get a number of records as an ADODB RecordSet.  $sql must be a complete SQL query.
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 function get_recordset.

param: string $sql the SQL select query to execute.
param: int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set).
param: int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set).
return: mixed an ADODB RecordSet object, or false if an error occured.

recordset_to_array($rs)   X-Ref
Utility function used by the following 4 methods. Note that for this to work, the first column
in the recordset must contain unique values, as it is used as the key to the associative array.

param: object an ADODB RecordSet object.
return: mixed mixed an array of objects, or false if an error occured or the RecordSet was empty.

rs_fetch_record(&$rs)   X-Ref
This function is used to get the current record from the recordset. It
doesn't advance the recordset position. You'll need to do that by
using the rs_next_record($recordset) function.

param: ADORecordSet the recordset to fetch current record from
return: ADOFetchObj the object containing the fetched information

rs_next_record(&$rs)   X-Ref
This function is used to advance the pointer of the recordset
to its next position/record.

param: ADORecordSet the recordset to be moved to the next record
return: boolean true if the movement was successful and false if not (end of recordset)

rs_fetch_next_record(&$rs)   X-Ref
This function is used to get the current record from the recordset. It
does advance the recordset position.
This is the prefered way to iterate over recordsets with code blocks like this:

$rs = get_recordset('SELECT .....');
while ($rec = rs_fetch_next_record($rs)) {
/// Perform actions with the $rec record here
}
rs_close($rs); /// Close the recordset if not used anymore. Saves memory (optional but recommended).

param: ADORecordSet the recordset to fetch current record from
return: mixed ADOFetchObj the object containing the fetched information or boolean false if no record (end of recordset)

rs_EOF($rs)   X-Ref
Returns true if no more records found

param: ADORecordSet the recordset
return: bool

rs_close(&$rs)   X-Ref
This function closes the recordset, freeing all the memory and associated resources.
Note that, once closed, the recordset must not be used anymore along the request.
Saves memory (optional but recommended).

param: ADORecordSet the recordset to be closed
return: void

onespace2empty(&$item, $key=null)   X-Ref
This function is used to convert all the Oracle 1-space defaults to the empty string
like a really DIRTY HACK to allow it to work better until all those NOT NULL DEFAULT ''
fields will be out from Moodle.

param: string the string to be converted to '' (empty string) if it's ' ' (one space)
param: mixed the key of the array in case we are using this function from array_walk,
return: boolean always true (the converted variable is returned by reference)

get_records($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='')   X-Ref
Get a number of records as an array of objects.

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.

param: string $table the table to query.
param: string $field a field to check (optional).
param: string $value the value the field must have (requred if field1 is given, else optional).
param: string $sort an order to sort the results in (optional, a valid SQL ORDER BY parameter).
param: string $fields a comma separated list of fields to return (optional, by default
param: int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set).
param: int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set).
return: mixed an array of objects, or false if no records were found or an error occured.

get_records_select($table, $select='', $sort='', $fields='*', $limitfrom='', $limitnum='')   X-Ref
Get a number of records as an array of objects.

Return value as for @see function get_records.

param: string $table the table to query.
param: string $select A fragment of SQL to be used in a where clause in the SQL call.
param: string $sort an order to sort the results in (optional, a valid SQL ORDER BY parameter).
param: string $fields a comma separated list of fields to return
param: int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set).
param: int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set).
return: mixed an array of objects, or false if no records were found or an error occured.

get_records_list($table, $field='', $values='', $sort='', $fields='*', $limitfrom='', $limitnum='')   X-Ref
Get a number of records as an array of objects.

Return value as for @see function get_records.

param: string $table The database table to be checked against.
param: string $field The field to search
param: string $values Comma separated list of possible value
param: string $sort Sort order (as valid SQL sort parameter)
param: string $fields A comma separated list of fields to be returned from the chosen table. If specified,
return: mixed an array of objects, or false if no records were found or an error occured.

get_records_sql($sql, $limitfrom='', $limitnum='')   X-Ref
Get a number of records as an array of objects.

Return value as for @see function get_records.

param: string $sql the SQL select query to execute. The first column of this SELECT statement
param: int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set).
param: int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set).
return: mixed an array of objects, or false if no records were found or an error occured.

recordset_to_menu($rs)   X-Ref
Utility function used by the following 3 methods.

param: object an ADODB RecordSet object with two columns.
return: mixed an associative array, or false if an error occured or the RecordSet was empty.

records_to_menu($records, $field1, $field2)   X-Ref
Utility function
Similar to recordset_to_menu

field1, field2 is needed because the order from get_records_sql is not reliable
param: records - records from get_records_sql() or get_records()
param: field1 - field to be used as menu index
param: field2 - feild to be used as coresponding menu value
return: mixed an associative array, or false if an error occured or the RecordSet was empty.

get_records_menu($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='')   X-Ref
Get the first two columns from a number of records as an associative array.

Arguments as for @see function get_recordset.

If no errors occur, and at least one records is found, the return value
is an associative whose keys come from the first field of each record,
and whose values are the corresponding second fields. If no records are found,
or an error occurs, false is returned.

param: string $table the table to query.
param: string $field a field to check (optional).
param: string $value the value the field must have (requred if field1 is given, else optional).
param: string $sort an order to sort the results in (optional, a valid SQL ORDER BY parameter).
param: string $fields a comma separated list of fields to return (optional, by default all fields are returned).
param: int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set).
param: int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set).
return: mixed an associative array, or false if no records were found or an error occured.

get_records_select_menu($table, $select='', $sort='', $fields='*', $limitfrom='', $limitnum='')   X-Ref
Get the first two columns from a number of records as an associative array.

Arguments as for @see function get_recordset_select.
Return value as for @see function get_records_menu.

param: string $table The database table to be checked against.
param: string $select A fragment of SQL to be used in a where clause in the SQL call.
param: string $sort Sort order (optional) - a valid SQL order parameter
param: string $fields A comma separated list of fields to be returned from the chosen table.
param: int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set).
param: int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set).
return: mixed an associative array, or false if no records were found or an error occured.

get_records_sql_menu($sql, $limitfrom='', $limitnum='')   X-Ref
Get the first two columns from a number of records as an associative array.

Arguments as for @see function get_recordset_sql.
Return value as for @see function get_records_menu.

param: string $sql The SQL string you wish to be executed.
param: int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set).
param: int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set).
return: mixed an associative array, or false if no records were found or an error occured.

get_field($table, $return, $field1, $value1, $field2='', $value2='', $field3='', $value3='')   X-Ref
Get a single value from a table row where all the given fields match the given values.

param: string $table the table to query.
param: string $return the field to return the value of.
param: string $field1 the first field to check (optional).
param: string $value1 the value field1 must have (requred if field1 is given, else optional).
param: string $field2 the second field to check (optional).
param: string $value2 the value field2 must have (requred if field2 is given, else optional).
param: string $field3 the third field to check (optional).
param: string $value3 the value field3 must have (requred if field3 is given, else optional).
return: mixed the specified value, or false if an error occured.

get_field_select($table, $return, $select)   X-Ref
Get a single value from a table row where a particular select clause is true.

param: string $table the table to query.
param: string $return the field to return the value of.
param: string $select A fragment of SQL to be used in a where clause in the SQL call.
return: mixed the specified value, or false if an error occured.

get_field_sql($sql)   X-Ref
Get a single value from a table.

param: string $sql an SQL statement expected to return a single value.
return: mixed the specified value, or false if an error occured.

get_fieldset_select($table, $return, $select)   X-Ref
Get a single value from a table row where a particular select clause is true.

param: string $table the table to query.
param: string $return the field to return the value of.
param: string $select A fragment of SQL to be used in a where clause in the SQL call.
return: mixed|false Returns the value return from the SQL statment or false if an error occured.

get_fieldset_sql($sql)   X-Ref
Get an array of data from one or more fields from a database
use to get a column, or a series of distinct values

param: string $sql The SQL string you wish to be executed.
return: mixed|false Returns the value return from the SQL statment or false if an error occured.

set_field($table, $newfield, $newvalue, $field1, $value1, $field2='', $value2='', $field3='', $value3='')   X-Ref
Set a single field in every table row where all the given fields match the given values.

param: string $table The database table to be checked against.
param: string $newfield the field to set.
param: string $newvalue the value to set the field to.
param: string $field1 the first field to check (optional).
param: string $value1 the value field1 must have (requred if field1 is given, else optional).
param: string $field2 the second field to check (optional).
param: string $value2 the value field2 must have (requred if field2 is given, else optional).
param: string $field3 the third field to check (optional).
param: string $value3 the value field3 must have (requred if field3 is given, else optional).
return: mixed An ADODB RecordSet object with the results from the SQL call or false.

set_field_select($table, $newfield, $newvalue, $select, $localcall = false)   X-Ref
Set a single field in every table row where the select statement evaluates to true.

param: string $table The database table to be checked against.
param: string $newfield the field to set.
param: string $newvalue the value to set the field to.
param: string $select a fragment of SQL to be used in a where clause in the SQL call.
param: boolean $localcall Leave this set to false. (Should only be set to true by set_field.)
return: mixed An ADODB RecordSet object with the results from the SQL call or false.

delete_records($table, $field1='', $value1='', $field2='', $value2='', $field3='', $value3='')   X-Ref
Delete the records from a table where all the given fields match the given values.

param: string $table the table to delete from.
param: string $field1 the first field to check (optional).
param: string $value1 the value field1 must have (requred if field1 is given, else optional).
param: string $field2 the second field to check (optional).
param: string $value2 the value field2 must have (requred if field2 is given, else optional).
param: string $field3 the third field to check (optional).
param: string $value3 the value field3 must have (requred if field3 is given, else optional).
return: mixed An ADODB RecordSet object with the results from the SQL call or false.

delete_records_select($table, $select='')   X-Ref
Delete one or more records from a table

param: string $table The database table to be checked against.
param: string $select A fragment of SQL to be used in a where clause in the SQL call (used to define the selection criteria).
return: object A PHP standard object with the results from the SQL call.

insert_record($table, $dataobject, $returnid=true, $primarykey='id')   X-Ref
Insert a record into a table and return the "id" field if required

If the return ID isn't required, then this just reports success as true/false.
$dataobject is an object containing needed data

param: string $table The database table to be checked against.
param: object $dataobject A data object with values for one or more fields in the record
param: bool $returnid Should the id of the newly created record entry be returned? If this option is not requested then true/false is returned.
param: string $primarykey (obsolete) This is now forced to be 'id'.

update_record($table, $dataobject)   X-Ref
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

param: string $table The database table to be checked against.
param: object $dataobject An object with contents equal to fieldname=>fieldvalue. Must have an entry for 'id' to map to the table specified.
return: bool

sql_paging_limit($page, $recordsperpage)   X-Ref
Returns the proper SQL to do paging

param: string $page Offset page number
param: string $recordsperpage Number of records per page
return: string

sql_ilike()   X-Ref
Returns the proper SQL to do LIKE in a case-insensitive way

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

return: string

sql_max($field)   X-Ref
Returns the proper SQL to do MAX

param: string $field
return: string

sql_fullname($firstname='firstname', $lastname='lastname')   X-Ref
Returns the proper SQL (for the dbms in use) to concatenate $firstname and $lastname

param: string $firstname User's first name
param: string $lastname User's last name
return: string

sql_concat()   X-Ref
Returns the proper SQL to do CONCAT between the elements passed
Can take many parameters - just a passthrough to $db->Concat()

param: string $element
return: string

sql_concat_join($separator="' '", $elements=array()   X-Ref
Returns the proper SQL to do CONCAT between the elements passed
with a given separator

param: string $separator
param: array  $elements
return: string

sql_isempty($tablename, $fieldname, $nullablefield, $textfield)   X-Ref
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 speciffying 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 conditins 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)

param: string $tablename name of the table (without prefix). Not used for now but can be
param: string $fieldname name of the field we are going to check
param: boolean $nullablefield to specify if the field us nullable (true) or no (false) in the DB
param: boolean $textfield to specify if it is a text (also called clob) field (true) or a varchar one (false)
return: string the sql code to be added to check for empty values

sql_isnotempty($tablename, $fieldname, $nullablefield, $textfield)   X-Ref
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 speciffying them.

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

... AND fieldname != '';

are being used. Final result should be:

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

(see parameters description below)

param: string $tablename name of the table (without prefix). Not used for now but can be
param: string $fieldname name of the field we are going to check
param: boolean $nullablefield to specify if the field us nullable (true) or no (false) in the DB
param: boolean $textfield to specify if it is a text (also called clob) field (true) or a varchar one (false)
return: string the sql code to be added to check for non empty values

sql_as()   X-Ref
Returns the proper AS keyword to be used to aliase columns
SQL defines the keyword as optional and nobody but PG
seems to require it. This function should be used inside all
the statements using column aliases.
Note than the use of table aliases doesn't require the
AS keyword at all, only columns for postgres.


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


sql_substr()   X-Ref
Returns the proper substr() function for each DB
Relies on ADOdb $db->substr property


sql_compare_text($fieldname, $numchars=32)   X-Ref
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.

param: string fieldname the name of the TEXT field we need to order by
param: string number of chars to use for the ordering (defaults to 32)
return: string the piece of SQL code to be used in your statement.

sql_order_by_text($fieldname, $numchars=32)   X-Ref
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.

param: string fieldname the name of the TEXT field we need to order by
param: string number of chars to use for the ordering (defaults to 32)
return: string the piece of SQL code to be used in your statement.

sql_position($needle, $haystack)   X-Ref
Returns the SQL for returning searching one string for the location of another.

param: string $needle the SQL expression that will be searched for.
param: string $haystack the SQL expression that will be searched in.
return: string the required SQL

sql_cast_char2int($fieldname, $text=false)   X-Ref
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!

param: string fieldname the name of the field to be casted
param: boolean text to specify if the original column is one TEXT (CLOB) column (true). Defaults to false.
return: string the piece of SQL code to be used in your statement.

sql_bitand($int1, $int2)   X-Ref
Returns the SQL text to be used in order to perform one bitwise AND operation
between 2 integers.

param: integer int1 first integer in the operation
param: integer int2 second integer in the operation
return: string the piece of SQL code to be used in your statement.

sql_bitor($int1, $int2)   X-Ref
Returns the SQL text to be used in order to perform one bitwise OR operation
between 2 integers.

param: integer int1 first integer in the operation
param: integer int2 second integer in the operation
return: string the piece of SQL code to be used in your statement.

sql_bitxor($int1, $int2)   X-Ref
Returns the SQL text to be used in order to perform one bitwise XOR operation
between 2 integers.

param: integer int1 first integer in the operation
param: integer int2 second integer in the operation
return: string the piece of SQL code to be used in your statement.

sql_bitnot($int1)   X-Ref
Returns the SQL text to be used in order to perform one bitwise NOT operation
with 1 integer.

param: integer int1 integer in the operation
return: string the piece of SQL code to be used in your statement.

sql_null_from_clause()   X-Ref
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


sql_ceil($fieldname)   X-Ref
Returns the correct CEIL expression applied to fieldname

param: string fieldname the field (or expression) we are going to ceil
return: string the piece of SQL code to be used in your ceiling statement

where_clause($field1='', $value1='', $field2='', $value2='', $field3='', $value3='')   X-Ref
Prepare a SQL WHERE clause to select records where the given fields match the given values.

Prepares a where clause of the form
WHERE field1 = value1 AND field2 = value2 AND field3 = value3
except that you need only specify as many arguments (zero to three) as you need.

param: string $field1 the first field to check (optional).
param: string $value1 the value field1 must have (requred if field1 is given, else optional).
param: string $field2 the second field to check (optional).
param: string $value2 the value field2 must have (requred if field2 is given, else optional).
param: string $field3 the third field to check (optional).
param: string $value3 the value field3 must have (requred if field3 is given, else optional).

column_type($table, $column)   X-Ref
Get the data type of a table column, using an ADOdb MetaType() call.

param: string $table The name of the database table
param: string $column The name of the field in the table
return: string Field type or false if error

execute_sql_arr($sqlarr, $continue=true, $feedback=true)   X-Ref
This function will execute an array of SQL commands, returning
true/false if any error is found and stopping/continue as desired.
It's widely used by all the ddllib.php functions

param: array sqlarr array of sql statements to execute
param: boolean continue to specify if must continue on error (true) or stop (false)
param: boolean feedback to specify to show status info (true) or not (false)
param: boolean true if everything was ok, false if some error was found

configure_dbconnection()   X-Ref
This internal function, called from setup.php, sets all the configuration
needed to work properly against any DB. It setups connection encoding
and some other variables.

This function must contain the init code needed for each dbtype supported.

oracle_dirty_hack($table, &$dataobject, $usecache = true)   X-Ref
This function will handle all the records before being inserted/updated to DB for Oracle
installations. This is because the "special feature" of Oracle where the empty string is
equal to NULL and this presents a problem with all our currently NOT NULL default '' fields.

Once Moodle DB will be free of this sort of false NOT NULLS, this hack could be removed safely

Note that this function is 100% private and should be used, exclusively by DML functions
in this file. Also, this is considered a DIRTY HACK to be removed when possible. (stronk7)

This function is private and must not be used outside dmllib at all

param: $table string the table where the record is going to be inserted/updated (without prefix)
param: $dataobject object the object to be inserted/updated
param: $usecache boolean flag to determinate if we must use the per request cache of metadata

db_detect_lobs($table, &$dataobject, &$clobs, &$blobs, $unset = false, $usecache = true)   X-Ref
This function will search for all the CLOBs and BLOBs fields passed in the dataobject, replacing
their contents by the fixed strings '@#CLOB#@' and '@#BLOB#@' and returning one array for all the
found CLOBS and another for all the found BLOBS
Used by Oracle drivers to perform the two-step insertion/update of LOBs and
by MSSQL to perform the same exclusively for BLOBs (IMAGE fields)

This function is private and must not be used outside dmllib at all

param: $table string the table where the record is going to be inserted/updated (without prefix)
param: $dataobject object the object to be inserted/updated
param: $clobs array of clobs detected
param: $dataobject array of blobs detected
param: $unset boolean to specify if we must unset found LOBs from the original object (true) or
param: $usecache boolean flag to determinate if we must use the per request cache of metadata

db_update_lobs($table, $sqlcondition, &$clobs, &$blobs)   X-Ref
This function will iterate over $clobs and $blobs array, executing the needed
UpdateClob() and UpdateBlob() ADOdb function calls to store LOBs contents properly
Records to be updated are always searched by PK (id always!)

Used by Orace CLOBS and BLOBS and MSSQL IMAGES

This function is private and must not be used outside dmllib at all

param: $table string the table where the record is going to be inserted/updated (without prefix)
param: $sqlcondition mixed value defining the records to be LOB-updated. It it's a number, must point
param: $clobs array of clobs to be updated
param: $blobs array of blobs to be updated

rcache_set($table, $id, $rec)   X-Ref
Set cached record.

If you have called rcache_getforfill() before, it will also
release the lock.

This function is private and must not be used outside dmllib at all

param: $table string
param: $id integer
param: $rec obj
return: bool

rcache_unset($table, $id)   X-Ref
Unset cached record if it exists.

This function is private and must not be used outside dmllib at all

param: $table string
param: $id integer
return: bool

rcache_get($table, $id)   X-Ref
Get cached record if available. ONLY use if you
are trying to get the cached record and will NOT
fetch it yourself if not cached.

Use rcache_getforfill() if you are going to fetch
the record if not cached...

This function is private and must not be used outside dmllib at all

param: $table string
param: $id integer
return: mixed object-like record on cache hit, false otherwise

rcache_getforfill($table, $id)   X-Ref
Get cached record if available. In most cases you want
to use this function -- namely if you are trying to get
the cached record and will fetch it yourself if not cached.
(and set the cache ;-)

Uses the getforfill caching mechanism. See lib/eaccelerator.class.php
for a detailed description of the technique.

Note: if you call rcache_getforfill() you are making an implicit promise
that if the cache is empty, you will later populate it, or cancel the promise
calling rcache_releaseforfill();

This function is private and must not be used outside dmllib at all

param: $table string
param: $id integer
return: mixed object-like record on cache hit, false otherwise

rcache_releaseforfill($table, $id)   X-Ref
Release the exclusive lock obtained by
rcache_getforfill(). See rcache_getforfill()
for more details.

This function is private and must not be used outside dmllib at all

param: $table string
param: $id integer
return: bool

rcache_unset_table($table)   X-Ref
Remove or invalidate all rcache entries related to
a table. Not all caching mechanisms cluster entries
by table so in those cases we use alternative strategies.

This function is private and must not be used outside dmllib at all

param: $table string the table to invalidate records for
return: bool



Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7