Question

I'm very new to Delphi and received the following piece of code (left out some irrelevant parts) for which I'm trying to understand what it does:

object SelectCosts: TIBQuery
    SQL.Strings = (
      'SELECT * FROM costs '
      'WHERE code = :code')
    ParamData = <
      item
        DataType = ftUnknown
        Name = 'code'
        ParamType = ptUnknown
      end>
  end

In another file, that query is used, but a parameter that is not defined in the query is added.

DM_HRV.SelectCosts.ParamByName('part').Value := 1;

Does this parameter 'part' change anything about the selection made? In other words: is the SQL query automatically changed into the following?

'SELECT * FROM costs '
  'WHERE code = :code'
  'AND part = :part'
Was it helpful?

Solution

That means that the SQL statement might be changed at run-time. so when that query is used the SQL already contains AND part = :part.

If the SQL statement does not contain this extra parameter part, an Exception will be raised when assigning ParamByName('part').Value := 1.

I'm assuming you didn't confuse SelectCosts reference (which is in DM_HRV and not other DM).

OTHER TIPS

The following statement in your post does not add a parameter, it sets its value:

DM_HRV.SelectCosts.ParamByName('part').Value := 1;

To add a parameter at runtime, use CreateParam as follows:

if DM_HRV.SelectCosts.Params.FindParam('Part') = nil then
   DM_HRV.SelectCosts.Params.createParam(ftString, 'Part', ptInput);

The query doesn't get modified automatically, you have to do that yourself.

In your first snip, the ParamType and InputType are not defined, you can change that in the IDE by access the parameter list (Params) property editor, and updating those values.

Adding a new parameter does not change the query. You have to do that yourself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top