Search in sources :

Example 81 with SQLWarning

use of java.sql.SQLWarning in project dbeaver by serge-rider.

the class TableToolDialog method getScriptListener.

@Override
protected SQLScriptProgressListener<PostgreObject> getScriptListener() {
    return new SQLScriptStatusDialog<PostgreObject>(getShell(), getTitle() + " progress", null) {

        @Override
        protected void createStatusColumns(Tree objectTree) {
            TreeColumn msgColumn = new TreeColumn(objectTree, SWT.NONE);
            msgColumn.setText("Message");
        }

        @Override
        public void processObjectResults(@NotNull PostgreObject object, @Nullable DBCStatement statement, @Nullable DBCResultSet resultSet) throws DBCException {
            if (statement == null) {
                return;
            }
            TreeItem treeItem = getTreeItem(object);
            if (treeItem != null) {
                try {
                    int warnNum = 0;
                    SQLWarning warning = ((JDBCStatement) statement).getWarnings();
                    while (warning != null) {
                        if (warnNum == 0) {
                            treeItem.setText(1, warning.getMessage());
                        } else {
                            TreeItem warnItem = new TreeItem(treeItem, SWT.NONE);
                            warnItem.setText(0, "");
                            warnItem.setText(1, warning.getMessage());
                        }
                        warnNum++;
                        warning = warning.getNextWarning();
                    }
                    if (warnNum == 0) {
                        treeItem.setText(1, "Done");
                    }
                } catch (SQLException e) {
                // ignore
                }
                treeItem.setExpanded(true);
            }
        }

        @Override
        public void endObjectProcessing(@NotNull PostgreObject object, Exception error) {
            super.endObjectProcessing(object, error);
            if (error != null) {
                TreeItem treeItem = getTreeItem(object);
                if (treeItem != null) {
                    treeItem.setText(1, error.getMessage());
                }
            }
        }
    };
}
Also used : SQLWarning(java.sql.SQLWarning) TreeItem(org.eclipse.swt.widgets.TreeItem) SQLException(java.sql.SQLException) NotNull(org.jkiss.code.NotNull) DBCStatement(org.jkiss.dbeaver.model.exec.DBCStatement) JDBCStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement) SQLScriptStatusDialog(org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog) DBCException(org.jkiss.dbeaver.model.exec.DBCException) SQLException(java.sql.SQLException) JDBCStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) PostgreObject(org.jkiss.dbeaver.ext.postgresql.model.PostgreObject) DBCResultSet(org.jkiss.dbeaver.model.exec.DBCResultSet) Nullable(org.jkiss.code.Nullable)

Example 82 with SQLWarning

use of java.sql.SQLWarning in project robovm by robovm.

the class OldStatementTest method testGetWarnings.

public void testGetWarnings() throws SQLException {
    Statement st = null;
    int errorCode1 = -1;
    int errorCode2 = -1;
    try {
        st = conn.createStatement();
        st.execute("select animals from zoooo");
        fail("SQLException was not thrown");
    } catch (SQLException e) {
        // expected
        errorCode1 = e.getErrorCode();
    }
    SQLWarning wrs = st.getWarnings();
    assertNull(wrs);
/*
        Statement st = null;
        int errorCode1 = -1;
        int errorCode2 = -1;

        try {
            st = conn.createStatement();
            st.execute("select animals from zoooo");
        } catch (SQLException e) {
            // expected
            errorCode1 = e.getErrorCode();
        }
        try {
            SQLWarning wrs = st.getWarnings();
            assertNull(wrs);
        } catch (Exception e) {
            fail("Unexpected Exception: " + e.getMessage());
        }
        try {
            st.execute("select horse from zoooooo");
        } catch (SQLException e) {
            // expected
            errorCode2 = e.getErrorCode();
        }

        try {
            SQLWarning wrs = st.getWarnings();
            assertEquals(errorCode1, wrs.getErrorCode());
            assertNotNull(wrs.getNextWarning());
            assertEquals(errorCode2, wrs.getErrorCode());
        } catch (Exception e) {
            fail("Unexpected Exception: " + e.getMessage());
        }

        try {
            st.close();
        } catch (SQLException ee) {
        }
        */
}
Also used : SQLWarning(java.sql.SQLWarning) SQLException(java.sql.SQLException) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement)

Example 83 with SQLWarning

use of java.sql.SQLWarning in project adempiere by adempiere.

the class Convert method execute.

//  setVerbose
/**************************************************************************
	 *  Execute SQL Statement (stops at first error).
	 *  If an error occurred hadError() returns true.
	 *  You can get details via getConversionError() or getException()
	 *  @param sqlStatements
	 *  @param conn connection
	 *  @return true if success
	 *  @throws IllegalStateException if no connection
	 */
public boolean execute(String sqlStatements, Connection conn) {
    if (conn == null)
        throw new IllegalStateException("Require connection");
    //
    String[] sql = convert(sqlStatements);
    m_exception = null;
    if (m_conversionError != null || sql == null)
        return false;
    boolean ok = true;
    int i = 0;
    String statement = null;
    try {
        if (m_stmt == null)
            m_stmt = conn.createStatement();
        //
        for (i = 0; ok && i < sql.length; i++) {
            statement = sql[i];
            if (statement.length() == 0) {
                if (m_verbose)
                    log.finer("Skipping empty (" + i + ")");
            } else {
                if (m_verbose)
                    log.info("Executing (" + i + ") <<" + statement + ">>");
                else
                    log.info("Executing " + i);
                try {
                    m_stmt.clearWarnings();
                    int no = m_stmt.executeUpdate(statement);
                    SQLWarning warn = m_stmt.getWarnings();
                    if (warn != null) {
                        if (m_verbose)
                            log.info("- " + warn);
                        else {
                            log.info("Executing (" + i + ") <<" + statement + ">>");
                            log.info("- " + warn);
                        }
                    }
                    if (m_verbose)
                        log.fine("- ok " + no);
                } catch (SQLException ex) {
                    //  Ignore Drop Errors
                    if (!statement.startsWith("DROP ")) {
                        ok = false;
                        m_exception = ex;
                    }
                    if (!m_verbose)
                        log.info("Executing (" + i + ") <<" + statement + ">>");
                    log.info("Error executing " + i + "/" + sql.length + " = " + ex);
                }
            }
        }
    //  for all statements
    } catch (SQLException e) {
        m_exception = e;
        if (!m_verbose)
            log.info("Executing (" + i + ") <<" + statement + ">>");
        log.info("Error executing " + i + "/" + sql.length + " = " + e);
        return false;
    }
    return ok;
}
Also used : SQLWarning(java.sql.SQLWarning) SQLException(java.sql.SQLException)

Example 84 with SQLWarning

use of java.sql.SQLWarning in project voltdb by VoltDB.

the class JDBCStatementBase method performPostExecute.

/**
     * processes chained warnings and any generated columns result set
     */
void performPostExecute() throws SQLException {
    resultOut.clearLobResults();
    generatedResult = null;
    if (resultIn == null) {
        return;
    }
    Result current = resultIn;
    while (current.getChainedResult() != null) {
        current = current.getUnlinkChainedResult();
        if (current.getType() == ResultConstants.WARNING) {
            SQLWarning w = Util.sqlWarning(current);
            if (rootWarning == null) {
                rootWarning = w;
            } else {
                rootWarning.setNextWarning(w);
            }
        } else if (current.getType() == ResultConstants.ERROR) {
            errorResult = current;
        } else if (current.getType() == ResultConstants.DATA) {
            generatedResult = current;
        }
    }
    if (resultIn.isData()) {
        currentResultSet = new JDBCResultSet(connection.sessionProxy, this, resultIn, resultIn.metaData, connection.connProperties);
    }
}
Also used : SQLWarning(java.sql.SQLWarning) Result(org.hsqldb_voltpatches.result.Result)

Example 85 with SQLWarning

use of java.sql.SQLWarning in project jdk8u_jdk by JetBrains.

the class SQLWarningTests method test13.

/**
     * Validate that the ordering of the returned SQLWarning is correct using
     * for-each loop
     */
@Test
public void test13() {
    SQLWarning ex = new SQLWarning("Warning 1", t1);
    SQLWarning ex1 = new SQLWarning("Warning 2");
    SQLWarning ex2 = new SQLWarning("Warning 3", t2);
    ex.setNextWarning(ex1);
    ex.setNextWarning(ex2);
    int num = 0;
    for (Throwable e : ex) {
        assertTrue(warnings[num++].equals(e.getMessage()));
    }
}
Also used : SQLWarning(java.sql.SQLWarning) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Aggregations

SQLWarning (java.sql.SQLWarning)153 SQLException (java.sql.SQLException)49 Statement (java.sql.Statement)37 PreparedStatement (java.sql.PreparedStatement)30 Connection (java.sql.Connection)26 ResultSet (java.sql.ResultSet)23 Test (org.testng.annotations.Test)19 Test (org.junit.Test)17 BaseTest (util.BaseTest)15 CallableStatement (java.sql.CallableStatement)13 ArrayList (java.util.ArrayList)9 JDBCStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement)8 ResultSetMetaData (java.sql.ResultSetMetaData)6 Expectations (org.jmock.Expectations)6 IOException (java.io.IOException)4 FilterChainImpl (com.alibaba.druid.filter.FilterChainImpl)3 PrestoWarning (com.facebook.presto.spi.PrestoWarning)3 Properties (java.util.Properties)3 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)3 StatementContext (org.apache.derby.iapi.sql.conn.StatementContext)3