2012-01-26 16:09:05 -05:00
|
|
|
<?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
|
|
|
|
*/
|
2012-01-30 07:57:17 -05:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PostgreSQL specifc class
|
|
|
|
*
|
|
|
|
* @extends DB_PDO
|
|
|
|
*/
|
|
|
|
class pgSQL extends DB_PDO {
|
|
|
|
|
2012-02-02 17:43:09 -05:00
|
|
|
/**
|
|
|
|
* Connect to a PosgreSQL database
|
|
|
|
*
|
|
|
|
* @param string $dsn
|
|
|
|
* @param string $username=null
|
|
|
|
* @param string $password=null
|
|
|
|
* @param array $options=array()
|
|
|
|
*/
|
2012-01-30 07:57:17 -05:00
|
|
|
function __construct($dsn, $username=null, $password=null, $options=array())
|
|
|
|
{
|
2012-02-01 16:36:55 -05:00
|
|
|
parent::__construct("pgsql:$dsn", $username, $password, $options);
|
2012-01-30 07:57:17 -05:00
|
|
|
}
|
2012-01-26 16:09:05 -05:00
|
|
|
|
2012-01-30 14:03:16 -05:00
|
|
|
/**
|
|
|
|
* Empty a table
|
|
|
|
*
|
|
|
|
* @param string $table
|
|
|
|
*/
|
|
|
|
function truncate($table)
|
|
|
|
{
|
2012-02-02 17:43:09 -05:00
|
|
|
$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);
|
2012-01-30 14:03:16 -05:00
|
|
|
}
|
|
|
|
|
2012-01-26 16:09:05 -05:00
|
|
|
}
|