Skip to content

Commit

Permalink
Throw exception on script execute
Browse files Browse the repository at this point in the history
  • Loading branch information
ebocher committed Jun 4, 2024
1 parent d5444b3 commit e461181
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,10 @@ class GroovyH2GISTest {
""")
def file = new File('target/myscript.sql')
file.delete()
file << 'CREATE TABLE super as SELECT * FROM h2gis;\n --COMMENTS HERE \nSELECT * FROM super;'
file << 'CREATE TABLE super as SELECT * FROM h2gis;\n --COMMENTS HERE \nALTER TABLE super RENAME to super_rename;'
h2GIS.executeScript("target/myscript.sql")
def concat = ""
h2GIS.getSpatialTable "super" eachRow { row -> concat += "$row.id $row.the_geom $row.geometry\n" }
h2GIS.getSpatialTable "super_rename" eachRow { row -> concat += "$row.id $row.the_geom $row.geometry\n" }
assertEquals("1 POINT (10 10) POINT (10 10)\n2 POINT (1 1) POINT (1 1)\n", concat)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,10 +566,11 @@ public void eachRow(GString gstring,

@Override
public boolean executeScript(String fileName, Map<String, String> bindings) throws Exception {
boolean b = false;
try {
File file = URIUtilities.fileFromString(fileName);
if (FileUtilities.isExtensionWellFormated(file, "sql")) {
boolean b = executeScript(new FileInputStream(file), bindings);
b = executeScript(new FileInputStream(file), bindings);
if (!getConnection().getAutoCommit()) {
super.commit();
}
Expand All @@ -583,8 +584,9 @@ public boolean executeScript(String fileName, Map<String, String> bindings) thro
} catch (SQLException e2) {
throw new SQLException("Unable to rollback.", e2);
}
throw e;
}
return false;
return b;
}

@Override
Expand All @@ -610,17 +612,16 @@ public boolean executeScript(InputStream stream, Map<String, String> bindings) t
}
}
try {
boolean b = execute(commandSQL);
execute(commandSQL);
if (!getConnection().getAutoCommit()) {
super.commit();
}
return b;
} catch (SQLException e) {
throw new SQLException("Unable to execute the Sql command '" + commandSQL + "'.\n" + e.getLocalizedMessage());
}
}
}
return false;
return true;
}

@Override
Expand Down

0 comments on commit e461181

Please sign in to comment.