1. Daniel Vivier
  2. PowerBuilder
  3. Friday, 8 May 2020 12:38 PM UTC

I have a DW where I'm trying to retrieve some rows from a table called DONOR, with two retrieval args (MemberNumber int, Email String) with SQL like:

SELECT ...
FROM DONOR
JOIN ...
WHERE (member_number = :MemberNumber and :MemberNumber > 0) OR
      (email = :Email and :Email > '')

If I pass in arguments 1 and NULL, it works correctly - selecting the donor with member_number = 1.

If I pass in arguments 0 and my email address (which definitely exists in the table!) I get no rows (and no error) if DisableBind is off, and the correct rows if DisableBind=1.

If I change the WHERE clause to:

WHERE member_number = :MemberNumber OR coalesce(email, 'zzz') = :Email

it works fine. (I added the coalesce so that donors with NULL in the email field weren't selected when NULL was passed for that retrieval arg!)

Any bright ideas what could be going on? This is in Firebird SQL. Thanks.

Miguel Leeuwe Accepted Answer Pending Moderation
  1. Monday, 11 May 2020 17:24 PM UTC
  2. PowerBuilder
  3. # 1

Maybe you'd have to include expressions like " :arg IS NULL" or ":arg is NOT NULL" when passing in a null value?

regards

Comment
There are no comments made yet.
mike S Accepted Answer Pending Moderation
  1. Friday, 8 May 2020 13:54 PM UTC
  2. PowerBuilder
  3. # 2

I would try to track down on the server side what is actually been sent/processed.  I have no idea if firebird has those types of tools?  

 

I'm a big fan of always using coalesce instead of an (OR col > somevalue):

so i would just write it with that, and if it works, i'd call it a day.....

( coalesce(member_number,-1) = :MemberNumber OR coalesce(email, '>') = :Email )

 

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Friday, 8 May 2020 15:06 PM UTC
  2. PowerBuilder
  3. # 3

When Bind Variables is active, PowerBuilder sends the SQL statement with the :varname occurences in it and the variable values are sent separately. The database server makes the variable substitutions before running the statement.

If Bind Variables is inactive, PowerBuilder makes the substitutions before sending the SQL statement.

Bind Variables allows the database server to cache the statement along with its execution plan. If the same statement is run frequently, it can be faster since it only has to do the variable substitution before running it.

It is possible that Firebird doesn't handle bind variables the way it should.

Comment
There are no comments made yet.
Daniel Vivier Accepted Answer Pending Moderation
  1. Friday, 8 May 2020 15:22 PM UTC
  2. PowerBuilder
  3. # 4

Thanks. I do understand what the binding variables does. I guess I was wondering whether anyone had any theory about why my original code could cause a problem with that, and perhaps whether anybody else had seen similar problems with other SQL servers - which could indicate that the problem might originate in PB, rather than the SQL server I'm using.

Comment
  1. Arnd Schmidt
  2. Friday, 8 May 2020 17:01 PM UTC
You can check, if this only works correct when a retrieval argument of type string is used in a unique way and is not referenced several times in a query.

I have a "ping back from the dark" that I ran into that issue before.

This can be some bad pointer, data binding ;-) or even "unsupported feature" in the ODBC Driver.
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 11 May 2020 15:55 PM UTC
  2. PowerBuilder
  3. # 5

Hi Dan;

  Did you try an SQL Trace? 

  SQLCA.DBMS = "TRACE ODB"

Regards ... Chris

Comment
  1. Daniel Vivier
  2. Monday, 11 May 2020 17:24 PM UTC
I just tried, Chris, that but am not really sure what I'm reading there. The bottom line is I have a solution (avoiding multiple references to the same retrieval argument in the SQL) and it's working so it's not really worth spending more time on it now.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.