| Total Complexity | 36 |
| Total Lines | 439 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | class Postgres80 extends Postgres81 |
||
| 17 | { |
||
| 18 | public $major_version = 8.0; |
||
| 19 | // Map of database encoding names to HTTP encoding names. If a |
||
| 20 | // database encoding does not appear in this list, then its HTTP |
||
| 21 | // encoding name is the same as its database encoding name. |
||
| 22 | public $codemap = [ |
||
| 23 | 'ALT' => 'CP866', |
||
| 24 | 'EUC_CN' => 'GB2312', |
||
| 25 | 'EUC_JP' => 'EUC-JP', |
||
| 26 | 'EUC_KR' => 'EUC-KR', |
||
| 27 | 'EUC_TW' => 'EUC-TW', |
||
| 28 | 'ISO_8859_5' => 'ISO-8859-5', |
||
| 29 | 'ISO_8859_6' => 'ISO-8859-6', |
||
| 30 | 'ISO_8859_7' => 'ISO-8859-7', |
||
| 31 | 'ISO_8859_8' => 'ISO-8859-8', |
||
| 32 | 'JOHAB' => 'CP1361', |
||
| 33 | 'KOI8' => 'KOI8-R', |
||
| 34 | 'LATIN1' => 'ISO-8859-1', |
||
| 35 | 'LATIN2' => 'ISO-8859-2', |
||
| 36 | 'LATIN3' => 'ISO-8859-3', |
||
| 37 | 'LATIN4' => 'ISO-8859-4', |
||
| 38 | // The following encoding map is a known error in PostgreSQL < 7.2 |
||
| 39 | // See the constructor for Postgres72. |
||
| 40 | 'LATIN5' => 'ISO-8859-5', |
||
| 41 | 'LATIN6' => 'ISO-8859-10', |
||
| 42 | 'LATIN7' => 'ISO-8859-13', |
||
| 43 | 'LATIN8' => 'ISO-8859-14', |
||
| 44 | 'LATIN9' => 'ISO-8859-15', |
||
| 45 | 'LATIN10' => 'ISO-8859-16', |
||
| 46 | 'SQL_ASCII' => 'US-ASCII', |
||
| 47 | 'TCVN' => 'CP1258', |
||
| 48 | 'UNICODE' => 'UTF-8', |
||
| 49 | 'WIN' => 'CP1251', |
||
| 50 | 'WIN874' => 'CP874', |
||
| 51 | 'WIN1256' => 'CP1256', |
||
| 52 | ]; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Return all database available on the server. |
||
| 56 | * |
||
| 57 | * @param null $currentdatabase |
||
|
|
|||
| 58 | * |
||
| 59 | * @return \ADORecordSet A list of databases, sorted alphabetically |
||
| 60 | */ |
||
| 61 | public function getDatabases($currentdatabase = null) |
||
| 62 | { |
||
| 63 | $conf = $this->conf; |
||
| 64 | $server_info = $this->server_info; |
||
| 65 | |||
| 66 | if (isset($conf['owned_only']) && $conf['owned_only'] && !$this->isSuperUser()) { |
||
| 67 | $username = $server_info['username']; |
||
| 68 | $this->clean($username); |
||
| 69 | $clause = " AND pu.usename='{$username}'"; |
||
| 70 | } else { |
||
| 71 | $clause = ''; |
||
| 72 | } |
||
| 73 | |||
| 74 | if ($currentdatabase != null) { |
||
| 75 | $this->clean($currentdatabase); |
||
| 76 | $orderby = "ORDER BY pdb.datname = '{$currentdatabase}' DESC, pdb.datname"; |
||
| 77 | } else { |
||
| 78 | $orderby = 'ORDER BY pdb.datname'; |
||
| 79 | } |
||
| 80 | |||
| 81 | if (!$conf['show_system']) { |
||
| 82 | $where = ' AND NOT pdb.datistemplate'; |
||
| 83 | } else { |
||
| 84 | $where = ' AND pdb.datallowconn'; |
||
| 85 | } |
||
| 86 | |||
| 87 | $sql = "SELECT pdb.datname AS datname, |
||
| 88 | pu.usename AS datowner, |
||
| 89 | pg_encoding_to_char(encoding) AS datencoding, |
||
| 90 | (SELECT description FROM pg_description pd WHERE pdb.oid=pd.objoid) AS datcomment, |
||
| 91 | (SELECT spcname FROM pg_catalog.pg_tablespace pt WHERE pt.oid=pdb.dattablespace) AS tablespace |
||
| 92 | FROM pg_database pdb, pg_user pu |
||
| 93 | WHERE pdb.datdba = pu.usesysid |
||
| 94 | {$where} |
||
| 95 | {$clause} |
||
| 96 | {$orderby}"; |
||
| 97 | |||
| 98 | return $this->selectSet($sql); |
||
| 99 | } |
||
| 100 | |||
| 101 | // Schema functions |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Return all schemas in the current database. |
||
| 105 | * |
||
| 106 | * @return \ADORecordSet All schemas, sorted alphabetically |
||
| 107 | */ |
||
| 108 | public function getSchemas() |
||
| 109 | { |
||
| 110 | $conf = $this->conf; |
||
| 111 | |||
| 112 | if (!$conf['show_system']) { |
||
| 113 | $where = "WHERE nspname NOT LIKE 'pg@_%' ESCAPE '@' AND nspname != 'information_schema'"; |
||
| 114 | } else { |
||
| 115 | $where = "WHERE nspname !~ '^pg_t(emp_[0-9]+|oast)$'"; |
||
| 116 | } |
||
| 117 | |||
| 118 | $sql = " |
||
| 119 | SELECT pn.nspname, pu.usename AS nspowner, |
||
| 120 | pg_catalog.obj_description(pn.oid, 'pg_namespace') AS nspcomment |
||
| 121 | FROM pg_catalog.pg_namespace pn |
||
| 122 | LEFT JOIN pg_catalog.pg_user pu ON (pn.nspowner = pu.usesysid) |
||
| 123 | {$where} |
||
| 124 | ORDER BY nspname"; |
||
| 125 | |||
| 126 | return $this->selectSet($sql); |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Return all information relating to a schema. |
||
| 131 | * |
||
| 132 | * @param string $schema The name of the schema |
||
| 133 | * |
||
| 134 | * @return \ADORecordSet Schema information |
||
| 135 | */ |
||
| 136 | public function getSchemaByName($schema) |
||
| 137 | { |
||
| 138 | $this->clean($schema); |
||
| 139 | $sql = " |
||
| 140 | SELECT nspname, nspowner, u.usename AS ownername, nspacl, |
||
| 141 | pg_catalog.obj_description(pn.oid, 'pg_namespace') as nspcomment |
||
| 142 | FROM pg_catalog.pg_namespace pn |
||
| 143 | LEFT JOIN pg_shadow as u ON pn.nspowner = u.usesysid |
||
| 144 | WHERE nspname='{$schema}'"; |
||
| 145 | |||
| 146 | return $this->selectSet($sql); |
||
| 147 | } |
||
| 148 | |||
| 149 | // Table functions |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Changes a user's password. |
||
| 153 | * |
||
| 154 | * @param string $username The username |
||
| 155 | * @param string $password The new password |
||
| 156 | * |
||
| 157 | * @return integer 0 if operation was successful |
||
| 158 | */ |
||
| 159 | public function changePassword($username, $password) |
||
| 160 | { |
||
| 161 | $enc = $this->_encryptPassword($username, $password); |
||
| 162 | $this->fieldClean($username); |
||
| 163 | $this->clean($enc); |
||
| 164 | |||
| 165 | $sql = "ALTER USER \"{$username}\" WITH ENCRYPTED PASSWORD '{$enc}'"; |
||
| 166 | |||
| 167 | return $this->execute($sql); |
||
| 168 | } |
||
| 169 | |||
| 170 | // View functions |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Gets all information for an aggregate. |
||
| 174 | * |
||
| 175 | * @param string $name The name of the aggregate |
||
| 176 | * @param string $basetype The input data type of the aggregate |
||
| 177 | * |
||
| 178 | * @return \ADORecordSet A recordset |
||
| 179 | */ |
||
| 180 | public function getAggregate($name, $basetype) |
||
| 181 | { |
||
| 182 | $c_schema = $this->_schema; |
||
| 183 | $this->clean($c_schema); |
||
| 184 | $this->clean($name); |
||
| 185 | $this->clean($basetype); |
||
| 186 | |||
| 187 | $sql = " |
||
| 188 | SELECT p.proname, |
||
| 189 | CASE p.proargtypes[0] |
||
| 190 | WHEN 'pg_catalog.\"any\"'::pg_catalog.regtype THEN NULL |
||
| 191 | ELSE pg_catalog.format_type(p.proargtypes[0], NULL) |
||
| 192 | END AS proargtypes, a.aggtransfn, format_type(a.aggtranstype, NULL) AS aggstype, |
||
| 193 | a.aggfinalfn, a.agginitval, u.usename, pg_catalog.obj_description(p.oid, 'pg_proc') AS aggrcomment |
||
| 194 | FROM pg_catalog.pg_proc p, pg_catalog.pg_namespace n, pg_catalog.pg_user u, pg_catalog.pg_aggregate a |
||
| 195 | WHERE n.oid = p.pronamespace AND p.proowner=u.usesysid AND p.oid=a.aggfnoid |
||
| 196 | AND p.proisagg AND n.nspname='{$c_schema}' |
||
| 197 | AND p.proname='{$name}' |
||
| 198 | AND CASE p.proargtypes[0] |
||
| 199 | WHEN 'pg_catalog.\"any\"'::pg_catalog.regtype THEN '' |
||
| 200 | ELSE pg_catalog.format_type(p.proargtypes[0], NULL) |
||
| 201 | END ='{$basetype}'"; |
||
| 202 | |||
| 203 | return $this->selectSet($sql); |
||
| 204 | } |
||
| 205 | |||
| 206 | // Sequence functions |
||
| 207 | |||
| 208 | public function hasAggregateSortOp() |
||
|
1 ignored issue
–
show
|
|||
| 209 | { |
||
| 210 | return false; |
||
| 211 | } |
||
| 212 | |||
| 213 | // Role, User/group functions |
||
| 214 | |||
| 215 | public function hasAlterTableSchema() |
||
|
1 ignored issue
–
show
|
|||
| 216 | { |
||
| 217 | return false; |
||
| 218 | } |
||
| 219 | |||
| 220 | // Aggregate functions |
||
| 221 | |||
| 222 | public function hasAutovacuum() |
||
|
1 ignored issue
–
show
|
|||
| 223 | { |
||
| 224 | return false; |
||
| 225 | } |
||
| 226 | |||
| 227 | // Capabilities |
||
| 228 | |||
| 229 | public function hasDisableTriggers() |
||
|
1 ignored issue
–
show
|
|||
| 230 | { |
||
| 231 | return false; |
||
| 232 | } |
||
| 233 | |||
| 234 | public function hasFunctionAlterSchema() |
||
| 235 | { |
||
| 236 | return false; |
||
| 237 | } |
||
| 238 | |||
| 239 | public function hasPreparedXacts() |
||
| 240 | { |
||
| 241 | return false; |
||
| 242 | } |
||
| 243 | |||
| 244 | public function hasRoles() |
||
| 245 | { |
||
| 246 | return false; |
||
| 247 | } |
||
| 248 | |||
| 249 | public function hasAlterSequenceSchema() |
||
| 252 | } |
||
| 253 | |||
| 254 | public function hasServerAdminFuncs() |
||
| 255 | { |
||
| 256 | return false; |
||
| 257 | } |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Protected method which alter a table |
||
| 261 | * SHOULDN'T BE CALLED OUTSIDE OF A TRANSACTION. |
||
| 262 | * |
||
| 263 | * @param $tblrs The table recordSet returned by getTable() |
||
| 264 | * @param $name The new name for the table |
||
| 265 | * @param $owner The new owner for the table |
||
| 266 | * @param $schema The new schema for the table |
||
| 267 | * @param $comment The comment on the table |
||
| 268 | * @param $tablespace The new tablespace for the table ('' means leave as is) |
||
| 269 | * |
||
| 270 | * @return int 0 success |
||
| 271 | */ |
||
| 272 | protected function _alterTable($tblrs, $name, $owner, $schema, $comment, $tablespace) |
||
|
1 ignored issue
–
show
|
|||
| 273 | { |
||
| 274 | /* $schema not supported in pg80- */ |
||
| 275 | |||
| 276 | // Comment |
||
| 277 | $status = $this->setComment('TABLE', '', $tblrs->fields['relname'], $comment); |
||
| 278 | if ($status != 0) { |
||
| 279 | return -4; |
||
| 280 | } |
||
| 281 | |||
| 282 | // Owner |
||
| 283 | $this->fieldClean($owner); |
||
| 284 | $status = $this->alterTableOwner($tblrs, $owner); |
||
| 285 | if ($status != 0) { |
||
| 286 | return -5; |
||
| 287 | } |
||
| 288 | |||
| 289 | // Tablespace |
||
| 290 | $this->fieldClean($tablespace); |
||
| 291 | $status = $this->alterTableTablespace($tblrs, $tablespace); |
||
| 292 | if ($status != 0) { |
||
| 293 | return -6; |
||
| 294 | } |
||
| 295 | |||
| 296 | // Rename |
||
| 297 | $this->fieldClean($name); |
||
| 298 | $status = $this->alterTableName($tblrs, $name); |
||
| 299 | if ($status != 0) { |
||
| 300 | return -3; |
||
| 301 | } |
||
| 302 | |||
| 303 | return 0; |
||
| 304 | } |
||
| 305 | |||
| 306 | /** |
||
| 307 | * Protected method which alter a view |
||
| 308 | * SHOULDN'T BE CALLED OUTSIDE OF A TRANSACTION. |
||
| 309 | * |
||
| 310 | * @param $vwrs The view recordSet returned by getView() |
||
| 311 | * @param $name The new name for the view |
||
| 312 | * @param $owner The new owner for the view |
||
| 313 | * @param $schema |
||
| 314 | * @param $comment The comment on the view |
||
| 315 | * |
||
| 316 | * @return int 0 success |
||
| 317 | */ |
||
| 318 | protected function _alterView($vwrs, $name, $owner, $schema, $comment) |
||
|
1 ignored issue
–
show
|
|||
| 319 | { |
||
| 320 | /* $schema not supported in pg80- */ |
||
| 321 | $this->fieldArrayClean($vwrs->fields); |
||
| 322 | |||
| 323 | // Comment |
||
| 324 | if ($this->setComment('VIEW', $vwrs->fields['relname'], '', $comment) != 0) { |
||
| 325 | return -4; |
||
| 326 | } |
||
| 327 | |||
| 328 | // Owner |
||
| 329 | $this->fieldClean($owner); |
||
| 330 | $status = $this->alterViewOwner($vwrs, $owner); |
||
| 331 | if ($status != 0) { |
||
| 332 | return -5; |
||
| 333 | } |
||
| 334 | |||
| 335 | // Rename |
||
| 336 | $this->fieldClean($name); |
||
| 337 | $status = $this->alterViewName($vwrs, $name); |
||
| 338 | if ($status != 0) { |
||
| 339 | return -3; |
||
| 340 | } |
||
| 341 | |||
| 342 | return 0; |
||
| 343 | } |
||
| 344 | |||
| 345 | /** |
||
| 346 | * Protected method which alter a sequence |
||
| 347 | * SHOULDN'T BE CALLED OUTSIDE OF A TRANSACTION. |
||
| 348 | * |
||
| 349 | * @param $seqrs The sequence recordSet returned by getSequence() |
||
| 350 | * @param $name The new name for the sequence |
||
| 351 | * @param $comment The comment on the sequence |
||
| 352 | * @param $owner The new owner for the sequence |
||
| 353 | * @param $schema The new schema for the sequence |
||
| 354 | * @param $increment The increment |
||
| 355 | * @param $minvalue The min value |
||
| 356 | * @param $maxvalue The max value |
||
| 357 | * @param $restartvalue The starting value |
||
| 358 | * @param $cachevalue The cache value |
||
| 359 | * @param $cycledvalue True if cycled, false otherwise |
||
| 360 | * @param $startvalue The sequence start value when issueing a restart |
||
| 361 | * |
||
| 362 | * @return int 0 success |
||
| 363 | */ |
||
| 364 | protected function _alterSequence( |
||
| 424 | } |
||
| 425 | |||
| 426 | /** |
||
| 427 | * Return all tables in current database (and schema). |
||
| 428 | * |
||
| 429 | * @param bool|true $all True to fetch all tables, false for just in current schema |
||
| 430 | * |
||
| 431 | * @return \ADORecordSet All tables, sorted alphabetically |
||
| 432 | */ |
||
| 433 | public function getTables($all = false) |
||
| 455 | } |
||
| 456 | |||
| 458 |