You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by pa...@apache.org on 2015/04/20 09:23:41 UTC
[1/9] incubator-groovy git commit: groovy-sql doco: initial JDBC
metadata handling doco
Repository: incubator-groovy
Updated Branches:
refs/heads/GROOVY_2_4_X cbf6aec77 -> 3a6b00180
groovy-sql doco: initial JDBC metadata handling doco
Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/5e96d4ae
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/5e96d4ae
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/5e96d4ae
Branch: refs/heads/GROOVY_2_4_X
Commit: 5e96d4aeb771fc0affd03007e78ffb6b42e1ca23
Parents: cbf6aec
Author: Paul King <pa...@asert.com.au>
Authored: Fri Apr 17 12:59:32 2015 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Mon Apr 20 17:22:38 2015 +1000
----------------------------------------------------------------------
.../groovy-sql/src/spec/doc/sql-userguide.adoc | 10 ++++++
.../groovy-sql/src/spec/test/SqlTest.groovy | 33 ++++++++++++++++++++
2 files changed, 43 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/5e96d4ae/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
----------------------------------------------------------------------
diff --git a/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc b/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
index 2c0202d..f679e6a 100644
--- a/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
+++ b/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
@@ -236,6 +236,16 @@ include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[ta
=== Fetching metadata
+JDBC metadata can be retrieved in numerous ways. Perhaps the most basic approach is to extract the metadata from any row as shown here:
+
+[source,groovy]
+.Using row metadata
+----
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_basic_metadata,indent=0]
+----
+
+Advanced options for metadata handling using closures are also possible.
+
(TBD)
=== Named and named-ordinal parameters
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/5e96d4ae/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
index 3e09362..bfa5daf 100644
--- a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
+++ b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
@@ -289,6 +289,39 @@ class SqlTest extends GroovyTestCase {
'''
}
+ void testMetadata() {
+ assertScript '''
+ import groovy.sql.Sql
+
+ def url = 'jdbc:hsqldb:mem:yourDB'
+ def user = 'sa'
+ def password = ''
+ def driver = 'org.hsqldb.jdbcDriver'
+ Sql.withInstance(url, user, password, driver) { sql ->
+ sql.execute """
+ DROP TABLE Author IF EXISTS
+ """
+ sql.execute """
+ CREATE TABLE Author (
+ id INTEGER GENERATED BY DEFAULT AS IDENTITY,
+ firstname VARCHAR(64),
+ lastname VARCHAR(64)
+ )
+ """
+ sql.execute "INSERT INTO Author (firstname, lastname) VALUES ('Dierk', 'Koenig')"
+
+ // tag::sql_basic_metadata[]
+ sql.eachRow("SELECT * FROM Author where firstname = 'Dierk'") { row ->
+ def md = row.getMetaData()
+ assert md.getTableName(1).toLowerCase() == 'author'
+ assert (1..md.columnCount).collect{ md.getColumnTypeName(it).toLowerCase() } == ['integer', 'varchar', 'varchar']
+ assert (1..md.columnCount).collect{ md.getColumnLabel(it).toLowerCase() } == ['id', 'firstname', 'lastname']
+ }
+ // end::sql_basic_metadata[]
+ }
+ '''
+ }
+
void testDeletingRows() {
assertScript '''
import groovy.sql.Sql
[2/9] incubator-groovy git commit: groovy-sql: update test dependency
(no longer need jdk5 artifact)
Posted by pa...@apache.org.
groovy-sql: update test dependency (no longer need jdk5 artifact)
Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/2b82324b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/2b82324b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/2b82324b
Branch: refs/heads/GROOVY_2_4_X
Commit: 2b82324bddab89e0502ed98a561e1f3feaff2cb1
Parents: a7139b6
Author: Paul King <pa...@asert.com.au>
Authored: Sat Apr 18 08:55:56 2015 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Mon Apr 20 17:22:39 2015 +1000
----------------------------------------------------------------------
subprojects/groovy-sql/build.gradle | 6 ++++--
subprojects/groovy-sql/src/spec/test/SqlTest.groovy | 2 +-
2 files changed, 5 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/2b82324b/subprojects/groovy-sql/build.gradle
----------------------------------------------------------------------
diff --git a/subprojects/groovy-sql/build.gradle b/subprojects/groovy-sql/build.gradle
index 563a5d1..4e82dc4 100644
--- a/subprojects/groovy-sql/build.gradle
+++ b/subprojects/groovy-sql/build.gradle
@@ -18,9 +18,11 @@
*/
dependencies {
compile rootProject
-// testCompile 'hsqldb:hsqldb:1.8.0.10'
- testCompile group: 'org.hsqldb', name: 'hsqldb', version: '2.3.2', classifier: 'jdk5'
+ testCompile group: 'org.hsqldb', name: 'hsqldb', version: '2.3.2'
+// uncomment to test with other databases (requires changes elsewhere too)
+// testCompile group: 'org.hsqldb', name: 'hsqldb', version: '2.3.2', classifier: 'jdk5'
// testCompile 'com.h2database:h2:1.3.164'
+// testCompile 'hsqldb:hsqldb:1.8.0.10'
testCompile project(':groovy-test')
}
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/2b82324b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
index eb249ce..40e237f 100644
--- a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
+++ b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
@@ -336,7 +336,7 @@ class SqlTest extends GroovyTestCase {
def md = sql.connection.metaData
assert md.driverName == 'HSQL Database Engine Driver'
assert md.databaseProductVersion == '2.3.2'
- assert ['JDBCMajorVersion', 'JDBCMinorVersion'].collect{ md[it] } == [3, 0]
+ assert ['JDBCMajorVersion', 'JDBCMinorVersion'].collect{ md[it] } == [4, 0]
assert md.stringFunctions.tokenize(',').contains('CONCAT')
def rs = md.getTables(null, null, 'AUTH%', null)
assert rs.next()
[9/9] incubator-groovy git commit: groovy-sql doco: stored procs
Posted by pa...@apache.org.
groovy-sql doco: stored procs
Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/3a6b0018
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/3a6b0018
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/3a6b0018
Branch: refs/heads/GROOVY_2_4_X
Commit: 3a6b00180cdb78d555076e3ba16575a7f3b84baa
Parents: 9673706
Author: Paul King <pa...@asert.com.au>
Authored: Mon Apr 20 14:31:29 2015 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Mon Apr 20 17:23:32 2015 +1000
----------------------------------------------------------------------
.../groovy-sql/src/spec/doc/sql-userguide.adoc | 52 ++++++++-
.../groovy-sql/src/spec/test/SqlTest.groovy | 117 +++++++++++++++++++
2 files changed, 168 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/3a6b0018/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
----------------------------------------------------------------------
diff --git a/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc b/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
index c371412..18db669 100644
--- a/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
+++ b/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
@@ -388,7 +388,57 @@ include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[ta
=== Stored procedures
-(TBD)
+The exact syntax for creating a stored procedure or function varies slightly between different databases.
+For the HSQLDB database we are using, we can create a stored function which returns the initials of all authors in a table
+as follows:
+
+[source,groovy]
+.Creating a stored function
+----
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_create_stored_proc,indent=0]
+----
+
+We can use a SQL `CALL` statement to invoke the function using Groovy's normal SQL retrieval methods.
+Here is an example using `eachRow`.
+
+[source,groovy]
+.Creating a stored procedure or function
+----
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_use_stored_proc,indent=0]
+----
+
+Here is the code for creating another stored function, this one taking the lastname as a parameter:
+
+[source,groovy]
+.Creating a stored function with a parameter
+----
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_create_stored_proc_param,indent=0]
+----
+
+We can use the placeholder syntax to specify where the parameter belongs and note the special placeholder position to indicate the result:
+
+[source,groovy]
+.Using a stored function with a parameter
+----
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_use_stored_proc_param,indent=0]
+----
+
+Finally, here is a stored procedure with input and output parameters:
+
+[source,groovy]
+.Creating a stored procedure with input and output parameters
+----
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_create_stored_proc_inout,indent=0]
+----
+
+To use the `CONCAT_NAME` stored procedure parameter, we make use of a special `call` method. Any input parameters are simply provided
+as parameters to the method call. For output parameters, the resulting type must be specified as shown here:
+
+[source,groovy]
+.Using a stored procedure with input and output parameters
+----
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_use_stored_proc_inout,indent=0]
+----
== Using DataSets
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/3a6b0018/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
index dc16d91..4cc8577 100644
--- a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
+++ b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
@@ -571,4 +571,121 @@ class SqlTest extends GroovyTestCase {
'''
}
+ void testStoredProcSimple() {
+ assertScript '''
+ import groovy.sql.Sql
+
+ def url = 'jdbc:hsqldb:mem:yourDB'
+ def user = 'sa'
+ def password = ''
+ def driver = 'org.hsqldb.jdbcDriver'
+ Sql.withInstance(url, user, password, driver) { sql ->
+ sql.execute """
+ DROP TABLE Author IF EXISTS
+ """
+ sql.execute """
+ CREATE TABLE Author (
+ id INTEGER GENERATED BY DEFAULT AS IDENTITY,
+ firstname VARCHAR(64),
+ lastname VARCHAR(64)
+ )
+ """
+ sql.execute "INSERT INTO Author (firstname, lastname) VALUES ('Dierk', 'Koenig')"
+ sql.execute "INSERT INTO Author (firstname, lastname) VALUES ('Jon', 'Skeet')"
+ sql.execute "INSERT INTO Author (firstname, lastname) VALUES ('Guillaume', 'Laforge')"
+ // tag::sql_create_stored_proc[]
+ sql.execute """
+ CREATE FUNCTION SELECT_AUTHOR_INITIALS()
+ RETURNS TABLE (firstInitial VARCHAR(1), lastInitial VARCHAR(1))
+ READS SQL DATA
+ RETURN TABLE (
+ SELECT LEFT(Author.firstname, 1) as firstInitial, LEFT(Author.lastname, 1) as lastInitial
+ FROM Author
+ )
+ """
+ // end::sql_create_stored_proc[]
+ // tag::sql_use_stored_proc[]
+ def result = []
+ sql.eachRow('CALL SELECT_AUTHOR_INITIALS()') {
+ result << "$it.firstInitial$it.lastInitial"
+ }
+ assert result == ['DK', 'JS', 'GL']
+ // end::sql_use_stored_proc[]
+ sql.execute "DROP FUNCTION SELECT_AUTHOR_INITIALS"
+ }
+ '''
+ }
+
+ void testStoredProcWithParam() {
+ assertScript '''
+ import groovy.sql.Sql
+
+ def url = 'jdbc:hsqldb:mem:yourDB'
+ def user = 'sa'
+ def password = ''
+ def driver = 'org.hsqldb.jdbcDriver'
+ Sql.withInstance(url, user, password, driver) { sql ->
+ sql.execute """
+ DROP TABLE Author IF EXISTS
+ """
+ sql.execute """
+ CREATE TABLE Author (
+ id INTEGER GENERATED BY DEFAULT AS IDENTITY,
+ firstname VARCHAR(64),
+ lastname VARCHAR(64)
+ )
+ """
+ sql.execute "INSERT INTO Author (firstname, lastname) VALUES ('Dierk', 'Koenig')"
+ sql.execute "INSERT INTO Author (firstname, lastname) VALUES ('Jon', 'Skeet')"
+ sql.execute "INSERT INTO Author (firstname, lastname) VALUES ('Guillaume', 'Laforge')"
+ // tag::sql_create_stored_proc_param[]
+ sql.execute """
+ CREATE FUNCTION FULL_NAME (p_lastname VARCHAR(64))
+ RETURNS VARCHAR(100)
+ READS SQL DATA
+ BEGIN ATOMIC
+ DECLARE ans VARCHAR(100);
+ SELECT CONCAT(firstname, ' ', lastname) INTO ans
+ FROM Author WHERE lastname = p_lastname;
+ RETURN ans;
+ END
+ """
+ // end::sql_create_stored_proc_param[]
+ // tag::sql_use_stored_proc_param[]
+ def result = sql.firstRow("{? = call FULL_NAME(?)}", ['Koenig'])
+ assert result[0] == 'Dierk Koenig'
+ // end::sql_use_stored_proc_param[]
+ sql.execute "DROP FUNCTION FULL_NAME"
+ }
+ '''
+ }
+
+ void testStoredProcWithInOut() {
+ assertScript '''
+ import groovy.sql.Sql
+
+ def url = 'jdbc:hsqldb:mem:yourDB'
+ def user = 'sa'
+ def password = ''
+ def driver = 'org.hsqldb.jdbcDriver'
+ Sql.withInstance(url, user, password, driver) { sql ->
+ // tag::sql_create_stored_proc_inout[]
+ sql.execute """
+ CREATE PROCEDURE CONCAT_NAME (OUT fullname VARCHAR(100),
+ IN first VARCHAR(50), IN last VARCHAR(50))
+ BEGIN ATOMIC
+ SET fullname = CONCAT(first, ' ', last);
+ END
+ """
+ // end::sql_create_stored_proc_inout[]
+ // tag::sql_use_stored_proc_inout[]
+ sql.call("{call CONCAT_NAME(?, ?, ?)}", [Sql.VARCHAR, 'Dierk', 'Koenig']) {
+ fullname -> assert fullname == 'Dierk Koenig'
+ }
+ // end::sql_use_stored_proc_inout[]
+ sql.execute "DROP PROCEDURE CONCAT_NAME"
+ }
+ '''
+ }
+
}
[8/9] incubator-groovy git commit: groovy-sql doco: pagination
Posted by pa...@apache.org.
groovy-sql doco: pagination
Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/96737065
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/96737065
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/96737065
Branch: refs/heads/GROOVY_2_4_X
Commit: 96737065e2e8f7f0b804453c694d337cc36053b4
Parents: 58ba4de
Author: Paul King <pa...@asert.com.au>
Authored: Mon Apr 20 09:21:26 2015 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Mon Apr 20 17:23:32 2015 +1000
----------------------------------------------------------------------
.../groovy-sql/src/spec/doc/sql-userguide.adoc | 13 +++++--
.../groovy-sql/src/spec/test/SqlTest.groovy | 37 ++++++++++++++++++++
2 files changed, 48 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/96737065/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
----------------------------------------------------------------------
diff --git a/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc b/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
index d0e4ff0..c371412 100644
--- a/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
+++ b/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
@@ -249,7 +249,7 @@ Even though the first sql execute succeeds initially, it will be rolled back and
=== Using batches
-When dealing with large volumes of data, it can be more efficient to chunk the data into batches. This is done
+When dealing with large volumes of data, particularly when inserting such data, it can be more efficient to chunk the data into batches. This is done
using the `withBatch` statement as shown in the following example:
[source,groovy]
@@ -297,7 +297,16 @@ to the one table.
=== Performing pagination
-(TBD)
+When presenting large tables of data to a user, it is often convenient to present information a page at
+a time. Many of Groovy's SQL retrieval methods have extra parameters which can be used to select a particular
+page of interest. The starting position and page size are specified as integers as shown in the following example
+using `rows`:
+
+[source,groovy]
+.Retrieving pages of data
+----
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_pagination,indent=0]
+----
=== Fetching metadata
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/96737065/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
index f5b5c9b..dc16d91 100644
--- a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
+++ b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
@@ -502,6 +502,43 @@ class SqlTest extends GroovyTestCase {
'''
}
+ void testPagination() {
+ assertScript '''
+ import groovy.sql.Sql
+
+ def url = 'jdbc:hsqldb:mem:yourDB'
+ def user = 'sa'
+ def password = ''
+ def driver = 'org.hsqldb.jdbcDriver'
+ Sql.withInstance(url, user, password, driver) { sql ->
+ sql.execute """
+ DROP TABLE Author IF EXISTS
+ """
+ sql.execute """
+ CREATE TABLE Author (
+ id INTEGER GENERATED BY DEFAULT AS IDENTITY,
+ firstname VARCHAR(64),
+ lastname VARCHAR(64)
+ )
+ """
+
+ sql.execute "INSERT INTO Author (firstname, lastname) VALUES ('Dierk', 'Koenig')"
+ sql.execute "INSERT INTO Author (firstname, lastname) VALUES ('Paul', 'King')"
+ sql.execute "INSERT INTO Author (firstname, lastname) VALUES ('Guillaume', 'Laforge')"
+ sql.execute "INSERT INTO Author (firstname, lastname) VALUES ('Hamlet', 'D''Arcy')"
+ sql.execute "INSERT INTO Author (firstname, lastname) VALUES ('Cedric', 'Champeau')"
+ sql.execute "INSERT INTO Author (firstname, lastname) VALUES ('Erik', 'Pragt')"
+ sql.execute "INSERT INTO Author (firstname, lastname) VALUES ('Jon', 'Skeet')"
+ // tag::sql_pagination[]
+ def qry = 'SELECT * FROM Author'
+ assert sql.rows(qry, 1, 3)*.firstname == ['Dierk', 'Paul', 'Guillaume']
+ assert sql.rows(qry, 4, 3)*.firstname == ['Hamlet', 'Cedric', 'Erik']
+ assert sql.rows(qry, 7, 3)*.firstname == ['Jon']
+ // end::sql_pagination[]
+ }
+ '''
+ }
+
void testDeletingRows() {
assertScript '''
import groovy.sql.Sql
[4/9] incubator-groovy git commit: groovy-sql doco: other metadata
handling doco
Posted by pa...@apache.org.
groovy-sql doco: other metadata handling doco
Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/a7139b6f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/a7139b6f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/a7139b6f
Branch: refs/heads/GROOVY_2_4_X
Commit: a7139b6fbd82fcec69b626c905e50489621d2c07
Parents: 5e96d4a
Author: Paul King <pa...@asert.com.au>
Authored: Fri Apr 17 21:45:31 2015 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Mon Apr 20 17:22:39 2015 +1000
----------------------------------------------------------------------
.../groovy-sql/src/spec/doc/sql-userguide.adoc | 35 ++++++++++++++++---
.../groovy-sql/src/spec/test/SqlTest.groovy | 36 ++++++++++++++++----
2 files changed, 61 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/a7139b6f/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
----------------------------------------------------------------------
diff --git a/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc b/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
index f679e6a..5d06fd8 100644
--- a/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
+++ b/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
@@ -236,17 +236,44 @@ include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[ta
=== Fetching metadata
-JDBC metadata can be retrieved in numerous ways. Perhaps the most basic approach is to extract the metadata from any row as shown here:
+JDBC metadata can be retrieved in numerous ways. Perhaps the most basic approach is to extract the
+metadata from any row as shown in the following example which examines the tablename, column names and column type names:
[source,groovy]
.Using row metadata
----
-include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_basic_metadata,indent=0]
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_basic_rs_metadata,indent=0]
----
-Advanced options for metadata handling using closures are also possible.
+And another slight variant to the previous example, this time also looking at the column label:
-(TBD)
+[source,groovy]
+.Also using row metadata
+----
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_basic_rs_metadata2,indent=0]
+----
+
+Accessing metadata is quite common, so Groovy also provides variants to many of its methods that let you
+supply a closure that will be called once with the row metadata in addition to the normal row closure
+which is called for each row. The following example illustrates the two closure variant for `eachRow`:
+
+[source,groovy]
+.Using row and metadata closures
+----
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_basic_rs_metadata3,indent=0]
+----
+
+Note that our SQL query will only return one row, so we could have equally used `firstRow` for the previous example.
+
+Finally, JDBC also provides metadata per connection (not just for rows). You can also access such metadata from Groovy as shown in this example:
+
+[source,groovy]
+.Using connection metadata
+----
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_basic_table_metadata,indent=0]
+----
+
+Consult the JavaDoc for your driver to find out what metadata information is available for you to access.
=== Named and named-ordinal parameters
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/a7139b6f/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
index bfa5daf..eb249ce 100644
--- a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
+++ b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
@@ -310,14 +310,38 @@ class SqlTest extends GroovyTestCase {
"""
sql.execute "INSERT INTO Author (firstname, lastname) VALUES ('Dierk', 'Koenig')"
- // tag::sql_basic_metadata[]
- sql.eachRow("SELECT * FROM Author where firstname = 'Dierk'") { row ->
+ // tag::sql_basic_rs_metadata[]
+ sql.eachRow("SELECT * FROM Author WHERE firstname = 'Dierk'") { row ->
def md = row.getMetaData()
- assert md.getTableName(1).toLowerCase() == 'author'
- assert (1..md.columnCount).collect{ md.getColumnTypeName(it).toLowerCase() } == ['integer', 'varchar', 'varchar']
- assert (1..md.columnCount).collect{ md.getColumnLabel(it).toLowerCase() } == ['id', 'firstname', 'lastname']
+ assert md.getTableName(1) == 'AUTHOR'
+ assert (1..md.columnCount).collect{ md.getColumnName(it) } == ['ID', 'FIRSTNAME', 'LASTNAME']
+ assert (1..md.columnCount).collect{ md.getColumnTypeName(it) } == ['INTEGER', 'VARCHAR', 'VARCHAR']
}
- // end::sql_basic_metadata[]
+ // end::sql_basic_rs_metadata[]
+ // tag::sql_basic_rs_metadata2[]
+ sql.eachRow("SELECT firstname AS first FROM Author WHERE firstname = 'Dierk'") { row ->
+ def md = row.getMetaData()
+ assert md.getColumnName(1) == 'FIRSTNAME'
+ assert md.getColumnLabel(1) == 'FIRST'
+ }
+ // end::sql_basic_rs_metadata2[]
+ // tag::sql_basic_rs_metadata3[]
+ def metaClosure = { meta -> assert meta.getColumnName(1) == 'FIRSTNAME' }
+ def rowClosure = { row -> assert row.FIRSTNAME == 'Dierk' }
+ sql.eachRow("SELECT firstname FROM Author WHERE firstname = 'Dierk'", metaClosure, rowClosure)
+ // end::sql_basic_rs_metadata3[]
+ // build currently uses the jdk5 classifier version of hsqldb.jar which is JDBC 3
+ // TODO remove this classifier since we now require jdk6+
+ // tag::sql_basic_table_metadata[]
+ def md = sql.connection.metaData
+ assert md.driverName == 'HSQL Database Engine Driver'
+ assert md.databaseProductVersion == '2.3.2'
+ assert ['JDBCMajorVersion', 'JDBCMinorVersion'].collect{ md[it] } == [3, 0]
+ assert md.stringFunctions.tokenize(',').contains('CONCAT')
+ def rs = md.getTables(null, null, 'AUTH%', null)
+ assert rs.next()
+ assert rs.getString('TABLE_NAME') == 'AUTHOR'
+ // end::sql_basic_table_metadata[]
}
'''
}
[6/9] incubator-groovy git commit: groovy-sql: doco for transactions
Posted by pa...@apache.org.
groovy-sql: doco for transactions
Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/46db4bc8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/46db4bc8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/46db4bc8
Branch: refs/heads/GROOVY_2_4_X
Commit: 46db4bc807a7fcb39223fbb40fecc301c99961bb
Parents: fb1eeb5
Author: Paul King <pa...@asert.com.au>
Authored: Sat Apr 18 21:41:10 2015 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Mon Apr 20 17:23:31 2015 +1000
----------------------------------------------------------------------
.../groovy-sql/src/spec/doc/sql-userguide.adoc | 23 +++++++++-
.../groovy-sql/src/spec/test/SqlTest.groovy | 46 ++++++++++++++++++++
2 files changed, 68 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/46db4bc8/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
----------------------------------------------------------------------
diff --git a/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc b/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
index ba2f11d..b78d5d1 100644
--- a/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
+++ b/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
@@ -224,7 +224,28 @@ include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[ta
=== Working with transactions
-(TBD)
+The easiest way to perform database operations within a transaction is to include the database operation within a `withTransaction` closure as shown in the following example:
+
+[source,groovy]
+.A successful transaction
+----
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_transaction_pass,indent=0]
+----
+
+Here the database starts empty and has two rows after successful completion of the operation. Outside the scope of the
+transaction, the database is never seen as having just one row.
+
+If something goes wrong, any earlier operations within the `withTransaction` block are rolled back.
+We can see that in operation in the following example where we use database metadata (more details coming up shortly) to find the
+maximum allowable size of the `firstname` column and then attempt to enter a firstname one larger than that maximum value as shown here:
+
+[source,groovy]
+.A failed transaction will cause a rollback
+----
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_transaction_fail,indent=0]
+----
+
+Even though the first sql execute succeeds initially, it will be rolled back and the number of rows will remain the same.
=== Using batches
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/46db4bc8/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
index 21d3959..070e2ac 100644
--- a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
+++ b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
@@ -382,6 +382,52 @@ class SqlTest extends GroovyTestCase {
'''
}
+ void testTransactions() {
+ assertScript '''
+ import groovy.sql.Sql
+
+ def url = 'jdbc:hsqldb:mem:yourDB'
+ def user = 'sa'
+ def password = ''
+ def driver = 'org.hsqldb.jdbcDriver'
+ Sql.withInstance(url, user, password, driver) { sql ->
+ sql.execute """
+ DROP TABLE Author IF EXISTS
+ """
+ sql.execute """
+ CREATE TABLE Author (
+ id INTEGER GENERATED BY DEFAULT AS IDENTITY,
+ firstname VARCHAR(64),
+ lastname VARCHAR(64)
+ )
+ """
+ // tag::sql_transaction_pass[]
+ assert sql.firstRow('SELECT COUNT(*) as num FROM Author').num == 0
+ sql.withTransaction {
+ sql.execute "INSERT INTO Author (firstname, lastname) VALUES ('Dierk', 'Koenig')"
+ sql.execute "INSERT INTO Author (firstname, lastname) VALUES ('Jon', 'Skeet')"
+ }
+ assert sql.firstRow('SELECT COUNT(*) as num FROM Author').num == 2
+ // end::sql_transaction_pass[]
+ // tag::sql_transaction_fail[]
+ def maxFirstnameLength
+ def metaClosure = { meta -> maxFirstnameLength = meta.getPrecision(1) }
+ def rowClosure = {}
+ def rowCountBefore = sql.firstRow('SELECT COUNT(*) as num FROM Author').num
+ try {
+ sql.withTransaction {
+ sql.execute "INSERT INTO Author (firstname) VALUES ('Dierk')"
+ sql.eachRow "SELECT firstname FROM Author WHERE firstname = 'Dierk'", metaClosure, rowClosure
+ sql.execute "INSERT INTO Author (firstname) VALUES (?)", 'X' * (maxFirstnameLength + 1)
+ }
+ } catch(ignore) { println ignore.message }
+ def rowCountAfter = sql.firstRow('SELECT COUNT(*) as num FROM Author').num
+ assert rowCountBefore == rowCountAfter
+ // end::sql_transaction_fail[]
+ }
+ '''
+ }
+
void testDeletingRows() {
assertScript '''
import groovy.sql.Sql
[7/9] incubator-groovy git commit: groovy-sql: doco for batching
Posted by pa...@apache.org.
groovy-sql: doco for batching
Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/58ba4de1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/58ba4de1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/58ba4de1
Branch: refs/heads/GROOVY_2_4_X
Commit: 58ba4de16d21376fadc759c4f75b17fe38e0f072
Parents: 46db4bc
Author: Paul King <pa...@asert.com.au>
Authored: Sun Apr 19 21:26:19 2015 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Mon Apr 20 17:23:31 2015 +1000
----------------------------------------------------------------------
.../groovy-sql/src/spec/doc/sql-userguide.adoc | 46 +++++++++++-
.../groovy-sql/src/spec/test/SqlTest.groovy | 74 ++++++++++++++++++++
2 files changed, 119 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/58ba4de1/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
----------------------------------------------------------------------
diff --git a/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc b/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
index b78d5d1..d0e4ff0 100644
--- a/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
+++ b/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
@@ -249,7 +249,51 @@ Even though the first sql execute succeeds initially, it will be rolled back and
=== Using batches
-(TBD)
+When dealing with large volumes of data, it can be more efficient to chunk the data into batches. This is done
+using the `withBatch` statement as shown in the following example:
+
+[source,groovy]
+.Batching SQL statements
+----
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_batch_statements,indent=0]
+----
+
+After executing these statements, there will be 7 new rows in the database. In fact, they will have been added in batches
+even though you can't easily tell that after that fact. If you want to confirm what is going on under the covers, you can
+add a little bit of extra logging into your program. Add the following lines before the `withBatch` statement:
+
+[source,groovy]
+.Logging additional SQL information
+----
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_batch_import_for_logging,indent=0]
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_batch_logging,indent=0]
+----
+
+With this extra logging turned on, and the changes made as per the above comment for the logging.properties file, you should see
+output such as:
+
+[source]
+.SQL logging output with batching enable
+----
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_batch_results,indent=0]
+----
+
+We should also note, that any combination of SQL statements can be added to the batch. They don't all have to be
+inserting a new row to the same table.
+
+We noted earlier that to avoid SQL injection, we encourage you to use prepared statements, this is achieved using the
+variants of methods which take GStrings or a list of extra parameters. Prepared statements can be used in combination
+with batches as shown in the following example:
+
+[source,groovy]
+.Batching prepared statements
+----
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_batch_prepared_statements,indent=0]
+----
+
+This provides a much safer option if the data could come from a user such as via a script or a web form. Of course, given
+that a prepared statement is being used, you are limited to a batch of the same SQL operation (insert in our example)
+to the one table.
=== Performing pagination
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/58ba4de1/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
index 070e2ac..f5b5c9b 100644
--- a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
+++ b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
@@ -428,6 +428,80 @@ class SqlTest extends GroovyTestCase {
'''
}
+ void testBatching() {
+ assertScript '''
+ import groovy.sql.Sql
+ // tag::sql_batch_import_for_logging[]
+ import java.util.logging.*
+
+ // end::sql_batch_import_for_logging[]
+
+ def url = 'jdbc:hsqldb:mem:yourDB'
+ def user = 'sa'
+ def password = ''
+ def driver = 'org.hsqldb.jdbcDriver'
+ Sql.withInstance(url, user, password, driver) { sql ->
+ sql.execute """
+ DROP TABLE Author IF EXISTS
+ """
+ sql.execute """
+ CREATE TABLE Author (
+ id INTEGER GENERATED BY DEFAULT AS IDENTITY,
+ firstname VARCHAR(64),
+ lastname VARCHAR(64)
+ )
+ """
+
+ // tag::sql_batch_logging[]
+ // next line will add fine logging
+ Logger.getLogger('groovy.sql').level = Level.FINE
+ // also adjust logging.properties file in JRE_HOME/lib to have:
+ // java.util.logging.ConsoleHandler.level = FINE
+ // end::sql_batch_logging[]
+
+ // tag::sql_batch_statements[]
+ sql.withBatch(3) { stmt ->
+ stmt.addBatch "INSERT INTO Author (firstname, lastname) VALUES ('Dierk', 'Koenig')"
+ stmt.addBatch "INSERT INTO Author (firstname, lastname) VALUES ('Paul', 'King')"
+ stmt.addBatch "INSERT INTO Author (firstname, lastname) VALUES ('Guillaume', 'Laforge')"
+ stmt.addBatch "INSERT INTO Author (firstname, lastname) VALUES ('Hamlet', 'D''Arcy')"
+ stmt.addBatch "INSERT INTO Author (firstname, lastname) VALUES ('Cedric', 'Champeau')"
+ stmt.addBatch "INSERT INTO Author (firstname, lastname) VALUES ('Erik', 'Pragt')"
+ stmt.addBatch "INSERT INTO Author (firstname, lastname) VALUES ('Jon', 'Skeet')"
+ }
+ // end::sql_batch_statements[]
+ assert sql.firstRow('SELECT COUNT(*) as num FROM Author').num == 7
+ /*
+ // tag::sql_batch_results[]
+ FINE: Successfully executed batch with 3 command(s)
+ Apr 19, 2015 8:38:42 PM groovy.sql.BatchingStatementWrapper processResult
+
+ FINE: Successfully executed batch with 3 command(s)
+ Apr 19, 2015 8:38:42 PM groovy.sql.BatchingStatementWrapper processResult
+
+ FINE: Successfully executed batch with 1 command(s)
+ Apr 19, 2015 8:38:42 PM groovy.sql.Sql getStatement
+ // end::sql_batch_results[]
+ */
+ sql.execute('DELETE FROM Author')
+ assert sql.firstRow('SELECT COUNT(*) as num FROM Author').num == 0
+ // tag::sql_batch_prepared_statements[]
+ def qry = 'INSERT INTO Author (firstname, lastname) VALUES (?,?)'
+ sql.withBatch(3, qry) { ps ->
+ ps.addBatch('Dierk', 'Koenig')
+ ps.addBatch('Paul', 'King')
+ ps.addBatch('Guillaume', 'Laforge')
+ ps.addBatch('Hamlet', "D'Arcy")
+ ps.addBatch('Cedric', 'Champeau')
+ ps.addBatch('Erik', 'Pragt')
+ ps.addBatch('Jon', 'Skeet')
+ }
+ // end::sql_batch_prepared_statements[]
+ assert sql.firstRow('SELECT COUNT(*) as num FROM Author').num == 7
+ }
+ '''
+ }
+
void testDeletingRows() {
assertScript '''
import groovy.sql.Sql
[5/9] incubator-groovy git commit: groovy-sql: doco for named and
named-ordinal placeholders
Posted by pa...@apache.org.
groovy-sql: doco for named and named-ordinal placeholders
Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/fb1eeb53
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/fb1eeb53
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/fb1eeb53
Branch: refs/heads/GROOVY_2_4_X
Commit: fb1eeb53e7232c688364bc71c1735196dc1b81eb
Parents: 8798de7
Author: Paul King <pa...@asert.com.au>
Authored: Sat Apr 18 12:01:24 2015 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Mon Apr 20 17:22:40 2015 +1000
----------------------------------------------------------------------
.../groovy-sql/src/spec/doc/sql-userguide.adoc | 35 +++++++++++++++++-
.../groovy-sql/src/spec/test/SqlTest.groovy | 38 ++++++++++++++++++++
2 files changed, 72 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/fb1eeb53/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
----------------------------------------------------------------------
diff --git a/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc b/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
index 5d06fd8..ba2f11d 100644
--- a/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
+++ b/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
@@ -277,7 +277,40 @@ Consult the JavaDoc for your driver to find out what metadata information is ava
=== Named and named-ordinal parameters
-(TBD)
+Groovy supports some additional alternative placeholder syntax variants. The GString variants
+are typically preferred over these alternatives but the alternatives are useful for Java integration
+purposes and sometimes in templating scenarios where GStrings might already be in heavy use as part
+of a template. The named parameter variants are much like the String plus list of parameter variants but
+instead of having a list of `?` placeholders followed by a list of parameters, you have one or more
+placeholders having the form `:propName` or `?.propName` and a single map, named arguments or a
+domain object as the parameter. The map or domain object should have a property named `propName`
+corresponding to each supplied placeholder.
+
+Here is an example using the colon form:
+
+[source,groovy]
+.Named parameters (colon form)
+----
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_named,indent=0]
+----
+
+And another example using the question mark form:
+
+[source,groovy]
+.Named parameters (question mark form)
+----
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_named2,indent=0]
+----
+
+If the information you need to supply is spread across multiple maps or domain objects you can
+use the question mark form with an additional ordinal index as shown here:
+
+[source,groovy]
+.Named-ordinal parameters
+----
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_named_ordinal1,indent=0]
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_named_ordinal2,indent=0]
+----
=== Stored procedures
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/fb1eeb53/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
index 22d087f..21d3959 100644
--- a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
+++ b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
@@ -344,6 +344,44 @@ class SqlTest extends GroovyTestCase {
'''
}
+ void testNamedOrdinal() {
+ assertScript '''
+ import groovy.sql.Sql
+
+ def url = 'jdbc:hsqldb:mem:yourDB'
+ def user = 'sa'
+ def password = ''
+ def driver = 'org.hsqldb.jdbcDriver'
+ // tag::sql_named_ordinal1[]
+ class Rockstar { String first, last }
+ // end::sql_named_ordinal1[]
+ Sql.withInstance(url, user, password, driver) { sql ->
+ sql.execute """
+ DROP TABLE Author IF EXISTS
+ """
+ sql.execute """
+ CREATE TABLE Author (
+ id INTEGER GENERATED BY DEFAULT AS IDENTITY,
+ firstname VARCHAR(64),
+ lastname VARCHAR(64)
+ )
+ """
+ // tag::sql_named[]
+ sql.execute "INSERT INTO Author (firstname, lastname) VALUES (:first, :last)", first: 'Dierk', last: 'Koenig'
+ // end::sql_named[]
+ // tag::sql_named2[]
+ sql.execute "INSERT INTO Author (firstname, lastname) VALUES (?.first, ?.last)", first: 'Jon', last: 'Skeet'
+ // end::sql_named2[]
+ // tag::sql_named_ordinal2[]
+ def pogo = new Rockstar(first: 'Paul', last: 'McCartney')
+ def map = [lion: 'King']
+ sql.execute "INSERT INTO Author (firstname, lastname) VALUES (?1.first, ?2.lion)", pogo, map
+ // end::sql_named_ordinal2[]
+ assert sql.firstRow('SELECT COUNT(*) as num FROM Author').num == 3
+ }
+ '''
+ }
+
void testDeletingRows() {
assertScript '''
import groovy.sql.Sql
[3/9] incubator-groovy git commit: groovy-sql: update test dependency
(no longer need jdk5 artifact)
Posted by pa...@apache.org.
groovy-sql: update test dependency (no longer need jdk5 artifact)
Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/8798de71
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/8798de71
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/8798de71
Branch: refs/heads/GROOVY_2_4_X
Commit: 8798de7172ade2c6938a72002a13829bd9430e25
Parents: 2b82324
Author: Paul King <pa...@asert.com.au>
Authored: Sat Apr 18 08:56:23 2015 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Mon Apr 20 17:22:39 2015 +1000
----------------------------------------------------------------------
subprojects/groovy-sql/src/spec/test/SqlTest.groovy | 2 --
1 file changed, 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/8798de71/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
index 40e237f..22d087f 100644
--- a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
+++ b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
@@ -330,8 +330,6 @@ class SqlTest extends GroovyTestCase {
def rowClosure = { row -> assert row.FIRSTNAME == 'Dierk' }
sql.eachRow("SELECT firstname FROM Author WHERE firstname = 'Dierk'", metaClosure, rowClosure)
// end::sql_basic_rs_metadata3[]
- // build currently uses the jdk5 classifier version of hsqldb.jar which is JDBC 3
- // TODO remove this classifier since we now require jdk6+
// tag::sql_basic_table_metadata[]
def md = sql.connection.metaData
assert md.driverName == 'HSQL Database Engine Driver'