From d5444b3e308b6b8a84681962094bc34865ad1d4f Mon Sep 17 00:00:00 2001 From: ebocher Date: Tue, 4 Jun 2024 14:43:02 +0200 Subject: [PATCH 1/3] CHANGELOG.md --- .../src/test/groovy/org/orbisgis/data/GroovyH2GISTest.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/h2gis/src/test/groovy/org/orbisgis/data/GroovyH2GISTest.groovy b/data/h2gis/src/test/groovy/org/orbisgis/data/GroovyH2GISTest.groovy index a949dc7a..87f0ab41 100644 --- a/data/h2gis/src/test/groovy/org/orbisgis/data/GroovyH2GISTest.groovy +++ b/data/h2gis/src/test/groovy/org/orbisgis/data/GroovyH2GISTest.groovy @@ -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) } From e46118113c21eb4c094212612797d9b06c371a5c Mon Sep 17 00:00:00 2001 From: ebocher Date: Tue, 4 Jun 2024 15:03:01 +0200 Subject: [PATCH 2/3] Throw exception on script execute --- .../groovy/org/orbisgis/data/GroovyH2GISTest.groovy | 4 ++-- .../java/org/orbisgis/data/jdbc/JdbcDataSource.java | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/data/h2gis/src/test/groovy/org/orbisgis/data/GroovyH2GISTest.groovy b/data/h2gis/src/test/groovy/org/orbisgis/data/GroovyH2GISTest.groovy index 87f0ab41..a1be8c77 100644 --- a/data/h2gis/src/test/groovy/org/orbisgis/data/GroovyH2GISTest.groovy +++ b/data/h2gis/src/test/groovy/org/orbisgis/data/GroovyH2GISTest.groovy @@ -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) } diff --git a/data/jdbc/src/main/java/org/orbisgis/data/jdbc/JdbcDataSource.java b/data/jdbc/src/main/java/org/orbisgis/data/jdbc/JdbcDataSource.java index ceed4b8a..43a7ff5d 100644 --- a/data/jdbc/src/main/java/org/orbisgis/data/jdbc/JdbcDataSource.java +++ b/data/jdbc/src/main/java/org/orbisgis/data/jdbc/JdbcDataSource.java @@ -566,10 +566,11 @@ public void eachRow(GString gstring, @Override public boolean executeScript(String fileName, Map 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(); } @@ -583,8 +584,9 @@ public boolean executeScript(String fileName, Map bindings) thro } catch (SQLException e2) { throw new SQLException("Unable to rollback.", e2); } + throw e; } - return false; + return b; } @Override @@ -610,17 +612,16 @@ public boolean executeScript(InputStream stream, Map 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 From 491d0da243021466bc127f022bcb5ba0c1934285 Mon Sep 17 00:00:00 2001 From: ebocher Date: Tue, 4 Jun 2024 15:03:35 +0200 Subject: [PATCH 3/3] Throw exception on script execute --- docs/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 54472b3e..d878ac8a 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,4 @@ ## Changelog for v2.1.1 -- Refactoring to manage data exceptions \ No newline at end of file +- Refactoring to manage data exceptions +- Fix exception on script template \ No newline at end of file