diff --git a/core/abstract/abstract_driver.php b/core/abstract/abstract_driver.php index 8cee9f9..4d87f4e 100644 --- a/core/abstract/abstract_driver.php +++ b/core/abstract/abstract_driver.php @@ -36,7 +36,7 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface { protected $statement; /** - * Character to escape indentifiers + * Character to escape identifiers * @var string */ protected $escape_char = '"'; @@ -100,6 +100,7 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface { /** * Allow invoke to work on table object * + * @codeCoverageIgnore * @param string $name * @param array $args * @return mixed @@ -120,6 +121,30 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface { // ! Concrete functions that can be overridden in child classes // -------------------------------------------------------------------------- + /** + * Get the SQL class for the current driver + * + * @return SQL_Interface + */ + public function get_sql() + { + return $this->sql; + } + + // -------------------------------------------------------------------------- + + /** + * Get the Util class for the current driver + * + * @return Abstract_Util + */ + public function get_util() + { + return $this->util; + } + + // -------------------------------------------------------------------------- + /** * Simplifies prepared statements for database queries * @@ -193,7 +218,7 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface { // before quoting it if ( ! empty($this->table_prefix)) { - // Split indentifier by period, will split into: + // Split identifier by period, will split into: // database.schema.table OR // schema.table OR // database.table OR @@ -436,7 +461,7 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface { */ public function get_columns($table) { - return $this->driver_query($this->sql->column_list($this->prefix_table($table)), FALSE); + return $this->driver_query($this->get_sql()->column_list($this->prefix_table($table)), FALSE); } // -------------------------------------------------------------------------- @@ -449,7 +474,7 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface { */ public function get_fks($table) { - return $this->driver_query($this->sql->fk_list($table), FALSE); + return $this->driver_query($this->get_sql()->fk_list($table), FALSE); } // -------------------------------------------------------------------------- @@ -462,7 +487,7 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface { */ public function get_indexes($table) { - return $this->driver_query($this->sql->index_list($this->prefix_table($table)), FALSE); + return $this->driver_query($this->get_sql()->index_list($this->prefix_table($table)), FALSE); } // -------------------------------------------------------------------------- @@ -491,7 +516,7 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface { // Call the appropriate method, if it exists if (is_string($query) && method_exists($this->sql, $query)) { - $query = $this->sql->$query(); + $query = $this->get_sql()->$query(); } // Return if the values are returned instead of a query, diff --git a/core/abstract/abstract_sql.php b/core/abstract/abstract_sql.php index a33332a..07f261f 100644 --- a/core/abstract/abstract_sql.php +++ b/core/abstract/abstract_sql.php @@ -1,46 +1,46 @@ -table_prefix = $params->prefix; } - // Create the Query Builder object - $conn = new Query_Builder($db); + // Create Query Builder object + $conn = new Query_Builder($db, new Query_Parser($db)); + // Save it for later if (isset($params->alias)) diff --git a/core/interfaces/driver_interface.php b/core/interfaces/driver_interface.php index df5aef9..21b447b 100644 --- a/core/interfaces/driver_interface.php +++ b/core/interfaces/driver_interface.php @@ -30,7 +30,6 @@ interface Driver_Interface { * @param string $username * @param string $password * @param array $driver_options - * @return void */ public function __construct($dsn, $username=NULL, $password=NULL, array $driver_options = array()); @@ -140,5 +139,19 @@ interface Driver_Interface { * @return \PDOStatement */ public function prepare_execute($sql, $params); + + /** + * Get the SQL class for the current driver + * + * @return SQL_Interface + */ + public function get_sql(); + + /** + * Get the Util class for the current driver + * + * @return Abstract_Util + */ + public function get_util(); } // End of driver_interface.php diff --git a/core/query_builder.php b/core/query_builder.php index 2ae8506..1e2fba8 100644 --- a/core/query_builder.php +++ b/core/query_builder.php @@ -100,7 +100,7 @@ class Query_Builder implements Query_Builder_Interface { /** * Value for limit string - * @var type string + * @var string */ protected $limit; @@ -162,14 +162,14 @@ class Query_Builder implements Query_Builder_Interface { protected $parser; /** - * Alias to $this->db->util - * @var DB_Util + * Alias to driver util class + * @var \Query\Driver\Abstract_Util */ public $util; /** - * Alias to $this->db->sql - * @var SQL_Interface + * Alias to driver sql class + * @var \Query\Driver\SQL_Interface */ public $sql; @@ -181,19 +181,19 @@ class Query_Builder implements Query_Builder_Interface { * Constructor * * @param \Query\Driver\Driver_Interface $db + * @param Query_Parser $parser */ - public function __construct(Driver_Interface $db) + public function __construct(Driver_Interface $db, Query_Parser $parser) { + // Inject driver and parser $this->db = $db; - - // Instantiate the Query Parser - $this->parser = new Query_Parser($this); + $this->parser = $parser; $this->queries['total_time'] = 0; - // Make things just slightly shorter - $this->sql = $this->db->sql; - $this->util = $this->db->util; + // Alias driver sql and util classes + $this->sql = $this->db->get_sql(); + $this->util = $this->db->get_util(); } // -------------------------------------------------------------------------- @@ -215,7 +215,7 @@ class Query_Builder implements Query_Builder_Interface { * Method to simplify select_ methods * * @param string $field - * @param string $as + * @param string|bool $as * @return string */ protected function _select($field, $as = FALSE) @@ -295,7 +295,7 @@ class Query_Builder implements Query_Builder_Interface { * Selects the minimum value of a field from a query * * @param string $field - * @param string $as + * @param string|bool $as * @return Query_Builder */ public function select_min($field, $as=FALSE) @@ -311,7 +311,7 @@ class Query_Builder implements Query_Builder_Interface { * Selects the average value of a field from a query * * @param string $field - * @param string $as + * @param string|bool $as * @return Query_Builder */ public function select_avg($field, $as=FALSE) @@ -327,7 +327,7 @@ class Query_Builder implements Query_Builder_Interface { * Selects the sum of a field from a query * * @param string $field - * @param string $as + * @param string|bool $as * @return Query_Builder */ public function select_sum($field, $as=FALSE) @@ -975,7 +975,7 @@ class Query_Builder implements Query_Builder_Interface { * @param $table * @param int|bool $limit * @param int|bool $offset - * @return PDOStatement + * @return \PDOStatement */ public function get($table='', $limit=FALSE, $offset=FALSE) { @@ -986,7 +986,7 @@ class Query_Builder implements Query_Builder_Interface { } // Set the limit, if it exists - if ($limit !== FALSE) + if (is_int($limit)) { $this->limit($limit, $offset); } @@ -997,13 +997,13 @@ class Query_Builder implements Query_Builder_Interface { // -------------------------------------------------------------------------- /** - * Convience method for get() with a where clause + * Convenience method for get() with a where clause * * @param string $table * @param array $where - * @param int $limit - * @param int $offset - * @return PDOStatement + * @param int|bool $limit + * @param int|bool $offset + * @return \PDOStatement */ public function get_where($table, $where=array(), $limit=FALSE, $offset=FALSE) { @@ -1061,7 +1061,7 @@ class Query_Builder implements Query_Builder_Interface { * * @param string $table * @param mixed $data - * @return PDOStatement + * @return \PDOStatement */ public function insert($table, $data=array()) { @@ -1081,7 +1081,7 @@ class Query_Builder implements Query_Builder_Interface { * * @param string $table * @param array $data - * @return PDOStatement + * @return \PDOStatement */ public function insert_batch($table, $data=array()) { @@ -1100,7 +1100,7 @@ class Query_Builder implements Query_Builder_Interface { * * @param string $table * @param mixed $data - * @return PDOStatement + * @return \PDOStatement */ public function update($table, $data=array()) { @@ -1120,7 +1120,7 @@ class Query_Builder implements Query_Builder_Interface { * * @param string $table * @param mixed $where - * @return PDOStatement + * @return \PDOStatement */ public function delete($table, $where='') { @@ -1143,7 +1143,7 @@ class Query_Builder implements Query_Builder_Interface { * @param string $type * @param string $table * @param bool $reset - * @resturn string + * @return string */ protected function _get_compile($type, $table, $reset) { @@ -1271,7 +1271,7 @@ class Query_Builder implements Query_Builder_Interface { * @param string $table * @param string $sql * @param array|null $vals - * @return PDOStatement + * @return \PDOStatement */ protected function _run($type, $table, $sql=NULL, $vals=NULL) { @@ -1311,7 +1311,7 @@ class Query_Builder implements Query_Builder_Interface { * @param string $name * @param array $params * @return mixed - * @throws BadMethodCallException + * @throws \BadMethodCallException */ public function __call($name, $params) { diff --git a/core/query_parser.php b/core/query_parser.php index 07fc54f..d2b7cfc 100644 --- a/core/query_parser.php +++ b/core/query_parser.php @@ -56,9 +56,9 @@ class Query_Parser { /** * Constructor/entry point into parser * - * @param \Query\Query_Builder $db + * @param Query_Builder $db */ - public function __construct(\Query\Query_Builder $db) + public function __construct(\Query\Driver\Driver_Interface $db) { $this->db = $db; } @@ -66,9 +66,10 @@ class Query_Parser { // -------------------------------------------------------------------------- /** - * Public parser method for seting the parse string + * Public parser method for setting the parse string * * @param string $sql + * @return array */ protected function parse_join($sql) { @@ -112,6 +113,8 @@ class Query_Parser { return implode('', $parts['combined']); } + // -------------------------------------------------------------------------- + /** * Returns a more useful match array * diff --git a/drivers/firebird/firebird_result.php b/drivers/firebird/firebird_result.php index 54189a0..28fe22a 100644 --- a/drivers/firebird/firebird_result.php +++ b/drivers/firebird/firebird_result.php @@ -57,7 +57,8 @@ class Firebird_Result extends \PDOStatement { * the query * * @param resource $link - * @param [\Query\Driver\Firebird] $db + * @param \Query\Driver\Firebird|null $db + * @return void */ public function __construct($link, Driver_Interface $db = NULL) { diff --git a/drivers/firebird/firebird_sql.php b/drivers/firebird/firebird_sql.php index a169b5d..0a4b205 100644 --- a/drivers/firebird/firebird_sql.php +++ b/drivers/firebird/firebird_sql.php @@ -28,7 +28,7 @@ class Firebird_SQL extends Abstract_SQL { * * @param string $sql * @param int $limit - * @param int $offset + * @param int|bool $offset * @return string */ public function limit($sql, $limit, $offset=FALSE) diff --git a/drivers/firebird/firebird_util.php b/drivers/firebird/firebird_util.php index b9b4ba0..6a513f2 100644 --- a/drivers/firebird/firebird_util.php +++ b/drivers/firebird/firebird_util.php @@ -28,7 +28,7 @@ namespace Query\Driver; class Firebird_Util extends Abstract_Util { /** - * Convienience public function to generate sql for creating a db table + * Convenience public function to generate sql for creating a db table * * @deprecated Use the table builder class instead * @param string $name diff --git a/tests/core/db_qb_test.php b/tests/core/db_qb_test.php index caf3832..465c1ff 100644 --- a/tests/core/db_qb_test.php +++ b/tests/core/db_qb_test.php @@ -153,13 +153,6 @@ abstract class QBTest extends Query_TestCase { $this->assertIsA($query, 'PDOStatement'); } - // -------------------------------------------------------------------------- - - public function testGetViews() - { - $this->assertTrue(is_array($this->db->get_views())); - } - // -------------------------------------------------------------------------- // ! Select tests // -------------------------------------------------------------------------- diff --git a/tests/core/db_test.php b/tests/core/db_test.php index f858652..221ced8 100644 --- a/tests/core/db_test.php +++ b/tests/core/db_test.php @@ -94,5 +94,12 @@ abstract class DBTest extends Query_TestCase { $this->assertTrue(is_array($keys)); } + // -------------------------------------------------------------------------- + + public function testGetViews() + { + $this->assertTrue(is_array($this->db->get_views())); + } + } // End of db_test.php \ No newline at end of file diff --git a/tests/db_files/FB_TEST_DB.FDB b/tests/db_files/FB_TEST_DB.FDB index f2e29a2..edd89ef 100755 Binary files a/tests/db_files/FB_TEST_DB.FDB and b/tests/db_files/FB_TEST_DB.FDB differ