Find whether the database may run GROUP BY unfettered with restrictions on the SELECT'd fields having to be represented in it or aggregate functions
boolean
can_arbitrary_groupby
()
Change the primary key of a table.
void
db_change_primary_key
(ID_TEXT $table_name, array $new_key, array $db)
-
ID_TEXT
$table_name: The name of the table to create the index on
-
array
$new_key: A list of fields to put in the new key
-
array
$db: The DB connection to make on
Close the database connections. We don't really need to close them (will close at exit), just disassociate so we can refresh them.
void
db_close_connections
()
Create a table index.
void
db_create_index
(ID_TEXT $table_name, ID_TEXT $index_name, string $_fields, array $db)
-
ID_TEXT
$table_name: The name of the table to create the index on
-
ID_TEXT
$index_name: The index name (not really important at all)
-
string
$_fields: Part of the SQL query: a comma-separated list of fields to use on the index
-
array
$db: The DB connection to make on
Create a new table.
void
db_create_table
(ID_TEXT $table_name, array $fields, array $db, [boolean $if_not_exists = false])
-
ID_TEXT
$table_name: The table name
-
array
$fields: A map of field names to ocPortal field types (with *#? encodings)
-
array
$db: The DB connection to make on
-
boolean
$if_not_exists: Whether to only do it if it does not currently exist
Get the default password for making db connections (used by the installer as a default).
string
db_default_password
()
Get the default user for making db connections (used by the installer as a default).
string
db_default_user
()
Delete a table.
void
db_drop_if_exists
(ID_TEXT $table_name, array $db)
-
ID_TEXT
$table_name: The table name
-
array
$db: The DB connection to delete on
This function is internal to the database system, allowing SQL statements to be build up appropriately. Some databases require IS NULL to be used to check for blank strings.
boolean
db_empty_is_null
()
Encode a LIKE string comparision fragement for the database system. The pattern is a mixture of characters and ? and % wilcard symbols.
string
db_encode_like
(string $pattern)
-
string
$pattern: The pattern
Escape a string so it may be inserted into a query. If SQL statements are being built up and passed using db_query then it is essential that this is used for security reasons. Otherwise, the abstraction layer deals with the situation.
string
db_escape_string
(string $string)
-
string
$string: The string
Assemble part of a WHERE clause for doing full-text search
string
db_full_text_assemble
(string $content, boolean $boolean)
-
string
$content: Our match string
-
boolean
$boolean: Whether to do a boolean full text search
Get a database connection. This function shouldn't be used by you, as a connection to the database is established automatically.
?array
db_get_connection
(boolean $persistent, string $db_name, string $db_host, string $db_user, string $db_password, [boolean $fail_ok = false])
-
boolean
$persistent: Whether to create a persistant connection
-
string
$db_name: The database name
-
string
$db_host: The database host (the server)
-
string
$db_user: The database connection username
-
string
$db_password: The database connection password
-
boolean
$fail_ok: Whether to on error echo an error and return with a NULL, rather than giving a critical error
Get the ID of the first row in an auto-increment table (used whenever we need to reference the first).
integer
db_get_first_id
()
Get a map of ocPortal field types, to actual mySQL types.
array
db_get_type_remap
()
Find whether full-text-search is present
boolean
db_has_full_text
(array $db)
-
array
$db: A DB connection
Find whether full-text-boolean-search is present
boolean
db_has_full_text_boolean
()
Find whether subquery support is present
boolean
db_has_subqueries
(array $db)
-
array
$db: A DB connection
Determine whether the database is a flat file database, and thus not have a meaningful connect username and password.
boolean
db_is_flat_file_simple
()
This function is a very basic query executor. It shouldn't usually be used by you, as there are abstracted versions available.
?mixed
db_query
(string $query, array $db, [?integer $max = NULL], [?integer $start = NULL], [boolean $fail_ok = false], [boolean $get_insert_id = false], [boolean $no_syndicate = false], [boolean $save_as_volatile = false])
-
string
$query: The complete SQL query
-
array
$db: A DB connection
-
?integer
$max: The maximum number of rows to affect (NULL: no limit)
-
?integer
$start: The start row to affect (NULL: no specification)
-
boolean
$fail_ok: Whether to not output an error on some kind of run-time failure (parse errors and clear programming errors are always fatal)
-
boolean
$get_insert_id: Whether to get the autoincrement ID created for an insert query
-
boolean
$no_syndicate: Whether to force the query to execute on the XML database driver (won't optimise by using MySQL). Useful for calls happening for multi-part queries from within this DB driver
-
boolean
$save_as_volatile: Whether we are saving as a 'volatile' file extension
Encode an SQL statement fragment for a conditional to see if two strings are equal.
string
db_string_equal_to
(ID_TEXT $attribute, string $compare)
-
ID_TEXT
$attribute: The attribute
-
string
$compare: The comparison
Encode an SQL statement fragment for a conditional to see if two strings are not equal.
string
db_string_not_equal_to
(ID_TEXT $attribute, string $compare)
-
ID_TEXT
$attribute: The attribute
-
string
$compare: The comparison
See if an item is a prefix to something in the delimiter array.
boolean
is_start_of_delimiter
(string $looking)
-
string
$looking: The item
Give out an error message and die, when a query fails.
?mixed
_bad_query
(string $query, [boolean $fail_ok = false], [?string $error = NULL])
-
string
$query: The query that failed
-
boolean
$fail_ok: Whether to not output an error on some kind of run-time failure (parse errors and clear programming errors are always fatal)
-
?string
$error: Error message (NULL: none)
Write a record to an XML file.
void
_delete_record
(PATH $path, array $db)
-
PATH
$path: The file path
-
array
$db: Database connection
Execute an ALTER query.
?mixed
_do_query_alter
(array $tokens, string $query, array $db, boolean $fail_ok)
-
array
$tokens: Tokens
-
string
$query: Query that was executed
-
array
$db: Database connection
-
boolean
$fail_ok: Whether to not output an error on some kind of run-time failure (parse errors and clear programming errors are always fatal)
Execute a CREATE query.
?mixed
_do_query_create
(array $tokens, string $query, array $db, boolean $fail_ok)
-
array
$tokens: Tokens
-
string
$query: Query that was executed
-
array
$db: Database connection
-
boolean
$fail_ok: Whether to not output an error on some kind of run-time failure (parse errors and clear programming errors are always fatal)
Execute a DELETE query.
?mixed
_do_query_delete
(array $tokens, string $query, array $db, ?integer $max, ?integer $start, boolean $fail_ok)
-
array
$tokens: Tokens
-
string
$query: Query that was executed
-
array
$db: Database connection
-
?integer
$max: The maximum number of rows to affect (NULL: no limit)
-
?integer
$start: The start row to affect (NULL: no specification)
-
boolean
$fail_ok: Whether to not output an error on some kind of run-time failure (parse errors and clear programming errors are always fatal)
Execute a DROP query.
?mixed
_do_query_drop
(array $tokens, string $query, array $db, boolean $fail_ok)
-
array
$tokens: Tokens
-
string
$query: Query that was executed
-
array
$db: Database connection
-
boolean
$fail_ok: Whether to not output an error on some kind of run-time failure (parse errors and clear programming errors are always fatal)
Wrapper to execute an INSERT query.
?mixed
_do_query_insert
(array $tokens, string $query, array $db, boolean $fail_ok, boolean $get_insert_id, ?integer &$random_key, [boolean $save_as_volatile = false])
-
array
$tokens: Tokens
-
string
$query: Query that was executed
-
array
$db: Database connection
-
boolean
$fail_ok: Whether to not output an error on some kind of run-time failure (parse errors and clear programming errors are always fatal)
-
boolean
$get_insert_id: Whether to get the autoincrement ID created for an insert query
-
?integer
&$random_key: The random key that we would use (NULL: not generated yet)
-
boolean
$save_as_volatile: Whether we are saving as a 'volatile' file extension
Execute an INSERT query.
?mixed
_do_query_insert__execute
(array $inserts, ID_TEXT $table_name, string $query, array $db, boolean $fail_ok, boolean $get_insert_id, ?integer &$random_key, [boolean $save_as_volatile = false])
-
array
$inserts: Rows being inserted
-
ID_TEXT
$table_name: Table name we're inserting into
-
string
$query: Query that was executed
-
array
$db: Database connection
-
boolean
$fail_ok: Whether to not output an error on some kind of run-time failure (parse errors and clear programming errors are always fatal)
-
boolean
$get_insert_id: Whether to get the autoincrement ID created for an insert query
-
?integer
&$random_key: The random key that we would use (NULL: not generated yet)
-
boolean
$save_as_volatile: Whether we are saving as a 'volatile' file extension
Parse an INSERT query.
?array
_do_query_insert__parse
(array $tokens, string $query, array $db, boolean $fail_ok)
-
array
$tokens: Tokens
-
string
$query: Query that was executed
-
array
$db: Database connection
-
boolean
$fail_ok: Whether to not output an error on some kind of run-time failure (parse errors and clear programming errors are always fatal)
Execute a SELECT query.
?mixed
_do_query_select
(array $tokens, string $query, array $db, ?integer $max, ?integer $start, boolean $fail_ok, integer &$at, [boolean $do_end_check = true])
-
array
$tokens: Tokens
-
string
$query: Query that was executed
-
array
$db: Database connection
-
?integer
$max: The maximum number of rows to affect (NULL: no limit)
-
?integer
$start: The start row to affect (NULL: no specification)
-
boolean
$fail_ok: Whether to not output an error on some kind of run-time failure (parse errors and clear programming errors are always fatal)
-
integer
&$at: Our offset counter
-
boolean
$do_end_check: Whether to not do the check to make sure we've parsed everything
Execute an UPDATE query.
?mixed
_do_query_update
(array $tokens, string $query, array $db, ?integer $max, ?integer $start, boolean $fail_ok)
-
array
$tokens: Tokens
-
string
$query: Query that was executed
-
array
$db: Database connection
-
?integer
$max: The maximum number of rows to affect (NULL: no limit)
-
?integer
$start: The start row to affect (NULL: no specification)
-
boolean
$fail_ok: Whether to not output an error on some kind of run-time failure (parse errors and clear programming errors are always fatal)
Escape a value for use in a filesystem path.
string
_escape_name
(string $in)
-
string
$in: Value to escape (original value)
Execute an expression.
?mixed
_execute_expression
(array $expr, array $bindings, string $query)
-
array
$expr: The expression
-
array
$bindings: Bindings available in the execution scope
-
string
$query: Query that was executed
Get results from a JOIN.
?array
_execute_join
(array $db, string $joined_as_prior, array $join, string $query, array $records, array $schema, array $where_expr, [boolean $fail_ok = false])
-
array
$db: Database connection
-
string
$joined_as_prior: The renaming of our table, so we can recognise it in the join condition
-
array
$join: Join op-tree
-
string
$query: Query that was executed
-
array
$records: Records so far
-
array
$schema: Schema so far
-
array
$where_expr: Expression filtering results (used for optimisation, seeing if we can get a quick key match)
-
boolean
$fail_ok: Whether to not output an error on some kind of run-time failure (parse errors and clear programming errors are always fatal)
Run SQL data filter functions over a result set.
array
_function_set_scoping
(array $set, array $select, array $rep, string $query)
-
array
$set: The set of results we are operating on
-
array
$select: Parse tree of what we are selecting
-
array
$rep: Record we are copying the function results into
-
string
$query: Query that was executed
Generate a GUID for a record, preferably from the key, but doesn't have to be.
string
_guid
([?array $schema = NULL], [?array $record = NULL])
-
?array
$schema: The schema (NULL: don't have/use)
-
?array
$record: The record (NULL: don't have/use)
Check to see if there is a key conflict problem.
boolean
_key_conflict_check
(array $db, string $table_name, array $schema, array $record, string $query, boolean $fail_ok, [?string $existing_identity = NULL])
-
array
$db: Database connection
-
string
$table_name: The table name
-
array
$schema: The schema
-
array
$record: The record
-
string
$query: Query that was executed
-
boolean
$fail_ok: Whether to not output an error on some kind of run-time failure (parse errors and clear programming errors are always fatal)
-
?string
$existing_identity: The GUID representing what we have now (so we don't think we're conflicting with ourself) (NULL: not yet added)
Check we've consumed all our tokens.
boolean
_parsing_check_ended
(integer $at, array $tokens, string $query, [boolean $fail_ok = false])
-
integer
$at: Our offset counter
-
array
$tokens: Tokens
-
string
$query: Query that was executed
-
boolean
$fail_ok: Whether to not output an error on some kind of run-time failure (parse errors and clear programming errors are always fatal)
Expect a certain token next.
boolean
_parsing_expects
(integer &$at, array $tokens, string $token, string $query, [boolean $fail_ok = false])
-
integer
&$at: Our offset counter
-
array
$tokens: Tokens
-
string
$token: Token expected
-
string
$query: Query that was executed
-
boolean
$fail_ok: Whether to not output an error on some kind of run-time failure (parse errors and clear programming errors are always fatal)
Reads the next token.
?string
_parsing_read
(integer &$at, array $tokens, string $query, [boolean $fail_ok = false])
-
integer
&$at: Our offset counter
-
array
$tokens: Tokens
-
string
$query: Query that was executed
-
boolean
$fail_ok: Whether it can return NULL if we're out of output (otherwise fails)
Parse an SQL expression.
?array
_parsing_read_expression
(integer &$at, array $tokens, string $query, array $db, [boolean $look_for_connectives = true], [boolean $look_for_any_connectives = true], [boolean $fail_ok = false])
-
integer
&$at: Our offset counter
-
array
$tokens: Tokens
-
string
$query: Query that was executed
-
array
$db: Database connection
-
boolean
$look_for_connectives: Whether to work as a connection point to seek out logic connection expression parts
-
boolean
$look_for_any_connectives: Whether to work as a connection point to seek out arithmetic connection expression parts
-
boolean
$fail_ok: Whether to not output an error on some kind of run-time failure (parse errors and clear programming errors are always fatal)
Read in all the records from a table.
?array
_read_all_records
(array $db, string $table_name, string $table_as, ?array $schema, ?array $where_expr, boolean $fail_ok, string $query, [boolean $include_unused_fields = false])
-
array
$db: Database connection
-
string
$table_name: The table name
-
string
$table_as: What the table will be renamed to (blank: N/A)
-
?array
$schema: Schema to type-set against (NULL: do not do type-setting)
-
?array
$where_expr: Expression filtering results (used for optimisation, seeing if we can get a quick key match) (NULL: no data to filter with)
-
boolean
$fail_ok: Whether to not output an error on some kind of run-time failure (parse errors and clear programming errors are always fatal)
-
string
$query: Query that was executed
-
boolean
$include_unused_fields: Whether to include fields that are present in the actual records but not in our schema
Read in a table specifier clause for a WHERE query.
?array
_read_join
(integer &$at, array $tokens, string $query, array $db, boolean $fail_ok, integer &$closing_brackets_needed)
-
integer
&$at: Our offset counter
-
array
$tokens: Tokens
-
string
$query: Query that was executed
-
array
$db: Database connection
-
boolean
$fail_ok: Whether to not output an error on some kind of run-time failure (parse errors and clear programming errors are always fatal)
-
integer
&$closing_brackets_needed: How many closing brackets we expect
Read a record from an XML file.
?array
_read_record
(PATH $path, [?array $schema = NULL], [?array $must_contain_strings = NULL], [boolean $include_unused_fields = false])
-
PATH
$path: The file path
-
?array
$schema: Schema to type-set against (NULL: do not do type-setting)
-
?array
$must_contain_strings: Substrings to check it is in, used for performance (NULL: none)
-
boolean
$include_unused_fields: Whether to include fields that are present in the actual records but not in our schema
Find the schema for a table.
?array
_read_schema
(array $db, string $table_name, [boolean $fail_ok = false])
-
array
$db: The database
-
string
$table_name: The table name
-
boolean
$fail_ok: Whether to not output an error on some kind of run-time failure (parse errors and clear programming errors are always fatal)
Optimize a join condition into a join scope set, if possible.
array
_setify_join_condition_for_optimisation
(array $join_condition, array $schema, array $records, string $joined_as)
-
array
$join_condition: Join condition (parsed WHERE-style clause)
-
array
$schema: Schema so far
-
array
$records: Records so far
-
string
$joined_as: The renaming of our table, so we can recognise it in the join condition
Take an expression and do our best to collapse it into a fixed mapping of stuff we know we are going to AND.
array
_turn_where_expr_to_map
(array $where_expr, string $table_as, [?array $schema = NULL], [boolean $not_full_accuracy = false])
-
array
$where_expr: The expression parse tree
-
string
$table_as: What the table will be renamed to (blank: N/A)
-
?array
$schema: Schema to type-set against (NULL: do not do type-setting)
-
boolean
$not_full_accuracy: Whether to do a not-full-accurate search
Type check some data destined to go into a table.
void
_type_check
(array $schema, array $record, string $query)
-
array
$schema: The schema
-
array
$record: The data
-
string
$query: Query that was executed
Unescape a value from a filesystem path back to the original.
string
_unescape_name
(string $in)
-
string
$in: Escaped value
Write a record to an XML file.
void
_write_record
(array $db, string $table_name, string $guid, array $record, [boolean $fail_ok = false], [boolean $save_as_volatile = false])
-
array
$db: Database connection
-
string
$table_name: The table name
-
string
$guid: The GUID
-
array
$record: The record map
-
boolean
$fail_ok: Whether to not output an error on some kind of run-time failure (parse errors and clear programming errors are always fatal)
-
boolean
$save_as_volatile: Whether we are saving as a 'volatile' file extension
Write in all the records to a table.
void
_write_records
(array $db, string $table_name, array $records, [boolean $fail_ok = false])
-
array
$db: Database connection
-
string
$table_name: The table name
-
array
$records: The list of record maps
-
boolean
$fail_ok: Whether to not output an error on some kind of run-time failure (parse errors and clear programming errors are always fatal)