Skip to content

Commit

Permalink
Merge pull request #9 from orbisgis/groovy_exemple
Browse files Browse the repository at this point in the history
Add groovy example page
  • Loading branch information
ebocher committed Nov 4, 2015
2 parents 91f2c09 + 2f4a9f5 commit 25f2ebe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Except where otherwise noted, this documenation is licensed under a *Creative Co
users/components
users/quickstart
users/attributes
users/groovy_with_sql

.. toctree::
:maxdepth: 2
Expand Down
29 changes: 29 additions & 0 deletions docs/users/groovy_with_sql.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Groovy script with SQL
========

Below is an example of how to use SQL instructions into Groovy script.

.. code-block:: groovy
import groovy.sql.Sql;
def sql = Sql.newInstance(grv_ds);
// Execute SQL request
sql.execute("DROP TABLE IF EXISTS TEST")
sql.execute("CREATE TABLE TEST AS SELECT 'POINT(1 3 10)'::geometry THE_GEOM")
// Fetch results and print point coordinates
// row["THE_GEOM"] is an instance of
// http://tsusiatsoftware.net/jts/javadoc/com/vividsolutions/jts/geom/Point.html
sql.eachRow("SELECT * FROM TEST") { row ->
pt = row["THE_GEOM"].getCoordinate()
print(pt.x+" "+pt.y+" "+pt.z)
}
To see more, you can consult this tutorial_ from the Groovy documentation.


.. _tutorial: http://docs.groovy-lang.org/latest/html/documentation/#_interacting_with_a_sql_database

0 comments on commit 25f2ebe

Please sign in to comment.