groovy
  1. groovy
  2. GROOVY-2859

make GroovyResultSet object printable

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.6-beta-1
    • Fix Version/s: 1.5.7, 1.6-beta-2
    • Component/s: SQL processing
    • Labels:
      None
    • Number of attachments :
      0

      Description

      If I try to print GroovyResultSet object, NullPointerException will be raised.

      So if groovy could convert the GroovyResultSet object into the List object whose elements are map object representing records retrieved from database when we print it, that would be great!

      currently, we have to write code as follows

      results3.info.eachRow { row ->
          println "name:${row.name}, address:${row.address}"
      }
      

      code like the following is what I expected, but will raise NPE

      println results3.info
      

      Thanks in advance.
      Daniel.Sun

        Issue Links

          Activity

          Hide
          Daniel.Sun added a comment -

          When I executed the following code:

          println results3.info.getClass()  // results3.info is a GroovyResultSet object
          

          MissingMethodException occurred:

          Caught: groovy.lang.MissingMethodException: No signature of method: groovy.sql.GroovyResultSet.getCl
          ass() is applicable for argument types: () values: {}
          

          I'm using groovy downloaded from http://build.canoo.com/groovy/artifacts//20080523211725

          Show
          Daniel.Sun added a comment - When I executed the following code: println results3.info.getClass() // results3.info is a GroovyResultSet object MissingMethodException occurred: Caught: groovy.lang.MissingMethodException: No signature of method: groovy.sql.GroovyResultSet.getCl ass() is applicable for argument types: () values: {} I'm using groovy downloaded from http://build.canoo.com/groovy/artifacts//20080523211725
          Hide
          Paul King added a comment -

          There is now a DGM method that converts a ResultSet to a GroovyRowResult. GroovyRowResult implements Map and all the normal java.lang.Object methods work on it. Will this suffice for this issue?

          Show
          Paul King added a comment - There is now a DGM method that converts a ResultSet to a GroovyRowResult . GroovyRowResult implements Map and all the normal java.lang.Object methods work on it. Will this suffice for this issue?
          Hide
          Daniel.Sun added a comment -

          GroovyRowResult will meet our requirement
          but how can I convert a GroovyResultSet object to a GroovyRowResult object ?
          Could you tell me the name of DGM method?

          Thanks,
          Daniel.Sun

          Show
          Daniel.Sun added a comment - GroovyRowResult will meet our requirement but how can I convert a GroovyResultSet object to a GroovyRowResult object ? Could you tell me the name of DGM method? Thanks, Daniel.Sun
          Hide
          Paul King added a comment -

          Given ResultSet rs just call rs.toRowResult().

          Show
          Paul King added a comment - Given ResultSet rs just call rs.toRowResult() .
          Hide
          Daniel.Sun added a comment -

          Thanks Paul

          Show
          Daniel.Sun added a comment - Thanks Paul
          Hide
          Daniel.Sun added a comment -

          Hi Paul,

          I tried to invoke the toRowResult method you mentioned, but failed:

          Caught: groovy.lang.MissingMethodException: No signature of method: groovy.sql.GroovyResultSet.toRowResult() is applicable for argument types: () values: {}

          Does toRowResult method exist in the groovy1.6.0beta1 ?

          Thanks,
          Daniel.Sun

          Show
          Daniel.Sun added a comment - Hi Paul, I tried to invoke the toRowResult method you mentioned, but failed: Caught: groovy.lang.MissingMethodException: No signature of method: groovy.sql.GroovyResultSet.toRowResult() is applicable for argument types: () values: {} Does toRowResult method exist in the groovy1.6.0beta1 ? Thanks, Daniel.Sun
          Hide
          Paul King added a comment -

          As per the fix version: 1.5.7, 1.6-beta-2

          Show
          Paul King added a comment - As per the fix version: 1.5.7, 1.6-beta-2
          Hide
          Daniel.Sun added a comment -

          I see

          Thanks Paul!

          Show
          Daniel.Sun added a comment - I see Thanks Paul!
          Hide
          Daniel.Sun added a comment -

          Hi Paul,

          I downloaded the latest distribution of groovy from http://build.canoo.com/groovy/artifacts//20080603122913

          and tried to convert GroovyResultSet object to RowResult object via toRowResult method.

          but I encountered java.sql.SQLException:结果集已耗尽, these Chinese words means 'the resultset has been exhausted'

          btw, I'm using Oracle10G

          Thanks,
          Daniel.Sun

          Show
          Daniel.Sun added a comment - Hi Paul, I downloaded the latest distribution of groovy from http://build.canoo.com/groovy/artifacts//20080603122913 and tried to convert GroovyResultSet object to RowResult object via toRowResult method. but I encountered java.sql.SQLException:结果集已耗尽, these Chinese words means 'the resultset has been exhausted' btw, I'm using Oracle10G Thanks, Daniel.Sun

            People

            • Assignee:
              Paul King
              Reporter:
              Daniel.Sun
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: