* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres.php,v 1.105 2003/05/15 10:02:22 chriskl Exp $
+ * $Id: Postgres.php,v 1.106 2003/05/15 14:34:46 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
* @return All tables, sorted alphabetically
*/
function &getTables() {
- if (!$this->_showSystem) $where = "WHERE tablename NOT LIKE 'pg_%' ";
+ global $conf;
+ if (!$conf['show_system']) $where = "WHERE tablename NOT LIKE 'pg_%' ";
else $where = '';
$sql = "SELECT tablename, tableowner FROM pg_tables {$where}ORDER BY tablename";
return $this->selectSet($sql);
}
- /**
- * Return all information relating to a table
- * @param $table The name of the table
- * @return Table information
- */
- function &getTableByName($table) {
- $this->clean($table);
- $sql = "SELECT * FROM pg_class WHERE relname='{$table}'";
- return $this->selectRow($sql);
- }
-
/**
* Retrieve the attribute definition of a table
* @param $table The name of the table
* @return A recordset
*/
function &getSequences() {
- if (!$this->_showSystem) $where = " AND relname NOT LIKE 'pg_%'";
- else $where = '';
- $sql = "SELECT c.relname, u.usename FROM pg_class c, pg_user u WHERE c.relowner=u.usesysid AND c.relkind = 'S'{$where} ORDER BY relname";
+ $sql = "SELECT c.relname, u.usename FROM pg_class c, pg_user u WHERE c.relowner=u.usesysid AND c.relkind = 'S' ORDER BY relname";
return $this->selectSet( $sql );
}
function &getSequence($sequence) {
$this->fieldClean($sequence);
- if (!$this->_showSystem) $where = " AND relname NOT LIKE 'pg_%'";
- else $where = '';
$sql = "SELECT sequence_name AS relname, * FROM \"{$sequence}\"";
return $this->selectSet( $sql );
function setColumnDefault($table, $column, $default) {
$this->fieldClean($table);
$this->fieldClean($column);
- // @@ How the heck do you clean default clause?
$sql = "ALTER TABLE \"{$table}\" ALTER COLUMN \"{$column}\" SET DEFAULT {$default}";
$sql = "ALTER TABLE \"{$table}\" ALTER COLUMN \"{$column}\" DROP DEFAULT";
- // @@ How do you do this?
return $this->execute($sql);
}
* @return All views
*/
function &getViews() {
- if (!$this->_showSystem)
+ global $conf;
+ if (!$conf['show_system'])
$where = "WHERE viewname NOT LIKE 'pg_%'";
else $where = '';
* @return A recordet
*/
function &getTypes($all = false) {
+ global $conf;
+
+ if ($all || $conf['show_system'])
+ $where = '';
+ else
+ $where = "AND pt.oid > '{$this->_lastSystemOID}'::oid";
+
$sql = "SELECT
pt.typname,
pu.usename AS typowner
pt.typowner = pu.usesysid
AND typrelid = 0
AND typname !~ '^_.*'
+ {$where}
ORDER BY typname
";
return $this->getFunctions(true);
}
+ /**
+ * Returns all details for a particular function
+ * @param $func The name of the function to retrieve
+ * @return Function info
+ */
+ function getFunction($function_oid) {
+ $this->clean($function_oid);
+
+ $sql = "SELECT
+ pc.oid,
+ proname,
+ lanname as language,
+ format_type(prorettype, NULL) as return_type,
+ prosrc as source,
+ probin as binary,
+ proretset,
+ proisstrict,
+ proiscachable,
+ oidvectortypes(pc.proargtypes) AS arguments
+ FROM
+ pg_proc pc, pg_language pl
+ WHERE
+ pc.oid = '$function_oid'::oid
+ AND pc.prolang = pl.oid
+ ";
+
+ return $this->selectSet($sql);
+ }
+
+ /**
+ * Returns an array containing a function's properties
+ * @param $f The array of data for the function
+ * @return An array containing the properties
+ */
+ function getFunctionProperties($f) {
+ $temp = array();
+
+ // Strict
+ if ($f['proisstrict'])
+ $temp[] = 'ISSTRICT';
+ else
+ $temp[] = '';
+
+ // Cachable
+ if ($f['proiscachable'])
+ $temp[] = 'ISCACHABLE';
+ else
+ $temp[] = '';
+
+ return $temp;
+ }
+
/**
* Updates a function. Postgres 7.1 doesn't have CREATE OR REPLACE function,
* so we do it with a drop and a recreate.
$status = $this->beginTransaction();
if ($status != 0) return -1;
- $status = $this->dropFunction($funcname, false);
+ $status = $this->dropFunction("$funcname({$args})", false);
if ($status != 0) {
$this->rollbackTransaction();
return -2;
* @return 0 success
*/
function createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, $replace = false) {
- if ($setof) return -99;
$this->fieldClean($funcname);
$this->clean($args);
$this->fieldClean($returns);
$sql .= ") RETURNS {$returns} AS '\n";
$sql .= $definition;
$sql .= "\n'";
- $sql .= " LANGUAGE \"{$language}\"";
+ $sql .= " LANGUAGE '{$language}'";
// Add flags
$first = true;
function hasRules() { return true; }
function hasLanguages() { return true; }
function hasDropColumn() { return false; }
+ function hasSRFs() { return true; }
}
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres71.php,v 1.30 2003/04/30 06:49:12 chriskl Exp $
+ * $Id: Postgres71.php,v 1.31 2003/05/15 14:34:47 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
// Table functions
- /**
- * Return all tables in current database
- * @return All tables, sorted alphabetically
- */
- function &getTables() {
- if (!$this->_showSystem) $where = "WHERE tablename NOT LIKE 'pg_%' ";
- else $where = '';
- $sql = "SELECT tablename, tableowner FROM pg_tables {$where}ORDER BY tablename";
- return $this->selectSet($sql);
- }
-
/**
* Returns a list of all functions in the database
* @param $all If true, will find all available functions, if false just userland ones
* @return All functions
*/
function &getFunctions($all = false) {
- if ($all)
+ global $conf;
+
+ if ($all || $conf['show_system'])
$where = '';
else
$where = "AND pc.oid > '{$this->_lastSystemOID}'::oid";
$sql = "SELECT
pc.oid,
proname,
+ proretset,
pt.typname AS return_type,
oidvectortypes(pc.proargtypes) AS arguments
FROM
SELECT
pc.oid,
proname,
+ proretset,
'OPAQUE' AS result,
oidvectortypes(pc.proargtypes) AS arguments
FROM
return $this->selectSet($sql);
}
- /**
- * Return all information relating to a table
- * @param $table The name of the table
- * @return Table information
- */
- function &getTableByName($table) {
- $this->clean($table);
- $sql = "SELECT * FROM pg_class WHERE relname='{$table}'";
- return $this->selectRow($sql);
- }
-
- /**
- * Renames a table
- * @param $table The table to be renamed
- * @param $newName The new name for the table
- * @return 0 success
- */
- function renameTable($table, $newName) {
- $this->clean($table);
- $this->clean($newName);
- $sql = "ALTER TABLE \"{$table}\" RENAME TO \"{$newName}\"";
-
- // @@ How do you do this?
- return $this->execute($sql);
- }
-
/**
* Changes the owner of a table
* @param $table The table whose owner is to change
* @return 0 success
*/
function setOwnerOfTable($table, $owner) {
- $this->clean($table);
- $this->clean($owner);
+ $this->fieldClean($table);
+ $this->fieldClean($owner);
$sql = "ALTER TABLE \"{$table}\" OWNER TO \"{$owner}\"";
- // @@ How do you do this?
- return $this->execute($sql);
- }
-
- // Column Functions
-
- /**
- * Add a new column to a table
- * @param $table The table to add to
- * @param $column The name of the new column
- * @param $type The type of the column
- * @param $size (optional) The optional size of the column (ie. 30 for varchar(30))
- * @return 0 success
- */
- function addColumnToTable($table, $column, $type, $size = '') {
- $this->clean($table);
- $this->clean($column);
- $this->clean($type);
- $this->clean($size);
- // @@ How the heck do you properly clean type and size?
-
- if ($size == '')
- $sql = "ALTER TABLE \"{$table}\" ADD COLUMN \"{$column}\" {$type}";
- else
- $sql = "ALTER TABLE \"{$table}\" ADD COLUMN \"{$column}\" {$type}({$size})";
-
- // @@ How do you do this?
- return $this->execute($sql);
- }
-
- /**
- * Sets default value of a column
- * @param $table The table from which to drop
- * @param $column The column name to set
- * @param $default The new default value
- * @return 0 success
- */
- function setColumnDefault($table, $column, $default) {
- $this->clean($table);
- $this->clean($column);
- // @@ How the heck do you clean default clause?
-
- $sql = "ALTER TABLE \"{$table}\" ALTER COLUMN \"{$column}\" SET DEFAULT {$default}";
-
- // @@ How do you do this?
- return $this->execute($sql);
- }
-
- /**
- * Drops default value of a column
- * @param $table The table from which to drop
- * @param $column The column name to drop default
- * @return 0 success
- */
- function dropColumnDefault($table, $column) {
- $this->clean($table);
- $this->clean($column);
-
- $sql = "ALTER TABLE \"{$table}\" ALTER COLUMN \"{$column}\" DROP DEFAULT";
-
- // @@ How do you do this?
- return $this->execute($sql);
- }
-
- /**
- * Sets whether or not a column can contain NULLs
- * @param $table The table that contains the column
- * @param $column The column to alter
- * @param $state True to set null, false to set not null
- * @return 0 success
- * @return -1 attempt to set not null, but column contains nulls
- * @return -2 transaction error
- * @return -3 lock error
- * @return -4 update error
- */
-
- /**
- * Renames a column in a table
- * @param $table The table containing the column to be renamed
- * @param $column The column to be renamed
- * @param $newName The new name for the column
- * @return 0 success
- */
- function renameColumn($table, $column, $newName) {
- $this->clean($table);
- $this->clean($column);
- $this->clean($newName);
-
- $sql = "ALTER TABLE \"{$table}\" RENAME COLUMN \"{$column}\" TO \"{$newName}\"";
-
- // @@ how?
return $this->execute($sql);
}
- // Operator functions
-
- /**
- * Returns a list of all operators in the database
- * @return All operators
- */
- function getOperators() {
- if (!$this->_showSystem)
- $where = "WHERE po.oid > '{$this->_lastSystemOID}'::oid";
- else $where = '';
-
- $sql = "
- SELECT
- po.oid,
- po.oprname,
- (SELECT typname FROM pg_type pt WHERE pt.oid=po.oprleft) AS oprleftname,
- (SELECT typname FROM pg_type pt WHERE pt.oid=po.oprright) AS oprrightname,
- (SELECT typname FROM pg_type pt WHERE pt.oid=po.oprresult) AS resultname
- FROM
- pg_operator po
- {$where}
- ORDER BY
- po.oprname, po.oid
- ";
-
- return $this->selectSet($sql);
- }
-
// Capabilities
function hasTables() { return true; }
function hasViews() { return true; }
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres72.php,v 1.43 2003/05/15 08:59:49 chriskl Exp $
+ * $Id: Postgres72.php,v 1.44 2003/05/15 14:34:47 chriskl Exp $
*/
return $this->selectSet($sql);
}
-
- /**
- * Returns all details for a particular function
- * @param $func The name of the function to retrieve
- * @return Function info
- */
- function getFunction($function_oid) {
- $this->clean($function_oid);
-
- $sql = "SELECT
- pc.oid,
- proname,
- lanname as language,
- format_type(prorettype, NULL) as return_type,
- prosrc as source,
- probin as binary,
- proretset,
- proisstrict,
- proiscachable,
- oidvectortypes(pc.proargtypes) AS arguments
- FROM
- pg_proc pc, pg_language pl
- WHERE
- pc.oid = '$function_oid'::oid
- AND pc.prolang = pl.oid
- ";
-
- return $this->selectSet($sql);
- }
-
- /**
- * Returns an array containing a function's properties
- * @param $f The array of data for the function
- * @return An array containing the properties
- */
- function getFunctionProperties($f) {
- $temp = array();
-
- // Strict
- if ($f['proisstrict'])
- $temp[] = 'ISSTRICT';
- else
- $temp[] = '';
-
- // Cachable
- if ($f['proiscachable'])
- $temp[] = 'ISCACHABLE';
- else
- $temp[] = '';
-
- return $temp;
- }
/**
* Updates (replaces) a function.
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres73.php,v 1.44 2003/05/15 08:59:51 chriskl Exp $
+ * $Id: Postgres73.php,v 1.45 2003/05/15 14:34:47 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
* @return All schemas, sorted alphabetically - but with PUBLIC first (if it exists)
*/
function &getSchemas() {
- if (!$this->_showSystem) $and = "AND nspname NOT LIKE 'pg_%'";
+ global $conf;
+
+ if (!$conf['show_system']) $and = "AND nspname NOT LIKE 'pg_%'";
else $and = '';
$sql = "SELECT pn.nspname, pu.usename AS nspowner FROM pg_namespace pn, pg_user pu
WHERE pn.nspowner = pu.usesysid
- AND nspname = 'public'
- UNION ALL
- SELECT pn.nspname, pu.usename AS nspowner FROM pg_namespace pn, pg_user pu
- WHERE pn.nspowner = pu.usesysid
- AND nspname != 'public' {$and}ORDER BY nspname";
+ {$and}ORDER BY nspname";
return $this->selectSet($sql);
}
return $this->selectSet( $sql );
}
- // Operator functions
-
- /**
- * Returns a list of all operators in the database
- * @return All operators
- */
- function getOperators() {
- if (!$this->_showSystem)
- $where = "WHERE po.oid > '{$this->_lastSystemOID}'::oid";
- else $where = '';
-
- $sql = "
- SELECT
- po.oid,
- po.oprname,
- (SELECT typname FROM pg_type pt WHERE pt.oid=po.oprleft) AS oprleftname,
- (SELECT typname FROM pg_type pt WHERE pt.oid=po.oprright) AS oprrightname,
- (SELECT typname FROM pg_type pt WHERE pt.oid=po.oprresult) AS resultname
- FROM
- pg_operator po
- {$where}
- ORDER BY
- po.oprname, po.oid
- ";
-
- return $this->selectSet($sql);
-
- }
-
/**
* Grabs a list of indexes for a table
* @param $table The name of a table whose indexes to retrieve
function hasCluster() { return true; }
function hasDropBehavior() { return true; }
function hasDropColumn() { return true; }
- function hasSRFs() { return true; }
}