Allocates a database connection.

@throws SQLException
161430
private void allocateConnection() throws SQLException
   {
      if (m_connection == null)
      {
         m_connection = m_dataSource.getConnection();
         m_allocatedConnection = true;
         queryDatabaseMetaData();
      }
   }
750581
protected function _refresh()
    {
        $this->_statement->execute($this->_params);
        if ($this->_statement->errorCode() !== '00000') {
            throw new DbException($this->_statement->errorInfo(), $this->_statement->queryString);
        }
        $this->_currentRowIndex = 0;
    }
169880
public void free() throws SQLException
    {
        if (freed)
        {
            return;
        }

        string = null;
        if (reader != null)
        {
            reader.close();
        }
        if (inputStream != null)
        {
            try
            {
                inputStream.close();
            }
            catch (IOException ioe)
            {
                // Do nothing
            }
        }
        freed = true;
    }
135423
Connection getConnection() throws SQLException {
		if (connection == null) {
			connection = connectionSupplier.getConnection();
			initSavepoints(connection);
		}
		return connection;
	}
1093688
protected final void doInsert(Connection c) throws SQLException {
		PreparedStatement stmt = null;
		try {
			stmt = c.prepareStatement("insert into foo values (?, ?)  ");
			stmt.setInt(1, rand.nextInt(99999));
			stmt.setString(2, "This is a text");
			stmt.executeUpdate();
		} finally {
			if (stmt != null) {
				stmt.close();
			}
		}
	}
1033160
public function getConnection()
    {
        if (empty($this->connection)) {

            if (empty($this->connectionConfig) || !is_array($this->connectionConfig))
                throw new DatabaseException("Connection config is empty or not an array.");

            $connCount = count($this->connectionConfig);
            for($i = 0; $i < $connCount; ++$i)
            {
                $connectionInfo = $this->connectionConfig[$i];

                if (empty($connectionInfo['port']))
                    $connectionInfo['port'] = 3306;

                $dsn = "mysql:dbname={$connectionInfo['database']};host={$connectionInfo['host']};port={$connectionInfo['port']}";
                if (!empty($connectionInfo['unix_socket']))
                    $dsn .= ';unix_socket='.$connectionInfo['unix_socket'];

                try {

                    $trx_attempt = 0;
                    while ($trx_attempt < $this->deadlockRetries) {

                        try {

                            $this->connection = new PDO($dsn, $connectionInfo['username'], $connectionInfo['password'], array(
                                PDO::ATTR_PERSISTENT => (!empty($connectionInfo['persistent'])?StringUtils::strToBool($connectionInfo['persistent']):false),
                                PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                                PDO::ATTR_CASE => PDO::CASE_NATURAL,
                                PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
                                PDO::MYSQL_ATTR_DIRECT_QUERY => true,
                                PDO::ATTR_TIMEOUT => (!empty($connectionInfo['timeout'])?$connectionInfo['timeout']:30) ));


                            $this->connDebugString = $connectionInfo['host'].':'.$connectionInfo['database'];
                            $this->currentDBName = $connectionInfo['database'];

                            $this->Logger->debug(array(
                                'SQL'                    => 'CONNECTION - DB: '.$this->connDebugString,
                            ));

                            return $this->connection;

                        } catch (PDOException $pe) {
                            if ((strpos($pe->getMessage(), 'Too many connections') !== FALSE) && ++$trx_attempt < $this->deadlockRetries)
                            {
                                usleep( pow(2,$trx_attempt) * 100000 );
                                continue;
                            }

                            throw $pe;
                        }
                    }

                } catch(PDOException $pe)
                {

                    // if the last connection fails
                    if($i == ($connCount-1))
                        throw new SQLConnectionException($pe->getMessage());
                }
            }
        }

        return $this->connection;
    }
584315
protected void openConnection() throws SQLException {
        if (connection == null) {
            try {
                Class.forName(configuration.getJdbcDriver());
            } catch (NullPointerException npe) {
                throw new RuntimeException("error while lookup jdbc driver class. jdbc driver is not configured.", npe);
            } catch (ClassNotFoundException e) {
                throw new RuntimeException("jdbc driver not found", e);
            }

            connection = DriverManager.getConnection(configuration.getJdbcUrl(), configuration.getJdbcUser(),
                    configuration.getJdbcPassword());
            connection.setAutoCommit(false);
        }
    }
1128551
public static function initializeDatabaseConnections()
    {
        // for backward compatibility, don't use MAX_DB_CONNECTION_INDEX directly,
        // but check if MAX_DB_CONNECTION_INDEX is defined
        $intMaxIndex = defined('MAX_DB_CONNECTION_INDEX') ? constant('MAX_DB_CONNECTION_INDEX') : 9;

        if (defined('DB_CONNECTION_0')) {
            // This causes a conflict with how DbBackedSessionHandler works.
            throw new \Exception('Do not define DB_CONNECTION_0. Start at DB_CONNECTION_1');
        }

        for ($intIndex = 1; $intIndex <= $intMaxIndex; $intIndex++) {
            $strConstantName = sprintf('DB_CONNECTION_%s', $intIndex);

            if (defined($strConstantName)) {
                // Expected Keys to be Set
                $strExpectedKeys = array(
                    'adapter',
                    'server',
                    'port',
                    'database',
                    'username',
                    'password',
                    'profiling',
                    'dateformat'
                );

                // Lookup the Serialized Array from the DB_CONFIG constants and unserialize it
                $strSerialArray = constant($strConstantName);
                $objConfigArray = unserialize($strSerialArray);

                // Set All Expected Keys
                foreach ($strExpectedKeys as $strExpectedKey) {
                    if (!array_key_exists($strExpectedKey, $objConfigArray)) {
                        $objConfigArray[$strExpectedKey] = null;
                    }
                }

                if (!$objConfigArray['adapter']) {
                    throw new \Exception('No Adapter Defined for ' . $strConstantName . ': ' . var_export($objConfigArray,
                            true));
                }

                if (!$objConfigArray['server']) {
                    throw new \Exception('No Server Defined for ' . $strConstantName . ': ' . constant($strConstantName));
                }

                $strDatabaseType = 'QCubed\\Database\\' . $objConfigArray['adapter'] . '\\Database';

                //if (!class_exists($strDatabaseType)) {
                //	throw new \Exception('Database adapter was not found: ' . $objConfigArray['adapter']);
                //}

                self::$Database[$intIndex] = new $strDatabaseType($intIndex, $objConfigArray);
            }
        }
    }
1366724
protected function useConfiguredDatabase()
    {
        try {
            $this->getDbConnection()->exec('USE `' . $this->getDbName() . '`');
        } catch (Exception $e) {
            throw new Exception("Could not connect to database " . $this->getDbName());
        }
    }
246634
public void preExecute() throws SQLException {
    lastQueryNanos = System.nanoTime();
    //if connection is closed or failed on slave
    if (this.currentProtocol != null && this.currentProtocol.isClosed()) {
      preAutoReconnect();
    }
  }
450945
public function loadCount()
    {
        $query = $this->source()->sqlLoadCount();

        $db = $this->source()->db();
        if (!$db) {
            throw new RuntimeException(
                'Could not instanciate a database connection.'
            );
        }
        $this->logger->debug($query);

        $sth = $db->prepare($query);
        $sth->execute();
        $res = $sth->fetchColumn(0);

        return (int)$res;
    }
1335791
public int deleteAll() throws SQLException {

		DeleteBuilder<Extensions, Void> db = deleteBuilder();
		int deleted = db.delete();

		return deleted;
	}
398140
private Connection getConnection() throws SQLException {
        return JDBC.connect(model.getDriver(), model.getUrl(),
                            model.getUser(), model.getPassword());

    }
678452
protected void setUp() throws SQLException {
		Connection c = null;
		try {
			c = DriverManager.getConnection("jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1");
			Statement stmt = c.createStatement();
			stmt.execute("create table foo (id number(6), dsc varchar2(256))");
			stmt.close();
		} finally {
			if (c != null) {
				c.close();
			}
		}
	}
224007
private void doClose() throws SQLException {
		try {
			if (batch) {
				doFlush();
			}
		} finally {
			if (lostCount > 0) {
				InternalLogger.log(Level.ERROR, "Lost log entries due to broken database connection: " + lostCount);
			}

			if (connection != null) {
				connection.close();
			}
		}
	}
982072
public void reset() throws SQLException {

        try {
            this.sessionProxy.resetSession();
        } catch (HsqlException e) {
            throw Util.sqlException(ErrorCode.X_08006, e.getMessage(), e);
        }
    }
48818
public void clear() throws SQLException {
        clearStatements();
        statements.clear();
        parameterSets.clear();
        connections.clear();
        resultSets.clear();
        executeGroups.clear();
    }