Rename db_util to abstract_util, mark create_table method as deprecated
This commit is contained in:
parent
4809016c31
commit
a3339200f0
@ -416,7 +416,7 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface {
|
||||
public function driver_query($query, $filtered_index=TRUE)
|
||||
{
|
||||
// Call the appropriate method, if it exists
|
||||
if (method_exists($this->sql, $query))
|
||||
if (is_string($query) && method_exists($this->sql, $query))
|
||||
{
|
||||
$query = $this->sql->$query();
|
||||
}
|
||||
|
@ -15,15 +15,13 @@
|
||||
|
||||
namespace Query\Driver;
|
||||
|
||||
use \Query;
|
||||
|
||||
/**
|
||||
* Abstract class defining database / table creation methods
|
||||
*
|
||||
* @package Query
|
||||
* @subpackage Drivers
|
||||
*/
|
||||
abstract class DB_Util {
|
||||
abstract class Abstract_Util {
|
||||
|
||||
/**
|
||||
* Reference to the current connection object
|
||||
@ -139,4 +137,4 @@ abstract class DB_Util {
|
||||
abstract public function backup_data();
|
||||
|
||||
}
|
||||
// End of db_util.php
|
||||
// End of abstract_util.php
|
@ -241,3 +241,4 @@ final class Connection_Manager {
|
||||
return $dsn;
|
||||
}
|
||||
}
|
||||
// End of connection_manager.php
|
||||
|
@ -353,9 +353,8 @@ class Firebird extends Abstract_Driver {
|
||||
// Start the block of sql statements
|
||||
$sql = "EXECUTE BLOCK AS BEGIN\n";
|
||||
|
||||
$vals = array(); // Values for insertion
|
||||
$table = $this->quote_table($table);
|
||||
$fields = array_keys(current($data));
|
||||
$fields = \array_keys(\current($data));
|
||||
|
||||
$insert_template = "INSERT INTO {$table} ("
|
||||
. implode(',', $this->quote_ident($fields))
|
||||
|
@ -24,7 +24,7 @@ namespace Query\Driver;
|
||||
* @method array get_tables()
|
||||
* @method object query(string $sql)
|
||||
*/
|
||||
class Firebird_Util extends DB_Util {
|
||||
class Firebird_Util extends Abstract_Util {
|
||||
|
||||
/**
|
||||
* Create an SQL backup file for the current database's structure
|
||||
|
@ -27,12 +27,13 @@ namespace Query\Driver;
|
||||
* @method mixed query(string $sql)
|
||||
* @method string quote(string $str)
|
||||
*/
|
||||
class MySQL_Util extends DB_Util {
|
||||
class MySQL_Util extends Abstract_Util {
|
||||
|
||||
/**
|
||||
* Convienience public function for creating a new MySQL table
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
* @param string $name
|
||||
* @param array $columns
|
||||
* @param array $constraints
|
||||
|
@ -23,7 +23,7 @@ namespace Query\Driver;
|
||||
* @method mixed query(string $sql)
|
||||
* @method array get_tables()
|
||||
*/
|
||||
class PgSQL_Util extends DB_Util {
|
||||
class PgSQL_Util extends Abstract_Util {
|
||||
|
||||
/**
|
||||
* Create an SQL backup file for the current database's structure
|
||||
|
@ -100,10 +100,42 @@ class SQLite extends Abstract_Driver {
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
/*public function insert_batch($table, $data=array())
|
||||
public function insert_batch($table, $data=array())
|
||||
{
|
||||
// This is not very applicable to the firebird database
|
||||
return NULL;
|
||||
}*/
|
||||
// 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', '>='))
|
||||
{
|
||||
return parent::insert_batch($table, $data);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Otherwise, do a union query as an analogue to a 'proper' batch insert
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
// Each member of the data array needs to be an array
|
||||
if ( ! is_array(current($data))) return NULL;
|
||||
|
||||
// Start the block of sql statements
|
||||
$table = $this->quote_table($table);
|
||||
$sql = "INSERT INTO {$table} \n";
|
||||
|
||||
// Create a key-value mapping for each field
|
||||
$first = array_shift($data);
|
||||
$cols = array();
|
||||
foreach($first as $colname => $datum)
|
||||
{
|
||||
$cols[] = $this->_quote($datum) . ' AS ' . $this->quote_ident($colname);
|
||||
}
|
||||
$sql .= "SELECT " . implode(', ', $cols) . "\n";
|
||||
|
||||
foreach($data as $item)
|
||||
{
|
||||
$vals = array_map(array($this, 'quote'), $item);
|
||||
$sql .= "UNION SELECT " . implode(',', $vals) . "\n";
|
||||
}
|
||||
|
||||
return array($sql, NULL);
|
||||
}
|
||||
}
|
||||
//End of sqlite_driver.php
|
@ -23,12 +23,13 @@ namespace Query\Driver;
|
||||
* @method mixed query(string $sql)
|
||||
* @method string quote(string $str)
|
||||
*/
|
||||
class SQLite_Util extends DB_Util {
|
||||
class SQLite_Util extends Abstract_Util {
|
||||
|
||||
/**
|
||||
* Convenience public function to create a new table
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
* @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
|
||||
@ -101,7 +102,6 @@ class SQLite_Util extends DB_Util {
|
||||
/**
|
||||
* Create an SQL backup file for the current database's data
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @param array $excluded
|
||||
* @return string
|
||||
*/
|
||||
|
@ -24,8 +24,6 @@
|
||||
// Set up in the bootstrap to mitigate
|
||||
// connection locking issues
|
||||
$this->db = Query('test_sqlite');
|
||||
|
||||
// echo '<hr /> SQLite Queries <hr />';
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user