You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2019/04/16 04:12:10 UTC

[groovy] branch master updated (5a2d84d -> be7961a)

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git.


    from 5a2d84d  GROOVY-9083: groovyConsole should be updated to understand method references and lambda expressions
     new 3502c9d  Added example in sql module for calling stored function with in out parameter
     new be7961a  GROOVY-9085: Add INOUT stored procedure example to asciidoc doc for groovy-sql (closes #893)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../groovy-sql/src/spec/doc/sql-userguide.adoc     | 12 +++++++
 .../groovy-sql/src/spec/test/SqlTest.groovy        | 37 ++++++++++++++++++++--
 2 files changed, 47 insertions(+), 2 deletions(-)


[groovy] 02/02: GROOVY-9085: Add INOUT stored procedure example to asciidoc doc for groovy-sql (closes #893)

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit be7961adfeb1144ec4d474fe9f65e0eea4efe390
Author: Paul King <pa...@asert.com.au>
AuthorDate: Tue Apr 16 14:12:04 2019 +1000

    GROOVY-9085: Add INOUT stored procedure example to asciidoc doc for groovy-sql (closes #893)
---
 .../groovy-sql/src/spec/doc/sql-userguide.adoc     | 11 +++---
 .../groovy-sql/src/spec/test/SqlTest.groovy        | 39 ++++++++++------------
 2 files changed, 22 insertions(+), 28 deletions(-)

diff --git a/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc b/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
index 357f1bf..2867a00 100644
--- a/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
+++ b/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
@@ -462,16 +462,15 @@ include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[ta
 ----
 
 [source,groovy]
-.Using a stored function with input/output parameter
+.Creating a stored procedure with an input/output parameter
 ----
-include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_use_stored_fun_inout_parameter,indent=0]
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_create_stored_fun_inout_parameter,indent=0]
 ----
 
-Printed message is "result: RET_OK -- message: MESSAGE_OK"
-
-Function `CHECK_ID_POSITIVE_IN_OUT` is defined in Oracle as:
+[source,groovy]
+.Using a stored procedure with an input/output parameter
 ----
-include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_create_stored_fun_inout_parameter,indent=0]
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_use_stored_fun_inout_parameter,indent=0]
 ----
 
 == Using DataSets
diff --git a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
index 72dcce6..6d9f33e 100644
--- a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
+++ b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
@@ -18,8 +18,8 @@
  */
 
 /**
-* Tests for groovy.sql.Sql.
-*/
+ * Tests for groovy.sql.Sql.
+ */
 class SqlTest extends GroovyTestCase {
 
     void testConnectingToHsqlDB() {
@@ -687,7 +687,7 @@ class SqlTest extends GroovyTestCase {
         }
         '''
     }
-    
+
     void testStoredFunWithInOutParameter() {
         assertScript '''
         import groovy.sql.Sql
@@ -699,31 +699,26 @@ class SqlTest extends GroovyTestCase {
         Sql.withInstance(url, user, password, driver) { sql ->
           // tag::sql_create_stored_fun_inout_parameter[]
           sql.execute """
-           CREATE OR REPLACE FUNCTION CHECK_ID_POSITIVE_IN_OUT ( p_err IN OUT VARCHAR2, pparam NUMBER)
-           RETURN VARCHAR2 IS
-           re VARCHAR2(15);
-
-           BEGIN
-            IF pparam > 0 THEN
-              p_err := p_err || '_OK';
-              re := 'RET_OK';
-            ELSE 
-              p_err := p_err || '_ERROR';
-              re := 'RET_ERROR';   
-            END IF;
-
-            RETURN re;
-           END;
+            CREATE PROCEDURE CHECK_ID_POSITIVE_IN_OUT ( INOUT p_err VARCHAR(64), IN pparam INTEGER, OUT re VARCHAR(15))
+            BEGIN ATOMIC
+              IF pparam > 0 THEN
+                set p_err = p_err || '_OK';
+                set re = 'RET_OK';
+              ELSE
+                set p_err = p_err || '_ERROR';
+                set re = 'RET_ERROR';
+              END IF;
+            END;
           """
           // end::sql_create_stored_fun_inout_parameter[]
           // tag::sql_use_stored_fun_inout_parameter[]
-          def scall = "{? = call CHECK_ID_POSITIVE_IN_OUT(?, ?)}"
-          sql.call scall, [Sql.VARCHAR, Sql.inout(Sql.VARCHAR("MESSAGE")), 1], {
-            res, p_err -> println("result: $res -- message: $p_err")
+          def scall = "{call CHECK_ID_POSITIVE_IN_OUT(?, ?, ?)}"
+          sql.call scall, [Sql.inout(Sql.VARCHAR("MESSAGE")), 1, Sql.VARCHAR], {
+            res, p_err -> assert res == 'MESSAGE_OK' && p_err == 'RET_OK'
           }
           // end::sql_use_stored_fun_inout_parameter[]
         }
         '''
-    }   
+    }
 
 }


[groovy] 01/02: Added example in sql module for calling stored function with in out parameter

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 3502c9d08400c58e30299c7c3d3ad35511d7b009
Author: Mariusz Wasak <ma...@gmail.com>
AuthorDate: Sat Mar 9 23:54:38 2019 +0100

    Added example in sql module for calling stored function with in out parameter
---
 .../groovy-sql/src/spec/doc/sql-userguide.adoc     | 13 ++++++++
 .../groovy-sql/src/spec/test/SqlTest.groovy        | 38 ++++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc b/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
index 31c1e34..357f1bf 100644
--- a/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
+++ b/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
@@ -461,6 +461,19 @@ as parameters to the method call. For output parameters, the resulting type must
 include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_use_stored_proc_inout,indent=0]
 ----
 
+[source,groovy]
+.Using a stored function with input/output parameter
+----
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_use_stored_fun_inout_parameter,indent=0]
+----
+
+Printed message is "result: RET_OK -- message: MESSAGE_OK"
+
+Function `CHECK_ID_POSITIVE_IN_OUT` is defined in Oracle as:
+----
+include::{rootProjectDir}/subprojects/groovy-sql/src/spec/test/SqlTest.groovy[tags=sql_create_stored_fun_inout_parameter,indent=0]
+----
+
 == Using DataSets
 
 (TBD)
diff --git a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
index a8c191f..72dcce6 100644
--- a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
+++ b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
@@ -687,5 +687,43 @@ class SqlTest extends GroovyTestCase {
         }
         '''
     }
+    
+    void testStoredFunWithInOutParameter() {
+        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_fun_inout_parameter[]
+          sql.execute """
+           CREATE OR REPLACE FUNCTION CHECK_ID_POSITIVE_IN_OUT ( p_err IN OUT VARCHAR2, pparam NUMBER)
+           RETURN VARCHAR2 IS
+           re VARCHAR2(15);
+
+           BEGIN
+            IF pparam > 0 THEN
+              p_err := p_err || '_OK';
+              re := 'RET_OK';
+            ELSE 
+              p_err := p_err || '_ERROR';
+              re := 'RET_ERROR';   
+            END IF;
+
+            RETURN re;
+           END;
+          """
+          // end::sql_create_stored_fun_inout_parameter[]
+          // tag::sql_use_stored_fun_inout_parameter[]
+          def scall = "{? = call CHECK_ID_POSITIVE_IN_OUT(?, ?)}"
+          sql.call scall, [Sql.VARCHAR, Sql.inout(Sql.VARCHAR("MESSAGE")), 1], {
+            res, p_err -> println("result: $res -- message: $p_err")
+          }
+          // end::sql_use_stored_fun_inout_parameter[]
+        }
+        '''
+    }   
 
 }