diff options
author | Felipe Figueroa <amenadiel@gmail.com> | 2018-08-22 22:21:21 +0300 |
---|---|---|
committer | Felipe Figueroa <amenadiel@gmail.com> | 2018-08-22 22:21:21 +0300 |
commit | d782640f5ec561d9088facb2bd162c37b4917fdb (patch) | |
tree | 13292dd48cfe0ce74a375dcf3e7b5418e6904a1c /src/database | |
parent | a9e85588a5d5885673888245ae9b816c48eecf07 (diff) |
Tag v 6.0.0-beta.49 adds role group and function definitionv6.0.0-beta.49
Diffstat (limited to 'src/database')
37 files changed, 141 insertions, 66 deletions
diff --git a/src/database/ADOdbBase.php b/src/database/ADOdbBase.php index 783a7300..8ce25a8a 100644 --- a/src/database/ADOdbBase.php +++ b/src/database/ADOdbBase.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database; @@ -177,10 +177,13 @@ class ADOdbBase public function execute($sql) { // Execute the statement - $rs = $this->conn->Execute($sql); + try { + $rs = $this->conn->Execute($sql); - // If failure, return error value - return $this->conn->ErrorNo(); + return $this->conn->ErrorNo(); + } catch (\Exception $e) { + return $e->getCode(); + } } /** @@ -202,13 +205,13 @@ class ADOdbBase public function selectSet($sql) { // Execute the statement - $rs = $this->conn->Execute($sql); + try { + $rs = $this->conn->Execute($sql); - if (!$rs) { - return $this->conn->ErrorNo(); + return $rs; + } catch (\Exception $e) { + return $e->getCode(); } - - return $rs; } /** diff --git a/src/database/Connection.php b/src/database/Connection.php index 542f258d..a4500ccd 100644 --- a/src/database/Connection.php +++ b/src/database/Connection.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database; diff --git a/src/database/Postgres.php b/src/database/Postgres.php index eff281cb..0c386c0b 100644 --- a/src/database/Postgres.php +++ b/src/database/Postgres.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database; diff --git a/src/database/Postgres10.php b/src/database/Postgres10.php index 2df7a573..694db9b6 100644 --- a/src/database/Postgres10.php +++ b/src/database/Postgres10.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database; diff --git a/src/database/Postgres74.php b/src/database/Postgres74.php index a987c461..29947136 100644 --- a/src/database/Postgres74.php +++ b/src/database/Postgres74.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database; @@ -323,6 +323,7 @@ class Postgres74 extends Postgres80 $oldtype, $comment ) { + $sql = ''; $status = $this->beginTransaction(); if ($status != 0) { return -1; @@ -355,7 +356,7 @@ class Postgres74 extends Postgres80 // Rename the column, if it has been changed if ($column != $name) { - $status = $this->renameColumn($table, $column, $name); + list($status, $sql) = $this->renameColumn($table, $column, $name); if ($status != 0) { $this->rollbackTransaction(); @@ -374,7 +375,7 @@ class Postgres74 extends Postgres80 return -5; } - return $this->endTransaction(); + return [$this->endTransaction(), $sql]; } /** diff --git a/src/database/Postgres80.php b/src/database/Postgres80.php index 01e88b2a..b204ac9c 100644 --- a/src/database/Postgres80.php +++ b/src/database/Postgres80.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database; diff --git a/src/database/Postgres81.php b/src/database/Postgres81.php index 662fe966..aebe7592 100644 --- a/src/database/Postgres81.php +++ b/src/database/Postgres81.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database; diff --git a/src/database/Postgres82.php b/src/database/Postgres82.php index bbdda825..ae271c64 100644 --- a/src/database/Postgres82.php +++ b/src/database/Postgres82.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database; diff --git a/src/database/Postgres83.php b/src/database/Postgres83.php index 0228c1ee..93594803 100644 --- a/src/database/Postgres83.php +++ b/src/database/Postgres83.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database; diff --git a/src/database/Postgres84.php b/src/database/Postgres84.php index 2c09c7e0..1d431d11 100644 --- a/src/database/Postgres84.php +++ b/src/database/Postgres84.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database; diff --git a/src/database/Postgres90.php b/src/database/Postgres90.php index 57ed91dc..2c9e95cc 100644 --- a/src/database/Postgres90.php +++ b/src/database/Postgres90.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database; diff --git a/src/database/Postgres91.php b/src/database/Postgres91.php index 80f3db99..41987b2d 100644 --- a/src/database/Postgres91.php +++ b/src/database/Postgres91.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database; diff --git a/src/database/Postgres92.php b/src/database/Postgres92.php index e6e96c87..181bed85 100644 --- a/src/database/Postgres92.php +++ b/src/database/Postgres92.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database; diff --git a/src/database/Postgres93.php b/src/database/Postgres93.php index abdfb771..341c979b 100644 --- a/src/database/Postgres93.php +++ b/src/database/Postgres93.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database; diff --git a/src/database/Postgres94.php b/src/database/Postgres94.php index f7a837d7..66adbd02 100644 --- a/src/database/Postgres94.php +++ b/src/database/Postgres94.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database; diff --git a/src/database/Postgres95.php b/src/database/Postgres95.php index 09f07f87..399e096b 100644 --- a/src/database/Postgres95.php +++ b/src/database/Postgres95.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database; diff --git a/src/database/Postgres96.php b/src/database/Postgres96.php index cd5db8ea..e25f8a1f 100644 --- a/src/database/Postgres96.php +++ b/src/database/Postgres96.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database; diff --git a/src/database/databasetraits/AggregateTrait.php b/src/database/databasetraits/AggregateTrait.php index 354fb733..a8b96bd5 100644 --- a/src/database/databasetraits/AggregateTrait.php +++ b/src/database/databasetraits/AggregateTrait.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database\Traits; diff --git a/src/database/databasetraits/ColumnTrait.php b/src/database/databasetraits/ColumnTrait.php index 6b5b466c..0f7a451f 100644 --- a/src/database/databasetraits/ColumnTrait.php +++ b/src/database/databasetraits/ColumnTrait.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database\Traits; @@ -130,8 +130,9 @@ trait ColumnTrait $comment ) { // Begin transaction - $status = $this->beginTransaction(); - $sql = ''; + $status = $this->beginTransaction(); + $sql = ''; + $sqlrename = ''; if ($status != 0) { $this->rollbackTransaction(); @@ -140,7 +141,7 @@ trait ColumnTrait // Rename the column, if it has been changed if ($column != $name) { - $status = $this->renameColumn($table, $column, $name); + list($status, $sqlrename) = $this->renameColumn($table, $column, $name); if ($status != 0) { $this->rollbackTransaction(); @@ -224,7 +225,7 @@ trait ColumnTrait return [-5, $sql]; } - return [$this->endTransaction(), $sql]; + return [$this->endTransaction(), $sqlrename.'<br>'.$sql]; } /** @@ -234,7 +235,7 @@ trait ColumnTrait * @param string $column The column to be renamed * @param string $newName The new name for the column * - * @return int 0 if operation was successful + * @return array [0 if operation was successful, sql of sentence] */ public function renameColumn($table, $column, $newName) { @@ -246,7 +247,9 @@ trait ColumnTrait $sql = "ALTER TABLE \"{$f_schema}\".\"{$table}\" RENAME COLUMN \"{$column}\" TO \"{$newName}\""; - return $this->execute($sql); + $status = $this->execute($sql); + + return [$status, $sql]; } /** @@ -312,7 +315,9 @@ trait ColumnTrait $sql .= ' CASCADE'; } - return $this->execute($sql); + $status = $this->execute($sql); + + return [$status, $sql]; } /** diff --git a/src/database/databasetraits/DatabaseTrait.php b/src/database/databasetraits/DatabaseTrait.php index b80b2b67..abdbb7aa 100644 --- a/src/database/databasetraits/DatabaseTrait.php +++ b/src/database/databasetraits/DatabaseTrait.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database\Traits; diff --git a/src/database/databasetraits/DomainTrait.php b/src/database/databasetraits/DomainTrait.php index e8ff2dae..c5522a46 100644 --- a/src/database/databasetraits/DomainTrait.php +++ b/src/database/databasetraits/DomainTrait.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database\Traits; diff --git a/src/database/databasetraits/FtsTrait.php b/src/database/databasetraits/FtsTrait.php index 02f09ed6..2a8a709a 100644 --- a/src/database/databasetraits/FtsTrait.php +++ b/src/database/databasetraits/FtsTrait.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database\Traits; diff --git a/src/database/databasetraits/FunctionTrait.php b/src/database/databasetraits/FunctionTrait.php index 0fbfea6d..884430dd 100644 --- a/src/database/databasetraits/FunctionTrait.php +++ b/src/database/databasetraits/FunctionTrait.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database\Traits; @@ -375,6 +375,35 @@ trait FunctionTrait return $this->selectSet($sql); } + /** + * Returns plain definition for a particular function. + * + * @param int $function_oid + * + * @return \PHPPgAdmin\ADORecordSet Function definition + */ + public function getFunctionDef($function_oid) + { + $this->clean($function_oid); + $sql = " + SELECT + f.proname as relname, + n.nspname, + u.usename AS relowner, + pg_catalog.obj_description(f.oid, 'pg_proc') as relcomment, + (SELECT spcname FROM pg_catalog.pg_tablespace pt WHERE pt.oid=f.pronamespace) AS tablespace, + pg_get_functiondef(f.oid), + pl.lanname AS prolanguage + FROM pg_catalog.pg_proc f + JOIN pg_catalog.pg_namespace n ON (f.pronamespace = n.oid) + JOIN pg_catalog.pg_language pl ON pl.oid = f.prolang + LEFT JOIN pg_catalog.pg_user u ON u.usesysid=f.proowner + WHERE f.oid='{$function_oid}' + "; + + return $this->selectSet($sql); + } + abstract public function fieldClean(&$str); abstract public function beginTransaction(); diff --git a/src/database/databasetraits/HasTrait.php b/src/database/databasetraits/HasTrait.php index 44f35921..7e3a14f9 100644 --- a/src/database/databasetraits/HasTrait.php +++ b/src/database/databasetraits/HasTrait.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database\Traits; diff --git a/src/database/databasetraits/IndexTrait.php b/src/database/databasetraits/IndexTrait.php index 58cd8fa0..4f2f2b68 100644 --- a/src/database/databasetraits/IndexTrait.php +++ b/src/database/databasetraits/IndexTrait.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database\Traits; diff --git a/src/database/databasetraits/OperatorTrait.php b/src/database/databasetraits/OperatorTrait.php index 9f75107f..0d902c47 100644 --- a/src/database/databasetraits/OperatorTrait.php +++ b/src/database/databasetraits/OperatorTrait.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database\Traits; diff --git a/src/database/databasetraits/PrivilegesTrait.php b/src/database/databasetraits/PrivilegesTrait.php index 88ff4acb..dbbc6ef7 100644 --- a/src/database/databasetraits/PrivilegesTrait.php +++ b/src/database/databasetraits/PrivilegesTrait.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database\Traits; diff --git a/src/database/databasetraits/RoleTrait.php b/src/database/databasetraits/RoleTrait.php index 74fd5afe..cdb301f5 100644 --- a/src/database/databasetraits/RoleTrait.php +++ b/src/database/databasetraits/RoleTrait.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database\Traits; @@ -21,9 +21,21 @@ trait RoleTrait public function getRoles($rolename = '') { $sql = ' - SELECT rolname, rolsuper, rolcreatedb, rolcreaterole, rolinherit, - rolcanlogin, rolconnlimit, rolvaliduntil, rolconfig - FROM pg_catalog.pg_roles'; + SELECT + r.rolname, + r1.rolname as group, + r.rolsuper, + r.rolcreatedb, + r.rolcreaterole, + r.rolinherit, + r.rolcanlogin, + r.rolconnlimit, + r.rolvaliduntil, + r.rolconfig + FROM pg_catalog.pg_roles r + LEFT JOIN pg_catalog.pg_auth_members m ON (m.member = r.oid) + LEFT JOIN pg_roles r1 ON (m.roleid=r1.oid) + '; if ($rolename) { $sql .= " WHERE rolname!='{$rolename}'"; } @@ -45,9 +57,21 @@ trait RoleTrait $this->clean($rolename); $sql = " - SELECT rolname, rolsuper, rolcreatedb, rolcreaterole, rolinherit, - rolcanlogin, rolconnlimit, rolvaliduntil, rolconfig - FROM pg_catalog.pg_roles WHERE rolname='{$rolename}'"; + SELECT + r.rolname, + r1.rolname as group, + r.rolsuper, + r.rolcreatedb, + r.rolcreaterole, + r.rolinherit, + r.rolcanlogin, + r.rolconnlimit, + r.rolvaliduntil, + r.rolconfig + FROM pg_catalog.pg_roles r + LEFT JOIN pg_catalog.pg_auth_members m ON (m.member = r.oid) + LEFT JOIN pg_roles r1 ON (m.roleid=r1.oid) + WHERE rolname='{$rolename}'"; return $this->selectSet($sql); } @@ -59,9 +83,15 @@ trait RoleTrait */ public function getUsers() { - $sql = 'SELECT usename, usesuper, usecreatedb, valuntil AS useexpires, useconfig - FROM pg_user - ORDER BY usename'; + $sql = 'SELECT + r.usename, + r1.rolname as group, + r.usesuper, + r.valuntil AS useexpires, + r.useconfig + FROM pg_catalog.pg_user r + LEFT JOIN pg_catalog.pg_auth_members m ON (m.member = r.usesysid) + LEFT JOIN pg_roles r1 ON (m.roleid=r1.oid)'; return $this->selectSet($sql); } @@ -77,9 +107,16 @@ trait RoleTrait { $this->clean($username); - $sql = "SELECT usename, usesuper, usecreatedb, valuntil AS useexpires, useconfig - FROM pg_user - WHERE usename='{$username}'"; + $sql = "SELECT + r.usename, + r1.rolname as group, + r.usesuper, + r.valuntil AS useexpires, + r.useconfig + FROM pg_catalog.pg_user r + LEFT JOIN pg_catalog.pg_auth_members m ON (m.member = r.usesysid) + LEFT JOIN pg_roles r1 ON (m.roleid=r1.oid) + WHERE r.usename='{$username}'"; return $this->selectSet($sql); } diff --git a/src/database/databasetraits/RowTrait.php b/src/database/databasetraits/RowTrait.php index 3440af3f..7e512511 100644 --- a/src/database/databasetraits/RowTrait.php +++ b/src/database/databasetraits/RowTrait.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database\Traits; diff --git a/src/database/databasetraits/SchemaTrait.php b/src/database/databasetraits/SchemaTrait.php index 92bbaf49..5fb270d6 100644 --- a/src/database/databasetraits/SchemaTrait.php +++ b/src/database/databasetraits/SchemaTrait.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database\Traits; diff --git a/src/database/databasetraits/SequenceTrait.php b/src/database/databasetraits/SequenceTrait.php index 9cbda431..998aaa7d 100644 --- a/src/database/databasetraits/SequenceTrait.php +++ b/src/database/databasetraits/SequenceTrait.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database\Traits; diff --git a/src/database/databasetraits/StatsTrait.php b/src/database/databasetraits/StatsTrait.php index 074a339e..6018a77f 100644 --- a/src/database/databasetraits/StatsTrait.php +++ b/src/database/databasetraits/StatsTrait.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database\Traits; diff --git a/src/database/databasetraits/TableTrait.php b/src/database/databasetraits/TableTrait.php index 813d966b..69558944 100644 --- a/src/database/databasetraits/TableTrait.php +++ b/src/database/databasetraits/TableTrait.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database\Traits; diff --git a/src/database/databasetraits/TablespaceTrait.php b/src/database/databasetraits/TablespaceTrait.php index be7b090c..1f587ea1 100644 --- a/src/database/databasetraits/TablespaceTrait.php +++ b/src/database/databasetraits/TablespaceTrait.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database\Traits; diff --git a/src/database/databasetraits/TriggerTrait.php b/src/database/databasetraits/TriggerTrait.php index bbde65f3..c012c7c5 100644 --- a/src/database/databasetraits/TriggerTrait.php +++ b/src/database/databasetraits/TriggerTrait.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database\Traits; diff --git a/src/database/databasetraits/TypeTrait.php b/src/database/databasetraits/TypeTrait.php index 82b66c8e..00756384 100644 --- a/src/database/databasetraits/TypeTrait.php +++ b/src/database/databasetraits/TypeTrait.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database\Traits; diff --git a/src/database/databasetraits/ViewTrait.php b/src/database/databasetraits/ViewTrait.php index 7857317b..9dadd1b8 100644 --- a/src/database/databasetraits/ViewTrait.php +++ b/src/database/databasetraits/ViewTrait.php @@ -1,7 +1,7 @@ <?php /** - * PHPPgAdmin v6.0.0-beta.48 + * PHPPgAdmin v6.0.0-beta.49 */ namespace PHPPgAdmin\Database\Traits; |