OpenSQLManager/src/databases/pgsql.php

144 lines
2.6 KiB
PHP
Raw Normal View History

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 {
/**
* 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())
{
parent::__construct("pgsql:$dsn", $username, $password, $options);
//Get db manip class
$class = __CLASS__.'_manip';
$this->manip = new $class;
2012-01-30 07:57:17 -05:00
}
2012-01-26 16:09:05 -05:00
/**
* Empty a table
*
* @param string $table
*/
function truncate($table)
{
$sql = 'TRUNCATE "' . $table . '"';
$this->query($sql);
}
/**
* Get list of databases for the current connection
*
* @return array
*/
function get_dbs()
{
$sql = "SELECT datname FROM pg_database WHERE datname NOT IN ('template0','template1') ORDER BY 1";
$res = $this->query($sql);
$dbs = $res->fetchAll(PDO::FETCH_ASSOC);
return $dbs;
}
/**
2012-02-02 19:07:26 -05:00
* Get the list of tables for the current db
*
* @return array
*/
2012-02-02 19:07:26 -05:00
function get_tables()
{
$sql = 'SELECT "tablename" FROM "pg_tables"
WHERE "tablename" NOT LIKE pg\_%
AND "tablename" NOT LIKE sql\%';
$res = $this->query($sql);
$tables = $res->fetchAll(PDO::FETCH_ASSOC);
return $tables;
}
/**
* Get the list of system tables
*
* @return array
*/
function get_system_tables()
{
$sql = 'SELECT "tablename" FROM "pg_tables"
WHERE "tablename" LIKE \'pg\_%\'
OR "tablename" LIKE \'sql\%\'';
$res = $this->query($sql);
$tables = $res->fetchAll(PDO::FETCH_ASSOC);
return $tables;
}
/**
* Get a list of schemas, either for the current connection, or
* for the current datbase, if specified.
*
* @param string $database=""
* @return array
*/
function get_schemas($database="")
{
$sql = 'SELECT ';
$res = $this->query($sql);
$schemas = $res->fetchAll(PDO::FETCH_ASSOC);
}
/**
2012-02-02 19:07:26 -05:00
* Get a list of views for the current db
*
* @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;
}
2012-02-06 16:56:16 -05:00
/**
* Return the number of rows returned for a SELECT query
*
* @return int
*/
function num_rows()
{
// TODO: Implement
}
}
2012-02-06 17:39:53 -05:00
//End of pgsql.php