diff --git a/build/header_comment.txt b/build/header_comment.txt index 6fd37bc..6f87c80 100644 --- a/build/header_comment.txt +++ b/build/header_comment.txt @@ -3,11 +3,11 @@ * * SQL Query Builder / Database Abstraction Layer * - * PHP version 5.4 + * PHP version 7 * * @package Query * @author Timothy J. Warren - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query - */ + */ \ No newline at end of file diff --git a/build/update_header_comments.php b/build/update_header_comments.php index 5292fc1..55ff43b 100644 --- a/build/update_header_comments.php +++ b/build/update_header_comments.php @@ -1,7 +1,9 @@ - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ @@ -29,7 +29,6 @@ abstract class AbstractQueryBuilder { const VALUE = 1; const BOTH = 2; - // -------------------------------------------------------------------------- // ! SQL Clause Strings // -------------------------------------------------------------------------- @@ -44,7 +43,7 @@ abstract class AbstractQueryBuilder { * Compiled 'from' clause * @var string */ - protected $from_string; + protected $from_string = ''; /** * Compiled arguments for insert / update @@ -213,8 +212,6 @@ abstract class AbstractQueryBuilder { return $var; } - // -------------------------------------------------------------------------- - /** * Method to simplify select_ methods * @@ -237,8 +234,6 @@ abstract class AbstractQueryBuilder { return "({$field}) AS {$as} "; } - // -------------------------------------------------------------------------- - /** * Helper function for returning sql strings * @@ -260,8 +255,6 @@ abstract class AbstractQueryBuilder { return $sql; } - // -------------------------------------------------------------------------- - /** * Simplify 'like' methods * @@ -270,7 +263,7 @@ abstract class AbstractQueryBuilder { * @param string $pos * @param string $like * @param string $conj - * @return QueryBuilder + * @return QueryBuilderInterface */ protected function _like($field, $val, $pos, $like='LIKE', $conj='AND') { @@ -301,15 +294,13 @@ abstract class AbstractQueryBuilder { return $this; } - // -------------------------------------------------------------------------- - /** * Simplify building having clauses * * @param mixed $key * @param mixed $val * @param string $conj - * @return QueryBuilder + * @return QueryBuilderInterface */ protected function _having($key, $val=[], $conj='AND') { @@ -337,8 +328,6 @@ abstract class AbstractQueryBuilder { return $this; } - // -------------------------------------------------------------------------- - /** * Do all the redundant stuff for where/having type methods * @@ -354,15 +343,13 @@ abstract class AbstractQueryBuilder { return $where; } - // -------------------------------------------------------------------------- - /** * Simplify generating where string * * @param mixed $key * @param mixed $val * @param string $defaultConj - * @return QueryBuilder + * @return QueryBuilderInterface */ protected function _where_string($key, $val=[], $defaultConj='AND') { @@ -400,8 +387,6 @@ abstract class AbstractQueryBuilder { return $this; } - // -------------------------------------------------------------------------- - /** * Simplify where_in methods * @@ -409,7 +394,7 @@ abstract class AbstractQueryBuilder { * @param mixed $val * @param string $in - The (not) in fragment * @param string $conj - The where in conjunction - * @return QueryBuilder + * @return QueryBuilderInterface */ protected function _where_in($key, $val=[], $in='IN', $conj='AND') { @@ -429,8 +414,6 @@ abstract class AbstractQueryBuilder { return $this; } - // -------------------------------------------------------------------------- - /** * Executes the compiled query * @@ -474,8 +457,6 @@ abstract class AbstractQueryBuilder { return $res; } - // -------------------------------------------------------------------------- - /** * Add an additional set of mapping pairs to a internal map * @@ -493,8 +474,6 @@ abstract class AbstractQueryBuilder { ]); } - // -------------------------------------------------------------------------- - /** * Convert the prepared statement into readable sql * @@ -530,8 +509,6 @@ abstract class AbstractQueryBuilder { $this->db->set_last_query($sql); } - // -------------------------------------------------------------------------- - /** * Sub-method for generating sql strings * @@ -580,8 +557,6 @@ abstract class AbstractQueryBuilder { return $sql; } - // -------------------------------------------------------------------------- - /** * String together the sql statements for sending to the db * @@ -633,6 +608,4 @@ abstract class AbstractQueryBuilder { return $sql; } -} - -// End of abstract_QueryBuilder.php \ No newline at end of file +} \ No newline at end of file diff --git a/src/Query/BadDBDriverException.php b/src/Query/BadDBDriverException.php index bcb4344..45e5894 100644 --- a/src/Query/BadDBDriverException.php +++ b/src/Query/BadDBDriverException.php @@ -1,18 +1,20 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ + + namespace Query; use InvalidArgumentException; diff --git a/src/Query/ConnectionManager.php b/src/Query/ConnectionManager.php index 425a96f..c092294 100644 --- a/src/Query/ConnectionManager.php +++ b/src/Query/ConnectionManager.php @@ -1,22 +1,24 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ + + namespace Query; -use InvalidArgumentException; use DomainException; +use InvalidArgumentException; /** * Connection manager class to manage connections for the @@ -45,7 +47,7 @@ final class ConnectionManager { * Private constructor to prevent multiple instances * @codeCoverageIgnore */ - private function __construct() + private function __construct() { } diff --git a/src/Query/Drivers/AbstractDriver.php b/src/Query/Drivers/AbstractDriver.php index 4494423..a095c62 100644 --- a/src/Query/Drivers/AbstractDriver.php +++ b/src/Query/Drivers/AbstractDriver.php @@ -1,23 +1,24 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ + namespace Query\Drivers; +use InvalidArgumentException; use PDO; use PDOStatement; -use InvalidArgumentException; /** * Base Database class @@ -31,7 +32,7 @@ abstract class AbstractDriver extends PDO implements DriverInterface { /** * Reference to the last executed query - * @var \PDOStatement + * @var PDOStatement */ protected $statement; @@ -63,7 +64,7 @@ abstract class AbstractDriver extends PDO implements DriverInterface { * Last query executed * @var string */ - protected $last_query; + protected $last_query = ''; /** * Prefix to apply to table names @@ -125,7 +126,7 @@ abstract class AbstractDriver extends PDO implements DriverInterface { * @param array $args * @return mixed */ - public function __call($name, $args = []) + public function __call(string $name, array $args = []) { if ( isset($this->$name) @@ -146,7 +147,7 @@ abstract class AbstractDriver extends PDO implements DriverInterface { * * @return string */ - public function get_last_query() + public function get_last_query(): string { return $this->last_query; } @@ -159,7 +160,7 @@ abstract class AbstractDriver extends PDO implements DriverInterface { * @param string $query_string * @return void */ - public function set_last_query($query_string) + public function set_last_query(string $query_string) { $this->last_query = $query_string; } diff --git a/src/Query/Drivers/AbstractSQL.php b/src/Query/Drivers/AbstractSQL.php index 99fa7b4..a48ef9c 100644 --- a/src/Query/Drivers/AbstractSQL.php +++ b/src/Query/Drivers/AbstractSQL.php @@ -1,19 +1,21 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ + + // -------------------------------------------------------------------------- namespace Query\Drivers; diff --git a/src/Query/Drivers/AbstractUtil.php b/src/Query/Drivers/AbstractUtil.php index d2a6802..33e6660 100644 --- a/src/Query/Drivers/AbstractUtil.php +++ b/src/Query/Drivers/AbstractUtil.php @@ -1,25 +1,21 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ -// -------------------------------------------------------------------------- - namespace Query\Drivers; -// -------------------------------------------------------------------------- - /** * Abstract class defining database / table creation methods * @@ -51,7 +47,7 @@ abstract class AbstractUtil { /** * Get the driver object for the current connection * - * @return Driver_Interface + * @return DriverInterface */ public function get_driver() { diff --git a/src/Query/Drivers/DriverInterface.php b/src/Query/Drivers/DriverInterface.php index 333e402..f287b71 100644 --- a/src/Query/Drivers/DriverInterface.php +++ b/src/Query/Drivers/DriverInterface.php @@ -1,18 +1,19 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ + namespace Query\Drivers; /** @@ -220,7 +221,7 @@ interface DriverInterface extends PDOInterface { /** * Get the Util class for the current driver * - * @return \Query\Drivers\AbstractUtil + * @return AbstractUtil */ public function get_util(); @@ -230,6 +231,6 @@ interface DriverInterface extends PDOInterface { * @param string $query_string * @return void */ - public function set_last_query($query_string); + public function set_last_query(string $query_string); } // End of driver_interface.php \ No newline at end of file diff --git a/src/Query/Drivers/Firebird/Driver.php b/src/Query/Drivers/Firebird/Driver.php index 4512fcc..1925cf7 100644 --- a/src/Query/Drivers/Firebird/Driver.php +++ b/src/Query/Drivers/Firebird/Driver.php @@ -1,23 +1,24 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ + namespace Query\Drivers\Firebird; -use Query\Drivers\AbstractDriver; use PDO; use PDOException; +use Query\Drivers\{AbstractDriver, DriverInterface}; /** * Firebird Database class @@ -27,14 +28,7 @@ use PDOException; * @package Query * @subpackage Drivers */ -class Driver extends AbstractDriver { - - /** - * Reference to the last query executed - * - * @var object - */ - protected $statement = NULL; +class Driver extends AbstractDriver implements DriverInterface { /** * Reference to the resource returned by diff --git a/src/Query/Drivers/Firebird/Result.php b/src/Query/Drivers/Firebird/Result.php index 78b4ade..2c86468 100644 --- a/src/Query/Drivers/Firebird/Result.php +++ b/src/Query/Drivers/Firebird/Result.php @@ -1,18 +1,20 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ + + namespace Query\Drivers\Firebird; use PDOStatement; diff --git a/src/Query/Drivers/Firebird/SQL.php b/src/Query/Drivers/Firebird/SQL.php index 0868971..56c1db1 100644 --- a/src/Query/Drivers/Firebird/SQL.php +++ b/src/Query/Drivers/Firebird/SQL.php @@ -1,18 +1,20 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ + + namespace Query\Drivers\Firebird; use Query\Drivers\AbstractSQL; diff --git a/src/Query/Drivers/Firebird/Util.php b/src/Query/Drivers/Firebird/Util.php index f8bb6d3..7efcdef 100644 --- a/src/Query/Drivers/Firebird/Util.php +++ b/src/Query/Drivers/Firebird/Util.php @@ -1,18 +1,19 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ + namespace Query\Drivers\Firebird; use Query\Drivers\AbstractUtil; diff --git a/src/Query/Drivers/Mysql/Driver.php b/src/Query/Drivers/Mysql/Driver.php index 0dbd5d1..5a3e6ac 100644 --- a/src/Query/Drivers/Mysql/Driver.php +++ b/src/Query/Drivers/Mysql/Driver.php @@ -1,21 +1,23 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ + + namespace Query\Drivers\Mysql; -use Query\Drivers\AbstractDriver; +use Query\Drivers\{AbstractDriver, DriverInterface}; /** * MySQL specific class @@ -23,7 +25,7 @@ use Query\Drivers\AbstractDriver; * @package Query * @subpackage Drivers */ -class Driver extends AbstractDriver { +class Driver extends AbstractDriver implements DriverInterface { /** * Set the backtick as the MySQL escape character diff --git a/src/Query/Drivers/Mysql/SQL.php b/src/Query/Drivers/Mysql/SQL.php index 2ee0662..949f5c3 100644 --- a/src/Query/Drivers/Mysql/SQL.php +++ b/src/Query/Drivers/Mysql/SQL.php @@ -1,18 +1,20 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ + + namespace Query\Drivers\Mysql; use Query\Drivers\AbstractSQL; diff --git a/src/Query/Drivers/Mysql/Util.php b/src/Query/Drivers/Mysql/Util.php index 3d2fb86..d821173 100644 --- a/src/Query/Drivers/Mysql/Util.php +++ b/src/Query/Drivers/Mysql/Util.php @@ -1,18 +1,20 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ + + namespace Query\Drivers\Mysql; use Query\Drivers\AbstractUtil; diff --git a/src/Query/Drivers/PDOInterface.php b/src/Query/Drivers/PDOInterface.php index 2cf0a2e..1909f39 100644 --- a/src/Query/Drivers/PDOInterface.php +++ b/src/Query/Drivers/PDOInterface.php @@ -1,18 +1,19 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ + namespace Query\Drivers; use PDO; diff --git a/src/Query/Drivers/PDOStatementInterface.php b/src/Query/Drivers/PDOStatementInterface.php index 27559bb..465867d 100644 --- a/src/Query/Drivers/PDOStatementInterface.php +++ b/src/Query/Drivers/PDOStatementInterface.php @@ -1,18 +1,20 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ + + namespace Query\Drivers; use PDO; @@ -111,12 +113,12 @@ interface PDOStatementInterface { /** * Fetches the next row from a result set * - * @param int $fetch_style - * @param int $cursor_orientation - * @param int $cursor_offset + * @param int $how + * @param int $orientation + * @param int $offset * @return mixed */ - public function fetch($fetch_style = PDO::ATTR_DEFAULT_FETCH_MODE, $cursor_orientation = PDO::FETCH_ORI_NEXT, $cursor_offset = 0); + public function fetch($how = PDO::ATTR_DEFAULT_FETCH_MODE, $orientation = PDO::FETCH_ORI_NEXT, $offset = 0); /** * Returns a single column from the next row of a result set diff --git a/src/Query/Drivers/Pgsql/Driver.php b/src/Query/Drivers/Pgsql/Driver.php index 752d2bb..e9bfee7 100644 --- a/src/Query/Drivers/Pgsql/Driver.php +++ b/src/Query/Drivers/Pgsql/Driver.php @@ -1,21 +1,22 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ + namespace Query\Drivers\Pgsql; -use Query\Drivers\AbstractDriver; +use Query\Drivers\{AbstractDriver, DriverInterface}; /** * PostgreSQL specific class @@ -23,7 +24,7 @@ use Query\Drivers\AbstractDriver; * @package Query * @subpackage Drivers */ -class Driver extends AbstractDriver { +class Driver extends AbstractDriver implements DriverInterface { /** * Connect to a PosgreSQL database diff --git a/src/Query/Drivers/Pgsql/SQL.php b/src/Query/Drivers/Pgsql/SQL.php index b0c3727..a536164 100644 --- a/src/Query/Drivers/Pgsql/SQL.php +++ b/src/Query/Drivers/Pgsql/SQL.php @@ -1,18 +1,20 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ + + namespace Query\Drivers\Pgsql; use Query\Drivers\AbstractSQL; diff --git a/src/Query/Drivers/Pgsql/Util.php b/src/Query/Drivers/Pgsql/Util.php index b6ef859..a1a463f 100644 --- a/src/Query/Drivers/Pgsql/Util.php +++ b/src/Query/Drivers/Pgsql/Util.php @@ -1,18 +1,20 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ + + namespace Query\Drivers\Pgsql; use Query\Drivers\AbstractUtil; diff --git a/src/Query/Drivers/SQLInterface.php b/src/Query/Drivers/SQLInterface.php index 7218eb9..a48170c 100644 --- a/src/Query/Drivers/SQLInterface.php +++ b/src/Query/Drivers/SQLInterface.php @@ -1,19 +1,21 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ + + // -------------------------------------------------------------------------- namespace Query\Drivers; diff --git a/src/Query/Drivers/Sqlite/Driver.php b/src/Query/Drivers/Sqlite/Driver.php index f9c78ae..a57444c 100644 --- a/src/Query/Drivers/Sqlite/Driver.php +++ b/src/Query/Drivers/Sqlite/Driver.php @@ -1,21 +1,24 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ + namespace Query\Drivers\Sqlite; -use Query\Drivers\AbstractDriver; +use PDO; +use PDOStatement; +use Query\Drivers\{AbstractDriver, DriverInterface}; /** * SQLite specific class @@ -23,12 +26,12 @@ use Query\Drivers\AbstractDriver; * @package Query * @subpackage Drivers */ -class Driver extends AbstractDriver { +class Driver extends AbstractDriver implements DriverInterface { /** * Reference to the last executed sql query * - * @var \PDOStatement + * @var PDOStatement */ protected $statement; @@ -57,9 +60,6 @@ class Driver extends AbstractDriver { parent::__construct($dsn, $user, $pass); } - - // -------------------------------------------------------------------------- - /** * List tables for the current database * @@ -69,11 +69,9 @@ class Driver extends AbstractDriver { { $sql = $this->sql->table_list(); $res = $this->query($sql); - return db_filter($res->fetchAll(\PDO::FETCH_ASSOC), 'name'); + return db_filter($res->fetchAll(PDO::FETCH_ASSOC), 'name'); } - // -------------------------------------------------------------------------- - /** * Retrieve foreign keys for the table * @@ -98,8 +96,6 @@ class Driver extends AbstractDriver { return $return_rows; } - // -------------------------------------------------------------------------- - /** * Create sql for batch insert * @@ -112,7 +108,7 @@ class Driver extends AbstractDriver { { // If greater than version 3.7.11, supports the same syntax as // MySQL and Postgres - if (version_compare($this->getAttribute(\PDO::ATTR_SERVER_VERSION), '3.7.11', '>=')) + if (version_compare($this->getAttribute(PDO::ATTR_SERVER_VERSION), '3.7.11', '>=')) { return parent::insert_batch($table, $data); } diff --git a/src/Query/Drivers/Sqlite/SQL.php b/src/Query/Drivers/Sqlite/SQL.php index 1880576..34805b9 100644 --- a/src/Query/Drivers/Sqlite/SQL.php +++ b/src/Query/Drivers/Sqlite/SQL.php @@ -1,18 +1,20 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ + + namespace Query\Drivers\Sqlite; use Query\Drivers\AbstractSQL; diff --git a/src/Query/Drivers/Sqlite/Util.php b/src/Query/Drivers/Sqlite/Util.php index 7f877f8..c2629c5 100644 --- a/src/Query/Drivers/Sqlite/Util.php +++ b/src/Query/Drivers/Sqlite/Util.php @@ -1,18 +1,20 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ + + namespace Query\Drivers\Sqlite; use Query\Drivers\AbstractUtil; diff --git a/src/Query/QueryBuilder.php b/src/Query/QueryBuilder.php index 15b5724..2e3f4cb 100644 --- a/src/Query/QueryBuilder.php +++ b/src/Query/QueryBuilder.php @@ -1,22 +1,23 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ namespace Query; -use Query\Drivers\DriverInterface; use BadMethodCallException; +use PDOStatement; +use Query\Drivers\DriverInterface; /** * Convenience class for creating sql queries - also the class that @@ -81,8 +82,6 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface $this->util = $this->db->get_util(); } - // -------------------------------------------------------------------------- - /** * Destructor * @codeCoverageIgnore @@ -92,17 +91,15 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface $this->db = NULL; } - // -------------------------------------------------------------------------- - /** - * Calls a function further down the inheritence chain + * Calls a function further down the inheritance chain * * @param string $name * @param array $params * @return mixed * @throws BadMethodCallException */ - public function __call($name, $params) + public function __call(string $name, array $params) { // Allow camel-case method calls $snake_name = \from_camel_case($name); @@ -119,7 +116,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface } - throw new BadMethodCallException("Method does not exist"); + throw new BadMethodCallException('Method does not exist'); } // -------------------------------------------------------------------------- @@ -132,10 +129,10 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param string $fields * @return QueryBuilderInterface */ - public function select($fields) + public function select(string $fields): QueryBuilderInterface { // Split fields by comma - $fields_array = explode(",", $fields); + $fields_array = explode(',', $fields); $fields_array = array_map('mb_trim', $fields_array); // Split on 'As' @@ -169,8 +166,6 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface return $this; } - // -------------------------------------------------------------------------- - /** * Selects the maximum value of a field from a query * @@ -178,15 +173,13 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param string|bool $as * @return QueryBuilderInterface */ - public function select_max($field, $as=FALSE) + public function select_max($field, $as=FALSE): QueryBuilderInterface { // Create the select string $this->select_string .= ' MAX'.$this->_select($field, $as); return $this; } - // -------------------------------------------------------------------------- - /** * Selects the minimum value of a field from a query * @@ -194,15 +187,13 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param string|bool $as * @return QueryBuilderInterface */ - public function select_min($field, $as=FALSE) + public function select_min($field, $as=FALSE): QueryBuilderInterface { // Create the select string $this->select_string .= ' MIN'.$this->_select($field, $as); return $this; } - // -------------------------------------------------------------------------- - /** * Selects the average value of a field from a query * @@ -210,15 +201,13 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param string|bool $as * @return QueryBuilderInterface */ - public function select_avg($field, $as=FALSE) + public function select_avg($field, $as=FALSE): QueryBuilderInterface { // Create the select string $this->select_string .= ' AVG'.$this->_select($field, $as); return $this; } - // -------------------------------------------------------------------------- - /** * Selects the sum of a field from a query * @@ -226,49 +215,43 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param string|bool $as * @return QueryBuilderInterface */ - public function select_sum($field, $as=FALSE) + public function select_sum($field, $as=FALSE): QueryBuilderInterface { // Create the select string $this->select_string .= ' SUM'.$this->_select($field, $as); return $this; } - // -------------------------------------------------------------------------- - /** * Adds the 'distinct' keyword to a query * * @return QueryBuilderInterface */ - public function distinct() + public function distinct(): QueryBuilderInterface { // Prepend the keyword to the select string $this->select_string = ' DISTINCT '.$this->select_string; return $this; } - // -------------------------------------------------------------------------- - /** * Tell the database to give you the query plan instead of result set * * @return QueryBuilderInterface */ - public function explain() + public function explain(): QueryBuilderInterface { $this->explain = TRUE; return $this; } - // -------------------------------------------------------------------------- - /** * Specify the database table to select from * * @param string $tblname * @return QueryBuilderInterface */ - public function from($tblname) + public function from($tblname): QueryBuilderInterface { // Split identifiers on spaces $ident_array = explode(' ', \mb_trim($tblname)); @@ -296,13 +279,11 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param string $pos * @return QueryBuilderInterface */ - public function like($field, $val, $pos='both') + public function like($field, $val, $pos='both'): QueryBuilderInterface { return $this->_like($field, $val, $pos, 'LIKE', 'AND'); } - // -------------------------------------------------------------------------- - /** * Generates an OR Like clause * @@ -311,13 +292,11 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param string $pos * @return QueryBuilderInterface */ - public function or_like($field, $val, $pos='both') + public function or_like($field, $val, $pos='both'): QueryBuilderInterface { return $this->_like($field, $val, $pos, 'LIKE', 'OR'); } - // -------------------------------------------------------------------------- - /** * Generates a NOT LIKE clause * @@ -326,13 +305,11 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param string $pos * @return QueryBuilderInterface */ - public function not_like($field, $val, $pos='both') + public function not_like($field, $val, $pos='both'): QueryBuilderInterface { return $this->_like($field, $val, $pos, 'NOT LIKE', 'AND'); } - // -------------------------------------------------------------------------- - /** * Generates a OR NOT LIKE clause * @@ -341,7 +318,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param string $pos * @return QueryBuilderInterface */ - public function or_not_like($field, $val, $pos='both') + public function or_not_like($field, $val, $pos='both'): QueryBuilderInterface { return $this->_like($field, $val, $pos, 'NOT LIKE', 'OR'); } @@ -357,13 +334,11 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param mixed $val * @return QueryBuilderInterface */ - public function having($key, $val=[]) + public function having($key, $val=[]): QueryBuilderInterface { return $this->_having($key, $val, 'AND'); } - // -------------------------------------------------------------------------- - /** * Generates a 'Having' clause prefixed with 'OR' * @@ -371,7 +346,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param mixed $val * @return QueryBuilderInterface */ - public function or_having($key, $val=[]) + public function or_having($key, $val=[]): QueryBuilderInterface { return $this->_having($key, $val, 'OR'); } @@ -390,13 +365,11 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param mixed $escape * @return QueryBuilderInterface */ - public function where($key, $val=[], $escape=NULL) + public function where($key, $val=[], $escape=NULL): QueryBuilderInterface { return $this->_where_string($key, $val, 'AND'); } - // -------------------------------------------------------------------------- - /** * Where clause prefixed with "OR" * @@ -404,13 +377,11 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param mixed $val * @return QueryBuilderInterface */ - public function or_where($key, $val=[]) + public function or_where($key, $val=[]): QueryBuilderInterface { return $this->_where_string($key, $val, 'OR'); } - // -------------------------------------------------------------------------- - /** * Where clause with 'IN' statement * @@ -418,13 +389,11 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param mixed $val * @return QueryBuilderInterface */ - public function where_in($field, $val=[]) + public function where_in($field, $val=[]): QueryBuilderInterface { return $this->_where_in($field, $val); } - // -------------------------------------------------------------------------- - /** * Where in statement prefixed with "or" * @@ -432,13 +401,11 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param mixed $val * @return QueryBuilderInterface */ - public function or_where_in($field, $val=[]) + public function or_where_in($field, $val=[]): QueryBuilderInterface { return $this->_where_in($field, $val, 'IN', 'OR'); } - // -------------------------------------------------------------------------- - /** * WHERE NOT IN (FOO) clause * @@ -446,13 +413,11 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param mixed $val * @return QueryBuilderInterface */ - public function where_not_in($field, $val=[]) + public function where_not_in($field, $val=[]): QueryBuilderInterface { return $this->_where_in($field, $val, 'NOT IN', 'AND'); } - // -------------------------------------------------------------------------- - /** * OR WHERE NOT IN (FOO) clause * @@ -460,7 +425,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param mixed $val * @return QueryBuilderInterface */ - public function or_where_not_in($field, $val=[]) + public function or_where_not_in($field, $val=[]): QueryBuilderInterface { return $this->_where_in($field, $val, 'NOT IN', 'OR'); } @@ -476,7 +441,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param mixed $val * @return QueryBuilderInterface */ - public function set($key, $val = NULL) + public function set($key, $val = NULL): QueryBuilderInterface { $this->_mixed_set($this->set_array_keys, $key, $val, self::KEY); $this->_mixed_set($this->values, $key, $val, self::VALUE); @@ -492,8 +457,6 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface return $this; } - // -------------------------------------------------------------------------- - /** * Creates a join phrase in a compiled query * @@ -502,7 +465,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param string $type * @return QueryBuilderInterface */ - public function join($table, $condition, $type='') + public function join($table, $condition, $type=''): QueryBuilderInterface { // Prefix and quote table name $table = explode(' ', mb_trim($table)); @@ -519,15 +482,13 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface return $this; } - // -------------------------------------------------------------------------- - /** * Group the results by the selected field(s) * * @param mixed $field * @return QueryBuilderInterface */ - public function group_by($field) + public function group_by($field): QueryBuilderInterface { if ( ! is_scalar($field)) { @@ -544,8 +505,6 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface return $this; } - // -------------------------------------------------------------------------- - /** * Order the results by the selected field(s) * @@ -553,14 +512,14 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param string $type * @return QueryBuilderInterface */ - public function order_by($field, $type="") + public function order_by($field, $type=""): QueryBuilderInterface { // When ordering by random, do an ascending order if the driver // doesn't support random ordering if (stripos($type, 'rand') !== FALSE) { $rand = $this->sql->random(); - $type = ($rand !== FALSE) ? $rand : 'ASC'; + $type = $rand ?? 'ASC'; } // Set fields for later manipulation @@ -583,8 +542,6 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface return $this; } - // -------------------------------------------------------------------------- - /** * Set a limit on the current sql statement * @@ -592,7 +549,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param int|bool $offset * @return QueryBuilderInterface */ - public function limit($limit, $offset=FALSE) + public function limit($limit, $offset=FALSE): QueryBuilderInterface { $this->limit = (int) $limit; $this->offset = $offset; @@ -609,7 +566,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * * @return QueryBuilderInterface */ - public function group_start() + public function group_start(): QueryBuilderInterface { $conj = (empty($this->query_map)) ? ' WHERE ' : ' '; @@ -618,15 +575,13 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface return $this; } - // -------------------------------------------------------------------------- - /** * Adds a paren to the current query for query grouping, * prefixed with 'NOT' * * @return QueryBuilderInterface */ - public function not_group_start() + public function not_group_start(): QueryBuilderInterface { $conj = (empty($this->query_map)) ? ' WHERE ' : ' AND '; @@ -635,44 +590,38 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface return $this; } - // -------------------------------------------------------------------------- - /** * Adds a paren to the current query for query grouping, * prefixed with 'OR' * * @return QueryBuilderInterface */ - public function or_group_start() + public function or_group_start(): QueryBuilderInterface { $this->_append_map('', ' OR (', 'group_start'); return $this; } - // -------------------------------------------------------------------------- - /** * Adds a paren to the current query for query grouping, * prefixed with 'OR NOT' * * @return QueryBuilderInterface */ - public function or_not_group_start() + public function or_not_group_start(): QueryBuilderInterface { $this->_append_map('', ' OR NOT (', 'group_start'); return $this; } - // -------------------------------------------------------------------------- - /** * Ends a query group * * @return QueryBuilderInterface */ - public function group_end() + public function group_end(): QueryBuilderInterface { $this->_append_map('', ')', 'group_end'); @@ -690,9 +639,9 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param string $table * @param int|bool $limit * @param int|bool $offset - * @return \PDOStatement + * @return PDOStatement */ - public function get($table='', $limit=FALSE, $offset=FALSE) + public function get($table='', $limit=FALSE, $offset=FALSE): PDOStatement { // Set the table if ( ! empty($table)) @@ -709,8 +658,6 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface return $this->_run("get", $table); } - // -------------------------------------------------------------------------- - /** * Convenience method for get() with a where clause * @@ -718,9 +665,9 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param array $where * @param int|bool $limit * @param int|bool $offset - * @return \PDOStatement + * @return PDOStatement */ - public function get_where($table, $where=[], $limit=FALSE, $offset=FALSE) + public function get_where($table, $where=[], $limit=FALSE, $offset=FALSE): PDOStatement { // Create the where clause $this->where($where); @@ -729,23 +676,19 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface return $this->get($table, $limit, $offset); } - // -------------------------------------------------------------------------- - /** * Retrieve the number of rows in the selected table * * @param string $table * @return int */ - public function count_all($table) + public function count_all($table): int { $sql = 'SELECT * FROM '.$this->db->quote_table($table); $res = $this->db->query($sql); return (int) count($res->fetchAll()); } - // -------------------------------------------------------------------------- - /** * Retrieve the number of results for the generated query - used * in place of the get() method @@ -754,7 +697,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param boolean $reset * @return int */ - public function count_all_results($table='', $reset = TRUE) + public function count_all_results(string $table='', bool $reset = TRUE): int { // Set the table if ( ! empty($table)) @@ -768,16 +711,14 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface return (int) count($rows); } - // -------------------------------------------------------------------------- - /** * Creates an insert clause, and executes it * * @param string $table * @param mixed $data - * @return \PDOStatement + * @return PDOStatement */ - public function insert($table, $data=[]) + public function insert($table, $data=[]): PDOStatement { if ( ! empty($data)) { @@ -787,16 +728,14 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface return $this->_run("insert", $table); } - // -------------------------------------------------------------------------- - /** * Creates and executes a batch insertion query * * @param string $table * @param array $data - * @return \PDOStatement + * @return PDOStatement */ - public function insert_batch($table, $data=[]) + public function insert_batch($table, $data=[]): PDOStatement { // Get the generated values and sql string list($sql, $data) = $this->db->insert_batch($table, $data); @@ -806,16 +745,14 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface : NULL; } - // -------------------------------------------------------------------------- - /** * Creates an update clause, and executes it * * @param string $table * @param mixed $data - * @return \PDOStatement + * @return PDOStatement */ - public function update($table, $data=[]) + public function update($table, $data=[]): PDOStatement { if ( ! empty($data)) { @@ -825,8 +762,6 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface return $this->_run("update", $table); } - // -------------------------------------------------------------------------- - /** * Creates a batch update, and executes it. * Returns the number of affected rows @@ -846,8 +781,6 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface : NULL; } - // -------------------------------------------------------------------------- - /** * Insertion with automatic overwrite, rather than attempted duplication * @@ -865,16 +798,14 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface return $this->_run("replace", $table); } - // -------------------------------------------------------------------------- - /** * Deletes data from a table * * @param string $table * @param mixed $where - * @return \PDOStatement + * @return PDOStatement */ - public function delete($table, $where='') + public function delete($table, $where=''): PDOStatement { // Set the where clause if ( ! empty($where)) @@ -889,8 +820,6 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface // ! SQL Returning Methods // -------------------------------------------------------------------------- - - /** * Returns the generated 'select' sql query * @@ -898,7 +827,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param bool $reset * @return string */ - public function get_compiled_select($table='', $reset=TRUE) + public function get_compiled_select(string $table='', bool $reset=TRUE): string { // Set the table if ( ! empty($table)) @@ -909,8 +838,6 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface return $this->_get_compile('select', $table, $reset); } - // -------------------------------------------------------------------------- - /** * Returns the generated 'insert' sql query * @@ -918,13 +845,11 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param bool $reset * @return string */ - public function get_compiled_insert($table, $reset=TRUE) + public function get_compiled_insert(string $table, bool $reset=TRUE): string { return $this->_get_compile('insert', $table, $reset); } - // -------------------------------------------------------------------------- - /** * Returns the generated 'update' sql query * @@ -932,13 +857,11 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param bool $reset * @return string */ - public function get_compiled_update($table='', $reset=TRUE) + public function get_compiled_update(string $table='', bool $reset=TRUE): string { return $this->_get_compile('update', $table, $reset); } - // -------------------------------------------------------------------------- - /** * Returns the generated 'delete' sql query * @@ -946,12 +869,11 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface * @param bool $reset * @return string */ - public function get_compiled_delete($table="", $reset=TRUE) + public function get_compiled_delete(string $table='', bool $reset=TRUE): string { return $this->_get_compile('delete', $table, $reset); } - // -------------------------------------------------------------------------- // ! Miscellaneous Methods // -------------------------------------------------------------------------- diff --git a/src/Query/QueryBuilderInterface.php b/src/Query/QueryBuilderInterface.php index 2f71c19..134e67e 100644 --- a/src/Query/QueryBuilderInterface.php +++ b/src/Query/QueryBuilderInterface.php @@ -1,23 +1,22 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ - -// -------------------------------------------------------------------------- - namespace Query; +use PDOStatement; + /** * Interface defining the Query Builder class * @@ -36,7 +35,7 @@ interface QueryBuilderInterface { * @param string $fields * @return QueryBuilderInterface */ - public function select($fields); + public function select(string $fields): QueryBuilderInterface; // -------------------------------------------------------------------------- @@ -47,7 +46,7 @@ interface QueryBuilderInterface { * @param string|bool $as * @return QueryBuilderInterface */ - public function select_max($field, $as=FALSE); + public function select_max($field, $as=FALSE): QueryBuilderInterface; // -------------------------------------------------------------------------- @@ -58,7 +57,7 @@ interface QueryBuilderInterface { * @param string|bool $as * @return QueryBuilderInterface */ - public function select_min($field, $as=FALSE); + public function select_min($field, $as=FALSE): QueryBuilderInterface; // -------------------------------------------------------------------------- @@ -69,7 +68,7 @@ interface QueryBuilderInterface { * @param string|bool $as * @return QueryBuilderInterface */ - public function select_avg($field, $as=FALSE); + public function select_avg($field, $as=FALSE): QueryBuilderInterface; // -------------------------------------------------------------------------- @@ -80,7 +79,7 @@ interface QueryBuilderInterface { * @param string|bool $as * @return QueryBuilderInterface */ - public function select_sum($field, $as=FALSE); + public function select_sum($field, $as=FALSE): QueryBuilderInterface; // -------------------------------------------------------------------------- @@ -89,7 +88,7 @@ interface QueryBuilderInterface { * * @return QueryBuilderInterface */ - public function distinct(); + public function distinct(): QueryBuilderInterface; // -------------------------------------------------------------------------- @@ -98,7 +97,7 @@ interface QueryBuilderInterface { * * @return QueryBuilderInterface */ - public function explain(); + public function explain(): QueryBuilderInterface; // -------------------------------------------------------------------------- @@ -108,7 +107,7 @@ interface QueryBuilderInterface { * @param string $tblname * @return QueryBuilderInterface */ - public function from($tblname); + public function from($tblname): QueryBuilderInterface; // -------------------------------------------------------------------------- // ! 'Like' methods @@ -122,7 +121,7 @@ interface QueryBuilderInterface { * @param string $pos * @return QueryBuilderInterface */ - public function like($field, $val, $pos='both'); + public function like($field, $val, $pos='both'): QueryBuilderInterface; // -------------------------------------------------------------------------- @@ -134,7 +133,7 @@ interface QueryBuilderInterface { * @param string $pos * @return QueryBuilderInterface */ - public function or_like($field, $val, $pos='both'); + public function or_like($field, $val, $pos='both'): QueryBuilderInterface; // -------------------------------------------------------------------------- @@ -146,7 +145,7 @@ interface QueryBuilderInterface { * @param string $pos * @return QueryBuilderInterface */ - public function not_like($field, $val, $pos='both'); + public function not_like($field, $val, $pos='both'): QueryBuilderInterface; // -------------------------------------------------------------------------- @@ -158,7 +157,7 @@ interface QueryBuilderInterface { * @param string $pos * @return QueryBuilderInterface */ - public function or_not_like($field, $val, $pos='both'); + public function or_not_like($field, $val, $pos='both'): QueryBuilderInterface; // -------------------------------------------------------------------------- // ! Having methods @@ -171,7 +170,7 @@ interface QueryBuilderInterface { * @param mixed $val * @return QueryBuilderInterface */ - public function having($key, $val=[]); + public function having($key, $val=[]): QueryBuilderInterface; // -------------------------------------------------------------------------- @@ -182,7 +181,7 @@ interface QueryBuilderInterface { * @param mixed $val * @return QueryBuilderInterface */ - public function or_having($key, $val=[]); + public function or_having($key, $val=[]): QueryBuilderInterface; // -------------------------------------------------------------------------- // ! 'Where' methods @@ -198,7 +197,7 @@ interface QueryBuilderInterface { * @param bool $escape * @return QueryBuilderInterface */ - public function where($key, $val=[], $escape = NULL); + public function where($key, $val=[], $escape = NULL): QueryBuilderInterface; // -------------------------------------------------------------------------- @@ -209,7 +208,7 @@ interface QueryBuilderInterface { * @param mixed $val * @return QueryBuilderInterface */ - public function or_where($key, $val=[]); + public function or_where($key, $val=[]): QueryBuilderInterface; // -------------------------------------------------------------------------- @@ -220,7 +219,7 @@ interface QueryBuilderInterface { * @param mixed $val * @return QueryBuilderInterface */ - public function where_in($field, $val=[]); + public function where_in($field, $val=[]): QueryBuilderInterface; // -------------------------------------------------------------------------- @@ -231,7 +230,7 @@ interface QueryBuilderInterface { * @param mixed $val * @return QueryBuilderInterface */ - public function or_where_in($field, $val=[]); + public function or_where_in($field, $val=[]): QueryBuilderInterface; // -------------------------------------------------------------------------- @@ -242,7 +241,7 @@ interface QueryBuilderInterface { * @param mixed $val * @return QueryBuilderInterface */ - public function where_not_in($field, $val=[]); + public function where_not_in($field, $val=[]): QueryBuilderInterface; // -------------------------------------------------------------------------- @@ -253,7 +252,7 @@ interface QueryBuilderInterface { * @param mixed $val * @return QueryBuilderInterface */ - public function or_where_not_in($field, $val=[]); + public function or_where_not_in($field, $val=[]): QueryBuilderInterface; // -------------------------------------------------------------------------- // ! Other Query Modifier methods @@ -266,7 +265,7 @@ interface QueryBuilderInterface { * @param mixed $val * @return QueryBuilderInterface */ - public function set($key, $val = NULL); + public function set($key, $val = NULL): QueryBuilderInterface; // -------------------------------------------------------------------------- @@ -278,7 +277,7 @@ interface QueryBuilderInterface { * @param string $type * @return QueryBuilderInterface */ - public function join($table, $condition, $type=''); + public function join($table, $condition, $type=''): QueryBuilderInterface; // -------------------------------------------------------------------------- @@ -288,7 +287,7 @@ interface QueryBuilderInterface { * @param mixed $field * @return QueryBuilderInterface */ - public function group_by($field); + public function group_by($field): QueryBuilderInterface; // -------------------------------------------------------------------------- @@ -299,7 +298,7 @@ interface QueryBuilderInterface { * @param string $type * @return QueryBuilderInterface */ - public function order_by($field, $type=""); + public function order_by($field, $type=""): QueryBuilderInterface; // -------------------------------------------------------------------------- @@ -310,7 +309,7 @@ interface QueryBuilderInterface { * @param int|bool $offset * @return QueryBuilderInterface */ - public function limit($limit, $offset=FALSE); + public function limit($limit, $offset=FALSE): QueryBuilderInterface; // -------------------------------------------------------------------------- // ! Query Grouping Methods @@ -321,17 +320,17 @@ interface QueryBuilderInterface { * * @return QueryBuilderInterface */ - public function group_start(); + public function group_start(): QueryBuilderInterface; // -------------------------------------------------------------------------- /** * Adds a paren to the current query for query grouping, * prefixed with 'NOT' - * + * * @return QueryBuilderInterface */ - public function not_group_start(); + public function not_group_start(): QueryBuilderInterface; // -------------------------------------------------------------------------- @@ -341,7 +340,7 @@ interface QueryBuilderInterface { * * @return QueryBuilderInterface */ - public function or_group_start(); + public function or_group_start(): QueryBuilderInterface; // -------------------------------------------------------------------------- @@ -351,7 +350,7 @@ interface QueryBuilderInterface { * * @return QueryBuilderInterface */ - public function or_not_group_start(); + public function or_not_group_start(): QueryBuilderInterface; // -------------------------------------------------------------------------- @@ -360,7 +359,7 @@ interface QueryBuilderInterface { * * @return QueryBuilderInterface */ - public function group_end(); + public function group_end(): QueryBuilderInterface; // -------------------------------------------------------------------------- // ! Query execution methods @@ -373,22 +372,22 @@ interface QueryBuilderInterface { * @param string $table * @param int|bool $limit * @param int|bool $offset - * @return \PDOStatement + * @return PDOStatement */ - public function get($table='', $limit=FALSE, $offset=FALSE); + public function get($table='', $limit=FALSE, $offset=FALSE): PDOStatement; // -------------------------------------------------------------------------- /** - * Convience method for get() with a where clause + * Convenience method for get() with a where clause * * @param string $table * @param array $where * @param int|bool $limit * @param int|bool $offset - * @return \PDOStatement + * @return PDOStatement */ - public function get_where($table, $where=[], $limit=FALSE, $offset=FALSE); + public function get_where($table, $where=[], $limit=FALSE, $offset=FALSE): PDOStatement; // -------------------------------------------------------------------------- @@ -398,7 +397,7 @@ interface QueryBuilderInterface { * @param string $table * @return int */ - public function count_all($table); + public function count_all($table): int; // -------------------------------------------------------------------------- @@ -410,7 +409,7 @@ interface QueryBuilderInterface { * @param bool $reset - Whether to keep the query after counting the results * @return int */ - public function count_all_results($table='', $reset=TRUE); + public function count_all_results(string $table='', bool $reset=TRUE): int; // -------------------------------------------------------------------------- @@ -419,9 +418,9 @@ interface QueryBuilderInterface { * * @param string $table * @param mixed $data - * @return \PDOStatement + * @return PDOStatement */ - public function insert($table, $data=[]); + public function insert($table, $data=[]): PDOStatement; // -------------------------------------------------------------------------- @@ -452,9 +451,9 @@ interface QueryBuilderInterface { * * @param string $table * @param mixed $data - * @return \PDOStatement + * @return PDOStatement */ - public function update($table, $data=[]); + public function update($table, $data=[]): PDOStatement; // -------------------------------------------------------------------------- @@ -476,9 +475,9 @@ interface QueryBuilderInterface { * * @param string $table * @param mixed $where - * @return \PDOStatement + * @return PDOStatement */ - public function delete($table, $where=''); + public function delete($table, $where=''): PDOStatement; // -------------------------------------------------------------------------- // ! SQL Returning Methods @@ -491,9 +490,7 @@ interface QueryBuilderInterface { * @param bool $reset * @return string */ - public function get_compiled_select($table='', $reset=TRUE); - - // -------------------------------------------------------------------------- + public function get_compiled_select(string $table='', bool $reset=TRUE): string; /** * Returns the generated 'insert' sql query @@ -502,9 +499,7 @@ interface QueryBuilderInterface { * @param bool $reset * @return string */ - public function get_compiled_insert($table, $reset=TRUE); - - // -------------------------------------------------------------------------- + public function get_compiled_insert(string $table, bool $reset=TRUE): string; /** * Returns the generated 'update' sql query @@ -513,9 +508,7 @@ interface QueryBuilderInterface { * @param bool $reset * @return string */ - public function get_compiled_update($table='', $reset=TRUE); - - // -------------------------------------------------------------------------- + public function get_compiled_update(string $table='', bool $reset=TRUE): string; /** * Returns the generated 'delete' sql query @@ -524,7 +517,7 @@ interface QueryBuilderInterface { * @param bool $reset * @return string */ - public function get_compiled_delete($table="", $reset=TRUE); + public function get_compiled_delete(string $table='', bool $reset=TRUE): string; // -------------------------------------------------------------------------- // ! Miscellaneous Methods diff --git a/src/Query/QueryParser.php b/src/Query/QueryParser.php index 31ad27b..85587d0 100644 --- a/src/Query/QueryParser.php +++ b/src/Query/QueryParser.php @@ -1,18 +1,20 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ + + namespace Query; use Query\Drivers\DriverInterface; diff --git a/src/common.php b/src/common.php index 21fb772..cb725f9 100644 --- a/src/common.php +++ b/src/common.php @@ -1,18 +1,19 @@ - - * @copyright 2012 - 2015 Timothy J. Warren + * @copyright 2012 - 2016 Timothy J. Warren * @license http://www.opensource.org/licenses/mit-license.html MIT License * @link https://git.timshomepage.net/aviat4ion/Query */ + use Query\ConnectionManager; require __DIR__ . '/../vendor/autoload.php'; @@ -23,25 +24,6 @@ require __DIR__ . '/../vendor/autoload.php'; * Global functions that don't really fit anywhere else */ -// -------------------------------------------------------------------------- - -if ( ! function_exists('do_include')) -{ - /** - * Bulk directory loading workaround for use - * with array_map and glob - * - * @param string $path - * @return void - */ - function do_include($path) - { - require_once($path); - } -} - -// -------------------------------------------------------------------------- - if ( ! function_exists('mb_trim')) { /** @@ -50,7 +32,7 @@ if ( ! function_exists('mb_trim')) * @param string $string * @return string */ - function mb_trim($string) + function mb_trim(string $string): string { return preg_replace("/(^\s+)|(\s+$)/us", "", $string); } @@ -67,7 +49,7 @@ if ( ! function_exists('db_filter')) * @param mixed $index * @return array */ - function db_filter($array, $index) + function db_filter(array $array, $index): array { $new_array = []; @@ -92,8 +74,8 @@ if ( ! function_exists('from_camel_case')) * @param string $input * @return string */ - function from_camel_case($input) - { + function from_camel_case(string $input): string + { preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches); $ret = $matches[0]; foreach ($ret as &$match) { @@ -103,6 +85,28 @@ if ( ! function_exists('from_camel_case')) } } +if ( ! function_exists('to_camel_case')) +{ + /** + * Create a camelCase string from snake_case + * + * @param string $snake_case + * @return string + */ + function to_camel_case(string $snake_case): string + { + $pieces = explode('_', $snake_case); + + $pieces[0] = mb_strtolower($pieces[0]); + for($i = 1; $i < count($pieces); $i++) + { + $pieces[$i] = ucfirst(mb_strtolower($pieces[$i])); + } + + return implode('', $pieces); + } +} + // -------------------------------------------------------------------------- if ( ! function_exists('array_zipper')) @@ -116,7 +120,7 @@ if ( ! function_exists('array_zipper')) * @param array $zipper_input * @return array */ - function array_zipper(Array $zipper_input) + function array_zipper(array $zipper_input): array { $output = []; @@ -138,40 +142,6 @@ if ( ! function_exists('array_zipper')) // -------------------------------------------------------------------------- -if ( ! function_exists('array_column')) -{ - /** - * Get an array out of an multi-dimensional array based on a common - * key - * - * @param array $array - * @param string $key - * @return array - */ - function array_column(Array $array, $key) - { - $output = []; - - // No point iterating over an empty array - if (empty($array)) - { - return $array; - } - - foreach($array as $inner_array) - { - if (array_key_exists($key, $inner_array)) - { - $output[] = $inner_array[$key]; - } - } - - return $output; - } -} - -// -------------------------------------------------------------------------- - if ( ! function_exists('regex_in_array')) { /** @@ -182,7 +152,7 @@ if ( ! function_exists('regex_in_array')) * @param string $pattern * @return bool */ - function regex_in_array(Array $array, $pattern) + function regex_in_array(array $array, string $pattern): bool { if (empty($array)) { diff --git a/tests/core/base_db_test.php b/tests/core/base_db_test.php index 5b17024..74505d1 100644 --- a/tests/core/base_db_test.php +++ b/tests/core/base_db_test.php @@ -1,16 +1,19 @@ - + * @copyright 2012 - 2016 Timothy J. Warren + * @license http://www.opensource.org/licenses/mit-license.html MIT License + * @link https://git.timshomepage.net/aviat4ion/Query */ + // -------------------------------------------------------------------------- /** diff --git a/tests/core/base_query_builder_test.php b/tests/core/base_query_builder_test.php index 255bb87..18d9431 100644 --- a/tests/core/base_query_builder_test.php +++ b/tests/core/base_query_builder_test.php @@ -1,14 +1,16 @@ - + * @copyright 2012 - 2016 Timothy J. Warren + * @license http://www.opensource.org/licenses/mit-license.html MIT License + * @link https://git.timshomepage.net/aviat4ion/Query */ // -------------------------------------------------------------------------- @@ -28,23 +30,13 @@ abstract class QBTest extends Query_TestCase { } } - // -------------------------------------------------------------------------- - public static function tearDownAfterClass() { self::$db = NULL; } - - // -------------------------------------------------------------------------- // ! Driver-specific results - // -------------------------------------------------------------------------- - abstract public function testQueryExplain(); - - // -------------------------------------------------------------------------- // ! Get tests - // -------------------------------------------------------------------------- - public function testInvalidConnectionName() { try @@ -57,8 +49,6 @@ abstract class QBTest extends Query_TestCase { } } - // -------------------------------------------------------------------------- - public function testFunctionGet() { $query = self::$db->select('id, COUNT(id) as count') @@ -69,8 +59,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testGet() { $query = self::$db->get('test'); @@ -78,8 +66,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testPrefixGet() { $query = self::$db->from('test')->get(); @@ -87,8 +73,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testGetWNumRows() { $query = self::$db->get('test'); @@ -97,8 +81,6 @@ abstract class QBTest extends Query_TestCase { $this->assertEqual(self::$db->num_rows(), $numrows); } - // -------------------------------------------------------------------------- - public function testGetLimit() { $query = self::$db->get('test', 2); @@ -106,8 +88,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testGetLimitSkip() { $query = self::$db->get('test', 2, 1); @@ -115,8 +95,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testGetWhere() { $query = self::$db->get_where('test', array('id !=' => 1), 2, 1); @@ -124,8 +102,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testHaving() { $query = self::$db->select('id') @@ -138,8 +114,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testOrHaving() { $query = self::$db->select('id') @@ -151,11 +125,7 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - - // -------------------------------------------------------------------------- // ! Select tests - // -------------------------------------------------------------------------- - public function testSelectWhereGet() { $query = self::$db->select('id, key as k, val') @@ -166,8 +136,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testSelectAvg() { $query = self::$db->select_avg('id', 'di') @@ -176,8 +144,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testSelectSum() { $query = self::$db->select_sum('id', 'di') @@ -186,8 +152,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testSelectDistinct() { $query = self::$db->select_sum('id', 'di') @@ -197,8 +161,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testSelectGet() { $query = self::$db->select('id, key as k, val') @@ -207,8 +169,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testSelectFromGet() { $query = self::$db->select('id, key as k, val') @@ -219,8 +179,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testSelectFromLimitGet() { $query = self::$db->select('id, key as k, val') @@ -233,8 +191,6 @@ abstract class QBTest extends Query_TestCase { } - // -------------------------------------------------------------------------- - public function testSelectWhereGet2() { $query = self::$db->select('id, key as k, val') @@ -244,8 +200,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testSelectMax() { $query = self::$db->select_max('id', 'di') @@ -254,8 +208,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testSelectMin() { $query = self::$db->select_min('id', 'di') @@ -264,8 +216,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testMultiOrderBy() { $query = self::$db->from('test') @@ -274,11 +224,7 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - - // -------------------------------------------------------------------------- // ! Grouping tests - // -------------------------------------------------------------------------- - public function testGroup() { $query = self::$db->select('id, key as k, val') @@ -293,8 +239,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testOrGroup() { $query = self::$db->select('id, key as k, val') @@ -312,8 +256,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testOrNotGroup() { $query = self::$db->select('id, key as k, val') @@ -331,8 +273,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testAndNotGroupStart() { $query = self::$db->select('id, key as k, val') @@ -350,8 +290,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testNotGroupStart() { $query = self::$db->select('id, key as k, val') @@ -365,8 +303,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testGroupCamelCase() { $query = self::$db->select('id, key as k, val') @@ -383,11 +319,7 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - - // -------------------------------------------------------------------------- // ! Where In tests - // -------------------------------------------------------------------------- - public function testWhereIn() { $query = self::$db->from('test') @@ -397,8 +329,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testOrWhereIn() { $query = self::$db->from('test') @@ -409,8 +339,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testWhereNotIn() { $query = self::$db->from('test') @@ -421,8 +349,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testOrWhereNotIn() { $query = self::$db->from('test') @@ -432,11 +358,7 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - - // -------------------------------------------------------------------------- // ! Query modifier tests - // -------------------------------------------------------------------------- - public function testOrderBy() { $query = self::$db->select('id, key as k, val') @@ -451,8 +373,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testOrderByRandom() { $query = self::$db->select('id, key as k, val') @@ -466,8 +386,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testGroupBy() { $query = self::$db->select('id, key as k, val') @@ -484,12 +402,8 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - //public function testOr - // -------------------------------------------------------------------------- - public function testOrWhere() { $query = self::$db->select('id, key as k, val') @@ -502,8 +416,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testLike() { $query = self::$db->from('test') @@ -513,8 +425,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testOrLike() { $query = self::$db->from('test') @@ -525,8 +435,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testOrNotLike() { $query = self::$db->from('test') @@ -537,8 +445,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testNotLike() { $query = self::$db->from('test') @@ -549,8 +455,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testLikeBefore() { $query = self::$db->from('test') @@ -560,8 +464,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testLikeAfter() { $query = self::$db->from('test') @@ -571,8 +473,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testJoin() { $query = self::$db->from('test ct') @@ -582,8 +482,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testLeftJoin() { $query = self::$db->from('test ct') @@ -593,8 +491,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testInnerJoin() { $query = self::$db->from('test ct') @@ -604,8 +500,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testJoinWithMultipleWhereValues() { $query = self::$db->from('test ct') @@ -618,11 +512,7 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - - // -------------------------------------------------------------------------- // ! DB update tests - // -------------------------------------------------------------------------- - public function testInsert() { $query = self::$db->set('id', 98) @@ -633,8 +523,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testInsertArray() { $query = self::$db->insert('test', array( @@ -646,8 +534,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testInsertBatch() { $data = array( @@ -673,8 +559,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testUpdate() { $query = self::$db->where('id', 7) @@ -687,8 +571,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testSetArrayUpdate() { $array = array( @@ -704,8 +586,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testWhereSetUpdate() { $query = self::$db->where('id', 36) @@ -717,8 +597,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testDelete() { $query = self::$db->delete('test', array('id' => 5)); @@ -726,8 +604,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - public function testDeleteWithMultipleWhereValues() { $query = self::$db->delete('test', array( @@ -737,11 +613,7 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - - // -------------------------------------------------------------------------- // ! Non-data read queries - // -------------------------------------------------------------------------- - public function testCountAll() { $query = self::$db->count_all('test'); @@ -749,8 +621,6 @@ abstract class QBTest extends Query_TestCase { $this->assertTrue(is_numeric($query)); } - // -------------------------------------------------------------------------- - public function testCountAllResults() { $query = self::$db->count_all_results('test'); @@ -758,8 +628,6 @@ abstract class QBTest extends Query_TestCase { $this->assertTrue(is_numeric($query)); } - // -------------------------------------------------------------------------- - public function testCountAllResults2() { $query = self::$db->select('id, key as k, val') @@ -772,19 +640,13 @@ abstract class QBTest extends Query_TestCase { $this->assertTrue(is_numeric($query)); } - // -------------------------------------------------------------------------- - public function testNumRows() { $query = self::$db->get('test'); $this->assertTrue(is_numeric(self::$db->num_rows())); } - - // -------------------------------------------------------------------------- // ! Compiled Query tests - // -------------------------------------------------------------------------- - public function testGetCompiledSelect() { $sql = self::$db->get_compiled_select('test'); @@ -825,11 +687,7 @@ abstract class QBTest extends Query_TestCase { $this->assertTrue(is_string($sql)); } - - // -------------------------------------------------------------------------- // ! Error tests - // -------------------------------------------------------------------------- - /** * Handles invalid drivers */ @@ -854,8 +712,6 @@ abstract class QBTest extends Query_TestCase { } } - // -------------------------------------------------------------------------- - public function testBadMethod() { try @@ -868,8 +724,6 @@ abstract class QBTest extends Query_TestCase { } } - // -------------------------------------------------------------------------- - public function testBadNumRows() { self::$db->set(array( diff --git a/tests/core/connection_manager_test.php b/tests/core/connection_manager_test.php index a2311a8..a24bf80 100644 --- a/tests/core/connection_manager_test.php +++ b/tests/core/connection_manager_test.php @@ -1,4 +1,18 @@ - + * @copyright 2012 - 2016 Timothy J. Warren + * @license http://www.opensource.org/licenses/mit-license.html MIT License + * @link https://git.timshomepage.net/aviat4ion/Query + */ + class Connection_Manager_Test extends Query_TestCase { diff --git a/tests/core/core_test.php b/tests/core/core_test.php index b71576a..1d70a34 100644 --- a/tests/core/core_test.php +++ b/tests/core/core_test.php @@ -1,15 +1,19 @@ - + * @copyright 2012 - 2016 Timothy J. Warren + * @license http://www.opensource.org/licenses/mit-license.html MIT License + * @link https://git.timshomepage.net/aviat4ion/Query */ + // -------------------------------------------------------------------------- /** diff --git a/tests/core/query_parser_test.php b/tests/core/query_parser_test.php index d872789..c890bff 100644 --- a/tests/core/query_parser_test.php +++ b/tests/core/query_parser_test.php @@ -1,16 +1,19 @@ - + * @copyright 2012 - 2016 Timothy J. Warren + * @license http://www.opensource.org/licenses/mit-license.html MIT License + * @link https://git.timshomepage.net/aviat4ion/Query */ + // -------------------------------------------------------------------------- /** diff --git a/tests/databases/firebird/FirebirdQBTest.php b/tests/databases/firebird/FirebirdQBTest.php index 25cea6f..a464004 100644 --- a/tests/databases/firebird/FirebirdQBTest.php +++ b/tests/databases/firebird/FirebirdQBTest.php @@ -1,16 +1,19 @@ - + * @copyright 2012 - 2016 Timothy J. Warren + * @license http://www.opensource.org/licenses/mit-license.html MIT License + * @link https://git.timshomepage.net/aviat4ion/Query */ + // -------------------------------------------------------------------------- /** diff --git a/tests/databases/firebird/FirebirdTest.php b/tests/databases/firebird/FirebirdTest.php index f8bbdbf..a87dbaf 100644 --- a/tests/databases/firebird/FirebirdTest.php +++ b/tests/databases/firebird/FirebirdTest.php @@ -1,16 +1,19 @@ - + * @copyright 2012 - 2016 Timothy J. Warren + * @license http://www.opensource.org/licenses/mit-license.html MIT License + * @link https://git.timshomepage.net/aviat4ion/Query */ + // -------------------------------------------------------------------------- @chmod(QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB', 0777); diff --git a/tests/databases/mysql/MySQLQBTest.php b/tests/databases/mysql/MySQLQBTest.php index dbe564c..a7f2947 100644 --- a/tests/databases/mysql/MySQLQBTest.php +++ b/tests/databases/mysql/MySQLQBTest.php @@ -1,16 +1,19 @@ - + * @copyright 2012 - 2016 Timothy J. Warren + * @license http://www.opensource.org/licenses/mit-license.html MIT License + * @link https://git.timshomepage.net/aviat4ion/Query */ + // -------------------------------------------------------------------------- /** diff --git a/tests/databases/mysql/MySQLTest.php b/tests/databases/mysql/MySQLTest.php index 4e9cd93..10d163e 100644 --- a/tests/databases/mysql/MySQLTest.php +++ b/tests/databases/mysql/MySQLTest.php @@ -1,16 +1,19 @@ - + * @copyright 2012 - 2016 Timothy J. Warren + * @license http://www.opensource.org/licenses/mit-license.html MIT License + * @link https://git.timshomepage.net/aviat4ion/Query */ + // -------------------------------------------------------------------------- /** diff --git a/tests/databases/pgsql/PgSQLQBTest.php b/tests/databases/pgsql/PgSQLQBTest.php index b9b7d67..fc3a168 100644 --- a/tests/databases/pgsql/PgSQLQBTest.php +++ b/tests/databases/pgsql/PgSQLQBTest.php @@ -1,15 +1,19 @@ - + * @copyright 2012 - 2016 Timothy J. Warren + * @license http://www.opensource.org/licenses/mit-license.html MIT License + * @link https://git.timshomepage.net/aviat4ion/Query */ + // -------------------------------------------------------------------------- /** diff --git a/tests/databases/pgsql/PgSQLTest.php b/tests/databases/pgsql/PgSQLTest.php index 5f854c6..c6cc3e6 100644 --- a/tests/databases/pgsql/PgSQLTest.php +++ b/tests/databases/pgsql/PgSQLTest.php @@ -1,15 +1,19 @@ - + * @copyright 2012 - 2016 Timothy J. Warren + * @license http://www.opensource.org/licenses/mit-license.html MIT License + * @link https://git.timshomepage.net/aviat4ion/Query */ + // -------------------------------------------------------------------------- /** diff --git a/tests/databases/sqlite/SQLiteQBTest.php b/tests/databases/sqlite/SQLiteQBTest.php index 7f77483..9dbbd75 100644 --- a/tests/databases/sqlite/SQLiteQBTest.php +++ b/tests/databases/sqlite/SQLiteQBTest.php @@ -1,15 +1,19 @@ - + * @copyright 2012 - 2016 Timothy J. Warren + * @license http://www.opensource.org/licenses/mit-license.html MIT License + * @link https://git.timshomepage.net/aviat4ion/Query */ + // -------------------------------------------------------------------------- /** diff --git a/tests/databases/sqlite/SQLiteTest.php b/tests/databases/sqlite/SQLiteTest.php index be31871..5b13700 100644 --- a/tests/databases/sqlite/SQLiteTest.php +++ b/tests/databases/sqlite/SQLiteTest.php @@ -1,15 +1,19 @@ - + * @copyright 2012 - 2016 Timothy J. Warren + * @license http://www.opensource.org/licenses/mit-license.html MIT License + * @link https://git.timshomepage.net/aviat4ion/Query */ + // -------------------------------------------------------------------------- /**