Subject RE: [IBO] Query with params returning incorrect results when app runs in background
Author Jason Wharton
Don't think this will fix your issue, but using RecordCount is unadvisable.  Use the IsEmpty property instead.
 
Jason Wharton
 


From: IBObjects@yahoogroups.com [mailto:IBObjects@yahoogroups.com]
Sent: Monday, October 29, 2018 8:59 AM
To: IBObjects@yahoogroups.com
Subject: [IBO] Query with params returning incorrect results when app runs in background

I have an issue with 5.9 (works in 5.5) that is hard to pinpoint.  It is in our database update exe and it only happens when running through the build system which has the unique setup of running it as gui app in the background via SSH so the gui is never shown.  if I run the app on the build machine normally where I can see the gui it runs fine.  But when run via ssh in our build pipeline it does not.  This makes it difficult to debug because it works fine when running it in the debugger because the gui is then in the foreground and works (I assume that is part of the issue).  My guess is that the issue revolves around function parameters not being internally set but when I run in 5.9 I am running with the patched code so it should not be the TParam.Create bug we found the other day.  Here is the code


class function TDVUtils.LayoutNameByTemplate(ADVType, ATemplate: String): String;

var

  qry :TIBOQuery;

begin

  try

    if not gDBADVUtils.AssignQuery('LayoutNameByTemplate', qry) then

      with qry do

        begin

          SQL.Add('select                              ');

          SQL.Add('  ANALYSIS_NAME                     ');

          SQL.Add('from                                ');

          SQL.Add('  ANALYSIS                          ');

          SQL.Add('where                               ');

          SQL.Add('      ANALYSIS_TYPE = :ANALYSIS_TYPE');

          SQL.Add('  and ANALYSIS_TEMPLATE = :TEMPLATE ');

          Prepare;

        end;

    with qry do

      begin

        ParamByName('ANALYSIS_TYPE').AsString := ADVType;

        ParamByName('TEMPLATE').AsString := ATemplate;

        Open;

        if RecordCount > 0 then

          Result := FieldByName('ANALYSIS_NAME').AsString

        else

          Result := '';

        Close;

      end;

  except

    On E: Exception do

      raise Exception.Create('Error in TDVUtils.LayoutNameByTemplate' + #13#10#13#10 +

        E.Message);

  end;

end;


The query returns 0 records when it should return 1 record.  The gDBADVUtils.AssignQuery is just part of a query caching mechanism and is not relevant to this issue.  


Any ideas how I should debug this thing that only errors when I am running it via a background console?  I can't step in to the IBO code to see where the issue is because while I'm debugging the error wont happen because the GUI is in the foreground (assumption).