Skip to content

Commit

Permalink
Merge pull request #396 from ebocher/master
Browse files Browse the repository at this point in the history
Fix exception on script template
  • Loading branch information
ebocher authored Jun 4, 2024
2 parents 054240a + 491d0da commit b27252e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ class GroovyH2GISTest {
file << 'CREATE TABLE super as SELECT * FROM $BINIOU;\n --COMMENTS HERE \nSELECT * FROM super;'
h2GIS.executeScript("target/myscript.sql", [BINIOU: 'h2gis'])
def concat = ""
h2GIS.spatialTable "super" eachRow { row -> concat += "$row.id $row.the_geom $row.geometry\n" }
h2GIS.getSpatialTable( "super") 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 All @@ -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
3 changes: 2 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
## Changelog for v2.1.1

- Refactoring to manage data exceptions
- Refactoring to manage data exceptions
- Fix exception on script template

0 comments on commit b27252e

Please sign in to comment.