Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL Dialect Doesn't Support NULLIF #11

Closed
dacc opened this issue Feb 23, 2012 · 10 comments
Closed

MySQL Dialect Doesn't Support NULLIF #11

dacc opened this issue Feb 23, 2012 · 10 comments

Comments

@dacc
Copy link

dacc commented Feb 23, 2012

Attempting to use nullif from a subtype of MySQLFactory causes an exception like the one below:

org.jooq.exception.SQLDialectNotSupportedException: Type class org.jooq.impl.CombinedCondition is not supported in dialect null
    at org.jooq.impl.AbstractDataType.getDataType(AbstractDataType.java:428)
    at org.jooq.impl.FieldTypeHelper.getDataType(FieldTypeHelper.java:781)
    at org.jooq.impl.Factory.getDataType(Factory.java:4470)
    at org.jooq.impl.Factory.val(Factory.java:4003)
    at org.jooq.impl.Factory.nullif(Factory.java:1578)

MySQL supports NULLIF as documented here:

http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html#function_nullif

@lukaseder
Copy link
Member

You cannot pass a condition to Factory.nullIf(). As specified in the MySQL docs, both arguments have to be expressions (i.e. org.jooq.Field, or T, which is any value that can be passed to Factory.val()). In jOOQ, a condition is not an expression/field

How are you calling nullif() ?

Maybe it would make sense to extend jOOQ in a way to allow org.jooq.Condition to be used as a Field across the API?

@dacc
Copy link
Author

dacc commented Feb 24, 2012

Ah ok, that must be why. Yes, being able to "cast" Conditions as a Field would be handy!

@lukaseder
Copy link
Member

OK, that idea will be tracked as:
#1178

It might mean substantial change, as a lot of new integration tests would be needed, so I can't promise when this will be done.

Cheers
Lukas

@dacc
Copy link
Author

dacc commented Feb 24, 2012

Ok sure. My work-around was to simply drop down to raw SQL, which wasn't too bad.

This often comes up when you want to count rows that match a certain condition. COUNT(NULLIF([condition], false)) is a handy way to do so, but maybe I could use a case(?)

@lukaseder
Copy link
Member

Yes, a CASE expression would be the most SQL-like style:

SUM(CASE WHEN [condition] THEN 1 ELSE 0 END)

I tend to feel that the NULLIF construct is a bit less readable. But I'm not so used to MySQL, so maybe it's common practice there? Still, it's a good use case for #1178

@dacc
Copy link
Author

dacc commented Feb 24, 2012

Oh yeah, not sure why I didn't do it that way -- I'll try it out tomorrow.

@dacc
Copy link
Author

dacc commented Mar 1, 2012

Worked great of course. Cheers!

@lukaseder
Copy link
Member

Glad it works!

I allowed myself to cite your nice feedback from Stack Overflow directly on my blog, if that is OK with you?
http://lukaseder.wordpress.com/2012/03/02/jooq-compared-to-ibatis/

@dacc
Copy link
Author

dacc commented Mar 2, 2012

Sure, feel free to use the second comment too. I've been meaning to write a more thorough testimonial if that would be useful.

@lukaseder
Copy link
Member

Yes, any success story (e.g. on your personal / company blog) is very welcome! If you have the time, I'd be interested in a more detailed pro / con comparison between jOOQ / iBATIS for your specific use case. Such a comparison could be a base for further discussion and feature requests in jOOQ...

Cheers
Lukas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants