Split database manipulation classes from database classes
This commit is contained in:
parent
0a11b13bb1
commit
4182776c21
@ -158,23 +158,5 @@ class firebird {
|
||||
{
|
||||
// TODO: Implement
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Database manipulation class
|
||||
*/
|
||||
class firebird_manip extends firebird {
|
||||
|
||||
function __construct($db, $user="sysdba", $pass="masterkey")
|
||||
{
|
||||
parent::__construct($db, $user, $pass);
|
||||
}
|
||||
|
||||
function create_table($name, $fields, $constraints=array())
|
||||
{
|
||||
$sql = "CREATE TABLE {$name}";
|
||||
}
|
||||
|
||||
}
|
||||
// End of firebird.php
|
33
src/databases/firebird_manip.php
Normal file
33
src/databases/firebird_manip.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* OpenSQLManager
|
||||
*
|
||||
* Free Database manager for Open Source Databases
|
||||
*
|
||||
* @author Timothy J. Warren
|
||||
* @copyright Copyright (c) 2012
|
||||
* @link https://github.com/aviat4ion/OpenSQLManager
|
||||
* @license http://philsturgeon.co.uk/code/dbad-license
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Firebird Database Manipulation class
|
||||
*
|
||||
* PDO-firebird isn't stable, so this is a wrapper of the ibase_ functions.
|
||||
*/
|
||||
class firebird_manip extends firebird {
|
||||
|
||||
function __construct($db, $user="sysdba", $pass="masterkey")
|
||||
{
|
||||
parent::__construct($db, $user, $pass);
|
||||
}
|
||||
|
||||
function create_table($name, $fields, $constraints=array())
|
||||
{
|
||||
$sql = "CREATE TABLE {$name}";
|
||||
}
|
||||
|
||||
}
|
||||
//End of firebird_manip.php
|
@ -79,12 +79,4 @@ class MySQL extends DB_PDO {
|
||||
// TODO: Implement
|
||||
}
|
||||
}
|
||||
|
||||
class MySQL_manip extends MySQL {
|
||||
|
||||
function __construct($dsn, $user=null, $pass=null, $opt=array())
|
||||
{
|
||||
parent::__construct($dsn, $user, $pass, $opt);
|
||||
}
|
||||
}
|
||||
//End of mysql.php
|
25
src/databases/mysql_manip.php
Normal file
25
src/databases/mysql_manip.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* OpenSQLManager
|
||||
*
|
||||
* Free Database manager for Open Source Databases
|
||||
*
|
||||
* @author Timothy J. Warren
|
||||
* @copyright Copyright (c) 2012
|
||||
* @link https://github.com/aviat4ion/OpenSQLManager
|
||||
* @license http://philsturgeon.co.uk/code/dbad-license
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* MySQL Database manipulation class
|
||||
*/
|
||||
class MySQL_manip extends MySQL {
|
||||
|
||||
function __construct($dsn, $user=null, $pass=null, $opt=array())
|
||||
{
|
||||
parent::__construct($dsn, $user, $pass, $opt);
|
||||
}
|
||||
}
|
||||
//End of mysqlL_manip.php
|
27
src/databases/odbc_manip.php
Normal file
27
src/databases/odbc_manip.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* OpenSQLManager
|
||||
*
|
||||
* Free Database manager for Open Source Databases
|
||||
*
|
||||
* @author Timothy J. Warren
|
||||
* @copyright Copyright (c) 2012
|
||||
* @link https://github.com/aviat4ion/OpenSQLManager
|
||||
* @license http://philsturgeon.co.uk/code/dbad-license
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ODBC Database Manipulation class
|
||||
*
|
||||
* @extends ODBC
|
||||
*/
|
||||
class ODBC_manip extends ODBC {
|
||||
|
||||
function __construct($dsn, $username=null, $password=null, $options=array())
|
||||
{
|
||||
parent::__construct("odbc:$dsn", $username, $password, $options);
|
||||
}
|
||||
}
|
||||
// End of odbc_manip.php
|
@ -103,16 +103,4 @@ class pgSQL extends DB_PDO {
|
||||
// TODO: Implement
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PostgreSQL DB Structure manipulation class
|
||||
*/
|
||||
class pgSQL_manip extends pgSQL {
|
||||
|
||||
function __construct($dsn, $username=null, $password=null, $options=array())
|
||||
{
|
||||
parent::__construct($dsn, $username, $password, $options);
|
||||
}
|
||||
|
||||
}
|
||||
//End of pgsql.php
|
28
src/databases/pgsql_manip.php
Normal file
28
src/databases/pgsql_manip.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* OpenSQLManager
|
||||
*
|
||||
* Free Database manager for Open Source Databases
|
||||
*
|
||||
* @author Timothy J. Warren
|
||||
* @copyright Copyright (c) 2012
|
||||
* @link https://github.com/aviat4ion/OpenSQLManager
|
||||
* @license http://philsturgeon.co.uk/code/dbad-license
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* PostgreSQL DB Structure manipulation class
|
||||
*
|
||||
* @extends PgSQL
|
||||
*/
|
||||
class pgSQL_manip extends pgSQL {
|
||||
|
||||
function __construct($dsn, $username=null, $password=null, $options=array())
|
||||
{
|
||||
parent::__construct($dsn, $username, $password, $options);
|
||||
}
|
||||
|
||||
}
|
||||
//End of pgsql_manip.php
|
@ -64,79 +64,4 @@ class SQLite extends DB_PDO {
|
||||
// TODO: Implement
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Database manipulation class
|
||||
*/
|
||||
class SQLite_manip extends SQLite {
|
||||
|
||||
function __construct($dsn)
|
||||
{
|
||||
parent::__construct($dsn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience 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
|
||||
*/
|
||||
function create_table($name, $columns, $constraints, $indexes)
|
||||
{
|
||||
$column_array = array();
|
||||
|
||||
// Reorganize into an array indexed with column information
|
||||
// Eg $column_array[$colname] = array(
|
||||
// 'type' => ...,
|
||||
// 'constraint' => ...,
|
||||
// 'index' => ...,
|
||||
// )
|
||||
foreach($columns as $colname => $type)
|
||||
{
|
||||
if(is_numeric($colname))
|
||||
{
|
||||
$colname = $type;
|
||||
}
|
||||
|
||||
$column_array[$colname] = array();
|
||||
$column_array[$colname]['type'] = ($type !== $colname) ? $type : '';
|
||||
}
|
||||
|
||||
if( ! empty($constraints))
|
||||
{
|
||||
foreach($constraints as $col => $const)
|
||||
{
|
||||
$column_array[$col]['constraint'] = $const;
|
||||
}
|
||||
}
|
||||
|
||||
if( ! empty($indexes))
|
||||
{
|
||||
foreach($indexes as $col => $ind)
|
||||
{
|
||||
$column_array[$col]['index'] = $ind;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate the sql for the creation of the table
|
||||
$sql = "CREATE TABLE {$name} (";
|
||||
$sql .= ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an sqlite database file
|
||||
*
|
||||
* @param $path
|
||||
*/
|
||||
function create_db($path)
|
||||
{
|
||||
// Create the file if it doesn't exist
|
||||
if( ! file_exists($path))
|
||||
{
|
||||
touch($path);
|
||||
}
|
||||
}
|
||||
}
|
||||
//End of sqlite.php
|
90
src/databases/sqlite_manip.php
Normal file
90
src/databases/sqlite_manip.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* OpenSQLManager
|
||||
*
|
||||
* Free Database manager for Open Source Databases
|
||||
*
|
||||
* @author Timothy J. Warren
|
||||
* @copyright Copyright (c) 2012
|
||||
* @link https://github.com/aviat4ion/OpenSQLManager
|
||||
* @license http://philsturgeon.co.uk/code/dbad-license
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* SQLite Database manipulation class
|
||||
*/
|
||||
class SQLite_manip extends SQLite {
|
||||
|
||||
function __construct($dsn)
|
||||
{
|
||||
parent::__construct($dsn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience 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
|
||||
*/
|
||||
function create_table($name, $columns, $constraints, $indexes)
|
||||
{
|
||||
$column_array = array();
|
||||
|
||||
// Reorganize into an array indexed with column information
|
||||
// Eg $column_array[$colname] = array(
|
||||
// 'type' => ...,
|
||||
// 'constraint' => ...,
|
||||
// 'index' => ...,
|
||||
// )
|
||||
foreach($columns as $colname => $type)
|
||||
{
|
||||
if(is_numeric($colname))
|
||||
{
|
||||
$colname = $type;
|
||||
}
|
||||
|
||||
$column_array[$colname] = array();
|
||||
$column_array[$colname]['type'] = ($type !== $colname) ? $type : '';
|
||||
}
|
||||
|
||||
if( ! empty($constraints))
|
||||
{
|
||||
foreach($constraints as $col => $const)
|
||||
{
|
||||
$column_array[$col]['constraint'] = $const;
|
||||
}
|
||||
}
|
||||
|
||||
if( ! empty($indexes))
|
||||
{
|
||||
foreach($indexes as $col => $ind)
|
||||
{
|
||||
$column_array[$col]['index'] = $ind;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate the sql for the creation of the table
|
||||
$sql = "CREATE TABLE {$name} (";
|
||||
$sql .= ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an sqlite database file
|
||||
*
|
||||
* @param $path
|
||||
*/
|
||||
function create_db($path)
|
||||
{
|
||||
// Create the file if it doesn't exist
|
||||
if( ! file_exists($path))
|
||||
{
|
||||
touch($path);
|
||||
}
|
||||
}
|
||||
}
|
||||
//End of sqlite_manip.php
|
@ -92,7 +92,8 @@ foreach(pdo_drivers() as $d)
|
||||
|
||||
if(is_file($file))
|
||||
{
|
||||
require_once($file);
|
||||
require_once("{$path}{$d}.php");
|
||||
require_once("{$path}{$d}_manip.php");
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,6 +101,7 @@ foreach(pdo_drivers() as $d)
|
||||
if(function_exists('ibase_connect'))
|
||||
{
|
||||
require_once("{$path}firebird.php");
|
||||
require_once("{$path}firebird_manip.php");
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
@ -40,14 +40,13 @@ $test_path = "./databases/";
|
||||
|
||||
foreach(pdo_drivers() as $d)
|
||||
{
|
||||
|
||||
$src_file = "{$src_path}{$d}.php";
|
||||
$test_file = "{$test_path}{$d}.php";
|
||||
|
||||
if(is_file($src_file))
|
||||
{
|
||||
require_once($src_file);
|
||||
require_once($test_file);
|
||||
require_once("{$src_path}{$d}.php");
|
||||
require_once("{$src_path}{$d}_manip.php");
|
||||
require_once("{$test_path}{$d}.php");
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,5 +54,6 @@ foreach(pdo_drivers() as $d)
|
||||
if(function_exists('ibase_connect'))
|
||||
{
|
||||
require_once("{$src_path}firebird.php");
|
||||
require_once("{$src_path}firebird_manip.php");
|
||||
require_once("{$test_path}firebird.php");
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user