groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [groovy] 02/02: GROOVY-9085: Add INOUT stored procedure example to asciidoc doc for groovy-sql (closes #893)
Date Tue, 16 Apr 2019 04:13:20 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 77457e945f1d58deb27bd2488eb1f6a222b7ca2a
Author: Paul King <paulk@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[]
         }
         '''
-    }   
+    }
 
 }


Mime
View raw message