Misc cleanup.
Start of SQL Standard-based driver.
This commit is contained in:
parent
ab41936835
commit
885d0a0ea5
80
drivers/standard_sql.php
Normal file
80
drivers/standard_sql.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* Query
|
||||
*
|
||||
* Free Query Builder / Database Abstraction Layer
|
||||
*
|
||||
* @author Timothy J. Warren
|
||||
* @copyright Copyright (c) 2012
|
||||
* @link https://github.com/aviat4ion/Query
|
||||
* @license http://philsturgeon.co.uk/code/dbad-license
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Dummy class for standardized sql
|
||||
*/
|
||||
class Standard_SQL extends DB_SQL {
|
||||
|
||||
/**
|
||||
* Convenience public function to create a new table
|
||||
*
|
||||
* @param string $name //Name of the table
|
||||
* @param array $columns //columns as straight array and/or column => type pairs
|
||||
* @param array $constraints // column => constraint pairs
|
||||
* @param array $indexes // column => index pairs
|
||||
* @return string
|
||||
*/
|
||||
public function create_table($names, $columns, array $constraints=array(), array $indexes=array())
|
||||
{
|
||||
// @todo Implement
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* SQL to drop the specified table
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
public function delete_table($name)
|
||||
{
|
||||
// @todo Implement
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Random ordering keyword
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function random()
|
||||
{
|
||||
// @todo check if standardized
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Limit clause
|
||||
*
|
||||
* @param string $sql
|
||||
* @param int $limit
|
||||
* @param int $offset
|
||||
* @return string
|
||||
*/
|
||||
public function limit($sql, $limit, $offset=FALSE)
|
||||
{
|
||||
if (is_numeric($offset))
|
||||
{
|
||||
$sql .= ' OFFSET '.$offset.' ROWS ';
|
||||
}
|
||||
|
||||
$sql .= ' FETCH FIRST '.$limit.' ROWS ONLY ';
|
||||
}
|
||||
}
|
||||
// End of standard_sql.php
|
@ -21,8 +21,6 @@ class Query_Builder {
|
||||
// Compiled query component strings
|
||||
private $select_string,
|
||||
$from_string,
|
||||
$insert_string,
|
||||
$update_string,
|
||||
$set_string,
|
||||
$order_string,
|
||||
$group_string;
|
||||
@ -78,29 +76,37 @@ class Query_Builder {
|
||||
$params->type = strtolower($params->type);
|
||||
$dbtype = ($params->type !== 'postgresql') ? $params->type : 'pgsql';
|
||||
|
||||
// Initiate the constructor for the selected database
|
||||
// Create the dsn for the database to connect to
|
||||
switch($dbtype)
|
||||
{
|
||||
default:
|
||||
$this->db = new $dbtype("host={$params->host};port={$params->port};dbname={$params->database}", $params->user, $params->pass);
|
||||
$dsn = "host={$params->host};dbname={$params->database}";
|
||||
|
||||
if ( ! empty($params->port))
|
||||
{
|
||||
$dsn .= ";port={$params->port}";
|
||||
}
|
||||
break;
|
||||
|
||||
case "sqlite":
|
||||
if ( ! empty($params->user) && ! empty($params->pass))
|
||||
{
|
||||
$this->db = new $dbtype($params->file, $params->user, $params->pass);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db = new $dbtype($params->file);
|
||||
}
|
||||
$dsn = $params->file;
|
||||
break;
|
||||
|
||||
case "firebird":
|
||||
$this->db = new $dbtype("{$params->host}:{$params->file}", $params->user, $params->pass);
|
||||
$dsn = "{$params->host}:{$params->file}";
|
||||
break;
|
||||
}
|
||||
|
||||
// Create the database connection
|
||||
if ( ! empty($params->user))
|
||||
{
|
||||
$this->db = new $dbtype($dsn, $params->user, $params->pass);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db = new $dbtype($dsn);
|
||||
}
|
||||
|
||||
// Make things just slightly shorter
|
||||
$this->sql =& $this->db->sql;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user