Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exception on script template #396

Merged
merged 3 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading