[ 
https://issues.apache.org/jira/browse/GROOVY-8128?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15943086#comment-15943086
 ] 

Michal Rydlo commented on GROOVY-8128:
--------------------------------------

Thanks for looking into this [~paulk]. If you just change the column type to 
integer it fails on PostgreSQL. This script:
{code}
@GrabConfig(systemClassLoader=true)
@Grab('org.postgresql:postgresql:42.0.0')
import groovy.sql.Sql
def sql = Sql.newInstance("jdbc:postgresql://localhost:5432/postgres", 
"username", "password", "org.postgresql.Driver")
println sql.rows('SELECT * FROM version()')
sql.execute 'DROP TABLE IF EXISTS A'
sql.execute 'CREATE TABLE A(x integer)'
sql.execute "INSERT INTO A SELECT ? UNION SELECT ?", [23, 45]
List rows = sql.rows('select * from A')
println "There are ${rows.size()} A row(s):"
println rows.collect { "$it.x" }.join(", ")
{code}

fails when run using Groovy 2.4.10:

{code}
$ ~/java/groovy-2.4.10/bin/groovy a.groovy
[[version:PostgreSQL 9.6.2 on x86_64-pc-linux-gnu, compiled by gcc (Debian 
4.9.2-10) 4.9.2, 64-bit]]
Mar 27, 2017 1:20:38 PM groovy.sql.Sql execute
WARNING: Failed to execute: INSERT INTO A SELECT ? UNION SELECT ? because: 
ERROR: column "x" is of type integer but expression is of type text
  Hint: You will need to rewrite or cast the expression.
  Position: 22
Caught: org.postgresql.util.PSQLException: ERROR: column "x" is of type integer 
but expression is of type text
  Hint: You will need to rewrite or cast the expression.
  Position: 22
org.postgresql.util.PSQLException: ERROR: column "x" is of type integer but 
expression is of type text
  Hint: You will need to rewrite or cast the expression.
  Position: 22
        at 
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2412)
        at 
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2125)
        at 
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:297)
        at 
org.postgresql.jdbc.PgPreparedStatement.getParameterMetaData(PgPreparedStatement.java:1569)
        at a.run(a.groovy:8)
{code}

> Breaking change in 2.4.9 with Sql query with GString
> ----------------------------------------------------
>
>                 Key: GROOVY-8128
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8128
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 2.4.9
>         Environment: Windows 7
>            Reporter: Mike Sauer
>            Priority: Critical
>
> The following code worked for releases 2.4.8 and below:
> {code}
>     def query = """\
>     SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED\r\n\
>     select u5f_documenttype from DocVersion dv left outer join 
> ClassDefinition cd on dv.object_class_id = cd.object_id 
>     where cd.symbolic_name in ('Retail', 'RetailWeb') and dv.is_current = 1
>     and u59_accountnumber = $acctNum and u5f_documenttype = 'Signature Card'
>     """
>     def docFound = 'No Doc'
>     consumerSql.eachRow(query) {
> {code}
> This code now fails in 2.4.9 and 2.4.10 with:
> {noformat}
> Mar 22, 2017 9:23:43 AM groovy.sql.Sql eachRow
> WARNING: Failed to execute:     SET TRANSACTION ISOLATION LEVEL READ 
> UNCOMMITTED
>     select u5f_documenttype from DocVersion dv left outer join 
> ClassDefinition cd on dv.object_class_id = cd.object_id 
>     where cd.symbolic_name in ('Retail', 'RetailWeb') and dv.is_current = 1
>     and u59_accountnumber = ? and u5f_documenttype = 'Signature Card'
>      because: com.microsoft.sqlserver.jdbc.SQLServerException: Unable to 
> identify the table     SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
>     select u5f_documenttype from DocVersion dv left outer join 
> ClassDefinition cd on dv.object_class_id = cd.object_id 
>     where cd.symbolic_name in ('Retail', 'RetailWeb') and dv.is_current = 1
>     and u59_accountnumber = ? and u5f_documenttype = 'Signature Card'
>      for the metadata.
> {noformat}
> I have tried changing to using placeholders and name parameters and I get 
> similar results.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to