示例#1
0
    /**
     * Get constraint
     * 
     * @param  string $constraintName
     * @param  string $table
     * @param  string $schema
     * @param  string $database
     * @return Object\ConstraintObject 
     */
    public function getConstraint($constraintName, $table, $schema = null)
    {
        if ($this->constraintData == null) {
            $this->loadConstraintData();
        }

        $found = false;
        foreach ($this->constraintData as $tableName => $constraints) {
            foreach ($constraints as $constraintData) {
                if ($tableName == $table && $constraintData['name'] == $constraintName) {
                    $found = $constraintData;
                    break 2;
                }
            }
        }

        if (!$found) {
            throw new \Exception('invalid constraint, or constraint not found');
        }

        $constraint = new Object\ConstraintObject($found['name'], $table);
        $constraint->setType($found['type']);
        $constraint->setKeys($this->getConstraintKeys($found['name'], $table, $schema));
        return $constraint;
    }
示例#2
0
 /**
  * Get constraint
  * 
  * @param  string $constraintName
  * @param  string $table
  * @param  string $schema
  * @param  string $database
  * @return Object\ConstraintObject 
  */
 public function getConstraint($constraintName, $table, $schema = null)
 {
     // set values for database & schema
     $database = $database ?: '__DEFAULT_DB__';
     if ($schema == null && $this->defaultSchema != null) {
         $schema = $this->defaultSchema;
     }
     if (!isset($this->data[$database][$schema]['constraints'])) {
         $this->loadConstraintData($schema, $database);
     }
     $found = false;
     foreach ($this->data[$database][$schema]['constraints']['names'] as $constraintInfo) {
         if ($constraintInfo['constraint_name'] == $constraintName && $constraintInfo['table_name'] == $table) {
             $found = $constraintInfo;
             break;
         }
     }
     if (!$found) {
         throw new \Exception('Cannot find a constraint by that name in this table');
     }
     $constraint = new Object\ConstraintObject($constraintName, $table, $schema);
     $constraint->setType($found['constraint_type']);
     $constraint->setKeys($this->getConstraintKeys($constraintName, $table, $schema, $database));
     return $constraint;
 }