Query\QueryBuilder
Convenience class for creating sql queries - also the class that instantiates the specific db driver
Synopsis
- // Inherited constants from AbstractQueryBuilder
- const KEY = 0;
- const VALUE = 1;
- const BOTH = 2;
- // members
- private array $string_vars = ;
- private array $array_vars = ;
- // Inherited members from AbstractQueryBuilder
- protected string $select_string;
- protected $from_string;
- protected $set_string;
- protected $order_string;
- protected $group_string;
- protected array $set_array_keys;
- protected array $order_array;
- protected array $group_array;
- protected array $values;
- protected array $where_values;
- protected $limit;
- protected $offset;
- protected array $query_map;
- protected $having_map;
- public string $conn_name;
- public $queries;
- protected bool $explain;
- public Driver_Interface $db;
- public Query_Parser $parser;
- public Abstract_Util $util;
- public SQL_Interface $sql;
- // methods
- public void __construct()
- public void __destruct()
- public mixed __call()
- public Query_Builder select()
- public Query_Builder select_max()
- public Query_Builder select_min()
- public Query_Builder select_avg()
- public Query_Builder select_sum()
- public Query_Builder distinct()
- public Query_Builder explain()
- public Query_Builder from()
- public Query_Builder like()
- public Query_Builder or_like()
- public Query_Builder not_like()
- public Query_Builder or_not_like()
- public Query_Builder having()
- public Query_Builder or_having()
- public Query_Builder where()
- public Query_Builder or_where()
- public Query_Builder where_in()
- public Query_Builder or_where_in()
- public Query_Builder where_not_in()
- public Query_Builder or_where_not_in()
- public Query_Builder set()
- public Query_Builder join()
- public Query_Builder group_by()
- public Query_Builder order_by()
- public Query_Builder limit()
- public Query_Builder group_start()
- public Query_Builder or_group_start()
- public Query_Builder or_not_group_start()
- public Query_Builder group_end()
- public PDOStatement get()
- public PDOStatement get_where()
- public int count_all()
- public int count_all_results()
- public PDOStatement insert()
- public PDOStatement insert_batch()
- public PDOStatement update()
- public PDOStatement delete()
- public string get_compiled_select()
- public string get_compiled_insert()
- public string get_compiled_update()
- public string get_compiled_delete()
- public void reset_query()
- // Inherited methods from AbstractQueryBuilder
- protected array _mixed_set()
- protected string _select()
- protected string _get_compile()
- protected Query_Builder _like()
- protected Query_Builder _having()
- protected array _where()
- protected Query_Builder _where_string()
- protected Query_Builder _where_in()
- protected PDOStatement _run()
- protected void _append_map()
- protected void _append_query()
- protected string _compile_type()
- protected string _compile()
Hierarchy
Coverage
Methods | 100% | 45 / 45 |
Lines | 100% | 148 / 148 |
Constants
Name | Value |
---|---|
KEY | 0 |
VALUE | 1 |
BOTH | 2 |
Members
private
- $array_vars
—
array
Array class variables to be reset - $string_vars
—
array
String class values to be reset
protected
- $explain
—
Query\bool
Whether to do only an explain on the query - $from_string
—
string
Compiled 'from' clause - $group_array
—
array
Key/val pairs for group by clause - $group_string
—
string
Group by clause - $having_map
—
array
Map for having clause - $limit
—
string
Value for limit string - $offset
—
int
Value for offset in limit string - $order_array
—
array
Key/val pairs for order by clause - $order_string
—
string
Order by clause - $query_map
—
array
Query component order mapping for complex select queries - $select_string
—
string
Compiled 'select' clause - $set_array_keys
—
array
Keys for insert/update statement - $set_string
—
string
Compiled arguments for insert / update - $values
—
array
Values to apply to prepared statements - $where_values
—
array
Values to apply to where clauses in prepared statements
public
- $conn_name
—
string
Convenience property for connection management - $db
—
Query\Driver_Interface
The current database driver - $parser
—
Query\Query_Parser
Query parser class instance - $queries
—
array
List of queries executed - $sql
—
\Query\Driver\SQL_Interface
Alias to driver sql class - $util
—
\Query\Driver\Abstract_Util
Alias to driver util class
Methods
public
- __construct() — Constructor
- __destruct() — Destructor
- __call() — Calls a function further down the inheritence chain
- count_all() — Retreive the number of rows in the selected table
- count_all_results() — Retrieve the number of results for the generated query - used in place of the get() method
- delete() — Deletes data from a table
- distinct() — Adds the 'distinct' keyword to a query
- explain() — Tell the database to give you the query plan instead of result set
- from() — Specify the database table to select from
- get() — Select and retrieve all records from the current table, and/or execute current compiled query
- get_compiled_delete() — Returns the generated 'delete' sql query
- get_compiled_insert() — Returns the generated 'insert' sql query
- get_compiled_select() — Returns the generated 'select' sql query
- get_compiled_update() — Returns the generated 'update' sql query
- get_where() — Convenience method for get() with a where clause
- group_by() — Group the results by the selected field(s)
- group_end() — Ends a query group
- group_start() — Adds a paren to the current query for query grouping
- having() — Generates a 'Having' clause
- insert() — Creates an insert clause, and executes it
- insert_batch() — Creates and executes a batch insertion query
- join() — Creates a join phrase in a compiled query
- like() — Creates a Like clause in the sql statement
- limit() — Set a limit on the current sql statement
- not_like() — Generates a NOT LIKE clause
- or_group_start() — Adds a paren to the current query for query grouping, prefixed with 'OR'
- or_having() — Generates a 'Having' clause prefixed with 'OR'
- or_like() — Generates an OR Like clause
- or_not_group_start() — Adds a paren to the current query for query grouping, prefixed with 'OR NOT'
- or_not_like() — Generates a OR NOT LIKE clause
- or_where() — Where clause prefixed with "OR"
- or_where_in() — Where in statement prefixed with "or"
- or_where_not_in() — OR WHERE NOT IN (FOO) clause
- order_by() — Order the results by the selected field(s)
- reset_query() — Clear out the class variables, so the next query can be run
- select() — Specifies rows to select in a query
- select_avg() — Selects the average value of a field from a query
- select_max() — Selects the maximum value of a field from a query
- select_min() — Selects the minimum value of a field from a query
- select_sum() — Selects the sum of a field from a query
- set() — Sets values for inserts / updates / deletes
- update() — Creates an update clause, and executes it
- where() — Specify condition(s) in the where clause of a query Note: this function works with key / value, or a passed array with key / value pairs
- where_in() — Where clause with 'IN' statement
- where_not_in() — WHERE NOT IN (FOO) clause
Inherited from Query\AbstractQueryBuilder
protected
- _append_map() — Add an additional set of mapping pairs to a internal map
- _append_query() — Convert the prepared statement into readable sql
- _compile() — String together the sql statements for sending to the db
- _compile_type() — Sub-method for generating sql strings
- _get_compile() — Helper function for returning sql strings
- _having() — Simplify building having clauses
- _like() — Simplify 'like' methods
- _mixed_set() — Set values in the class, with either an array or key value pair
- _run() — Executes the compiled query
- _select() — Method to simplify select_ methods
- _where() — Do all the repeditive stuff for where/having type methods
- _where_in() — Simplify where_in methods
- _where_string() — Simplify generating where string
History
-
2015-11-10T11:18:11-05:00 (commit #1e2a7ee)
Author: Timothy J Warren (tim@timshomepage.net) / Commiter: Timothy J Warren (tim@timshomepage.net)
Actually fix tests
-
2015-11-10T10:12:23-05:00 (commit #b5a141f)
Author: Timothy J Warren (tim@timshomepage.net) / Commiter: Timothy J Warren (tim@timshomepage.net)
Make class names Pascal Case
-
2015-11-10T06:45:55-05:00 (commit #e6ac4a7)
Author: Timothy J Warren (tim@timshomepage.net) / Commiter: Timothy J Warren (tim@timshomepage.net)
Set up jenkins build
-
2015-07-29T16:51:17-04:00 (commit #8511c6a)
Author: Timothy J. Warren (tim@timshomepage.net) / Commiter: Timothy J. Warren (tim@timshomepage.net)
Move library into src folder, fix simpletest test runner
-
2015-07-17T16:01:41-04:00 (commit #b4118ce)
Author: Timothy J. Warren (tim@timshomepage.net) / Commiter: Timothy J. Warren (tim@timshomepage.net)
Update docs
-
2015-07-16T16:56:13-04:00 (commit #bfc3ea3)
Author: Timothy J. Warren (tim@timshomepage.net) / Commiter: Timothy J. Warren (tim@timshomepage.net)
Reorganize drivers into a more modern layout
-
2014-11-07T12:14:46-05:00 (commit #6755818)
Author: Timothy J. Warren (tim@timshomepage.net) / Commiter: Timothy J. Warren (tim@timshomepage.net)
Fix some issues with multiple array items in where statements
-
2014-08-08T13:48:20-04:00 (commit #dd672df)
Author: Timothy J. Warren (tim@timshomepage.net) / Commiter: Timothy J. Warren (tim@timshomepage.net)
Reorganize classes to autoload by namespace
-
2014-06-30T11:21:40-04:00 (commit #2ccac50)
Author: Timothy J. Warren (tim@timshomepage.net) / Commiter: Timothy J. Warren (tim@timshomepage.net)
Fix small docblock discrepency
-
2014-06-30T11:16:50-04:00 (commit #d4838ba)
Author: Timothy J. Warren (tim@timshomepage.net) / Commiter: Timothy J. Warren (tim@timshomepage.net)
Add an additional type check to limit
-
2014-06-09T17:02:14-04:00 (commit #1abd835)
Author: Timothy J. Warren (tim@timshomepage.net) / Commiter: Timothy J. Warren (tim@timshomepage.net)
Attempting some Quercus compatibility, test-suite runs with simpletest as well as PHPUnit
-
2014-04-28T16:41:46-04:00 (commit #6a38213)
Author: Timothy J. Warren (tim@timshomepage.net) / Commiter: Timothy J. Warren (tim@timshomepage.net)
Improve some tests and docblocks
-
2014-04-24T21:29:40-04:00 (commit #315dc5e)
Author: Timothy J. Warren (tim@timshomepage.net) / Commiter: Timothy J. Warren (tim@timshomepage.net)
method shortening
-
2014-04-24T20:14:19-04:00 (commit #2ae38be)
Author: Timothy J. Warren (tim@timshomepage.net) / Commiter: Timothy J. Warren (tim@timshomepage.net)
Remove some variable setting logic duplication
-
2014-04-24T17:07:50-04:00 (commit #81be910)
Author: Timothy J. Warren (tim@timshomepage.net) / Commiter: Timothy J. Warren (tim@timshomepage.net)
Split Query Builder class
-
2014-04-24T14:50:53-04:00 (commit #993a2ab)
Author: Timothy J. Warren (tim@timshomepage.net) / Commiter: Timothy J. Warren (tim@timshomepage.net)
Allow camelCase method calls, update interfaces with missing methods