Throws an exception on db error or db connect error
8169
private function AssertSuccess()
    {
        if ($this->db)
        {
            if ($this->IsConnected())
            {
                $errorCode = $this->db->errno;
                if ($errorCode != 0)
                {
                    if ($this->inTransaction)
                        $this->RollBack();

                    throw new DBExceptions\DatabaseException($this->db->error, $errorCode, $this->lastQuery);
                }
            }
            else
            {
                $errorCode = $this->db->connect_errno;
                if ($errorCode != 0)
                {
                    throw new DBExceptions\DatabaseException($this->db->connect_error, $errorCode);
                }
            }
        }
    }
345011
protected function _handleDbConnectionException(\OxidEsales\Eshop\Core\Exception\DatabaseException $exception)
    {
        $exceptionHandler = $this->getExceptionHandler();
        $exceptionHandler->handleDatabaseException($exception);
    }
773958
private void executeOperation(DbUnitDatabasePopulator populator, DataSource dataSource) throws Exception {

        Connection connection = null;

        try {
            connection = getConnection(dataSource);
            populator.populate(connection);

        } finally {
            if (connection != null && !isConnectionTransactional(connection, dataSource)) {
                // if the connection is transactional, closing it. Otherwise,
                // expects that the framework will do it
                releaseConnection(connection, dataSource);
            }
        }
    }
1146921
ThrowableInformation getException(Connection connection, long id)
      throws SQLException {

    PreparedStatement statement = null;

    try {
      statement = connection.prepareStatement(sqlException);
      statement.setLong(1, id);
      ResultSet rs = statement.executeQuery();

      Vector v = new Vector();

      while (rs.next()) {
        //int i = rs.getShort(1);
        v.add(rs.getString(1));
      }

      int len = v.size();
      String[] strRep = new String[len];
      for (int i = 0; i < len; i++) {
        strRep[i] = (String) v.get(i);
      }
      // we've filled strRep, we now attach it to the event
      return new ThrowableInformation(strRep);
    } finally {
      if (statement != null) {
        statement.close();
      }
    }
  }
350511
def handle_database_error(cls, session, exception):
        """"""

        session.rollback()

        if isinstance(exception, IntegrityError):
            cls.handle_integrity_error(exception)
        elif isinstance(exception, FlushError):
            cls.handle_flush_error(exception)
        else:
            raise exception
816657
public void connect() throws Exception {
        if (connection != null && !connection.isConnected()) {
            connection.connect();
            transaction = connection.getModbusTransport().createTransaction();
            setTransaction(transaction);
        }
    }
296727
public function check()
	{
		// Check if the db connector has been set.
		if (!($this->db instanceof MysqliDriver))
		{
			throw new \Exception('Database connection wrong type.');
		}

		// Check if the tables have been specified.
		if (empty($this->from))
		{
			throw new \Exception('ERROR: No Tables Specified');
		}

		return $this;
	}
189924
public static SQLException unwrapSQLException(Throwable throwable) {
        if (throwable == null) {
            return null;
        } else if (throwable instanceof SQLException) {
            return (SQLException) throwable;
        } else if (throwable.getCause() != null) {
            // recursive call to unwrap the cause
            return unwrapSQLException(throwable.getCause());
        } else {
            // didn't find any SQLException in the cause stack
            return null;
        }
    }
602342
public function init() {
        if (VERBOSE) echo 'INIT:' ,PHP_EOL;
        if (VERBOSE) echo ' CONNECTING API' ,PHP_EOL;
        $this->api->auth();
        if (VERBOSE) echo ' API CONNECTED' ,PHP_EOL;
        if (VERBOSE) echo ' CONNECTING SQL' ,PHP_EOL;
        $this->db->connect();
        if (VERBOSE) echo ' SQL CONNECTED' ,PHP_EOL;
        if (VERBOSE) echo ' CHECKING PATHS' ,PHP_EOL;
        if (DEBUG) echo '  CHECKING TMP DIR AT : '.$this->tmp_dir ,PHP_EOL;
        if (!file_exists($this->tmp_dir)) {
            throw new Exception("Path for 'tmp_dir' not found at '".$this->tmp_dir."'!");
        }
        if (DEBUG) echo '  CHECKING DUMP DIR AT : '.$this->dumps_dir ,PHP_EOL;
        if (!file_exists($this->dumps_dir)) {
            throw new Exception("Path for 'dumps_dir' not found at '".$this->dumps_dir."'!");
        }
        if (VERBOSE) echo ' PATHS FOUND' ,PHP_EOL;
    }
1198483
function handleDisconnect() {
    _connection = _mysql.createConnection(_dbConfig);

    _connection.connect(function (err) {
        if (err) {
            console.log('error when connecting to db:', err);
            setTimeout(handleDisconnect, 2000);
        }
    });

    _connection.on('error', function (err) {
        console.log('db error', err);
        if (err.code === 'PROTOCOL_CONNECTION_LOST') {
            handleDisconnect();
        } else {
            throw err;
        }
    });
}
852040
function logQueryError (dbQueryId, options, err) {
    // require log client
    if (!this.logClient) {
        return
    }
    // do not log if query options flag is false
    if (options.log === false) {
        return
    }
    // log error
    this.logClient.log('dbResponse', {
        data: {
            code: err.code,
            isOperational: err.isOperational,
            message: err.message,
        },
        dbQueryId: dbQueryId.id,
        dbResponseSuccess: false,
        dbResponseCreateTime: microTimestamp(),
    })
}
1326523
private void doExecute(Connection conn) throws SQLException
    {
        PreparedStatement stmt;
        int size;

        size = _methods.size();
        if ( size == 0 )
        {
            return;
        }
        stmt = conn.prepareStatement(_sql);
        try
        {
            m_platform.afterStatementCreate(stmt);
        }
        catch ( PlatformException e )
        {
            if ( e.getCause() instanceof SQLException )
            {
                throw (SQLException)e.getCause();
            }
            else
            {
                throw new SQLException(e.getMessage());
            }
        }
        try
        {
            m_platform.beforeBatch(stmt);
        }
        catch ( PlatformException e )
        {
            if ( e.getCause() instanceof SQLException )
            {
                throw (SQLException)e.getCause();
            }
            else
            {
                throw new SQLException(e.getMessage());
            }
        }
        try
        {
            for ( int i = 0; i < size; i++ )
            {
                Method method = (Method) _methods.get(i);
                try
                {
                    if ( method.equals(ADD_BATCH) )
                    {
                        /**
                         * we invoke on the platform and pass the stmt as an arg.
                         */
                        m_platform.addBatch(stmt);
                    }
                    else
                    {
                        method.invoke(stmt, (Object[]) _params.get(i));
                    }
                }
                catch (IllegalArgumentException ex)
                {
					StringBuffer buffer = generateExceptionMessage(i, stmt, ex);
					throw new SQLException(buffer.toString());
                }
                catch ( IllegalAccessException ex )
                {
					StringBuffer buffer = generateExceptionMessage(i, stmt, ex);
                    throw new SQLException(buffer.toString());
                }
                catch ( InvocationTargetException ex )
                {
                    Throwable th = ex.getTargetException();

                    if ( th == null )
                    {
                        th = ex;
                    }
                    if ( th instanceof SQLException )
                    {
                        throw ((SQLException) th);
                    }
                    else
                    {
                        throw new SQLException(th.toString());
                    }
                }
				catch (PlatformException e)
				{
					throw new SQLException(e.toString());
				}
            }
            try
            {
                /**
                 * this will call the platform specific call
                 */
                m_platform.executeBatch(stmt);
            }
            catch ( PlatformException e )
            {
                if ( e.getCause() instanceof SQLException )
                {
                    throw (SQLException)e.getCause();
                }
                else
                {
                    throw new SQLException(e.getMessage());
                }
            }

        }
        finally
        {
            stmt.close();
            _methods.clear();
            _params.clear();
        }
    }
1150243
public static void init(SQLInputs sqlInputs) throws Exception {
        if (sqlInputs != null) {
            sqlInputs.setStrDelim(",");
            sqlInputs.setStrColumns("");
            sqlInputs.setLRows(new ArrayList<String>());
            sqlInputs.setIUpdateCount(0);
            sqlInputs.setSqlCommand(null);
            sqlInputs.setDbServer(null);
            sqlInputs.setDbName(null);
            sqlInputs.setDbType(null);
            sqlInputs.setUsername(null);
            sqlInputs.setPassword(null);
            sqlInputs.setAuthenticationType(null);
            sqlInputs.setDbUrl(null);
            sqlInputs.setDbClass(null);
            sqlInputs.setNetcool(false);
            sqlInputs.setLRowsFiles(new ArrayList<List<String>>());
            sqlInputs.setLRowsNames(new ArrayList<List<String>>());
            sqlInputs.setSkip(0L);
            sqlInputs.setInstance(null);
            sqlInputs.setTimeout(0);
            sqlInputs.setKey(null);
            sqlInputs.setIgnoreCase(false);
            sqlInputs.setResultSetConcurrency(-1000000);
            sqlInputs.setResultSetType(-1000000);
            sqlInputs.setTrustAllRoots(false);
            sqlInputs.setTrustStore("");
        } else throw new Exception("Cannot init null Sql inputs!");
    }
391939
public function check()
	{
		// Check if the db connector has been set.
		if (!($this->db instanceof PgsqlDriver))
		{
			throw new \Exception('Database connection wrong type.');
		}

		// Check if the tables have been specified.
		if (empty($this->from))
		{
			throw new \Exception('ERROR: No Tables Specified');
		}

		return $this;
	}
615996
public void open() throws DBException
    {
        if (m_JDBCConnection == null)
        {
            String strJdbcDriver = this.getProperty(SQLParams.JDBC_DRIVER_PARAM);
            if ((strJdbcDriver == null) || (strJdbcDriver.length() == 0))
            { // If a JDBC driver isn't specified, set up for the default driver
                String strDataSource = this.getProperty(SQLParams.DATASOURCE_PARAM);
                if (strDataSource == null)
                    strDataSource = this.getProperty(SQLParams.DEFAULT_DATASOURCE_PARAM);
                if (strDataSource == null)
                    strDataSource = SQLParams.DEFAULT_DATASOURCE;
                boolean bDataSourceConnection = false;
                if (strDataSource != null)
                    bDataSourceConnection = this.setupDataSourceConnection(strDataSource);

                String strDatabaseProductName = null;
                try {
					if (m_JDBCConnection != null)
					{
						strDatabaseProductName = m_JDBCConnection.getMetaData().getDatabaseProductName();
						strDatabaseProductName = this.fixDatabaseProductName(strDatabaseProductName);
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
                if ((strDatabaseProductName == null) || (strDatabaseProductName.length() == 0))
                	strDatabaseProductName = this.getProperty(SQLParams.DATABASE_PRODUCT_PARAM);
                if ((strDatabaseProductName == null) || (strDatabaseProductName.length() == 0))
                    strDatabaseProductName = DEFAULT_DATABASE_PRODUCT;
                this.setProperty(SQLParams.INTERNAL_DB_NAME, strDatabaseProductName);
                this.setupDatabaseProperties(); // If I haven't read the db properties, read them now!

                if (!bDataSourceConnection)
                {	// Datasource connection could be supplied in the db properties
                    String strDBDataSource = this.getProperty(SQLParams.DATASOURCE_PARAM);
                    if (strDBDataSource == null)
                    	strDBDataSource = this.getProperty(SQLParams.DEFAULT_DATASOURCE_PARAM);
                    if (strDBDataSource != null)
                    	if (!strDBDataSource.equalsIgnoreCase(strDataSource))
                        	bDataSourceConnection = this.setupDataSourceConnection(strDBDataSource);                	
                }
                if (!bDataSourceConnection)
                    bDataSourceConnection = this.setupDirectDataSourceConnection();
                if (!bDataSourceConnection)
                {
                    strJdbcDriver = this.getProperty(SQLParams.JDBC_DRIVER_PARAM);  // Default driver
                    if (strJdbcDriver == null)
                        strJdbcDriver = this.getProperty(BASE_DATABASE_JDBC_DRIVER);    // Special case - base database
                }
            }
            if (strJdbcDriver != null)
                this.setupJDBCConnection(strJdbcDriver);
            this.initConnection();
            this.loadDatabaseProperties();
        }
        
        super.open(); // Do any inherited
    }
710592
public void doOpen() throws DBException
    {
        super.doOpen();
        try   {
            m_pTable.open(this);
        } catch (DBException ex)    {
            throw DatabaseException.toDatabaseException(ex);
        }
    }
650434
private void execute(String sql) throws SQLException {
        Statement statement = connection.createStatement();
        try {
            statement.executeUpdate(substitute(sql));
        } finally {
            DbUtils.closeQuietly(statement);
        }
    }