Lots of updates
Added mention of Mariadb to read me, made db_pdo an abstract class, created manip_subclasses for database drivers, created start of unit tests.
This commit is contained in:
parent
df192c1bb8
commit
c85f791de5
@ -3,7 +3,7 @@
|
||||
OpenSQLManager is an attempt to create an alternative to Navicat that is free and open. It is build with PHP-GTK, so I'm looking for a way to create normal binaries.
|
||||
|
||||
### Included pre-configured version of php for windows
|
||||
Because php-gtk is such a pain to compile on Windows, I've put together this package from the latest php-gtk windows package in `php-gtk2-win.7z`.
|
||||
Because php-gtk is such a pain to compile on Windows, I've put together this package from the latest php-gtk windows package. It's available in the downloads section.
|
||||
|
||||
## PHP Requirements
|
||||
* Version 5.2 - 5.3.*
|
||||
@ -21,7 +21,7 @@ Because php-gtk is such a pain to compile on Windows, I've put together this pac
|
||||
The databases currently slated to be supported are:
|
||||
|
||||
* [PostgreSQL](http://www.postgresql.org)
|
||||
* [MySQL](http://www.mysql.com/)
|
||||
* [MySQL](http://www.mysql.com/) / [MariaDB](http://mariadb.org/)
|
||||
* [SQLite](http://sqlite.org/)
|
||||
|
||||
Plan to implement, not support:
|
||||
|
@ -17,7 +17,7 @@
|
||||
*
|
||||
* Extends PDO to simplify cross-database issues
|
||||
*/
|
||||
class DB_PDO extends PDO {
|
||||
abstract class DB_PDO extends PDO {
|
||||
|
||||
protected $statement;
|
||||
|
||||
@ -108,10 +108,10 @@ class DB_PDO extends PDO {
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
abstract function create_database($name){}
|
||||
|
||||
|
||||
/**
|
||||
* Abstract functions to override in child classes
|
||||
*/
|
||||
abstract function get_dbs(){}
|
||||
|
||||
}
|
||||
|
||||
// End of db_pdo.php
|
@ -20,6 +20,7 @@
|
||||
class firebird {
|
||||
|
||||
protected $conn, $statement;
|
||||
private $esc_char = "''";
|
||||
|
||||
/**
|
||||
* Open the link to the database
|
||||
@ -40,6 +41,18 @@ class firebird {
|
||||
{
|
||||
ibase_close($this->conn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty a database table
|
||||
*
|
||||
* @param string $table
|
||||
*/
|
||||
function truncate($table)
|
||||
{
|
||||
// Firebird lacka a truncate command
|
||||
$sql = "DELETE FROM {$table}";
|
||||
$this->query($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper function to better match PDO
|
||||
@ -52,6 +65,28 @@ class firebird {
|
||||
$this->statement = ibase_query($this->conn, $sql);
|
||||
return $this->statement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the databases for the current connection
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function get_dbs()
|
||||
{
|
||||
// I don't think this is possible with Firebird
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class firebird_manip extends firebird {
|
||||
|
||||
function __construct($db, $user="sysdba", $pass="masterkey")
|
||||
{
|
||||
parent::__construct($db, $user, $pass);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
// End of firebird.php
|
@ -19,6 +19,14 @@
|
||||
*/
|
||||
class MySQL extends DB_PDO {
|
||||
|
||||
/**
|
||||
* Connect to MySQL Database
|
||||
*
|
||||
* @param string $dsn
|
||||
* @param string $username=null
|
||||
* @param string $password=null
|
||||
* @param array $options=array()
|
||||
*/
|
||||
function __construct($dsn, $username=null, $password=null, $options=array())
|
||||
{
|
||||
$options = array_merge(array(
|
||||
@ -37,8 +45,28 @@ class MySQL extends DB_PDO {
|
||||
function truncate($table)
|
||||
{
|
||||
$sql = "TRUNCATE `{$table}`";
|
||||
|
||||
$this->query($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the datbases available for the current connection
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_dbs()
|
||||
{
|
||||
$sql = "SHOW TABLES";
|
||||
$res = $this->query($sql);
|
||||
|
||||
return $res->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MySQL_manip extends MySQL {
|
||||
|
||||
function __construct($dsn, $user=null, $pass=null, $opt=array())
|
||||
{
|
||||
parent::__construct($dsn, $user, $pass, $opt);
|
||||
}
|
||||
}
|
@ -26,6 +26,8 @@ class ODBC extends DB_PDO {
|
||||
parent::__construct("odbc:$dsn", $username, $password, $options);
|
||||
}
|
||||
|
||||
function get_dbs(){}
|
||||
|
||||
}
|
||||
|
||||
// End of odbc.php
|
@ -19,6 +19,14 @@
|
||||
*/
|
||||
class pgSQL extends DB_PDO {
|
||||
|
||||
/**
|
||||
* Connect to a PosgreSQL database
|
||||
*
|
||||
* @param string $dsn
|
||||
* @param string $username=null
|
||||
* @param string $password=null
|
||||
* @param array $options=array()
|
||||
*/
|
||||
function __construct($dsn, $username=null, $password=null, $options=array())
|
||||
{
|
||||
parent::__construct("pgsql:$dsn", $username, $password, $options);
|
||||
@ -31,7 +39,55 @@ class pgSQL extends DB_PDO {
|
||||
*/
|
||||
function truncate($table)
|
||||
{
|
||||
|
||||
$sql = 'TRUNCATE "' . $table . '"';
|
||||
$this->query($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of databases for the current db connection
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_dbs()
|
||||
{
|
||||
$sql = 'SELECT "tablename" FROM "pg_tables"
|
||||
WHERE "tablename" NOT LIKE pg\_%
|
||||
AND "tablename" NOT LIKE sql\%';
|
||||
|
||||
$res = $this->query($sql);
|
||||
|
||||
$dbs = $res->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
return $dbs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of views for the current db connection
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_views()
|
||||
{
|
||||
$sql = 'SELECT "viewname" FROM "pg_views"
|
||||
WHERE viewname NOT LIKE pg\_%';
|
||||
|
||||
$res = $this->query($sql);
|
||||
|
||||
$views = $res->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
return $views;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
@ -19,16 +19,6 @@
|
||||
*/
|
||||
class SQLite extends DB_PDO {
|
||||
|
||||
/**
|
||||
* Static function to simply creating dsn for the current database driver
|
||||
*
|
||||
* @return SQLite object
|
||||
*/
|
||||
static function connect()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Open SQLite Database
|
||||
*
|
||||
@ -53,6 +43,49 @@ class SQLite extends DB_PDO {
|
||||
$this->query($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* List databases for the current connection
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function get_dbs()
|
||||
{
|
||||
// SQLite doesn't have a way of doing this
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
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 srtring
|
||||
*/
|
||||
function create_table($name, $columns, $constraints, $indexes)
|
||||
{
|
||||
$sql = "CREATE TABLE {$name} (";
|
||||
|
||||
foreach($columns as $colname => $type)
|
||||
{
|
||||
if(is_numeric($colname))
|
||||
{
|
||||
$colname = $type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an sqlite database file
|
||||
*
|
||||
|
19
tests/index.php
Normal file
19
tests/index.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Unit test bootstrap - Using php simpletest
|
||||
*/
|
||||
|
||||
define('BASE_DIR', '../src');
|
Loading…
Reference in New Issue
Block a user