Split database manipulation classes from database classes

This commit is contained in:
Timothy Warren 2012-02-07 15:27:33 -05:00
parent 0a11b13bb1
commit 4182776c21
12 changed files with 212 additions and 120 deletions

View File

@ -157,24 +157,6 @@ class firebird {
function num_rows()
{
// 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

View 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

View File

@ -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

View 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

View 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

View File

@ -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

View 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

View File

@ -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

View 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

View File

@ -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");
}
// --------------------------------------------------------------------------

View File

@ -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.