Code Duplication    Length = 34-36 lines in 2 locations

sources/lib/Inspector/LegacyInspector.php 1 location

@@ 128-161 (lines=34) @@
125
     * @return \PommProject\Foundation\ConvertedResultIterator|null
126
     * @deprecated
127
     */
128
    public function getTableFieldInformation($oid)
129
    {
130
        $sql = <<<SQL
131
select
132
    att.attname      as "name",
133
    case
134
        when name.nspname = 'pg_catalog' then typ.typname
135
        else format('%s.%s', name.nspname, typ.typname)
136
    end as "type",
137
    pg_catalog.pg_get_expr(def.adbin, def.adrelid) as "default",
138
    att.attnotnull   as "is_notnull",
139
    dsc.description  as "comment",
140
    att.attnum       as "position",
141
    att.attnum = any(ind.indkey) as "is_primary"
142
from
143
  pg_catalog.pg_attribute att
144
    join pg_catalog.pg_type  typ  on att.atttypid = typ.oid
145
    join pg_catalog.pg_class cla  on att.attrelid = cla.oid
146
    left join pg_catalog.pg_description dsc on cla.oid = dsc.objoid and att.attnum = dsc.objsubid
147
    left join pg_catalog.pg_attrdef def     on att.attrelid = def.adrelid and att.attnum = def.adnum
148
    left join pg_catalog.pg_index ind       on cla.oid = ind.indrelid and ind.indisprimary
149
    left join pg_catalog.pg_namespace name  on typ.typnamespace = name.oid
150
where
151
{condition}
152
order by
153
    att.attnum
154
SQL;
155
        $where = Where::create('att.attrelid = $*', [$oid])
156
            ->andWhere('att.attnum > 0')
157
            ->andWhere('not att.attisdropped')
158
            ;
159
160
        return $this->executeSql($sql, $where);
161
    }
162
163
    /**
164
     * getSchemaOid

sources/lib/Inspector/RelationInspector.php 1 location

@@ 144-179 (lines=36) @@
141
     * @param  Where $where
142
     * @return ConvertedResultIterator
143
     */
144
    protected function getTableFieldInformationWhere(Where $where)
145
    {
146
        $sql = <<<SQL
147
select
148
    att.attname      as "name",
149
    case
150
        when name.nspname = 'pg_catalog' then typ.typname
151
        else format('%s.%s', name.nspname, typ.typname)
152
    end as "type",
153
    pg_catalog.pg_get_expr(def.adbin, def.adrelid) as "default",
154
    att.attnotnull   as "is_notnull",
155
    dsc.description  as "comment",
156
    att.attnum       as "position",
157
    att.attnum = any(ind.indkey) as "is_primary"
158
from
159
  pg_catalog.pg_attribute att
160
    join pg_catalog.pg_type  typ  on att.atttypid = typ.oid
161
    join pg_catalog.pg_class cla  on att.attrelid = cla.oid
162
    join pg_catalog.pg_namespace clns on cla.relnamespace = clns.oid
163
    left join pg_catalog.pg_description dsc on cla.oid = dsc.objoid and att.attnum = dsc.objsubid
164
    left join pg_catalog.pg_attrdef def     on att.attrelid = def.adrelid and att.attnum = def.adnum
165
    left join pg_catalog.pg_index ind       on cla.oid = ind.indrelid and ind.indisprimary
166
    left join pg_catalog.pg_namespace name  on typ.typnamespace = name.oid
167
where
168
{condition}
169
order by
170
    att.attnum
171
SQL;
172
173
        $where = $where
174
            ->andWhere('att.attnum > 0')
175
            ->andWhere('not att.attisdropped')
176
            ;
177
178
        return $this->executeSql($sql, $where);
179
    }
180
181
    /**
182
     * getTableFieldInformation