0

Trying to solve my issue and I noticed that there are not much info about the possible errors regarding SQL Logic error on ZeosDBO, most errors are regarding SQLite, that's not my case. So I decided to start this thread hopefully it'll be used by others posting the possible scenarios where the issue would happen.

My current scenario is PostgresSQL 15.3 + ZeosDBO 7.2.14 + Delphi 11.3. It doesn't show any errors while trying to fetch database connection status, since this is query-based I assume that zeos7 + pg15 works, here's the query that fetches connection status:

  SELECT 
    COUNT(*) AS TOTALCONNECTIONS
  , (SELECT COUNT(*) FROM pg_stat_activity  
      WHERE state = 'active') AS TOTALACTIVE
  , (SELECT COUNT(*) FROM pg_stat_activity  
      WHERE state = 'idle') AS TOTALIDLE
    FROM pg_stat_activity

Later when I'm trying to reply a login request, where the schema happens, the error starts popping, this is the query and code piece where it happens:

    with FDataSet do
    begin
      Close;
      SQL.Clear;
      if not Schema.IsEmpty then
        SQL.Add('set search_path = ' + QuotedStr(Schema) + ';');
      SQL.Add('SELECT ');
      SQL.Add('  L1.LIC_STATUS');
      SQL.Add(', S1.SYS_ID');
      SQL.Add(', U1.UNI_ID');
      SQL.Add('  FROM licenca L1');
      SQL.Add('  JOIN Empresa E1 on E1.EMP_ID = L1.EMP_ID');
      SQL.Add('  JOIN Sistema S1 on S1.SYS_ID = L1.SYS_ID');
      SQL.Add('  JOIN Unidade U1 on U1.EMP_ID = E1.EMP_ID');
      SQL.Add(' WHERE S1.SYS_SIGLA ILIKE :sigla');
      SQL.Add('   AND U1.UNI_CPFCNPJ LIKE :cpfcnpj');
      ParamByName('sigla').AsString := QuotedStr(sigla)
      ParamByName('cpfcnpj').AsString := QuotedStr(cpfcnpj)
      Open;  <=== error: "SQL Error: SQL logic error"

I already put a breakpoint under Open; to check if the SQL.Text were wrong somehow but the exact same query works on pgadmin without any errors, yes with schema.

I'm porting the system that was working previously with FireDAC to Zeos and I'm stuck in this error that I can't find any documentation regarding it.

Anything I could try?

Edit: Found the issue, it has nothing to do with the query. It was the inheritance which the class is generated from, that was losing the connection, fixed that and now it works.

Curiously enough, it was switching to 'sqlite-3' protocol on the error of the inheritance so apparently this type of error happens only on SQLite?

Mobius one
  • 171
  • 3
  • 12
  • Don't use Quotedstr with parameters. To be sure the parameter gets a string, use AsString in stead of Value. Like ParamByName('sigla').AsString := sigla – Eirik A. Jun 20 '23 at 19:38
  • thanks, but the issue had nothing to do with the query, it was an Inheritance error. – Mobius one Jun 20 '23 at 20:58

0 Answers0