
Holds a single instance of the fDatabase class and provides database manipulation functionality for ORM code
1.0.0b32 | Added support to addWhereClause() for the ^~ and $~ operators 6/20/11 |
---|---|
1.0.0b31 | Fixed a bug with addWhereClause() generating invalid SQL 5/10/11 |
1.0.0b30 | Fixed insertFromAndGroupByClauses() to insert MAX() around columns in related tables in the ORDER BY clause when a GROUP BY is used 2/3/11 |
1.0.0b29 | Added code to handle old PCRE engines that don't support unicode character properties 12/6/10 |
1.0.0b28 | Fixed a bug in the fProgrammerException that is thrown when an improperly formatted OR condition is provided 11/24/10 |
1.0.0b27 | Fixed addWhereClause() to ignore fuzzy search clauses with no values to match 10/19/10 |
1.0.0b26 | Fixed insertFromAndGroupByClauses() to handle SQL where a table is references in more than one capitalization 7/26/10 |
1.0.0b25 | Fixed insertFromAndGroupByClauses() to properly handle recursive relationships 7/22/10 |
1.0.0b24 | Fixed parseSearchTerms() to work with non-ascii terms 6/30/10 |
1.0.0b23 | Fixed error messages in retrieve() 4/23/10 |
1.0.0b22 | Added support for IBM DB2, fixed an issue with building record sets or records that have recursive relationships 4/13/10 |
1.0.0b21 | Changed injectFromAndGroupByClauses() to be able to handle table aliases that contain other aliases inside of them 3/3/10 |
1.0.0b20 | Fixed a bug where joining to a table two separate ways could cause table alias issues and incorrect SQL to be generated 12/16/09 |
1.0.0b19 | Added the ability to compare columns with the =:, !:, <:, <=:, >: and >=: operators 12/8/09 |
1.0.0b18 | Fixed a bug affecting where conditions with columns that are not null but have a default value 11/3/09 |
1.0.0b17 | Added support for multiple databases 10/28/09 |
1.0.0b16 | Internal Backwards Compatibility Break - Renamed methods and significantly changed parameters and functionality for SQL statements to use value placeholders, identifier escaping and to handle schemas 10/22/09 |
1.0.0b15 | Streamlined intersection operator SQL and added support for the second value being NULL 9/21/09 |
1.0.0b14 | Added support for the intersection operator >< to createWhereClause() 7/13/09 |
1.0.0b13 | Added support for the AND LIKE operator &~ to createWhereClause() 7/9/09 |
1.0.0b12 | Added support for the NOT LIKE operator !~ to createWhereClause() 7/8/09 |
1.0.0b11 | Added support for concatenated columns to escapeBySchema() 6/19/09 |
1.0.0b10 | Updated createWhereClause() to properly handle NULLs for arrays of values when doing = and != comparisons 6/17/09 |
1.0.0b9 | Changed replacement values in preg_replace() calls to be properly escaped 6/11/09 |
1.0.0b8 | Fixed a bug with creatingWhereClause() where a null value would not be escaped property 5/12/09 |
1.0.0b7 | Fixed a bug where an OR condition in createWhereClause() could not have one of the values be an array 4/22/09 |
1.0.0b6 | insertFromAndGroupByClauses() will no longer wrap ungrouped columns if in a CAST or CASE statement for ORDER BY clauses of queries with a GROUP BY clause 3/23/09 |
1.0.0b5 | Fixed parseSearchTerms() to include stop words when they are the only thing in the search string 12/31/08 |
1.0.0b4 | Fixed a bug where loading a related record in the same table through a one-to-many relationship caused recursion 12/24/08 |
1.0.0b3 | Fixed a bug from 1.0.0b2 12/5/08 |
1.0.0b2 | Added support for != and <> to createWhereClause() and createHavingClause() 12/4/08 |
1.0.0b | The initial implementation 8/4/07 |
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Creates a HAVING clause from an array of conditions
array addHavingClause( fDatabase $db, fSchema $schema, array $params, string $table, array $conditions )
fDatabase | $db | The database the query will be executed on |
fSchema | $schema | The schema for the database |
array | $params | The params for the fDatabase::query() call |
string | $table | The table the query is being executed on |
array | $conditions | The array of conditions - see fRecordSet::build() for format |
The params with the HAVING clause added
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Adds an ORDER BY clause to an array of params for an fDatabase::query() call
array addOrderByClause( fDatabase $db, fSchema $schema, array $params, string $table, array $order_bys )
fDatabase | $db | The database the query will be executed on |
fSchema | $schema | The schema object for the database the query will be executed on |
array | $params | The parameters for the fDatabase::query() call |
string | $table | The table any ambigious column references will refer to |
array | $order_bys | The array of order bys to use - see fRecordSet::build() for format |
The params with a SQL ORDER BY clause added
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Add the appropriate SQL and params for a WHERE clause condition for primary keys of the table specified
array addPrimaryKeyWhereParams( fSchema $schema, array $params, string $table, string $table_alias, array &$values, array &$old_values )
fSchema | $schema | The schema for the database the query will be run on |
array | $params | The currently constructed params for fDatabase::query() - the first param should be a SQL statement |
string | $table | The table to build the where clause for |
string | $table_alias | The alias for the table |
array | &$values | The values array for the fActiveRecord object |
array | &$old_values | The old values array for the fActiveRecord object |
The params to pass to fDatabase::query(), including the new primary key where condition
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Adds a WHERE clause, from an array of conditions, to the parameters for an fDatabase::query() call
array addWhereClause( fDatabase $db, fSchema $schema, array $params, string $table, array $conditions )
fDatabase | $db | The database the query will be executed on |
fSchema | $schema | The schema for the database |
array | $params | The parameters for the fDatabase::query() call |
string | $table | The table any ambigious column references will refer to |
array | $conditions | The array of conditions - see fRecordSet::build() for format |
The params with the SQL WHERE clause added
Allows attaching an fDatabase-compatible objects for by ORM code
If a $name other than default is used, any fActiveRecord classes that should use it will need to be configured by passing the class name and $name to mapClassToDatabase(). The $name parameter should be unique per database or database master/slave setup.
The $role is used by code to allow for master/slave database setups. There can only be one database object attached for either of the roles, 'read' or 'write'. If the role 'both' is specified, it will be applied to both the 'read' and 'write' roles. Any sort of logic for picking one out of multiple databases should be done before this method is called.
void attach( fDatabase $database, string $name='default', string $role='both' )
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Finds all of the table names in the SQL and creates the appropriate FROM and GROUP BY clauses with all necessary joins
The SQL string should contain two placeholders, :from_clause and :group_by_clause, although the later may be omitted if necessary. All columns should be qualified with their full table name.
Here is an example SQL string to pass in presumming that the tables users and groups are in a relationship:
SELECT users.* FROM :from_clause WHERE groups.group_id = 5 :group_by_clause ORDER BY lower(users.first_name) ASC
array injectFromAndGroupByClauses( fDatabase $db, fSchema $schema, array $params, string $table )
fDatabase | $db | The database the query is to be executed on |
fSchema | $schema | The schema for the database |
array | $params | The parameters for the fDatabase::query() call |
string | $table | The main table to be queried |
The params with the SQL FROM and GROUP BY clauses injected
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Makes a condition for a SQL statement out of fDatabase::escape() placeholders
string makeCondition( fSchema $schema, string $table, string $column, string $comparison_operator, mixed $value )
fSchema | $schema | The schema object for the database the query will be executed on |
string | $table | The table to create the condition for |
string | $column | The column to make the condition for |
string | $comparison_operator | The comparison operator for the condition |
mixed | $value | The value for the condition, which allows the $comparison_operator to be tweaked for NULL values |
A SQL condition using fDatabase::escape() placeholders
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Parses a search string into search terms, supports quoted phrases and removes extra punctuation
void parseSearchTerms( string $terms, boolean $ignore_stop_words=FALSE )
string | $terms | A text string from a form input to parse into search terms |
boolean | $ignore_stop_words | If stop words should be ignored, this setting will be ignored if all words are stop words |
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Resets the configuration of the class
void reset( )
Return the instance of the fDatabase class
fDatabase retrieve( string $class='fActiveRecord', string $role='either' )
string | $class | The class to retrieve the database for - if not specified, the default database will be returned |
string | $role | If the database will be used for 'write', 'read' or 'either' operations |
The database instance
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Removed aggregate function calls from where conditions array and puts them in a having conditions array
array splitHavingConditions( array &$where_conditions )
array | &$where_conditions | The where conditions to look through for aggregate functions |
The conditions to be put in a HAVING clause