• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Groovy If else statement ignoring the if condition in block of code

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello. I have a piece of code that I've been working on using JDBC and Groovy, to retrieve id's from a specified filter for report results.
I have my filter wrapped in an if else statement, which checks for All book types in the if and everything else in the else.

However, when I select 'All' as my filter choice, the if appears to be ignored and the else code is run, which cannot return a correct id for this choice, causing it to fail.
I am at a loss as to why this block of code is being ignored.

The code is as follows:



This code is then passed into another query which gets back the book type by the specified id:

 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't see anything wrong with the if statement. I would put an assert in the else part of the if to see if all of your assumptions are correct.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Um, what is the actual value of bookType? You can either put a break point in there to see the value when it gets there, or a log message, or even a println "${bookType}"

Maybe there isn't an "ALL" value, maybe it is "All" or "all" where it is a different case. The only time an else will run is if the "if" is truly false. I like that truly false. Or just false.

Mark
reply
    Bookmark Topic Watch Topic
  • New Topic