Subject Re: [IBO] Slightly surprised by IBO
Author Helen Borrie
At 09:26 PM 13/09/2011, Svein Erling Tysvær wrote:
>In a TIB_Query, I did something like
>
>SELECT *
>FROM OneTable
>WHERE MyField = :MyField
>UNION
>SELECT *
>FROM AnotherTable
>WHERE MyField = :MyField
>
>MyTibQuery.ParamByName('MyField').AsString:='IBO';
>
>Only results from AnotherTable appeared in the result set. Copying the query to IB_SQL, I discovered why - it expected two parameters! I then discovered that I had (erroneously) defined MyField as CHAR in OneTable, and as VARCHAR in AnotherTable. So I just changed the definition for one of the fields and everything worked as expected.
>
>Is this behaviour as intended?

Yup, it's the way parameters work. In the API, they are unnamed. Applications have to pass these unnamed parameters in the order they appear in the SQL statement. IBO is kind to us by letting us give them names so we can track them easily in the application code.

>If so, then fine, just a small gotcha for me to remember whenever I try to 'reuse' a parameter. I guess that two different parameters with identical names also means that the first parameter only can be accessed through Params and not ParamByName?

Well, it's an "old gotcha" - but parameters are not variables! Think of them as members of an array that you can give a unique name to and you'll be close enough. You can have a variable *in your application* that you assign to multiple parameters - which seems to be what is called for in your example.

Helen