cincura.net wrote:
Yep. The generated SQL needs some small tweaking. This piece "THEN @p3 ELSE @p5 END" has parameters without types (Firebird needs to be able to infer types from the SQL and or metadata, it's not using any data from client). Hence it should rather be something like "THEN CAST(@p3 AS xxx) ELSE CAST(@p5 as xxx) END". That will make Firebird happy.
This is a little strange, though it somehow does sound familiar too, as the parameters do have types, it doesn't infer the types from the parameters coming in? casting them is a bit problematic to do automatically I think, as the case statement is generated using a pattern. I have to test whether a cast to int added to the pattern (It's the IIF function call mapping) works always in this situation.
In linq they are cast, hence I think the reason why it works in the linq provider, which does contain the cast. The query is a bit convoluted due to the Any() helper method. Typical query could be to simply fetch the ID with an exists predicate, which would result in 0 or 1 rows, and check if there's a row returned, if not, it doesn't exist.
We'll fix this in the next release (v5.4), as it requires more work than a quick fix, as the pattern (the IIF pattern) is the one used by the Functions.IIF() function in queryspec, and the Any() call simply uses that to build the query. But IIF() of course can return any type as the result, so additional code is needed to fix this.