You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2026/10/20 01:28:02 UTC
[jira] [Closed] (GROOVY-5373) Sql DataSet fails to work with non-literals in queries (enhancement required)
[ https://issues.apache.org/jira/browse/GROOVY-5373?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King closed GROOVY-5373.
-----------------------------
> Sql DataSet fails to work with non-literals in queries (enhancement required)
> -----------------------------------------------------------------------------
>
> Key: GROOVY-5373
> URL: https://issues.apache.org/jira/browse/GROOVY-5373
> Project: Groovy
> Issue Type: New Feature
> Components: SQL processing
> Affects Versions: 2.0-beta-3, 2.1.4, 2.2.0-beta-1
> Reporter: Dr. Russel Winder
> Assignee: Paul King
> Priority: Major
> Fix For: 6.0.0-alpha-1
>
>
> All the examples of using _findAll_ in the _Sql_ _DataSet_ class use literals for the search values of queries. Using free variables causes failure as Groovy does not implement lexical closure automatically. However this can be realized using the Closure delegate field. I therefore believe that the following example fails because the _Sql.SqlWhereVisitor_ fails to lookup variables but assumes that all query values are literals.
> {code}
> @Grab('org.xerial:sqlite-jdbc:3.7.2')
> @GrabConfig(systemClassLoader=true)
> import groovy.sql.DataSet
> import groovy.sql.Sql
> final words = []
> Sql.withInstance('jdbc:sqlite:database.db', 'org.sqlite.JDBC') {database ->
> final wordsTable = new DataSet(database, 'words')
> (0 ..< 4).each {i ->
> // This doesn't work as SqlWhereVisitor doesn't resolve variables it only looks for
> // literals. cf. http://jira.codehaus.org/browse/GROOVY-5373
> final query = {item -> item.id == i}
> query.delegate = {i: i}
> query.resolveStrategy = Closure.DELEGATE_FIRST
> words << wordsTable.findAll(query).firstRow().word
> }
> }
> println words.join('')
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)