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

Round out eachRows() and rows() variants taking metaDataClosure.

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.7-beta-1
    • 1.6.6, 1.7-rc-1
    • SQL processing
    • None
    • Any
    • Patch

    Description

      Currently Sql has these variants of eachRows() and rows():

      eachRow(String sql, Closure closure)
      eachRow(String sql, Closure metaClosure, Closure closure)
      eachRow(String sql, List params, Closure closure)
      eachRow(GString sql, Closure closure)
      
      rows(String sql)
      rows(GString sql)
      rows(String sql, Closure metaClosure)
      rows(String sql, List params)
      

      This patch rounds out support for metaDataClosures so that they can be used in variants taking params and GStrings.

      I've needed this on most of these methods on one occasion or another, and I don't see any reason why each variant should not be supported:

      eachRow(String sql, Closure closure)
      eachRow(String sql, Closure metaClosure, Closure closure)
      eachRow(String sql, List params, Closure closure)
      eachRow(String sql, List params, Closure metaClosure, Closure closure)
      eachRow(GString sql, Closure closure)
      eachRow(GString sql, Closure metaClosure, Closure closure)
      
      rows(String sql)
      rows(String sql, Closure metaClosure)
      rows(String sql, List params)
      rows(String sql, Closure metaClosure, List params)
      rows(GString sql)
      rows(GString sql, Closure metaClosure)
      

      I have expanded the tests to cover all of these variants. I've renamed some of the test methods to name them according to the signatures of the methods they test. This is a more systematic naming convention, which seems to be required with all of these variants.

      I noticed a couple of tests with misleading names. For example, currently in trunk:

          void testRowsGString() {
              def sql = createSql()
              def table = 'PERSON'
              GString query = "select * from $table"
              def result = sql.rows(query.toString())
              assert result.size() == 3
          }
      

      Either I am misunderstanding this test, or else it's wrong. By calling toString() on the GString, the test is not passing it as a GString, and not exercising the GString variant of the rows() method. Perhaps this test has been modified from a previous form.

      In my patch I've corrected this for the rows() GString test, but left alone another test method called testFirstRowWithGString(). If I'm right we should fix that too. (I cam come back to it with another patch if I'm right.)

      I created the patch using git diff, but I tested it on svn trunk (on Linux) using GNU patch thus:

      patch -p1 -i metaclosure.patch
      

      It works for me. Please let me know if there's anything I can do to make patches in a more convenient format for you.

      I hope you find this agreeable!

      John Hurst

      Attachments

        1. metaclosure.patch
          27 kB
          John Hurst

        Activity

          People

            paulk Paul King
            john.b.hurst John Hurst
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: