Collects primary key information.
@param CPgsqlTableSchema $table the table metadata
@param string $indices pgsql primary key index list
15453
protected function findPrimaryKey($table,$indices)
	{
		$indices=implode(', ',preg_split('/\s+/',$indices));
		$sql=<<<EOD
SELECT attnum, attname FROM pg_catalog.pg_attribute WHERE
	attrelid=(
		SELECT oid FROM pg_catalog.pg_class WHERE relname=:table AND relnamespace=(
			SELECT oid FROM pg_catalog.pg_namespace WHERE nspname=:schema
		)
	)
	AND attnum IN ({$indices})
EOD;
		$command=$this->getDbConnection()->createCommand($sql);
		$command->bindValue(':table',$table->name);
		$command->bindValue(':schema',$table->schemaName);
		foreach($command->queryAll() as $row)
		{
			$name=$row['attname'];
			if(isset($table->columns[$name]))
			{
				$table->columns[$name]->isPrimaryKey=true;
				if($table->primaryKey===null)
					$table->primaryKey=$name;
				elseif(is_string($table->primaryKey))
					$table->primaryKey=array($table->primaryKey,$name);
				else
					$table->primaryKey[]=$name;
			}
		}
	}
473951
protected function getKeys($table,$table2=null) {
		$pdo = $this->adapter->getDatabase()->getPDO();
		$keys = $pdo->cubrid_schema(PDO::CUBRID_SCH_EXPORTED_KEYS,$table);//print_r($keys);
		if ($table2) $keys = array_merge($keys, $pdo->cubrid_schema(PDO::CUBRID_SCH_IMPORTED_KEYS,$table2) );//print_r($keys);
		
		return $keys;
	}
869888
public function getPrimaryKey($table, $resultSet = null){
		if($resultSet instanceof PDOStatement){
			$i = 0;
			while($col = $resultSet->getColumnMeta($i++)){
				if(in_array('primary_key', $col['flags']))
					$primaryKey = $col['name'];
			}
		}
		if(isset($primaryKey))
			return $primaryKey;
		throw new ImplementationException;
	}
867763
public function getCreateIndexSQLQueries(Index $index, $table)
    {
        if ($index->isUnique()) {
            return array($this->getAlterTableSQLQuery($table, 'ADD', $this->getIndexSQLDeclaration($index)));
        }

        if (!$this->supportIndexes()) {
            throw PlatformException::methodNotSupported(__METHOD__);
        }

        return array('CREATE INDEX '.$index->getName().' ON '.$table.' ('.implode(', ', $index->getColumnNames()).')');
    }
1314542
public function indexes($table)
    {
        return Cache::remember("{$table}_indexes", $this->lifetime(), function () use ($table) {
            return $this->manager->listTableIndexes($table);
        });
    }
208662
public function getTableKeys($table)
	{
		$keys = array();

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

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

		$table = strtoupper($table);

		$this->setQuery('pragma table_info( ' . $table . ')');
		$rows = $this->loadObjectList();

		foreach ($rows as $column)
		{
			if ($column->PK == 1)
			{
				$keys[$column->NAME] = $column;
			}
		}

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

		return $keys;
	}
1151224
public function getPrimaryKey($table)
	{
		$keys = $this->getTableKeys($table);
		$key  = false;

		if ($keys && count($keys) > 0)
		{
			foreach ($keys as $k)
			{
				if ($k->Key_name == 'PRIMARY')
				{
					$key = $k->Column_name;
				}
			}
		}

		return $key;
	}
1265773
public function getPrimaryKeys($table)
    {
        $pk = [];
        $cols = $this->getColumns($table);
        if ($cols) {
            foreach ($cols as $key => $val){
                if(isset($val['is_primary']) && $val['is_primary']) {
                    $pk[] = $key;
                }
            }
        }
        
        return $pk;
    }
596102
public void getTablesAndIndexes(Map<String, StmtTargetTableScan> tablesRead,
            Collection<String> indexes)
    {
        for (AbstractPlanNode node : m_inlineNodes.values()) {
            node.getTablesAndIndexes(tablesRead, indexes);
        }
        for (AbstractPlanNode node : m_children) {
            node.getTablesAndIndexes(tablesRead, indexes);
        }
        getTablesAndIndexesFromSubqueries(tablesRead, indexes);
    }
257244
public function createIndex($table, array $indexDef, $options = []) {
        $sql = 'create '.
            (self::val('type', $indexDef) === Db::INDEX_UNIQUE ? 'unique ' : '').
            'index '.
            (self::val(Db::OPTION_IGNORE, $options) ? 'if not exists ' : '').
            $this->buildIndexName($table, $indexDef).
            ' on '.
            $this->prefixTable($table).
            $this->bracketList($indexDef['columns'], '`');

        $this->queryDefine($sql);
    }
42493
protected function getAlternatePrimaryKeys($table)
    {
        $alternatePrimaryKey = false;
        $primaryKeys = [];
        foreach ($table['columns'] as $column) {
            $columnName = $column['COLUMN_NAME'];
            $columnKey = $column['COLUMN_KEY'];
            if ($columnKey !== 'PRI') {
                continue;
            }
            if ($columnName !== 'id') {
                $alternatePrimaryKey = true;
            }
            $primaryKeys[] = '"' . $columnName . '"';
        }
        if ($alternatePrimaryKey) {
            return $primaryKeys;
        }

        return null;
    }
831511
public function createIndex(Index $index, $table)
    {
        $this->_execSql($this->_platform->getCreateIndexSQL($index, $table));
    }
986310
public function createTable($table, array $primaryKey, $data) {
		$parts = [];
		foreach ($primaryKey as $key) {
			$pk = $data->$key;
			if ($pk == null) $parts[] = $key . ' ' . $this->dataTypes['pk_default'];
			else $parts[] = $key . ' ' . $this->getType($pk) . ' NOT NULL';
		}

		$pkField = implode(', ', $parts) . ', PRIMARY KEY(' . implode(', ', $primaryKey) . ')';
		$this->pdo->query('CREATE TABLE IF NOT EXISTS ' . $table . ' (' . $pkField . ')');
	}
387235
public function getCreateIndexSQL(Index $index, $table)
    {
        if ($table instanceof Table) {
            $table = $table->getQuotedName($this);
        }
        $name    = $index->getQuotedName($this);
        $columns = $index->getColumns();

        if (count($columns) === 0) {
            throw new InvalidArgumentException("Incomplete definition. 'columns' required.");
        }

        if ($index->isPrimary()) {
            return $this->getCreatePrimaryKeySQL($index, $table);
        }

        $query  = 'CREATE ' . $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $name . ' ON ' . $table;
        $query .= ' (' . $this->getIndexFieldDeclarationListSQL($index) . ')' . $this->getPartialIndexSQL($index);

        return $query;
    }
103149
function getPrimaryKeys($tableName) {
        $primary_key_index = $this->schema->listTableDetails($tableName)->getPrimaryKey();
        return $primary_key_index ? $primary_key_index->getColumns() : [];
    }
309707
protected function addForeignKeys(Table $table)
	{
		return;
		$database = $table->getDatabase();

		$stmt = $this->dbh->query("SHOW CREATE TABLE `" . $table->getName(). "`");
		$row = $stmt->fetch(PDO::FETCH_NUM);

		$foreignKeys = array(); // local store to avoid duplicates

		// Get the information on all the foreign keys
		$regEx = '/CONSTRAINT `([^`]+)` FOREIGN KEY \((.+)\) REFERENCES `([^`]*)` \((.+)\)(.*)/';
		if (preg_match_all($regEx,$row[1],$matches)) {
			$tmpArray = array_keys($matches[0]);
			foreach ($tmpArray as $curKey) {
				$name = $matches[1][$curKey];
				$rawlcol = $matches[2][$curKey];
				$ftbl = $matches[3][$curKey];
				$rawfcol = $matches[4][$curKey];
				$fkey = $matches[5][$curKey];

				$lcols = array();
				foreach(preg_split('/`, `/', $rawlcol) as $piece) {
					$lcols[] = trim($piece, '` ');
				}

				$fcols = array();
				foreach(preg_split('/`, `/', $rawfcol) as $piece) {
					$fcols[] = trim($piece, '` ');
				}

				//typical for mysql is RESTRICT
				$fkactions = array(
					'ON DELETE'	=> ForeignKey::RESTRICT,
					'ON UPDATE'	=> ForeignKey::RESTRICT,
				);

				if ($fkey) {
					//split foreign key information -> search for ON DELETE and afterwords for ON UPDATE action
					foreach (array_keys($fkactions) as $fkaction) {
						$result = NULL;
						preg_match('/' . $fkaction . ' (' . ForeignKey::CASCADE . '|' . ForeignKey::SETNULL . ')/', $fkey, $result);
						if ($result && is_array($result) && isset($result[1])) {
							$fkactions[$fkaction] = $result[1];
						}
					}
				}

				// restrict is the default
				foreach ($fkactions as $key => $action) {
					if ($action == ForeignKey::RESTRICT) {
						$fkactions[$key] = null;
					}
				}

				$localColumns = array();
				$foreignColumns = array();
				;
				$foreignTable = $database->getTable($ftbl, true);

				foreach($fcols as $fcol) {
					$foreignColumns[] = $foreignTable->getColumn($fcol);
				}
				foreach($lcols as $lcol) {
					$localColumns[] = $table->getColumn($lcol);
				}

				if (!isset($foreignKeys[$name])) {
					$fk = new ForeignKey($name);
					$fk->setForeignTableCommonName($foreignTable->getCommonName());
					$fk->setForeignSchemaName($foreignTable->getSchema());
					$fk->setOnDelete($fkactions['ON DELETE']);
					$fk->setOnUpdate($fkactions['ON UPDATE']);
					$table->addForeignKey($fk);
					$foreignKeys[$name] = $fk;
				}

				for($i=0; $i < count($localColumns); $i++) {
					$foreignKeys[$name]->addReference($localColumns[$i], $foreignColumns[$i]);
				}

			}

		}

	}
571074
public function dropAndCreateIndex(Index $index, $table)
    {
        $this->tryMethod('dropIndex', $index->getQuotedName($this->_platform), $table);
        $this->createIndex($index, $table);
    }