Code Duplication    Length = 26-26 lines in 2 locations

src/database/databasetraits/IndexTrait.php 2 locations

@@ 265-290 (lines=26) @@
262
     *
263
     * @return int 0 if operation was successful
264
     */
265
    public function addPrimaryKey($table, $fields, $name = '', $tablespace = '')
266
    {
267
        if (!is_array($fields) || sizeof($fields) == 0) {
268
            return -1;
269
        }
270
271
        $f_schema = $this->_schema;
272
        $this->fieldClean($f_schema);
273
        $this->fieldClean($table);
274
        $this->fieldArrayClean($fields);
275
        $this->fieldClean($name);
276
        $this->fieldClean($tablespace);
277
278
        $sql = "ALTER TABLE \"{$f_schema}\".\"{$table}\" ADD ";
279
        if ($name != '') {
280
            $sql .= "CONSTRAINT \"{$name}\" ";
281
        }
282
283
        $sql .= 'PRIMARY KEY ("'.join('","', $fields).'")';
284
285
        if ($tablespace != '' && $this->hasTablespaces()) {
286
            $sql .= " USING INDEX TABLESPACE \"{$tablespace}\"";
287
        }
288
289
        return $this->execute($sql);
290
    }
291
292
    /**
293
     * Adds a unique constraint to a table.
@@ 302-327 (lines=26) @@
299
     *
300
     * @return int 0 if operation was successful
301
     */
302
    public function addUniqueKey($table, $fields, $name = '', $tablespace = '')
303
    {
304
        if (!is_array($fields) || sizeof($fields) == 0) {
305
            return -1;
306
        }
307
308
        $f_schema = $this->_schema;
309
        $this->fieldClean($f_schema);
310
        $this->fieldClean($table);
311
        $this->fieldArrayClean($fields);
312
        $this->fieldClean($name);
313
        $this->fieldClean($tablespace);
314
315
        $sql = "ALTER TABLE \"{$f_schema}\".\"{$table}\" ADD ";
316
        if ($name != '') {
317
            $sql .= "CONSTRAINT \"{$name}\" ";
318
        }
319
320
        $sql .= 'UNIQUE ("'.join('","', $fields).'")';
321
322
        if ($tablespace != '' && $this->hasTablespaces()) {
323
            $sql .= " USING INDEX TABLESPACE \"{$tablespace}\"";
324
        }
325
326
        return $this->execute($sql);
327
    }
328
329
    // Function functions
330