Filter the credentials and remove the ones that
can't be saved to disk.

@param ConnectionKey $connection
@param array         $credentials

@return string[]
558417
protected function filterUnsavableCredentials(ConnectionKey $connection, $credentials)
    {
        $defined = $this->getServerCredentials($connection);
        foreach ($credentials as $key => $value) {
            if (array_get($defined, $key) === true) {
                unset($credentials[$key]);
            }
        }

        return $credentials;
    }
435291
public function selectConnection(array $connections)
    {
        $weighted = [];

        foreach ($connections as $connection) {
            foreach (range(0, $connection['weight']) as $i) {
                $weighted[] = $connection;
            }
        }

        $index = mt_rand(0, count($weighted) - 1);

        return $weighted[$index];
    }
1206029
private static Set<Credential> sanitizeCredentials(final Credential[] credentials) {
        if (credentials != null && credentials.length > 0) {
            return Arrays.stream(credentials)
                .filter(Objects::nonNull)
                .collect(Collectors.toCollection(LinkedHashSet::new));
        }
        return new HashSet<>(0);
    }
701254
public function queryBuilder(ConnectionInterface $connection, String $connectionId=null) : QueryBuilderProvider
	{
		return new PdoQueryBuilder($connection, $connectionId);
	}
835888
protected function getChannelsFilteredByLocale(array $connections, ?string $locale): array
    {
        if ($locale === null) {
            return $this->getChannels($connections);
        }

        if ($this->connectionNameLocaleMap === null) {
            $this->addConnectionNameLocaleMap();
        }

        $channels = [];
        foreach ($connections as $key => $connection) {
            if (!isset($this->connectionNameLocaleMap[$connection->getName()][$locale])) {
                continue;
            }

            $channels[$key] = $connection->getChannel();
        }

        return $channels;
    }
1336246
private function connect(array &$connections)
    {
        $exceptions = [];
        while (count($connections) > 0) {
            /** @var Connection $connection */
            $connection = array_pop($connections);

            try {
                if ($connection->open()) {
                    return $connection;
                }
            } catch (DatabaseException $e) {
                $exceptions[] = $e->getMessage();
            }
        }

        throw new ConnectionException(
            'Unable to select connection.',
            '',
            0,
            count($exceptions) > 0 ? new ConnectionException(implode(' ', $exceptions)) : null
        );
    }
1230663
private function stripLinkNodeKeys($data, Connection $connection)
    {
        if (is_array($data['children']) && count($data['children'])) {
            /*
            $qb = $connection->createQueryBuilder();
            $qb
                ->select(array('id', 'sort'))
                ->from('tree', 't')
                ->where($qb->expr()->eq('t.parent_id', $data['id']))
                ->where($qb->expr()->in('t.id',array_keys($data['children'])))
                ->orderBy('t.sort');

            $sortTids = $connection->fetchAll($qb->getSQL());
            $sortedTids = [];
            foreach (array_keys($data['children']) as $tid) {
                $sortedTids[$tid] = $sortTids[$tid];
            }

            array_multisort($sortedTids, $data['children']);
            */

            $data['children'] = array_values($data['children']);

            foreach ($data['children'] as $key => $item) {
                $data['children'][$key] = $this->stripLinkNodeKeys($item, $connection);
            }
        }

        return $data;
    }
1361932
public function sanitizeConnection($connection = null, $server = null)
    {
        if (!$connection) {
            return $this->connections->getCurrentConnectionKey();
        }

        return $connection instanceof ConnectionKey ? $connection : $this->createConnectionKey($connection, $server);
    }
938249
public static function createDelete(Connection $connection, $table){
		$obj = new self($connection);
		$obj->type = Manager::STMT_DELETE;
		$obj->source = $table;
		return $obj;
	}
1357316
public function reprChainFields($connection, array $fields)
    {
        $result = array();
        foreach ($fields as $field) {
            if ($field === true) {
                $result[] = '*';
            } else {
                $result[] = $this->reprField($connection, $field);
            }
        }
        return implode('.', $result);
    }
466691
def clear_credentials():
    """"""
    global identity, regions, services, cloudservers, cloudfiles, cloud_cdn
    global cloud_loadbalancers, cloud_databases, cloud_blockstorage, cloud_dns
    global cloud_networks, cloud_monitoring, autoscale, images, queues
    identity = None
    regions = tuple()
    services = tuple()
    cloudservers = None
    cloudfiles = None
    cloud_cdn = None
    cloud_loadbalancers = None
    cloud_databases = None
    cloud_blockstorage = None
    cloud_dns = None
    cloud_networks = None
    cloud_monitoring = None
    autoscale = None
    images = None
    queues = None
545436
protected function makeCommand($connection, $connectionName)
    {
        $cmd[] = 'mysqldump -u ' . $connection['username'];
        $cmd[] = '--password=' . $connection['password'];
        $cmd[] = $connection['database'];
        $cmd[] = ' -h ' . $connection['host'];
        if ( ! empty($connection['port'])) {
            $cmd[] = '-P ' . $connection['port'];
        }
        $cmd[] = '> ' . $this->filename($connectionName);
        return implode(' ', $cmd);
    }
1014202
private function connect(Credentials $credentials) : PDO
    {
        if ($this->pdo === null) {
            $this->pdo = new PDO($credentials->getDSN(), $credentials->getUsername(), $credentials->getPassword());
        }

        return $this->pdo;
    }
958182
private function removeInToManyRelationship(
        Connection $connection,
        string $primaryIdentity,
        string $name,
        iterable $secondaryIdentities
    ): int {
        $removeToMany = $this->builderOnRemoveInBelongsToManyRelationship(
            $name,
            $this
                ->createBuilderFromConnection($connection, $this->getModelClass())
                ->prepareDeleteInToManyRelationship($name, $primaryIdentity, $secondaryIdentities)
        );
        $removed = $removeToMany->execute();

        return $removed;
    }
1336650
public function createConnectionKey($connection = null, $server = null, $stage = null)
    {
        if ($connection instanceof ConnectionKey) {
            return $connection;
        }

        // Concatenate
        $handle = new ConnectionKey([
            'name' => $connection,
            'server' => (int) $server,
            'stage' => $stage,
        ]);

        // Populate credentials
        $handle->servers = $this->getServersCredentials($handle);

        return $handle;
    }
1039327
public function getServerCredentials($connection = null, $server = 0)
    {
        $connection = $this->sanitizeConnection($connection);
        $servers = $this->getServersCredentials($connection);

        return (array) Arr::get($servers, $server ?: $connection->server);
    }
1163087
def delete(*keys, **connection_args):
    '''
    
    '''
    # Get connection args from keywords if set
    conn_args = {}
    for arg in ['host', 'port', 'db', 'password']:
        if arg in connection_args:
            conn_args[arg] = connection_args[arg]

    server = _connect(**conn_args)
    return server.delete(*keys)