Get DSN - SqLite formatting

sqlite:/tmp/foo.db

@return     string  [description]
960340
public function getDsn(): string
  {
/*
  # File connection
  $connection = new PDO('sqlite:<filename>', null, null
    array(PDO::ATTR_PERSISTENT => true)
  );

  # Memory connection
  $connection = new PDO('sqlite::memory:', null, null
    array(PDO::ATTR_PERSISTENT => true)
  );
*/
    # Build the DSN
    $_dsn = $this->getDriver().':'.$this->getFilename();

    # Set it
    $this->setDsn($_dsn);

    return $_dsn;
  }
910970
public function getDatabaseTimezoneName()
    {
        if ($this->databaseTimezoneName === null) {
            $this->databaseTimezoneName = $this->connection->fetchColumn('select @@time_zone') ?: '';
        }

        return $this->databaseTimezoneName;
    }
686854
protected function GetConnectionString()
	{
		$cstring = new DBConnectionString();
		$cstring->Host = RequestUtil::Get('host');
		$cstring->Port = RequestUtil::Get('port');
		$cstring->Username = RequestUtil::Get('username');
		$cstring->Password = RequestUtil::Get('password');
		$cstring->DBName = RequestUtil::Get('schema');
		$cstring->Type = RequestUtil::Get('type','MySQL');
		return $cstring;
	}
487226
private function getDbName() {
        if (!isset($this->dbname)) {
            $this->dbname = $this->getPDO()->query('select database()')->fetchColumn();
        }
        return $this->dbname;
    }
994830
public function getDsn()
    {
        if (!$this->config) {
            return '';
        }
        $dsn = array();

        if ($this->config->getHost()) {
            $dsn[] = 'host='.$this->config->getHost();
        }

        if ($this->config->getPort()) {
            $dsn[] = 'port='.$this->config->getPort();
        }

        if ($this->config->getName()) {
            $dsn[] = 'dbname='.$this->config->getName();
        }

        if ($this->config->getUser()) {
            $dsn[] = 'user='.$this->config->getUser();
        }

        if ($this->config->getPass()) {
            $dsn[] = 'password='.$this->config->getPass();
        }

        return $this->getPrefix().implode(';', $dsn);
    }
701328
public function getDsn()
    {
        if (!$this->config) {
            return '';
        }
        $dsn = array();

        if ($this->config->getSock()) {
            $dsn[] = 'unix_socket='.$this->config->getSock();
        }

        if ($this->config->getHost()) {
            $dsn[] = 'host='.$this->config->getHost();
        }

        if ($this->config->getPort()) {
            $dsn[] = 'port='.$this->config->getPort();
        }

        if ($this->config->getName()) {
            $dsn[] = 'dbname='.$this->config->getName();
        }

        if ($this->config->getChar() && in_array('charset', $this->getElements())) {
            $dsn[] = 'charset='.$this->config->getChar();
        }

        return $this->getPrefix().implode(';', $dsn);
    }
809085
private function getDumpFolderPath()
    {
        if (is_null($this->tmpFilePath)) {
            $dumpName = $this->getDumpName();
            $databaseName = \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('dbName');
            $this->tmpFilePath = $this->tempDirectory . '/' . $databaseName . '_dbdump/'. $dumpName .'/';
            $this->getFileHandler()->createDirectory($this->tmpFilePath);
        }

        return $this->tmpFilePath;
    }
655163
function getDN($format = self::DN_ARRAY, $dn = null)
    {
        if (!isset($dn)) {
            $dn = isset($this->currentCert['tbsCertList']) ? $this->currentCert['tbsCertList']['issuer'] : $this->dn;
        }

        switch ((int) $format) {
            case self::DN_ARRAY:
                return $dn;
            case self::DN_ASN1:
                $asn1 = new ASN1();
                $asn1->loadOIDs($this->oids);
                $filters = array();
                $filters['rdnSequence']['value'] = array('type' => ASN1::TYPE_UTF8_STRING);
                $asn1->loadFilters($filters);
                $this->_mapOutDNs($dn, 'rdnSequence', $asn1);
                return $asn1->encodeDER($dn, $this->Name);
            case self::DN_CANON:
                //  No SEQUENCE around RDNs and all string values normalized as
                // trimmed lowercase UTF-8 with all spacing as one blank.
                // constructed RDNs will not be canonicalized
                $asn1 = new ASN1();
                $asn1->loadOIDs($this->oids);
                $filters = array();
                $filters['value'] = array('type' => ASN1::TYPE_UTF8_STRING);
                $asn1->loadFilters($filters);
                $result = '';
                $this->_mapOutDNs($dn, 'rdnSequence', $asn1);
                foreach ($dn['rdnSequence'] as $rdn) {
                    foreach ($rdn as $i => $attr) {
                        $attr = &$rdn[$i];
                        if (is_array($attr['value'])) {
                            foreach ($attr['value'] as $type => $v) {
                                $type = array_search($type, $asn1->ANYmap, true);
                                if ($type !== false && isset($asn1->stringTypeSize[$type])) {
                                    $v = $asn1->convert($v, $type);
                                    if ($v !== false) {
                                        $v = preg_replace('/\s+/', ' ', $v);
                                        $attr['value'] = strtolower(trim($v));
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    $result .= $asn1->encodeDER($rdn, $this->RelativeDistinguishedName);
                }
                return $result;
            case self::DN_HASH:
                $dn = $this->getDN(self::DN_CANON, $dn);
                $hash = new Hash('sha1');
                $hash = $hash->hash($dn);
                extract(unpack('Vhash', $hash));
                return strtolower(bin2hex(pack('N', $hash)));
        }

        // Default is to return a string.
        $start = true;
        $output = '';

        $result = array();
        $asn1 = new ASN1();
        $asn1->loadOIDs($this->oids);
        $filters = array();
        $filters['rdnSequence']['value'] = array('type' => ASN1::TYPE_UTF8_STRING);
        $asn1->loadFilters($filters);
        $this->_mapOutDNs($dn, 'rdnSequence', $asn1);

        foreach ($dn['rdnSequence'] as $field) {
            $prop = $field[0]['type'];
            $value = $field[0]['value'];

            $delim = ', ';
            switch ($prop) {
                case 'id-at-countryName':
                    $desc = 'C';
                    break;
                case 'id-at-stateOrProvinceName':
                    $desc = 'ST';
                    break;
                case 'id-at-organizationName':
                    $desc = 'O';
                    break;
                case 'id-at-organizationalUnitName':
                    $desc = 'OU';
                    break;
                case 'id-at-commonName':
                    $desc = 'CN';
                    break;
                case 'id-at-localityName':
                    $desc = 'L';
                    break;
                case 'id-at-surname':
                    $desc = 'SN';
                    break;
                case 'id-at-uniqueIdentifier':
                    $delim = '/';
                    $desc = 'x500UniqueIdentifier';
                    break;
                case 'id-at-postalAddress':
                    $delim = '/';
                    $desc = 'postalAddress';
                    break;
                default:
                    $delim = '/';
                    $desc = preg_replace('#.+-([^-]+)$#', '$1', $prop);
            }

            if (!$start) {
                $output.= $delim;
            }
            if (is_array($value)) {
                foreach ($value as $type => $v) {
                    $type = array_search($type, $asn1->ANYmap, true);
                    if ($type !== false && isset($asn1->stringTypeSize[$type])) {
                        $v = $asn1->convert($v, $type);
                        if ($v !== false) {
                            $value = $v;
                            break;
                        }
                    }
                }
                if (is_array($value)) {
                    $value = array_pop($value); // Always strip data type.
                }
            } elseif (is_object($value) && $value instanceof Element) {
                $callback = function ($x) {
                    return "\x" . bin2hex($x[0]);
                };
                $value = strtoupper(preg_replace_callback('#[^\x20-\x7E]#', $callback, $value->element));
            }
            $output.= $desc . '=' . $value;
            $result[$desc] = isset($result[$desc]) ?
                array_merge((array) $dn[$prop], array($value)) :
                $value;
            $start = false;
        }

        return $format == self::DN_OPENSSL ? $result : $output;
    }
468495
public function getDbName()
    {
        // Special handler for "NULL" relations
        if ($this->name === "NULL") {
            return $this->name;
        }

        // Ensure that we're dealing with a DataObject.
        if (!is_subclass_of($this->model, DataObject::class)) {
            throw new InvalidArgumentException(
                "Model supplied to " . static::class . " should be an instance of DataObject."
            );
        }
        $tablePrefix = DataQuery::applyRelationPrefix($this->relation);
        $schema = DataObject::getSchema();

        if ($this->aggregate) {
            $column = $this->aggregate['column'];
            $function = $this->aggregate['function'];

            $table = $column ?
                $schema->tableForField($this->model, $column) :
                $schema->baseDataTable($this->model);

            if (!$table) {
                throw new InvalidArgumentException(sprintf(
                    'Invalid column %s for aggregate function %s on %s',
                    $column,
                    $function,
                    $this->model
                ));
            }
            return sprintf(
                '%s("%s%s".%s)',
                $function,
                $tablePrefix,
                $table,
                $column ? "\"$column\"" : '"ID"'
            );
        }


        // Check if this column is a table on the current model
        $table = $schema->tableForField($this->model, $this->name);
        if ($table) {
            return $schema->sqlColumnForField($this->model, $this->name, $tablePrefix);
        }

        // fallback to the provided name in the event of a joined column
        // name (as the candidate class doesn't check joined records)
        $parts = explode('.', $this->fullName);
        return '"' . implode('"."', $parts) . '"';
    }
1137360
protected function getDatabaseName()
    {
        // Check globals
        global $database;

        if (!empty($database)) {
            return $this->getDatabasePrefix() . $database . $this->getDatabaseSuffix();
        }

        global $databaseConfig;

        if (!empty($databaseConfig['database'])) {
            return $databaseConfig['database']; // Note: Already includes prefix
        }

        // Check environment
        $database = Environment::getEnv('SS_DATABASE_NAME');

        if ($database) {
            return $this->getDatabasePrefix() . $database . $this->getDatabaseSuffix();
        }

        // Auto-detect name
        $chooseName = Environment::getEnv('SS_DATABASE_CHOOSE_NAME');

        if ($chooseName) {
            // Find directory to build name from
            $loopCount = (int)$chooseName;
            $databaseDir = $this->basePath;
            for ($i = 0; $i < $loopCount-1; $i++) {
                $databaseDir = dirname($databaseDir);
            }

            // Build name
            $database = str_replace('.', '', basename($databaseDir));
            $prefix = $this->getDatabasePrefix();

            if ($prefix) {
                $prefix = 'SS_';
            } else {
                // If no prefix, hard-code prefix into database global
                $prefix = '';
                $database = 'SS_' . $database;
            }

            return $prefix . $database;
        }

        // no DB name (may be optional for some connectors)
        return null;
    }
451719
public function dsql()
    {
        $dsql = $this->owner->persistence->initQuery($this->owner);
        $dsql->reset('table');
        $dsql->table($this->foreign_table, $this->foreign_alias);

        return $dsql;
    }
1365233
public function
	GetDSN() {
	/*//
	@type string
	get the connection dsn string for this database connection.
	//*/

		switch(strtolower($this->Type)) {
			case 'mysql': return sprintf(
				'%s:host=%s;dbname=%s;charset=%s',
				$this->Type,
				$this->Hostname,
				$this->Database,
				$this->Charset
			);
			case 'sqlite': return sprintf(
				'%s:%s',
				$this->Type,
				$this->Database
			);
			default: return sprintf(
				'%s:host=%s;dbname=%s, %s, %s;charset=%s',
				$this->Type,
				$this->Hostname,
				$this->Database,
				$this->Username,
				$this->Password,
				$this->Charset
			);
		}
	}
884070
protected function getDSN():string {
		$dsn = $this->drivername.':dbname=';

		if($this->options->host !== null){
			$dsn .= $this->options->host;

			if(is_numeric($this->options->port)){
				$dsn .= '/'.$this->options->port;
			}

			$dsn .= ':';
		}

		$dsn .= $this->options->database;

		if($this->options->firebird_encoding !== null){
			$dsn .= ';encoding='.$this->options->firebird_encoding;
		}

		return $dsn;
	}
206716
public function getDsn()
    {
        if ($this->checkParam()) {
            $sDsn = 'sqlite:';
            if ($this->getMemory() === true) {
                $sDsn .= ':memory:';
            } else {
                $sDsn .= $this->getDatabase();
            }
            return $sDsn;
        } else {
            return false;
        }
    }
984332
public function getDsn($p)
    {
        $this->engine = isset($p['engine']) ? $p['engine'] : $this->engine;
        return $this->engine . ':dbname=' . $p['database'] . ';host=' . $p['host'] . ';charset=' . (isset($p['charset']) ? $p['charset'] : 'utf8');
    }
1137206
public function getConnectionString(){
        $connection_string = array();

        $type = $this->getType();
        array_push($connection_string, $type);

        if($type == self::SQLite){
        	$filename = 'db.sqlite';
        	if(isset($this->properties['filename']))
        		$filename = $this->properties['filename'];
        	array_push($connection_string, ":$filename");
        }
        else {
	        array_push($connection_string, ':host=');
	        array_push($connection_string,
	            (isset($this->properties['host']))?
	            $this->properties['host']:'localhost'
	        );
	        array_push($connection_string, ';dbname=');
	        array_push($connection_string,
	            (isset($this->properties['name']))?
	            $this->properties['name']:null
	        );
        }
        
        array_push($connection_string, ';charset=');
        array_push($connection_string, $this->getCharset());
        return implode($connection_string);
    }
589367
protected function _dsn()
    {
        // baseline of DSN parts
        $dsn = $this->_config;

        // don't pass the username, password, charset, persistent and driver_options in the DSN
        unset($dsn['username']);
        unset($dsn['password']);
        unset($dsn['options']);
        unset($dsn['charset']);
        unset($dsn['persistent']);
        unset($dsn['driver_options']);

        // use all remaining parts in the DSN
        foreach ($dsn as $key => $val) {
            $dsn[$key] = "$key=$val";
        }

        return $this->_pdoType . ':' . implode(';', $dsn);
    }