/** * The first warning reported by calls on this Statement is returned. A * Statement's execute methods clear its java.sql.SQLWarning chain. * Subsequent Statement warnings will be chained to this * java.sql.SQLWarning. * * <p> * The Warning chain is automatically cleared each time a statement is (re)executed. * </p> * * <p> * <B>Note:</B> If you are processing a ResultSet then any warnings associated with ResultSet reads will be chained on the ResultSet object. * </p> * * @return the first java.sql.SQLWarning or null * * @exception SQLException * if a database access error occurs */ public java.sql.SQLWarning getWarnings() throws SQLException { synchronized (checkClosed().getConnectionMutex()) { if (this.clearWarningsCalled) { return null; } if (this.connection.versionMeetsMinimum(4, 1, 0)) { SQLWarning pendingWarningsFromServer = SQLError.convertShowWarningsToSQLWarnings(this.connection); if (this.warningChain != null) { this.warningChain.setNextWarning(pendingWarningsFromServer); } else { this.warningChain = pendingWarningsFromServer; } return this.warningChain; } return this.warningChain; } }
/** * Tests fix for BUG#18740 - Data truncation and getWarnings() only returns * last warning in set. * * @throws Exception * if the test fails. */ public void testBug18740() throws Exception { if (!versionMeetsMinimum(5, 0, 2)) { createTable("testWarnings", "(field1 smallint(6), field2 varchar(6), UNIQUE KEY field1(field1))"); try { this.stmt.executeUpdate( "INSERT INTO testWarnings VALUES (10001, 'data1'), (10002, 'data2 foo'), (10003, 'data3'), (10004999, 'data4'), (10005, 'data5')"); } catch (SQLException sqlEx) { String sqlStateToCompare = "01004"; if (isJdbc4()) { sqlStateToCompare = "22001"; } assertEquals(sqlStateToCompare, sqlEx.getSQLState()); assertEquals(sqlStateToCompare, sqlEx.getNextException().getSQLState()); SQLWarning sqlWarn = this.stmt.getWarnings(); assertEquals("01000", sqlWarn.getSQLState()); assertEquals("01000", sqlWarn.getNextWarning().getSQLState()); } } }
private void execute(boolean script, boolean export, Writer fileOutput, Statement statement, final String sql) throws IOException, SQLException { final SqlExceptionHelper sqlExceptionHelper = new SqlExceptionHelper(); String formatted = formatter.format( sql ); if (delimiter != null) formatted += delimiter; if (script) System.out.println(formatted); LOG.debug(formatted); if ( outputFile != null ) { fileOutput.write( formatted + "\n" ); } if ( export ) { statement.executeUpdate( sql ); try { SQLWarning warnings = statement.getWarnings(); if ( warnings != null) { sqlExceptionHelper.logAndClearWarnings( connectionHelper.getConnection() ); } } catch( SQLException sqle ) { LOG.unableToLogSqlWarnings(sqle); } } }
/** * Validate that the ordering of the returned SQLWarning is correct using * traditional while loop */ @Test public void test14() { 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; SQLWarning sqe = ex; while (sqe != null) { assertTrue(warnings[num++].equals(sqe.getMessage())); Throwable c = sqe.getCause(); while (c != null) { assertTrue(msgs[num++].equals(c.getMessage())); c = c.getCause(); } sqe = sqe.getNextWarning(); } }
/** * Serialize a SQLWarning and make sure you can read it back properly */ @Test public void test10() throws Exception { SQLWarning e = new SQLWarning(reason, state, errorCode, t); SQLWarning ex1 = createSerializedException(e); assertTrue(reason.equals(ex1.getMessage()) && ex1.getSQLState().equals(state) && cause.equals(ex1.getCause().toString()) && ex1.getErrorCode() == errorCode); }
/** * Create SQLWarning with message, SQLState, and Throwable */ @Test public void test6() { SQLWarning ex = new SQLWarning(reason, state, t); assertTrue(ex.getMessage().equals(reason) && ex.getSQLState().equals(state) && cause.equals(ex.getCause().toString()) && ex.getErrorCode() == 0); }
/** * Sets the warning chain */ void setWarnings(SQLWarning w) { synchronized (rootWarning_mutex) { rootWarning = w; } }
/** * Adds another SQLWarning to this Connection object's warning chain. * * @param w the SQLWarning to add to the chain */ void addWarning(SQLWarning w) { // PRE: w is never null synchronized (rootWarning_mutex) { if (rootWarning == null) { rootWarning = w; } else { rootWarning.setNextWarning(w); } } }
/** * Generic algorithm to walk the hierarchy of SQLWarnings * * @param warning The warning to walk * @param handler The handler */ public void walkWarnings( SQLWarning warning, WarningHandler handler) { if ( warning == null || handler.doProcess() ) { return; } handler.prepare( warning ); while ( warning != null ) { handler.handleWarning( warning ); warning = warning.getNextWarning(); } }
/** * Create SQLWarning with message, SQLState, errorCode, and Throwable */ @Test public void test5() { SQLWarning ex = new SQLWarning(reason, state, errorCode, t); assertTrue(ex.getMessage().equals(reason) && ex.getSQLState().equals(state) && cause.equals(ex.getCause().toString()) && ex.getErrorCode() == errorCode); }
/** * Create SQLWarning with null Throwable */ @Test public void test8() { SQLWarning ex = new SQLWarning((Throwable) null); assertTrue(ex.getMessage() == null && ex.getSQLState() == null && ex.getCause() == null && ex.getErrorCode() == 0); }
/** * Create SQLWarning with no-arg constructor */ @Test public void test1() { SQLWarning ex = new SQLWarning(); assertTrue(ex.getMessage() == null && ex.getSQLState() == null && ex.getCause() == null && ex.getErrorCode() == 0); }
/** * Create SQLWarning with message, SQLState, and error code */ @Test public void test4() { SQLWarning ex = new SQLWarning(reason, state, errorCode); assertTrue(ex.getMessage().equals(reason) && ex.getSQLState().equals(state) && ex.getCause() == null && ex.getErrorCode() == errorCode); }
/** * processes chained warnings and any generated columns result set */ void performPostExecute() throws SQLException { resultOut.clearLobResults(); generatedResult = null; if (resultIn == null) { return; } rootWarning = null; Result current = resultIn; while (current.getChainedResult() != null) { current = current.getUnlinkChainedResult(); if (current.getType() == ResultConstants.WARNING) { SQLWarning w = JDBCUtil.sqlWarning(current); if (rootWarning == null) { rootWarning = w; } else { rootWarning.setNextWarning(w); } } else if (current.getType() == ResultConstants.ERROR) { errorResult = current; } else if (current.getType() == ResultConstants.GENERATED) { generatedResult = current; } else if (current.getType() == ResultConstants.DATA) { resultIn.addChainedResult(current); } } if (rootWarning != null) { connection.setWarnings(rootWarning); } }
/** * Create SQLWarning and setting all objects to null */ @Test public void test() { SQLWarning e = new SQLWarning(null, null, errorCode, null); assertTrue(e.getMessage() == null && e.getSQLState() == null && e.getCause() == null && e.getErrorCode() == errorCode); }
/** * Create SQLWarning with Throwable */ @Test public void test9() { SQLWarning ex = new SQLWarning(t); assertTrue(ex.getMessage().equals(cause) && ex.getSQLState() == null && cause.equals(ex.getCause().toString()) && ex.getErrorCode() == 0); }
public SQLWarning getWarnings() throws SQLException { try { if (this.wrappedStmt != null) { return this.wrappedStmt.getWarnings(); } throw SQLError.createSQLException("Statement already closed", SQLError.SQL_STATE_ILLEGAL_ARGUMENT, this.exceptionInterceptor); } catch (SQLException sqlEx) { checkAndFireConnectionError(sqlEx); } return null; }
@Override public SQLWarning getWarnings() throws SQLException { ensureOpen(); return null; }
@Override public SQLWarning getWarnings() throws SQLException { return null; }
public static final SQLWarning sqlWarning(HsqlException e) { return new SQLWarning(e.getMessage(), e.getSQLState(), e.getErrorCode()); }
public SQLWarning getWarnings() throws SQLException { throw new SQLException("Not Implemented: getWarnings()"); }
public Collection<SQLWarning> getWarnings() { return dataView.getWarnings(); }
@Override public SQLWarning getWarnings() throws SQLException { throw unsupported(); }
@Override public SQLWarning getWarnings() throws SQLException { return warningChain; }
@Override public SQLWarning getWarnings() throws SQLException { throw SQLError.noSupport(); }
@Override public SQLWarning getWarnings() throws SQLException { checkClosed(); return null; }
public static SQLWarning sqlWarning(Result r) { return new SQLWarning(r.getMainString(), r.getSubString(), r.getErrorCode()); }
@Override public SQLWarning getWarnings() throws SQLException { throwIfClosed(); return super.getWarnings(); }
@Override public SQLWarning getWarnings() throws SQLException { throw new UnsupportedOperationException("Not supported yet."); }