More Query Builder additions

This commit is contained in:
Timothy Warren 2012-03-01 12:05:32 -05:00
parent 8b404a9465
commit 8886218c66
2 changed files with 43 additions and 10 deletions

View File

@ -23,13 +23,24 @@ class Query_Builder {
/**
* Constructor
*
* @param string $conn_name - the name of the connection
* @param mixed $conn_name - the name of the connection/parameters
*/
function __construct($conn_name)
{
$this->settings =& Settings::get_instance();
$params = $this->settings->get_db($conn_name);
// Add some flexibility for testing
if(class_exists('settings'))
{
$this->settings =& Settings::get_instance();
$params = (is_scalar($conn_name))
? $this->settings->get_db($conn_name)
: $conn_name;
}
else
{
$params = $conn_name;
}
$params->type = strtolower($params->type);
$dbtype = ($params->type !== 'postgresql') ? $params->type : 'pgsql';
@ -42,7 +53,14 @@ class Query_Builder {
break;
case "sqlite":
$this->db = new $dbtype($params->file, $params->user, $params->pass);
if ( ! empty($params->user) && ! empty($params->pass))
{
$this->db = new $dbtype($params->file, $params->user, $params->pass);
}
else
{
$this->db = new $dbtype($params->file);
}
break;
case "firebird":
@ -53,6 +71,18 @@ class Query_Builder {
// --------------------------------------------------------------------------
public function __get($key)
{
if (isset($this->db->$key))
{
return $this->db->$key;
}
return NULL;
}
// --------------------------------------------------------------------------
/**
* Shortcut to directly call database methods
*
@ -62,14 +92,15 @@ class Query_Builder {
*/
public function __call($name, $params)
{
if (is_callable($this->$db->$name))
if (isset($this->db->$name))
{
return call_user_func_array(array(&$this->db, $name), $params);
}
else
{
return NULL;
if (is_callable($this->db->$name))
{
return call_user_func_array($this->db->$name, $params);
}
}
return NULL;
}
// --------------------------------------------------------------------------

View File

@ -32,6 +32,8 @@ function do_include($path)
// Include core tests
require_once("core.php");
require_once("../sys/common/db_pdo.php");
require_once("../sys/common/query_builder.php");
// Include db tests
// Load db classes based on capability