Skip to content

Commit b93256a

Browse files
committed
Added a new option throwWarning to ScriptRunner. Related to mybatis/migrations#46
1 parent 800f852 commit b93256a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/main/java/org/apache/ibatis/jdbc/ScriptRunner.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2015 the original author or authors.
2+
* Copyright 2009-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
2323
import java.sql.ResultSet;
2424
import java.sql.ResultSetMetaData;
2525
import java.sql.SQLException;
26+
import java.sql.SQLWarning;
2627
import java.sql.Statement;
2728

2829
/**
@@ -37,6 +38,7 @@ public class ScriptRunner {
3738
private Connection connection;
3839

3940
private boolean stopOnError;
41+
private boolean throwWarning;
4042
private boolean autoCommit;
4143
private boolean sendFullScript;
4244
private boolean removeCRs;
@@ -56,6 +58,10 @@ public void setStopOnError(boolean stopOnError) {
5658
this.stopOnError = stopOnError;
5759
}
5860

61+
public void setThrowWarning(boolean throwWarning) {
62+
this.throwWarning = throwWarning;
63+
}
64+
5965
public void setAutoCommit(boolean autoCommit) {
6066
this.autoCommit = autoCommit;
6167
}
@@ -227,6 +233,12 @@ private void executeStatement(String command) throws SQLException {
227233
}
228234
if (stopOnError) {
229235
hasResults = statement.execute(sql);
236+
if (throwWarning) {
237+
SQLWarning warning = statement.getWarnings();
238+
if (warning != null) {
239+
throw warning;
240+
}
241+
}
230242
} else {
231243
try {
232244
hasResults = statement.execute(sql);

0 commit comments

Comments
 (0)