From 65b10c52c99ef15df7e9c8c378c3947b202fdea1 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Fri, 28 Mar 2014 15:16:39 -0400 Subject: [PATCH] Miscellaneous cleanup --- classes/query_builder.php | 48 +- classes/query_builder_interface.php | 11 + common.php | 15 +- docs/classes/iDB_SQL.html | 279 -------- docs/classes/iQuery_Builder.html | 998 ---------------------------- docs/classes/idriver.html | 302 --------- 6 files changed, 33 insertions(+), 1620 deletions(-) delete mode 100644 docs/classes/iDB_SQL.html delete mode 100644 docs/classes/iQuery_Builder.html delete mode 100644 docs/classes/idriver.html diff --git a/classes/query_builder.php b/classes/query_builder.php index 84518be..0753b98 100644 --- a/classes/query_builder.php +++ b/classes/query_builder.php @@ -1037,7 +1037,7 @@ class Query_Builder implements Query_Builder_Interface { * * @param string $table * @param mixed $data - * @return mixed + * @return PDOStatement */ public function insert($table, $data=array()) { @@ -1079,7 +1079,7 @@ class Query_Builder implements Query_Builder_Interface { * * @param string $table * @param mixed $data - * @return mixed + * @return PDOStatement */ public function update($table, $data=array()) { @@ -1099,7 +1099,7 @@ class Query_Builder implements Query_Builder_Interface { * * @param string $table * @param mixed $where - * @return mixed + * @return PDOStatement */ public function delete($table, $where='') { @@ -1253,7 +1253,7 @@ class Query_Builder implements Query_Builder_Interface { * @param string $type * @param string $table * @param string $sql - * @param mixed $vals + * @param array|null $vals * @return PDOStatement */ protected function _run($type, $table, $sql=NULL, $vals=NULL) @@ -1388,33 +1388,27 @@ class Query_Builder implements Query_Builder_Interface { // Get the base clause for the query $sql = $this->_compile_type($type, $this->db->quote_table($table)); - // Set the where clause - if ( ! empty($this->query_map)) + $clauses = array( + 'query_map', + 'group_string', + 'order_string', + 'having_map', + ); + + // Set each type of subclause + foreach($clauses as $clause) { - foreach($this->query_map as $q) + $param = $this->$clause; + if (is_array($param)) { - $sql .= $q['conjunction'] . $q['string']; + foreach($param as $q) + { + $sql .= $q['conjunction'] . $q['string']; + } } - } - - // Set the group_by clause - if ( ! empty($this->group_string)) - { - $sql .= $this->group_string; - } - - // Set the order_by clause - if ( ! empty($this->order_string)) - { - $sql .= $this->order_string; - } - - // Set the having clause - if ( ! empty($this->having_map)) - { - foreach($this->having_map as $h) + else { - $sql .= $h['conjunction'] . $h['string']; + $sql .= $param; } } diff --git a/classes/query_builder_interface.php b/classes/query_builder_interface.php index 30e5d84..4dea64e 100644 --- a/classes/query_builder_interface.php +++ b/classes/query_builder_interface.php @@ -409,6 +409,17 @@ interface Query_Builder_Interface { // -------------------------------------------------------------------------- + /** + * Creates and executes a batch insertion query + * + * @param string $table + * @param array $data + * @return string + */ + public function insert_batch($table, $data=array()); + + // -------------------------------------------------------------------------- + /** * Creates an update clause, and executes it * diff --git a/common.php b/common.php index 36d5eda..dede99d 100644 --- a/common.php +++ b/common.php @@ -155,7 +155,7 @@ function Query($params = '') if (isset($params->options)) { - $options = (array)$params->options; + $options = (array) $params->options; } // -------------------------------------------------------------------------- @@ -165,19 +165,6 @@ function Query($params = '') // Create the dsn for the database to connect to if ($dbtype === 'firebird') $dsn = "{$params->host}:{$params->file}"; elseif ($dbtype === 'sqlite') $dsn = $params->file; - elseif ($dbtype === 'pdo_firebird') - { - $dbtype = 'firebird'; - - if ( ! empty($params->port)) - { - $dsn = "{$dbtype}:dbname={$params->host}/{$params->port}:{$params->file}"; - } - else - { - $dsn = "{$dbtype}:dbname={$params->host}:{$params->file}"; - } - } else { if ( ! empty($params->conn_db)) diff --git a/docs/classes/iDB_SQL.html b/docs/classes/iDB_SQL.html deleted file mode 100644 index 4fe295e..0000000 --- a/docs/classes/iDB_SQL.html +++ /dev/null @@ -1,279 +0,0 @@ - - - - - -Query » \iDB_SQL - - - - - - - - - - -
- -
- -
- -
-

parent for database manipulation subclasses

-
-
- - - - - - - - - -
packageQuery
subpackageQuery
-

- Methods

-
-

Get information about the columns in the -specified table

-
column_list(string $table) : string
-
-
-
-

Parameters

-
-

$table

-string -
-

Returns

-
string
-
-
-
-

Returns sql to list other databases

-
db_list() : string
-
-
-
-

Returns

-
string
-
-
-
-

Modify the query to get the query plan

-
explain(string $sql) : string
-
-
-
-

Parameters

-
-

$sql

-string -
-

Returns

-
string
-
-
-
-

Return sql to list functions

-
function_list() : NULL
-
-
-
-

Returns

-
NULL
-
-
-
-

Get database specific sql for limit clause

-
limit(string $sql, int $limit, int $offset = FALSE) : string
-
-
-
- - - -
abstract
-

Parameters

-
-

$sql

-string -
-
-

$limit

-int -
-
-

$offset

-int -
-

Returns

-
string
-
-
-
-

Return sql to list stored procedures

-
procedure_list() : string
-
-
-
-

Returns

-
string
-
-
-
-

Get the sql for random ordering

-
random() : string
-
-
-
- - - -
abstract
-

Returns

-
string
-
-
-
-

Return sql to list sequences

-
sequence_list() : string
-
-
-
-

Returns

-
string
-
-
-
-

Returns sql to list system tables

-
system_table_list() : string
-
-
-
-

Returns

-
string
-
-
-
-

Returns sql to list tables

-
table_list() : string
-
-
-
-

Returns

-
string
-
-
-
-

Returns sql to list triggers

-
trigger_list() : string
-
-
-
-

Returns

-
string
-
-
-
-

Return sql to list database field types

-
type_list() : mixed
-
-
-
-

Returns

-
mixed
-
-
-
-

Returns sql to list views

-
view_list() : string
-
-
-
-

Returns

-
string
-
-
-
-
-
-
-
-
- - diff --git a/docs/classes/iQuery_Builder.html b/docs/classes/iQuery_Builder.html deleted file mode 100644 index 21c1d05..0000000 --- a/docs/classes/iQuery_Builder.html +++ /dev/null @@ -1,998 +0,0 @@ - - - - - -Query » \iQuery_Builder - - - - - - - - - - -
- -
-
-
-
- -
-
- -
-
- -
-
- -
-

Interface defining the Query Builder class

-
-
- - - - - - - - - -
packageQuery
subpackageQuery
-

- Methods

-
-

Retreive the number of rows in the selected table

-
count_all(string $table) : int
-
-
-
-

Parameters

-
-

$table

-string -
-

Returns

-
int
-
-
-
-

Retrieve the number of results for the generated query - used -in place of the get() method

-
count_all_results(string $table = '') : int
-
-
-
-

Parameters

-
-

$table

-string -
-

Returns

-
int
-
-
-
-

Deletes data from a table

-
delete(string $table, mixed $where = '') : mixed
-
-
-
-

Parameters

-
-

$table

-string -
-
-

$where

-mixed -
-

Returns

-
mixed
-
-
-
-

Adds the 'distinct' keyword to a query

-
distinct() : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Returns

-
\iQuery_Builder
-
-
-
-

Shows the query plan for the query

-
explain() : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Returns

-
\iQuery_Builder
-
-
-
-

Specify the database table to select from

-
from(string $tblname) : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Parameters

-
-

$tblname

-string -
-

Returns

-
\iQuery_Builder
-
-
-
-

Select and retrieve all records from the current table, and/or -execute current compiled query

-
get(mixed $table = '', int $limit = FALSE, int $offset = FALSE) : object
-
-
-
-

Parameters

-

$table

-
-

$limit

-int -
-
-

$offset

-int -
-

Returns

-
object
-
-
-
-

Returns the generated 'delete' sql query

-
get_compiled_delete(string $table = "", bool $reset = TRUE) : string
-
-
-
-

Parameters

-
-

$table

-string -
-
-

$reset

-bool -
-

Returns

-
string
-
-
-
-

Returns the generated 'insert' sql query

-
get_compiled_insert(string $table, bool $reset = TRUE) : string
-
-
-
-

Parameters

-
-

$table

-string -
-
-

$reset

-bool -
-

Returns

-
string
-
-
-
-

Returns the generated 'select' sql query

-
get_compiled_select(string $table = '', bool $reset = TRUE) : string
-
-
-
-

Parameters

-
-

$table

-string -
-
-

$reset

-bool -
-

Returns

-
string
-
-
-
-

Returns the generated 'update' sql query

-
get_compiled_update(string $table = '', bool $reset = TRUE) : string
-
-
-
-

Parameters

-
-

$table

-string -
-
-

$reset

-bool -
-

Returns

-
string
-
-
-
-

Convience method for get() with a where clause

-
get_where(string $table, array $where = array(), int $limit = FALSE, int $offset = FALSE) : object
-
-
-
-

Parameters

-
-

$table

-string -
-
-

$where

-array -
-
-

$limit

-int -
-
-

$offset

-int -
-

Returns

-
object
-
-
-
-

Group the results by the selected field(s)

-
group_by(mixed $field) : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Parameters

-
-

$field

-mixed -
-

Returns

-
\iQuery_Builder
-
-
-
-

Ends a query group

-
group_end() : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Returns

-
\iQuery_Builder
-
-
-
-

Adds a paren to the current query for query grouping

-
group_start() : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Returns

-
\iQuery_Builder
-
-
-
-

Generates a 'Having' clause

-
having(mixed $key, mixed $val = array()) : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Parameters

-
-

$key

-mixed -
-
-

$val

-mixed -
-

Returns

-
\iQuery_Builder
-
-
-
-

Creates an insert clause, and executes it

-
insert(string $table, mixed $data = array()) : mixed
-
-
-
-

Parameters

-
-

$table

-string -
-
-

$data

-mixed -
-

Returns

-
mixed
-
-
-
-

Creates a join phrase in a compiled query

-
join(string $table, string $condition, string $type = '') : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Parameters

-
-

$table

-string -
-
-

$condition

-string -
-
-

$type

-string -
-

Returns

-
\iQuery_Builder
-
-
-
-

Creates a Like clause in the sql statement

-
like(string $field, mixed $val, string $pos = 'both') : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Parameters

-
-

$field

-string -
-
-

$val

-mixed -
-
-

$pos

-string -
-

Returns

-
\iQuery_Builder
-
-
-
-

Set a limit on the current sql statement

-
limit(int $limit, int $offset = FALSE) : string
-
-
-
-

Parameters

-
-

$limit

-int -
-
-

$offset

-int -
-

Returns

-
string
-
-
-
-

Generates a NOT LIKE clause

-
not_like(string $field, mixed $val, string $pos = 'both') : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Parameters

-
-

$field

-string -
-
-

$val

-mixed -
-
-

$pos

-string -
-

Returns

-
\iQuery_Builder
-
-
-
-

Adds a paren to the current query for query grouping, -prefixed with 'OR'

-
or_group_start() : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Returns

-
\iQuery_Builder
-
-
-
-

Generates a 'Having' clause prefixed with 'OR'

-
or_having(mixed $key, mixed $val = array()) : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Parameters

-
-

$key

-mixed -
-
-

$val

-mixed -
-

Returns

-
\iQuery_Builder
-
-
-
-

Generates an OR Like clause

-
or_like(string $field, mixed $val, string $pos = 'both') : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Parameters

-
-

$field

-string -
-
-

$val

-mixed -
-
-

$pos

-string -
-

Returns

-
\iQuery_Builder
-
-
-
-

Adds a paren to the current query for query grouping, -prefixed with 'OR NOT'

-
or_not_group_start() : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Returns

-
\iQuery_Builder
-
-
-
-

Generates a OR NOT LIKE clause

-
or_not_like(string $field, mixed $val, string $pos = 'both') : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Parameters

-
-

$field

-string -
-
-

$val

-mixed -
-
-

$pos

-string -
-

Returns

-
\iQuery_Builder
-
-
-
-

Where clause prefixed with "OR"

-
or_where(string $key, mixed $val = array()) : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Parameters

-
-

$key

-string -
-
-

$val

-mixed -
-

Returns

-
\iQuery_Builder
-
-
-
-

Where in statement prefixed with "or"

-
or_where_in(string $field, mixed $val = array()) : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Parameters

-
-

$field

-string -
-
-

$val

-mixed -
-

Returns

-
\iQuery_Builder
-
-
-
-

OR WHERE NOT IN (FOO) clause

-
or_where_not_in(string $field, mixed $val = array()) : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Parameters

-
-

$field

-string -
-
-

$val

-mixed -
-

Returns

-
\iQuery_Builder
-
-
-
-

Order the results by the selected field(s)

-
order_by(string $field, string $type = "") : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Parameters

-
-

$field

-string -
-
-

$type

-string -
-

Returns

-
\iQuery_Builder
-
-
-
-

Clear out the class variables, so the next query can be run

-
reset_query() : void
-
-
-
-
-

Specifies rows to select in a query

-
select(string $fields) : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Parameters

-
-

$fields

-string -
-

Returns

-
\iQuery_Builder
-
-
-
-

Selects the average value of a field from a query

-
select_avg(string $field, string $as = FALSE) : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Parameters

-
-

$field

-string -
-
-

$as

-string -
-

Returns

-
\iQuery_Builder
-
-
-
-

Selects the maximum value of a field from a query

-
select_max(string $field, string $as = FALSE) : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Parameters

-
-

$field

-string -
-
-

$as

-string -
-

Returns

-
\iQuery_Builder
-
-
-
-

Selects the minimum value of a field from a query

-
select_min(string $field, string $as = FALSE) : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Parameters

-
-

$field

-string -
-
-

$as

-string -
-

Returns

-
\iQuery_Builder
-
-
-
-

Selects the sum of a field from a query

-
select_sum(string $field, string $as = FALSE) : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Parameters

-
-

$field

-string -
-
-

$as

-string -
-

Returns

-
\iQuery_Builder
-
-
-
-

Sets values for inserts / updates / deletes

-
set(mixed $key, mixed $val = NULL) : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Parameters

-
-

$key

-mixed -
-
-

$val

-mixed -
-

Returns

-
\iQuery_Builder
-
-
-
-

Creates an update clause, and executes it

-
update(string $table, mixed $data = array()) : mixed
-
-
-
-

Parameters

-
-

$table

-string -
-
-

$data

-mixed -
-

Returns

-
mixed
-
-
-
-

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(mixed $key, mixed $val = array(), bool $escape = NULL) : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Parameters

-
-

$key

-mixed -
-
-

$val

-mixed -
-
-

$escape

-bool -
-

Returns

-
\iQuery_Builder
-
-
-
-

Where clause with 'IN' statement

-
where_in(mixed $field, mixed $val = array()) : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Parameters

-
-

$field

-mixed -
-
-

$val

-mixed -
-

Returns

-
\iQuery_Builder
-
-
-
-

WHERE NOT IN (FOO) clause

-
where_not_in(string $field, mixed $val = array()) : \iQuery_Builder
-
-
-
- - - -
fluentThis method is part of a fluent interface and will return the same instance
-

Parameters

-
-

$field

-string -
-
-

$val

-mixed -
-

Returns

-
\iQuery_Builder
-
-
-
-
-
-
-
-
- - diff --git a/docs/classes/idriver.html b/docs/classes/idriver.html deleted file mode 100644 index 51face8..0000000 --- a/docs/classes/idriver.html +++ /dev/null @@ -1,302 +0,0 @@ - - - - - -Query » \idriver - - - - - - - - - - -
- -
- -
- -
-

PDO Interface to implement for database drivers

-
-
-

- Methods

-
-

Constructor/Connection method

-
__construct(string $dsn, \[string] $username = NULL, \[string] $password = NULL, \[array] $driver_options = array()) : void
-
-
-
-

Parameters

-
-

$dsn

-string -
-
-

$username

-\[string] -
-
-

$password

-\[string] -
-
-

$driver_options

-\[array] -
-
-
-
-

Begin a transaction

-
beginTransaction() : bool
-
-
-
-

Returns

-
bool
-
-
-
-

Commit a transaction

-
commit() : bool
-
-
-
-

Returns

-
bool
-
-
-
-

Return the current error code

-
errorCode() : mixed
-
-
-
-

Returns

-
mixed
-
-
-
-

Return information about the current error

-
errorInfo() : array
-
-
-
-

Returns

-
array
-
-
-
-

Execute an SQL statement and return the number of affected rows

-
exec(string $statement) : int
-
-
-
-

Parameters

-
-

$statement

-string -
-

Returns

-
int
-
-
-
-

Get a connection attribute for the current db driver

-
getAttribute(int $attribute) 
-
-
-
- - - -
returmmixed
-

Parameters

-
-

$attribute

-int -
-
-
-
-

Check if currently in a transaction

-
inTransaction() : bool
-
-
-
-

Returns

-
bool
-
-
-
-

Returns the id of the last row inserted into the database

-
lastInsertId(\[string] $name = NULL) : string
-
-
-
-

Parameters

-
-

$name

-\[string] -
-

Returns

-
string
-
-
-
-

Prepare a statement for execution

-
prepare(string $statement, \[array] $driver_options = array()) : \PDOStatement
-
-
-
-

Parameters

-
-

$statement

-string -
-
-

$driver_options

-\[array] -
-

Returns

- -
-
-
-

Executes an sql statement

-
query() : \PDOStatement
-
-
-
-

Returns

- -
-
-
-

Quotes a string for use in a query

-
quote(string $string, \[int] $parameter_type = \PDO::PARAM_STRING
-
-
-
-

Parameters

-
-

$string

-string -
-
-

$parameter_type

-\[int]

#return string

-
-
-
-

Rollback a transaction

-
rollback() : bool
-
-
-
-

Returns

-
bool
-
-
-
-

Set a connection attribute

-
setAttribute(int $attribute, mixed $value) : bool
-
-
-
-

Parameters

-
-

$attribute

-int -
-
-

$value

-mixed -
-

Returns

-
bool
-
-
-
-
-
-
-
-
- -