Récupère les contraintes d'une table à partir du code SQL de sa création.

@param  string $table
@return array[string]
320935
public function getTableConstraintsInfo($table)
    {
        preg_match_all(
            '/CONSTRAINT `\w+` FOREIGN KEY \(`(.+)`\) REFERENCES `(\w+)` \(`.+`\)/Us',
            $this->getSqlCreateTable($table),
            $matches
        );

        $constraintsInfo = [];

        foreach ($matches[0] as $index => $constraint) {
            $constraintsInfo[] = [
                'foreignKey'   => $matches[1][$index],
                'relatedTable' => $matches[2][$index]
            ];
        }

        return $constraintsInfo;
    }
55935
public function getColumns($table)
    {
        $table = $this->prefixTable($table);

        if (empty($this->queriesResultCache[ 'tableColumns' ][ $table ])) {
            $result = $this->query('PRAGMA TABLE_INFO(' . $this->protectIdentifiers($table, true, null, false) . ')');

            if ($result->count()) {
                foreach ($result as $row) {
                    // Do we know from where to get the column's name?
                    if ( ! isset($key)) {
                        if (isset($row[ 'name' ])) {
                            $key = 'name';
                        }
                    }

                    $this->queriesResultCache[ 'tableColumns' ][ $table ][ $row->offsetGet($key) ] = $row;
                }
            }
        }

        return $this->queriesResultCache[ 'tableColumns' ][ $table ];
    }
148735
public static function describe(string $table) :array {

		// set the cachefile name
		$cache_name = ucfirst($table).'Nulls';

		// check if it has been cached already
		if(Cache::has($cache_name)) {

			// get it from the cache
			return Cache::get($cache_name);

		}
		// else it is not available from the cache
		else {

			// the list of allowed null columns
			$allowed_nulls = [];

			// query the database
			foreach(self::query()
				->query(str_replace('*table*', $table, self::$_config['nulls']['query']))
				->execute() as $column) {

				// populate the list
				$allowed_nulls[$column->get(self::$_config['nulls']['column_for_name'])] = 
					self::$_config['nulls']['true'] == $column->get(self::$_config['nulls']['column_for_value']) ? true : false;

			}

			// save the results in the cache
			Cache::put($cache_name, $allowed_nulls);

			// and finaly return the results
			return $allowed_nulls;

		}

	}
953201
protected function table( $table )
	{
		return $this->db->connection( $this->connection )->table( $table )->useWritePdo();
	}
901087
public function getTableCols(string $table): array
    {
        $schema = $this->conn->getSchemaManager();
        $tableCols = $schema->listTableColumns($table);
        $cols = [];
        foreach ($tableCols as $col) {
            $cols[$col->getName()] = [
                'length' => $col->getLength(),
                'type' => $col->getType(),
                'unsigned' => $col->getUnsigned(),
            ];
        }

        return $cols;
    }
260493
protected static function findConstraints($table)
    {
        $result = [];
        $sql = static::getCreateTableSql($table);

        $regexp = '/CONSTRAINT\s+([^\(^\s]+)\s*FOREIGN KEY\s+\(([^\)]+)\)\s+REFERENCES\s+([^\(^\s]+)\s*\(([^\)]+)\)/mi';
        if (preg_match_all($regexp, $sql, $matches, PREG_SET_ORDER)) {
            foreach ($matches as $match) {
                $fks = array_map('trim', explode(',', str_replace('`', '', $match[2])));
                $pks = array_map('trim', explode(',', str_replace('`', '', $match[4])));
                $index = implode('_', $fks);
                $result[$index] = [
                    'name' => str_replace('`', '', $match[1]),
                    'table' => $table->name,
                    'column' => $fks,
                    'ftable' => str_replace('`', '', $match[3]),
                    'fcolumn' => $pks,
                ];
            }
        }
        return $result;
    }
384743
public function getColumns($table): ?array
	{
		return $this->driverQuery($this->getSql()->columnList($this->prefixTable($table)), FALSE);
	}
989236
protected function findConstraints($table)
	{
		$row=$this->getDbConnection()->createCommand('SHOW CREATE TABLE '.$table->rawName)->queryRow();
		$matches=array();
		$regexp='/FOREIGN KEY\s+\(([^\)]+)\)\s+REFERENCES\s+([^\(^\s]+)\s*\(([^\)]+)\)/mi';
		foreach($row as $sql)
		{
			if(preg_match_all($regexp,$sql,$matches,PREG_SET_ORDER))
				break;
		}
		foreach($matches as $match)
		{
			$keys=array_map('trim',explode(',',str_replace(array('`','"'),'',$match[1])));
			$fks=array_map('trim',explode(',',str_replace(array('`','"'),'',$match[3])));
			foreach($keys as $k=>$name)
			{
				$table->foreignKeys[$name]=array(str_replace(array('`','"'),'',$match[2]),$fks[$k]);
				if(isset($table->columns[$name]))
					$table->columns[$name]->isForeignKey=true;
			}
		}
	}
346326
public function FetchColumnSql($Table) {
      if ($Table[0] != '`' && !StringBeginsWith($Table, $this->Database->DatabasePrefix))
         $Table = $this->Database->DatabasePrefix.$Table;
      
      return "show columns from ".$this->FormatTableName($Table);
   }
192680
protected function generateColumns($table)
    {
        $columns = [];
        $needPK = true;
        foreach ($table->columns as $column) {
            if ($column->autoIncrement) {
                $columns[$column->name] = $column->type == Schema::TYPE_BIGINT ? '$this->bigPrimaryKey()' : '$this->primaryKey()';
                $needPK = false;
                continue;
            }
            $columns[$column->name] = $this->getSchemaType($column);
        }
        if ($needPK && !empty($table->primaryKey)) {
            $pks = implode(']], [[', $table->primaryKey);
            $columns[0] = "PRIMARY KEY ([[{$pks}]])";
        }

        return $columns;
    }
469546
public function get_indexes($table) {
        $indexes = array();
        $tablename = strtoupper($this->prefix.$table);

        $sql = "SELECT i.INDEX_NAME, i.UNIQUENESS, c.COLUMN_POSITION, c.COLUMN_NAME, ac.CONSTRAINT_TYPE
                  FROM ALL_INDEXES i
                  JOIN ALL_IND_COLUMNS c ON c.INDEX_NAME=i.INDEX_NAME
             LEFT JOIN ALL_CONSTRAINTS ac ON (ac.TABLE_NAME=i.TABLE_NAME AND ac.CONSTRAINT_NAME=i.INDEX_NAME AND ac.CONSTRAINT_TYPE='P')
                 WHERE i.TABLE_NAME = '$tablename'
              ORDER BY i.INDEX_NAME, c.COLUMN_POSITION";

        $stmt = $this->parse_query($sql);
        $result = oci_execute($stmt, $this->commit_status);
        $this->query_end($result, $stmt);
        $records = null;
        oci_fetch_all($stmt, $records, 0, -1, OCI_FETCHSTATEMENT_BY_ROW);
        oci_free_statement($stmt);

        foreach ($records as $record) {
            if ($record['CONSTRAINT_TYPE'] === 'P') {
                //ignore for now;
                continue;
            }
            $indexname = strtolower($record['INDEX_NAME']);
            if (!isset($indexes[$indexname])) {
                $indexes[$indexname] = array('primary' => ($record['CONSTRAINT_TYPE'] === 'P'),
                                             'unique'  => ($record['UNIQUENESS'] === 'UNIQUE'),
                                             'columns' => array());
            }
            $indexes[$indexname]['columns'][] = strtolower($record['COLUMN_NAME']);
        }

        return $indexes;
    }
712934
public function get_table_definition($table) {
		$statement = $this->get_statement('DESC ' . $this->quote_identifier($table), []);
		$statement->execute();
		$result = $statement->fetch_assoc();
		return $result;
	}
691263
public function getTableKeys($table)
	{
		$this->connect();

		/** @var OracleQuery $query */
		$query = $this->getQuery(true);

		$fieldCasing = $this->getOption(\PDO::ATTR_CASE);

		$this->setOption(\PDO::ATTR_CASE, \PDO::CASE_UPPER);

		$table = strtoupper($table);
		$query->select('*');
		$query->from('ALL_CONSTRAINTS');
		$query->where('table_name = :tableName');

		$query->bind(':tableName', $table);

		$this->setQuery($query);
		$keys = $this->loadObjectList();

		$this->setOption(\PDO::ATTR_CASE, $fieldCasing);

		return $keys;
	}
432760
public function getTableIndexes( $table )
    {
        $query = "SELECT * FROM sqlite_master WHERE type='index' AND tbl_name = '$table'";

        $results = $this->query( $query );

        $indexes = [ ];

        foreach ( $results as $result )
        {
            $indexes[ ] = $result[ 'name' ];
        }

        return $indexes;
    }
376876
protected function parseSchemaAndTable($table)
    {
        $table = explode('.', $table);

        if (is_array($schema = $this->connection->getConfig('schema'))) {
            if (in_array($table[0], $schema)) {
                return [array_shift($table), implode('.', $table)];
            }

            $schema = head($schema);
        }

        return [$schema ?: 'public', implode('.', $table)];
    }
574881
function GetForeignKeys($table)
    {
        $sql = new Sql\Builder($this);
        $fields = array('TABLE_SCHEMA', 'TABLE_NAME', 'REFERENCED_COLUMN_NAME', 'CONSTRAINT_NAME');
        
        $tbl = $sql->Table('information_schema.key_column_usage', $fields);
        
        $where = $sql->Equals($tbl->Field('TABLE_SCHEMA'), $sql->Value($this->dbName))->
                And_($sql->Equals($tbl->Field('TABLE_NAME'), $sql->Value($table)))->
                And_($sql->IsNotNull($tbl->Field('REFERENCED_COLUMN_NAME')));
        $what = $sql->SelectList($tbl->Field('CONSTRAINT_NAME'));
        
        
        $select = $sql->Select(true, $what, $tbl, $where);
        $result = array();
        $reader = $this->ExecuteQuery((string)$select);
        while ($reader->Read())
        {
            $result[] = $reader->ByIndex(0);
        }
        return $result;
    }
837112
public function PrefixTable($Table) {
      $Prefix = $this->Database->DatabasePrefix;
      
      if ($Prefix != '' && substr($Table, 0, strlen($Prefix)) != $Prefix)
         $Table = $Prefix.$Table;

      return $Table;
   }