Recent

Author Topic: TSQLQuery: ServerFilter causes Access Violation  (Read 990 times)

Milsa

  • Sr. Member
  • ****
  • Posts: 323
TSQLQuery: ServerFilter causes Access Violation
« on: July 19, 2024, 08:30:29 am »
I have database application for work organization.

I set filter to (this show Lazarus during debugging):
Code: Pascal  [Select][+][-]
  1. Filter = ANSISTRING($0C0E5F44)^: 'tor.partner_id = 10 AND done = 0'

It is ok, filter works.

But I add to filter new condition:
Code: Pascal  [Select][+][-]
  1. Filter = ANSISTRING($0C07C23C)^: 'tor.partner_id = 10 AND tor.product_id = 114 AND done = 0'

It doesn't matter in which order I add the conditions, it always crashes if there are 3.

Order is set to:
Code: Pascal  [Select][+][-]
  1. SELECT
  2.   tor.*,
  3.   tpr.name AS partner_name,
  4.   tp.name AS product_name,
  5.   SUM(tpw.hours) AS tpw_sum_hours
  6. FROM [order] tor
  7. INNER JOIN [partner] tpr ON tpr.id = tor.partner_id AND tpr.hide = 0
  8. INNER JOIN [product] tp ON tp.id = tor.product_id AND tp.hide = 0
  9. LEFT JOIN [product_work] tpw ON tpw.product_id = tp.id AND tpw.hide = 0
  10. WHERE tor.hide = 0 AND tor.done = 0 AND tor.burden = 1
  11. GROUP BY tor.id
  12. ORDER BY serial;

Today I try newest version of Lazarus (3.4). The problem persists.
« Last Edit: July 19, 2024, 08:33:02 am by Milsa »
I work with Lazarus 2.2.2, FPC 3.2.2, date 2022-05-15
This information is actual to: 28st Dec 2022

Milsa

  • Sr. Member
  • ****
  • Posts: 323
Re: TSQLQuery: ServerFilter causes Access Violation
« Reply #1 on: July 19, 2024, 08:40:35 am »
Application crashes in line 2441.
I work with Lazarus 2.2.2, FPC 3.2.2, date 2022-05-15
This information is actual to: 28st Dec 2022

Milsa

  • Sr. Member
  • ****
  • Posts: 323
Re: TSQLQuery: ServerFilter causes Access Violation
« Reply #2 on: July 19, 2024, 08:43:10 am »
This is structure of my tables:
Code: Pascal  [Select][+][-]
  1. CREATE TABLE [order] (
  2.     id            INTEGER   PRIMARY KEY AUTOINCREMENT
  3.                             NOT NULL,
  4.     serial        TEXT (20) NOT NULL
  5.                             UNIQUE,
  6.     partner_id    INTEGER   NOT NULL
  7.                             REFERENCES partner (id),
  8.     product_id    INTEGER   NOT NULL
  9.                             REFERENCES product (id),
  10.     description   TEXT,
  11.     priority      INTEGER   NOT NULL,
  12.     date_finished DATE,
  13.     color         INTEGER   DEFAULT (0)
  14.                             NOT NULL,
  15.     done          INTEGER   DEFAULT (0)
  16.                             NOT NULL,
  17.     overtime      INTEGER   DEFAULT (0)
  18.                             NOT NULL,
  19.     noinsert      INTEGER   NOT NULL
  20.                             DEFAULT (0),
  21.     burden        INTEGER   DEFAULT (0)
  22.                             NOT NULL,
  23.     hide          INTEGER   DEFAULT (0)
  24.                             NOT NULL
  25. );
  26.  
Code: Pascal  [Select][+][-]
  1. CREATE TABLE partner (
  2.     id   INTEGER PRIMARY KEY AUTOINCREMENT
  3.                  NOT NULL,
  4.     name TEXT    NOT NULL
  5.                  UNIQUE,
  6.     hide INTEGER NOT NULL
  7.                  DEFAULT (0)
  8. );
  9.  
Code: Pascal  [Select][+][-]
  1. CREATE TABLE product (
  2.     id   INTEGER PRIMARY KEY AUTOINCREMENT
  3.                  NOT NULL,
  4.     name TEXT    NOT NULL
  5.                  UNIQUE,
  6.     hide INTEGER NOT NULL
  7.                  DEFAULT (0)
  8. );
  9.  
I work with Lazarus 2.2.2, FPC 3.2.2, date 2022-05-15
This information is actual to: 28st Dec 2022

Milsa

  • Sr. Member
  • ****
  • Posts: 323
Re: TSQLQuery: ServerFilter causes Access Violation
« Reply #3 on: July 19, 2024, 08:52:13 am »
The problem started appearing around Lazarus 2. I didn't notice this problem until then. Maybe it's a bug in the Lazarus code. But I can't confirm this for sure. I would have to try all the older versions of Lazarus one by one
I work with Lazarus 2.2.2, FPC 3.2.2, date 2022-05-15
This information is actual to: 28st Dec 2022

af0815

  • Hero Member
  • *****
  • Posts: 1379
Re: TSQLQuery: ServerFilter causes Access Violation
« Reply #4 on: July 19, 2024, 10:14:35 am »
Have you tuned on all debugging capabilities of Lazarus ?

Access violation like this are often dangling pointers. You can only go though the code there step by step and look in the watches to find out if the used variables and their content (and pointers) are the same you want to see.
regards
Andreas

Zvoni

  • Hero Member
  • *****
  • Posts: 2747
Re: TSQLQuery: ServerFilter causes Access Violation
« Reply #5 on: July 23, 2024, 08:24:18 am »
Is ParseSQL set to False?
https://www.freepascal.org/docs-html/fcl/sqldb/tsqlquery.serverfilter.html

EDIT: Don't set ServerFiltered to False in Line 2438?
From my Link above
Quote
If the dataset is active and ServerFiltered is set to true, then changing this property will re-fetch the data from the server.
« Last Edit: July 23, 2024, 11:14:21 am by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

CharlyTango

  • Jr. Member
  • **
  • Posts: 90
Re: TSQLQuery: ServerFilter causes Access Violation
« Reply #6 on: July 23, 2024, 03:17:11 pm »
Firstly, I would check whether the SQL statement you are sending is syntactically and result-wise correct.
I would test this with an external programme.
As I don't know which operating system you are using, I can't recommend one.

And the I'd follow af0815's advice to step-debug your code to see where exactly a problem exists.

It would also be interesting to see how exactly you create the SQL statement in the code. Even better would be a small test project against an SQL database so that you can see the problem in real life
Lazarus stable, Win32/64

 

TinyPortal © 2005-2018