Reorganize drivers into a more modern layout

This commit is contained in:
Timothy Warren 2015-07-16 16:56:13 -04:00
parent 232761398e
commit bfc3ea33ca
29 changed files with 66 additions and 64 deletions

View File

@ -13,7 +13,7 @@
// --------------------------------------------------------------------------
namespace Query\Driver;
namespace Query;
// --------------------------------------------------------------------------
@ -98,10 +98,10 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface {
// Load the sql and util class for the driver
$this_class = get_class($this);
$ns_array = explode("\\", $this_class);
$base_class = array_pop($ns_array);
$namespace = implode('\\', $ns_array);
$sql_class = "{$namespace}\\SQL\\{$base_class}_SQL";
$util_class = "{$namespace}\\Util\\{$base_class}_Util";
array_pop($ns_array);
$driver = array_pop($ns_array);
$sql_class = "\\Query\\Drivers\\{$driver}\\SQL";
$util_class = "\\Query\\Drivers\\{$driver}\\Util";
$this->sql = new $sql_class();
$this->util = new $util_class($this);

View File

@ -14,7 +14,6 @@
// --------------------------------------------------------------------------
namespace Query;
use \Query\Driver\Driver_Interface;
// --------------------------------------------------------------------------

View File

@ -13,7 +13,7 @@
// --------------------------------------------------------------------------
namespace Query\Driver\SQL;
namespace Query;
/**
* parent for database manipulation subclasses

View File

@ -13,8 +13,7 @@
// --------------------------------------------------------------------------
namespace Query\Driver\Util;
use Query\Driver\Driver_Interface;
namespace Query;
// --------------------------------------------------------------------------

View File

@ -121,7 +121,9 @@ final class Connection_Manager {
{
list($dsn, $dbtype, $params, $options) = $this->parse_params($params);
$driver = "\\Query\\Driver\\{$dbtype}";
$dbtype = ucfirst($dbtype);
$driver = "\\Query\\Drivers\\{$dbtype}\\Driver";
//echo $driver . "\n";
// Create the database connection
$db = ( ! empty($params->user))
@ -164,9 +166,10 @@ final class Connection_Manager {
{
$params->type = strtolower($params->type);
$dbtype = ($params->type !== 'postgresql') ? $params->type : 'pgsql';
$dbtype = ucfirst($dbtype);
// Make sure the class exists
if ( ! class_exists("Query\\Driver\\{$dbtype}"))
if ( ! class_exists("\\Query\\Drivers\\{$dbtype}\\Driver"))
{
throw new BadDBDriverException('Database driver does not exist, or is not supported');
}

View File

@ -13,7 +13,7 @@
// --------------------------------------------------------------------------
namespace Query\Driver;
namespace Query;
/**
* PDO Interface to implement for database drivers

View File

@ -13,7 +13,7 @@
// --------------------------------------------------------------------------
namespace Query\Driver;
namespace Query\Drivers\Firebird;
/**
* Firebird Database class
@ -23,7 +23,7 @@ namespace Query\Driver;
* @package Query
* @subpackage Drivers
*/
class Firebird extends Abstract_Driver {
class Driver extends \Query\Abstract_Driver {
/**
* Reference to the last query executed

View File

@ -13,7 +13,7 @@
// --------------------------------------------------------------------------
namespace Query\Driver;
namespace Query\Drivers\Firebird;
/**
* Firebird result class to emulate PDOStatement Class - only implements
@ -22,7 +22,7 @@ namespace Query\Driver;
* @package Query
* @subpackage Drivers
*/
class Firebird_Result extends \PDOStatement {
class Result extends \PDOStatement {
/**
* Reference to fbird resource

View File

@ -13,7 +13,7 @@
// --------------------------------------------------------------------------
namespace Query\Driver\SQL;
namespace Query\Drivers\Firebird;
/**
* Firebird Specific SQL
@ -21,7 +21,7 @@ namespace Query\Driver\SQL;
* @package Query
* @subpackage Drivers
*/
class Firebird_SQL extends Abstract_SQL {
class SQL extends \Query\Abstract_SQL {
/**
* Limit clause

View File

@ -13,7 +13,7 @@
// --------------------------------------------------------------------------
namespace Query\Driver\Util;
namespace Query\Drivers\Util;
/**
* Firebird-specific backup, import and creation methods
@ -21,7 +21,7 @@ namespace Query\Driver\Util;
* @package Query
* @subpackage Drivers
*/
class Firebird_Util extends Abstract_Util {
class Firebird extends \Query\Abstract_Util {
/**
* Convenience public function to generate sql for creating a db table

View File

@ -13,7 +13,7 @@
// --------------------------------------------------------------------------
namespace Query\Driver;
namespace Query\Drivers\Mysql;
/**
* MySQL specific class
@ -21,7 +21,7 @@ namespace Query\Driver;
* @package Query
* @subpackage Drivers
*/
class MySQL extends Abstract_Driver {
class Driver extends \Query\Abstract_Driver {
/**
* Set the backtick as the MySQL escape character

View File

@ -13,7 +13,7 @@
// --------------------------------------------------------------------------
namespace Query\Driver\SQL;
namespace Query\Drivers\Mysql;
/**
* MySQL specifc SQL
@ -21,7 +21,7 @@ namespace Query\Driver\SQL;
* @package Query
* @subpackage Drivers
*/
class MySQL_SQL extends Abstract_SQL {
class SQL extends \Query\Abstract_SQL {
/**
* Limit clause

View File

@ -13,7 +13,7 @@
// --------------------------------------------------------------------------
namespace Query\Driver\Util;
namespace Query\Drivers\Mysql;
/**
* MySQL-specific backup, import and creation methods
@ -21,7 +21,7 @@ namespace Query\Driver\Util;
* @package Query
* @subpackage Drivers
*/
class MySQL_Util extends Abstract_Util {
class Util extends \Query\Abstract_Util {
/**
* Create an SQL backup file for the current database's structure

View File

@ -13,7 +13,7 @@
// --------------------------------------------------------------------------
namespace Query\Driver;
namespace Query\Drivers\Pgsql;
/**
* PostgreSQL specifc class
@ -21,7 +21,7 @@ namespace Query\Driver;
* @package Query
* @subpackage Drivers
*/
class PgSQL extends Abstract_Driver {
class Driver extends \Query\Abstract_Driver {
/**
* Connect to a PosgreSQL database

View File

@ -12,7 +12,7 @@
// --------------------------------------------------------------------------
namespace Query\Driver\SQL;
namespace Query\Drivers\Pgsql;
/**
* PostgreSQL specifc SQL
@ -20,7 +20,7 @@ namespace Query\Driver\SQL;
* @package Query
* @subpackage Drivers
*/
class PgSQL_SQL extends Abstract_SQL {
class SQL extends \Query\Abstract_SQL {
/**
* Get the query plan for the sql query

View File

@ -13,7 +13,7 @@
// --------------------------------------------------------------------------
namespace Query\Driver\Util;
namespace Query\Drivers\Pgsql;
/**
* Posgres-specific backup, import and creation methods
@ -21,7 +21,7 @@ namespace Query\Driver\Util;
* @package Query
* @subpackage Drivers
*/
class PgSQL_Util extends Abstract_Util {
class Util extends \Query\Abstract_Util {
/**
* Create an SQL backup file for the current database's structure

View File

@ -13,7 +13,7 @@
// --------------------------------------------------------------------------
namespace Query\Driver;
namespace Query\Drivers\Sqlite;
/**
* SQLite specific class
@ -21,7 +21,7 @@ namespace Query\Driver;
* @package Query
* @subpackage Drivers
*/
class SQLite extends Abstract_Driver {
class Driver extends \Query\Abstract_Driver {
/**
* Reference to the last executed sql query

View File

@ -13,7 +13,7 @@
// --------------------------------------------------------------------------
namespace Query\Driver\SQL;
namespace Query\Drivers\Sqlite;
/**
* SQLite Specific SQL
@ -21,7 +21,7 @@ namespace Query\Driver\SQL;
* @package Query
* @subpackage Drivers
*/
class SQLite_SQL extends Abstract_SQL {
class SQL extends \Query\Abstract_SQL {
/**
* Get the query plan for the sql query

View File

@ -13,7 +13,7 @@
// --------------------------------------------------------------------------
namespace Query\Driver\Util;
namespace Query\Drivers\Sqlite;
/**
* SQLite-specific backup, import and creation methods
@ -23,7 +23,7 @@ namespace Query\Driver\Util;
* @method mixed query(string $sql)
* @method string quote(string $str)
*/
class SQLite_Util extends Abstract_Util {
class Util extends \Query\Abstract_Util {
/**
* Create an SQL backup file for the current database's data

View File

@ -14,7 +14,6 @@
// --------------------------------------------------------------------------
namespace Query;
use Query\Driver\Driver_Interface;
// --------------------------------------------------------------------------

View File

@ -58,7 +58,7 @@ class Query_Parser {
*
* @param Driver\Driver_Interface $db
*/
public function __construct(Driver\Driver_Interface $db)
public function __construct(Driver_Interface $db)
{
$this->db = $db;
}

View File

@ -13,7 +13,7 @@
// --------------------------------------------------------------------------
namespace Query\Driver\SQL;
namespace Query;
/**
* parent for database manipulation subclasses

View File

@ -39,7 +39,7 @@ require(QBASE_PATH.'common.php');
// Load Query Classes
spl_autoload_register(function ($class)
{
$class_segments = explode('\\', $class);
/*$class_segments = explode('\\', $class);
$driver_class = strtolower(array_pop($class_segments));
// Load DB Driver classes
@ -49,15 +49,12 @@ spl_autoload_register(function ($class)
// Firebird is a special case, since it's not a PDO driver
// @codeCoverageIgnoreStart
if (
in_array($driver_class, \PDO::getAvailableDrivers())
|| function_exists('\\fbird_connect') && $driver_class === 'firebird'
)
if (function_exists('\\fbird_connect') && $driver_class === 'firebird')
{
array_map('\\do_include', glob("{$driver_path}/*.php"));
}
// @codeCoverageIgnoreEnd
}
}*/
// Load other classes
$path = str_replace('\\', DIRECTORY_SEPARATOR, $class);

View File

@ -59,6 +59,7 @@ class CoreTest extends Query_TestCase {
// Make sure at least one of the supported drivers is enabled
$supported = array(
'firebird',
'mysql',
'pgsql',
'odbc',

View File

@ -33,7 +33,7 @@ class FirebirdTest extends DBtest {
}
// test the db driver directly
$this->db = new \Query\Driver\Firebird('localhost:'.$dbpath);
$this->db = new \Query\Drivers\Firebird\Driver('localhost:'.$dbpath);
$this->db->table_prefix = 'create_';
$this->tables = $this->db->get_tables();
}
@ -75,7 +75,7 @@ class FirebirdTest extends DBtest {
public function testConnection()
{
$this->assertIsA($this->db, '\\Query\\Driver\\Firebird');
$this->assertIsA($this->db, '\\Query\\Drivers\\Firebird\\Driver');
}
// --------------------------------------------------------------------------

View File

@ -29,13 +29,13 @@ class MySQLTest extends DBTest {
$params = json_decode(file_get_contents(QTEST_DIR . "/settings.json"));
$params = $params->mysql;
$this->db = new \Query\Driver\MySQL("mysql:host={$params->host};dbname={$params->database}", $params->user, $params->pass, array(
$this->db = new \Query\Drivers\Mysql\Driver("mysql:host={$params->host};dbname={$params->database}", $params->user, $params->pass, array(
PDO::ATTR_PERSISTENT => TRUE
));
}
elseif (($var = getenv('CI')))
{
$this->db = new \Query\Driver\MySQL('host=127.0.0.1;port=3306;dbname=test', 'root');
$this->db = new \Query\Drivers\Mysql\Driver('host=127.0.0.1;port=3306;dbname=test', 'root');
}
$this->db->table_prefix = 'create_';
@ -52,7 +52,7 @@ class MySQLTest extends DBTest {
public function testConnection()
{
$this->assertIsA($this->db, '\\Query\\Driver\\MySQL');
$this->assertIsA($this->db, '\\Query\\Drivers\\Mysql\\Driver');
}
// --------------------------------------------------------------------------

View File

@ -20,7 +20,7 @@ class PgSQLQBTest extends QBTest {
public function setUp()
{
// If the database isn't installed, skip the tests
if ( ! class_exists("Query\\Driver\\PgSQL") && ! IS_QUERCUS)
if ( ! class_exists("Query\\Drivers\\Pgsql\\Driver") && ! IS_QUERCUS)
{
$this->markTestSkipped("Postgres extension for PDO not loaded");
}

View File

@ -22,10 +22,10 @@ class PgTest extends DBTest {
public function setUp()
{
$class = "Query\\Driver\\PgSQL";
$class = "Query\\Drivers\\Pgsql\\Driver";
// If the database isn't installed, skip the tests
if ( ! class_exists($class) && ! IS_QUERCUS)
if (( ! class_exists($class)) && ! IS_QUERCUS)
{
$this->markTestSkipped("Postgres extension for PDO not loaded");
}
@ -50,7 +50,9 @@ class PgTest extends DBTest {
public function testExists()
{
$this->assertTrue(in_array('pgsql', PDO::getAvailableDrivers()));
$drivers = \PDO::getAvailableDrivers();
print_r($drivers);
$this->assertTrue(in_array('pgsql', $drivers));
}
// --------------------------------------------------------------------------
@ -59,7 +61,7 @@ class PgTest extends DBTest {
{
if (empty($this->db)) return;
$this->assertIsA($this->db, '\\Query\\Driver\\PgSQL');
$this->assertIsA($this->db, '\\Query\\Drivers\\Pgsql\\Driver');
}
// --------------------------------------------------------------------------

View File

@ -162,10 +162,12 @@ SQL;
public function testConnection()
{
$db = new \Query\Driver\SQLite(QTEST_DIR.QDS.'db_files'.QDS.'test_sqlite.db');
$class = '\\Query\\Drivers\\Sqlite\\Driver';
$this->assertIsA($db, '\\Query\\Driver\\SQLite');
$this->assertIsA($this->db->db, '\\Query\\Driver\\SQLite');
$db = new $class(QTEST_DIR.QDS.'db_files'.QDS.'test_sqlite.db');
$this->assertIsA($db, $class);
$this->assertIsA($this->db->db, $class);
unset($db);
}