parse db settings

@deprecated will be replaced by datasource settings

@param DOMNode $db
559418
private function parseDbSettings(\DOMNode $db) {

		$context = $this->isLocalhost ? 'local' : 'remote';
		$xpath = new \DOMXPath($db->ownerDocument);

		$d = $xpath->query("db_connection[@context='$context']", $db);
		
		if(!$d->length) {
			$d = $db->getElementsByTagName('db_connection');
		}

		if($d->length) {
			$this->db = new \stdClass();

			foreach($d->item(0)->childNodes as $node) {

				if($node->nodeType !== XML_ELEMENT_NODE) {
					continue;
				}

				$v = trim($node->nodeValue);
				$k = $node->nodeName;

				$this->db->$k = $v;

			}
		}

	}
818279
public function setDbName($dbName = null)
    {
        $this->dbName = ($dbName === null ? Propel::getDefaultDB() : $dbName);
    }
1315916
protected function setDB (\Native5\Core\Database\DB $db) {
        if (empty($db))
            throw new \InvalidArgumentException("Emoty DB object received");

        $this->db = $db;
    }
502678
function DB()
	{
	global $_ADODB_ACTIVE_DBS;

		if ($this->_dbat < 0) {
			$false = false;
			$this->Error("No database connection set: use ADOdb_Active_Record::SetDatabaseAdaptor(\$db)", "DB");
			return $false;
		}
		$activedb = $_ADODB_ACTIVE_DBS[$this->_dbat];
		$db = $activedb->db;
		return $db;
	}
1102937
private function parseDatasources(\DOMXPath $xpath, \DOMNode $typeRootNode)
    {
        $datasources = [];

        foreach ($xpath->query(self::DATASOURCES_PATH, $typeRootNode) as $datasourceNode) {
            $datasources[$datasourceNode->getAttribute('name')] = $datasourceNode->nodeValue;
        }

        return $datasources;
    }
953270
public function setDatabase($database)
    {
        if (is_string($database)) {
            $database = $this->db->getDatabase($database);
        }

        $this->database = $database;

        return $this;
    }
1118369
static public function setdown($db=null, $table=null) {
		$self = get_called_class();
		if (is_null($db) || is_null($table))
			$df = $self::resolveConfiguration();
		if (!is_object($db=(is_string($db=($db?:$df['db']))?\Base::instance()->get($db):$db)))
			trigger_error(self::E_CONNECTION,E_USER_ERROR);
		if (strlen($table=strtolower($table?:$df['table']))==0)
			trigger_error(self::E_NO_TABLE,E_USER_ERROR);
		if (isset($df) && !empty($df['fieldConf']))
			$fields = $df['fieldConf'];
		else
			$fields = array();
		$deletable = array();
		$deletable[] = $table;
		foreach ($fields as $key => $field) {
			$field = static::resolveRelationConf($field);
			if (array_key_exists('has-many',$field)) {
				if (!is_array($relConf = $field['has-many']))
					continue;
				$rel = $relConf[0]::resolveConfiguration();
				// check if foreign conf matches m:m
				if (array_key_exists($relConf[1],$rel['fieldConf']) && !is_null($relConf[1])
					&& key($rel['fieldConf'][$relConf[1]]) == 'has-many') {
					// compute mm table name
					$deletable[] = isset($relConf[2]) ? $relConf[2] :
						static::getMMTableName(
							$rel['table'], $relConf[1], $table, $key,
							$rel['fieldConf'][$relConf[1]]['has-many']);
				}
			}
		}

		if($db instanceof Jig) {
			/** @var Jig $db */
			$dir = $db->dir();
			foreach ($deletable as $item)
				if(file_exists($dir.$item))
					unlink($dir.$item);
		} elseif($db instanceof SQL) {
			/** @var SQL $db */
			$schema = new Schema($db);
			$tables = $schema->getTables();
			foreach ($deletable as $item)
				if(in_array($item, $tables))
					$schema->dropTable($item);
		} elseif($db instanceof Mongo) {
			/** @var Mongo $db */
			foreach ($deletable as $item)
				$db->selectCollection($item)->drop();
		}
	}
151762
function parseDB(callback) {
    pgStructure(getConfig('database.host'), getConfig('database.database'), getConfig('database.user'),
        getConfig('database.password'), { port: getConfig('database.port'), schema: getConfig('database.schema') },
        callback);
}
1123814
public function setDbo(&$db)
	{
		if (!($db instanceof \Hubzero\Database\Driver))
		{
			return false;
		}

		$this->_db = $db;
		$this->_tbl->setDBO($this->_db);

		return true;
	}
584428
protected function db($db = '')
    {
        $db = $db ? $db : $this->use_db;

        return Connection::getInstance($db);
    }
1270431
def _parse_canonical_dbpointer(doc):
    """"""
    dbref = doc['$dbPointer']
    if len(doc) != 1:
        raise TypeError('Bad $dbPointer, extra field(s): %s' % (doc,))
    if isinstance(dbref, DBRef):
        dbref_doc = dbref.as_doc()
        # DBPointer must not contain $db in its value.
        if dbref.database is not None:
            raise TypeError(
                'Bad $dbPointer, extra field $db: %s' % (dbref_doc,))
        if not isinstance(dbref.id, ObjectId):
            raise TypeError(
                'Bad $dbPointer, $id must be an ObjectId: %s' % (dbref_doc,))
        if len(dbref_doc) != 2:
            raise TypeError(
                'Bad $dbPointer, extra field(s) in DBRef: %s' % (dbref_doc,))
        return dbref
    else:
        raise TypeError('Bad $dbPointer, expected a DBRef: %s' % (doc,))
44754
public static function setDbType($dbType) {
        $dbTypeCast = (string) $dbType;
        
        if (array_search($dbTypeCast, self::$dbList) === false) {
            throw new DBException('Illegal database type provided to DB Service');
        }
        
        self::$dbType = $dbTypeCast;
    }
1053584
function _DBParameter($sql)
	{
		$savelog = $this->conn->LogSQL(false);
		if (is_array($sql)) {
		global $ADODB_FETCH_MODE;

			$sql1 = $sql[0];
			$key = $sql[1];
			if (sizeof($sql)>2) $pos = $sql[2];
			else $pos = 1;
			if (sizeof($sql)>3) $coef = $sql[3];
			else $coef = false;
			$ret = false;
			$save = $ADODB_FETCH_MODE;
			$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
			if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false);

			$rs = $this->conn->Execute($sql1);

			if (isset($savem)) $this->conn->SetFetchMode($savem);
			$ADODB_FETCH_MODE = $save;
			if ($rs) {
				while (!$rs->EOF) {
					$keyf = reset($rs->fields);
					if (trim($keyf) == $key) {
						$ret = $rs->fields[$pos];
						if ($coef) $ret *= $coef;
						break;
					}
					$rs->MoveNext();
				}
				$rs->Close();
			}
			$this->conn->LogSQL($savelog);
			return $ret;
		} else {
			if (strncmp($sql,'=',1) == 0) {
				$fn = substr($sql,1);
				return $this->$fn();
			}
			$sql = str_replace('$DATABASE',$this->conn->database,$sql);
			$ret = $this->conn->GetOne($sql);
			$this->conn->LogSQL($savelog);

			return $ret;
		}
	}
310540
protected function initGlobalDatabaseElement($database)
    {
        if (\in_array($database, $this->databases)) {
            return;
        }

        $databaseDocument = new \DOMDocument(static::$GLOBAL_SCHEMA_XML_VERSION, static::$GLOBAL_SCHEMA_XML_ENCODING);

        $databaseElement = $databaseDocument->createElement('database');

        $databaseElement->setAttribute('name', $database);

        $identifierQuotingNoticeComment = $databaseElement->ownerDocument->createComment(
            "Attribute 'identifierQuoting' generated"
        );
        $databaseElement->appendChild($identifierQuotingNoticeComment);
        $databaseElement->setAttribute('identifierQuoting', 'true');

        $databaseDocument->appendChild($databaseElement);

        $this->databases[] = $database;
        $this->globalDatabaseElements[$database] = $databaseElement;
        $this->sourceDatabaseElements[$database] = [];
        $this->externalSchemaDatabaseElements[$database] = [];
    }
1287157
private function updateDatabase()
    {
        set_time_limit(0);
        $blog = $this->db->insert('blog', array('page', 'path', 'title', 'featured', 'published', 'updated', 'author_id', 'category_id', 'search', 'content'));
        $tagged = $this->db->insert('tagged', array('blog_id', 'tag_id'));
        $sitemap = new Sitemap();
        $sitemap->reset('blog');
        $this->normalizeFolders();
        $finder = new Finder();
        $finder->files()->in($this->folder.'content')->name('index.html.twig')->sortByName();
        foreach ($finder as $file) {
            if ($info = $this->blogInfo(str_replace('\\', '/', $file->getRelativePath()))) {
                $id = $this->db->insert($blog, array_values($info));
                $page = unserialize($info['page']);
                if (isset($page['keywords']) && !empty($page['keywords'])) {
                    $tags = array_filter(array_map('trim', explode(',', $page['keywords'])));
                    foreach ($tags as $tag) {
                        $this->db->insert($tagged, array($id, $this->getId('tags', $tag)));
                    }
                }
                $category = 'blog';
                if ($info['category_id'] > 0) {
                    $category .= '/'.array_search($info['category_id'], $this->ids['categories']);
                }
                if ($info['search']) {
                    $sitemap->upsert($category, array(
                        'id' => $id,
                        'path' => $info['path'],
                        'title' => $info['title'],
                        'description' => (isset($page['description'])) ? (string) $page['description'] : '',
                        'keywords' => (isset($page['keywords'])) ? (string) $page['keywords'] : '',
                        'image' => (isset($page['image'])) ? (string) $page['image'] : '',
                        'content' => $info['content'],
                        'updated' => $info['updated'],
                    ));
                }
            }
        }
        $sitemap->delete();
        unset($sitemap);
        $this->db->close($blog);
        $this->db->close($tagged);
        $this->updateConfig();
    }
832341
public function configure( DbAdapter $db )
    {
        $sm         = $this->getServiceLocator();
        $platform   = $db->getPlatform();
        $driver     = $db->getDriver();
        $matches    = array();
        $fulldomain = strtolower( $this->getDomain() );
        $config     = $driver->getConnection()
                             ->getConnectionParameters();

        /// TODO: remove this
        if ( isset( $_SERVER['GRIDGUYZ_DOMAIN'] ) )
        {
            $domain     = $_SERVER['GRIDGUYZ_DOMAIN'];
            $subdomain  = isset( $_SERVER['GRIDGUYZ_SUBDOMAIN'] )
                        ? $_SERVER['GRIDGUYZ_SUBDOMAIN']
                        : '';
        }
        elseif ( preg_match( '/^[\da-fA-F:]+/', $fulldomain ) ||    // probably ipv6
                 preg_match( '/^\d+(\.\d+){3}$/', $fulldomain ) )   // ipv4
        {
            $subdomain  = '';
            $domain     = $fulldomain;
        }
        else
        {
            $fullLength = strlen( $fulldomain );

            if ( empty( $config['validDomains'] ) )
            {
                $validDomains = array( 'localhost' );
            }
            else
            {
                $validDomains = array_map(
                    'strtolower',
                    (array) $config['validDomains']
                );
            }

            if ( ! empty( $config['defaultDomain'] ) )
            {
                $defaultDomain = strtolower( $config['defaultDomain'] );

                if ( ! in_array( $defaultDomain, $validDomains ) )
                {
                    array_unshift( $validDomains, $defaultDomain );
                }
            }

            foreach ( $validDomains as $validDomain )
            {
                if ( $fulldomain == $validDomain )
                {
                    $subdomain  = '';
                    $domain     = $fulldomain;
                    break;
                }

                $length = $fullLength - strlen( $validDomain ) - 1;

                if ( $length > 0 &&
                     ( '.' . $validDomain ) == substr( $fulldomain, $length ) )
                {
                    $subdomain  = substr( $fulldomain, 0, $length );
                    $domain     = $validDomain;
                    break;
                }
            }
        }

        if ( ! isset( $subdomain ) || ! isset( $domain ) )
        {
            if ( preg_match( '/^(.+)\.([a-z0-9-]+\.[a-z]+)$/', $fulldomain, $matches ) )
            {
                $subdomain  = $matches[1];
                $domain     = $matches[2];
            }
            else
            {
                $subdomain  = '';
                $domain     = $fulldomain;
            }
        }

        $query = $db->query( '
            SELECT *
              FROM ' . $platform->quoteIdentifier( 'subdomain' ) . '
             WHERE LOWER( ' . $platform->quoteIdentifier( 'subdomain' ) . ' )
                 = LOWER( ' . $driver->formatParameterName( 'subdomain' ) . ' )
        ' );

        $result = $query->execute( array(
            'subdomain' => $subdomain
        ) );

        if ( $result->getAffectedRows() > 0 )
        {
            $schema = $db->getCurrentSchema();

            foreach ( $result as $data )
            {
                $info = new SiteInfo( array(
                    'schema'        => $schema,
                    'domain'        => $domain,
                    'subdomain'     => $subdomain,
                    'subdomainId'   => $data['id'],
                    'fulldomain'    => $fulldomain,
                    'scheme'        => $this->getScheme(),
                    'port'          => $this->getPort(),
                ) );

                $sm->setService( 'SiteInfo', $info );
                return $db;
            }
        }
        else if ( $domain )
        {
            $sm->setService(
                'RedirectToDomain',
                new RedirectionService(
                    $this->getScheme(),
                    $domain,
                    $this->getPort(),
                    'sub-domain not found',
                    false
                )
            );
        }
        else
        {
            if ( empty( $config['defaultDomain'] ) )
            {
                throw new Exception\InvalidArgumentException(
                    'Domain not found, and default domain not set'
                );
            }
            else
            {
                $sm->setService(
                    'RedirectToDomain',
                    new RedirectionService(
                        $this->getScheme(),
                        $config['defaultDomain'],
                        $this->getPort(),
                        'sub-domain not found',
                        false
                    )
                );
            }
        }

        return $db;
    }
643120
protected function parseBind($sql)
    {
        //$sql = str_replace('%'.$key.'%', $this->parseOptionsItem($key, $this->query[$key]), $sql);
        if (!empty($this->query['bind'])) {
            $count = 1;
            foreach ($this->query['bind'] as $v) {
                if (is_array($v)) {
                    $sql = str_replace($v[0], $this->formatValue($v[1]), $sql, $count);
                } else {
                    $sql = str_replace('?', $this->formatValue($v), $sql, $count);
                }
            }
        }
        return $sql;
    }