Code Duplication    Length = 17-39 lines in 8 locations

src/database/Postgres.php 4 locations

@@ 1025-1044 (lines=20) @@
1022
     *
1023
     * @return All schemas, sorted alphabetically
1024
     */
1025
    public function getSchemas()
1026
    {
1027
        $conf = $this->conf;
1028
1029
        if (!$conf['show_system']) {
1030
            $where = "WHERE nspname NOT LIKE 'pg@_%' ESCAPE '@' AND nspname != 'information_schema'";
1031
        } else {
1032
            $where = "WHERE nspname !~ '^pg_t(emp_[0-9]+|oast)$'";
1033
        }
1034
1035
        $sql = "
1036
			SELECT pn.nspname, pu.rolname AS nspowner,
1037
				pg_catalog.obj_description(pn.oid, 'pg_namespace') AS nspcomment
1038
			FROM pg_catalog.pg_namespace pn
1039
				LEFT JOIN pg_catalog.pg_roles pu ON (pn.nspowner = pu.oid)
1040
			{$where}
1041
			ORDER BY nspname";
1042
1043
        return $this->selectSet($sql);
1044
    }
1045
1046
    /**
1047
     * Sets the current working schema.  Will also set Class variable.
@@ 6098-6136 (lines=39) @@
6095
     *
6096
     * @return All casts
6097
     */
6098
    public function getCasts()
6099
    {
6100
        $conf = $this->conf;
6101
6102
        if ($conf['show_system']) {
6103
            $where = '';
6104
        } else {
6105
            $where = '
6106
				AND n1.nspname NOT LIKE $$pg\_%$$
6107
				AND n2.nspname NOT LIKE $$pg\_%$$
6108
				AND n3.nspname NOT LIKE $$pg\_%$$
6109
			';
6110
        }
6111
6112
        $sql = "
6113
			SELECT
6114
				c.castsource::pg_catalog.regtype AS castsource,
6115
				c.casttarget::pg_catalog.regtype AS casttarget,
6116
				CASE WHEN c.castfunc=0 THEN NULL
6117
				ELSE c.castfunc::pg_catalog.regprocedure END AS castfunc,
6118
				c.castcontext,
6119
				obj_description(c.oid, 'pg_cast') as castcomment
6120
			FROM
6121
				(pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p ON c.castfunc=p.oid JOIN pg_catalog.pg_namespace n3 ON p.pronamespace=n3.oid),
6122
				pg_catalog.pg_type t1,
6123
				pg_catalog.pg_type t2,
6124
				pg_catalog.pg_namespace n1,
6125
				pg_catalog.pg_namespace n2
6126
			WHERE
6127
				c.castsource=t1.oid
6128
				AND c.casttarget=t2.oid
6129
				AND t1.typnamespace=n1.oid
6130
				AND t2.typnamespace=n2.oid
6131
				{$where}
6132
			ORDER BY 1, 2
6133
		";
6134
6135
        return $this->selectSet($sql);
6136
    }
6137
6138
    /**
6139
     * Returns a list of all conversions in the database.
@@ 7329-7350 (lines=22) @@
7326
     *
7327
     * @return \PHPPgAdmin\Database\A recordset
7328
     */
7329
    public function getLanguages($all = false)
7330
    {
7331
        $conf = $this->conf;
7332
7333
        if ($conf['show_system'] || $all) {
7334
            $where = '';
7335
        } else {
7336
            $where = 'WHERE lanispl';
7337
        }
7338
7339
        $sql = "
7340
			SELECT
7341
				lanname, lanpltrusted,
7342
				lanplcallfoid::pg_catalog.regproc AS lanplcallf
7343
			FROM
7344
				pg_catalog.pg_language
7345
			{$where}
7346
			ORDER BY lanname
7347
		";
7348
7349
        return $this->selectSet($sql);
7350
    }
7351
7352
    /**
7353
     * Creates a new aggregate in the database.
@@ 8897-8922 (lines=26) @@
8894
     *
8895
     * @return A recordset
8896
     */
8897
    public function getLocks()
8898
    {
8899
        $conf = $this->conf;
8900
8901
        if (!$conf['show_system']) {
8902
            $where = 'AND pn.nspname NOT LIKE $$pg\_%$$';
8903
        } else {
8904
            $where = "AND nspname !~ '^pg_t(emp_[0-9]+|oast)$'";
8905
        }
8906
8907
        $sql = "
8908
			SELECT
8909
				pn.nspname, pc.relname AS tablename, pl.pid, pl.mode, pl.granted, pl.virtualtransaction,
8910
				(select transactionid from pg_catalog.pg_locks l2 where l2.locktype='transactionid'
8911
					and l2.mode='ExclusiveLock' and l2.virtualtransaction=pl.virtualtransaction) as transaction
8912
			FROM
8913
				pg_catalog.pg_locks pl,
8914
				pg_catalog.pg_class pc,
8915
				pg_catalog.pg_namespace pn
8916
			WHERE
8917
				pl.relation = pc.oid AND pc.relnamespace=pn.oid
8918
			{$where}
8919
			ORDER BY pid,nspname,tablename";
8920
8921
        return $this->selectSet($sql);
8922
    }
8923
8924
    /**
8925
     * Sends a cancel or kill command to a process.

src/database/Postgres74.php 2 locations

@@ 252-268 (lines=17) @@
249
         *
250
         * @return A recordset
251
         */
252
        public function getLocks()
253
        {
254
            $conf = $this->conf;
255
256
            if (!$conf['show_system']) {
257
                $where = "AND pn.nspname NOT LIKE 'pg\\\\_%'";
258
            } else {
259
                $where = "AND nspname !~ '^pg_t(emp_[0-9]+|oast)$'";
260
            }
261
262
            $sql = "SELECT pn.nspname, pc.relname AS tablename, pl.transaction, pl.pid, pl.mode, pl.granted
263
		FROM pg_catalog.pg_locks pl, pg_catalog.pg_class pc, pg_catalog.pg_namespace pn
264
		WHERE pl.relation = pc.oid AND pc.relnamespace=pn.oid {$where}
265
		ORDER BY nspname,tablename";
266
267
            return $this->selectSet($sql);
268
        }
269
270
        /**
271
         * Returns the current database encoding.
@@ 585-623 (lines=39) @@
582
         *
583
         * @return All casts
584
         */
585
        public function getCasts()
586
        {
587
            $conf = $this->conf;
588
589
            if ($conf['show_system']) {
590
                $where = '';
591
            } else {
592
                $where = "
593
				AND n1.nspname NOT LIKE 'pg\\\\_%'
594
				AND n2.nspname NOT LIKE 'pg\\\\_%'
595
				AND n3.nspname NOT LIKE 'pg\\\\_%'
596
			";
597
            }
598
599
            $sql = "
600
			SELECT
601
				c.castsource::pg_catalog.regtype AS castsource,
602
				c.casttarget::pg_catalog.regtype AS casttarget,
603
				CASE WHEN c.castfunc=0 THEN NULL
604
				ELSE c.castfunc::pg_catalog.regprocedure END AS castfunc,
605
				c.castcontext,
606
				obj_description(c.oid, 'pg_cast') as castcomment
607
			FROM
608
				(pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p ON c.castfunc=p.oid JOIN pg_catalog.pg_namespace n3 ON p.pronamespace=n3.oid),
609
				pg_catalog.pg_type t1,
610
				pg_catalog.pg_type t2,
611
				pg_catalog.pg_namespace n1,
612
				pg_catalog.pg_namespace n2
613
			WHERE
614
				c.castsource=t1.oid
615
				AND c.casttarget=t2.oid
616
				AND t1.typnamespace=n1.oid
617
				AND t2.typnamespace=n2.oid
618
				{$where}
619
			ORDER BY 1, 2
620
		";
621
622
            return $this->selectSet($sql);
623
        }
624
625
        public function hasAlterColumnType()
626
        {

src/database/Postgres80.php 1 location

@@ 102-121 (lines=20) @@
99
         *
100
         * @return All schemas, sorted alphabetically
101
         */
102
        public function getSchemas()
103
        {
104
            $conf = $this->conf;
105
106
            if (!$conf['show_system']) {
107
                $where = "WHERE nspname NOT LIKE 'pg@_%' ESCAPE '@' AND nspname != 'information_schema'";
108
            } else {
109
                $where = "WHERE nspname !~ '^pg_t(emp_[0-9]+|oast)$'";
110
            }
111
112
            $sql = "
113
			SELECT pn.nspname, pu.usename AS nspowner,
114
				pg_catalog.obj_description(pn.oid, 'pg_namespace') AS nspcomment
115
			FROM pg_catalog.pg_namespace pn
116
				LEFT JOIN pg_catalog.pg_user pu ON (pn.nspowner = pu.usesysid)
117
			{$where}
118
			ORDER BY nspname";
119
120
            return $this->selectSet($sql);
121
        }
122
123
        /**
124
         * Return all information relating to a schema.

src/database/Postgres82.php 1 location

@@ 49-65 (lines=17) @@
46
         *
47
         * @return A recordset
48
         */
49
        public function getLocks()
50
        {
51
            $conf = $this->conf;
52
53
            if (!$conf['show_system']) {
54
                $where = 'AND pn.nspname NOT LIKE $$pg\_%$$';
55
            } else {
56
                $where = "AND nspname !~ '^pg_t(emp_[0-9]+|oast)$'";
57
            }
58
59
            $sql = "SELECT pn.nspname, pc.relname AS tablename, pl.transaction, pl.pid, pl.mode, pl.granted
60
		FROM pg_catalog.pg_locks pl, pg_catalog.pg_class pc, pg_catalog.pg_namespace pn
61
		WHERE pl.relation = pc.oid AND pc.relnamespace=pn.oid {$where}
62
		ORDER BY nspname,tablename";
63
64
            return $this->selectSet($sql);
65
        }
66
67
        // Sequence functions
68