Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-1916

I need to get the metaData even when I get no results/I'd like an easier way to get the metaData from the Sql class.

    XMLWordPrintableJSON

Details

    • Wish
    • Status: Closed
    • Trivial
    • Resolution: Fixed
    • 1.0-beta-1
    • 1.1-beta-2
    • groovy-jdk, SQL processing
    • None
    • suse linux 10.0, jdk 1.6, but it probably affects all systems.
    • Patch

    Description

      I was not able to find a way to get sql metadata even when there are no rows returned
      with the current Groovy sql stuff, so I subclassed groovy.sql.Sql and added a new
      version of eachRow and rows such that each takes an additional "metaClosure" so
      that I can feed the metaClosure the result set's meta data. that way, even if I don't have any
      rows returned, I can be sure to have the meta data. And I don't have to
      delve into the row processing closure to get the meta data from the first row
      or anything like that.

      I made my own subclass and added the following methods:

      public List rows( final String sql,
      final Closure metaClosure )

      public void eachRow( final String sql,
      final Closure metaClosure,
      final Closure rowClosure )

      So now I can:

      def metaData
      def results = sql.rows( query )

      { metaData = it }

      I didn't make a groovier version of the metadata class the way there's a
      GroovyRowResult and GroovyResultSet class. I was very impressed with how
      easy it was to do what I needed to do.

      I have attached the methods I added, but they are not in the approved groovy format.

      Attachments

        1. Sql.java
          3 kB
          Thomas R. Corbin

        Activity

          People

            blackdrag Jochen Theodorou
            trcorbin Thomas R. Corbin
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: