[groovy-user] No errors/exceptions when using Sql.eachRow in Groovy 1.8.5

109 views
Skip to first unread message

Dan Fraser

unread,
Feb 2, 2012, 4:20:36 PM2/2/12
to us...@groovy.codehaus.org
I'm working on a script using Sql.eachRow in Groovy 1.8.5.

When an error/exception occurs within the eachRow closure, I have found
that the script will hang with no error output. Putting a simple syntax
error inside the closure will reproduce the behaviour.

Am I doing something wrong, or is this a bug?

Thanks,

Dan

--
Dan Fraser

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Tim Yates

unread,
Feb 2, 2012, 5:44:36 PM2/2/12
to us...@groovy.codehaus.org

Do you have an example that replicates this problem?

Tim

dfraser

unread,
Feb 3, 2012, 9:07:07 AM2/3/12
to us...@groovy.codehaus.org
The output from the following script on my system is:

dfraser$ groovy -cp ../lib/mysql-connector-java-5.1.18-bin.jar
Poptool.groovy
fizz
in loop
[hang]

It doesn't actually exit or print anything else.

Do you see a problem?

If I remove the throw, it gets to about 11500 rows and then hangs, probably
due to an exception, and I'm not sure why because there is no error message!

--snip--

package com.company.poptool

import groovy.sql.Sql

def sql = Sql.newInstance("jdbc:mysql://localhost:3306/pop", "user",
"pass", "com.mysql.jdbc.Driver")

sql.withStatement{ stmt -> stmt.fetchSize = Integer.MIN_VALUE }

def archiveTable = 'arch_2012-01-16'
def count = 0;

println("fizz")
sql.eachRow("select * from `${Sql.expand archiveTable}`") { row ->
count ++
println("in loop")
if (count % 100 == 0) {
println count
}
throw new IllegalArgumentException("boo!")
}
println("buzz")

--
View this message in context: http://groovy.329449.n5.nabble.com/No-errors-exceptions-when-using-Sql-eachRow-in-Groovy-1-8-5-tp5451985p5453942.html
Sent from the groovy - user mailing list archive at Nabble.com.

Dinko Srkoc

unread,
Feb 4, 2012, 1:06:57 PM2/4/12
to us...@groovy.codehaus.org
Hi Dan,

I tried your example with both Informix and PostgreSQL but was unable
to reproduce the problem. The things I had to change to be able to run
the example are:

* set the fetchSize to a positive number
* removed the "`" from the query

I don't think the culprit is groovy.sql.Sql as I don't see anything in
the source that would cause the hang, could it be MySQL's driver? Have
you tried another DBMS?

Cheers,
Dinko

dfraser

unread,
Feb 5, 2012, 10:29:34 AM2/5/12
to us...@groovy.codehaus.org
Hi, Dinko!  Thanks for doing the test. I re-wrote the code in Plain Old Java to see what was going on. I had the connection.close() in a finally block, which was blocking the termination of the program (including throwing exceptions) for some odd MySQL reason.  Groovy must put a try/finally around the sql operations. 

So there we go... it is a combination of finally and MySQL weirdness.  

Thanks again for testing.  It's not Groovy's fault at all. :)

--
Dan Fraser

On Feb 4, 2012, at 13:09, "Dinko Srkoc [via Groovy]" <[hidden email]> wrote:

Hi Dan,

I tried your example with both Informix and PostgreSQL but was unable
to reproduce the problem. The things I had to change to be able to run
the example are:

* set the fetchSize to a positive number
* removed the  "`" from the query

I don't think the culprit is groovy.sql.Sql as I don't see anything in
the source that would cause the hang, could it be MySQL's driver? Have
you tried another DBMS?

Cheers,
Dinko


If you reply to this email, your message will be added to the discussion below:
http://groovy.329449.n5.nabble.com/No-errors-exceptions-when-using-Sql-eachRow-in-Groovy-1-8-5-tp5451985p5456593.html
To unsubscribe from No errors/exceptions when using Sql.eachRow in Groovy 1.8.5, click here.
NAML


View this message in context: Re: No errors/exceptions when using Sql.eachRow in Groovy 1.8.5
Reply all
Reply to author
Forward
0 new messages