Recent

Author Topic: Visual artefact in TDBGrid  (Read 1759 times)

LemonParty

  • Jr. Member
  • **
  • Posts: 83
Visual artefact in TDBGrid
« on: February 20, 2024, 08:03:58 pm »
I have a DBGrid, when I open SQLQuery in it I see dublicated records. Lazarus version 2.2.6. Is this a bug?

dseligo

  • Hero Member
  • *****
  • Posts: 1406
Re: Visual artefact in TDBGrid
« Reply #1 on: February 20, 2024, 11:26:57 pm »
Probably you did something wrong in your query.

vfclists

  • Hero Member
  • *****
  • Posts: 1146
    • HowTos Considered Harmful?
Re: Visual artefact in TDBGrid
« Reply #2 on: February 21, 2024, 10:10:03 am »
I have a DBGrid, when I open SQLQuery in it I see dublicated records. Lazarus version 2.2.6. Is this a bug?

Questions like this are generally useless without code.

Do you get the same duplication when you run the same query using some other utility?

Is it a DISTINCT query?
Lazarus 3.0/FPC 3.2.2

rvk

  • Hero Member
  • *****
  • Posts: 6572
Re: Visual artefact in TDBGrid
« Reply #3 on: February 21, 2024, 10:18:24 am »
I have a DBGrid, when I open SQLQuery in it I see dublicated records. Lazarus version 2.2.6. Is this a bug?
Those are just duplicate records in your database.
You can even see that some of those #5 records have different values (the first 2).
So after that, you probably just added duplicate records to your database.

BTW. This also means you don't have constraints build in your database to prevent duplicates (which is very BAD   ;D ).

wp

  • Hero Member
  • *****
  • Posts: 12457
Re: Visual artefact in TDBGrid
« Reply #4 on: February 21, 2024, 10:25:03 am »
And what is the # column? An ID? Or just a counter? In any way, something is wrong here, too. This reminds me of some bug of the grid which repeated records at the end. Was it related to filtering? Cannot remember any details...

It would be very helpful if you could set up a small test project to demonstrate the issue

rvk

  • Hero Member
  • *****
  • Posts: 6572
Re: Visual artefact in TDBGrid
« Reply #5 on: February 21, 2024, 10:40:24 am »
First make sure that there aren't duplicated records in your database.
You can do that with your favorite databasemanager.

Zvoni

  • Hero Member
  • *****
  • Posts: 2737
Re: Visual artefact in TDBGrid
« Reply #6 on: February 21, 2024, 11:18:41 am »
Probably you did something wrong in your query.
Agreed.
Show the Table-structure and the SELECT-Query

and this thread is again proof positive, why i don't like DB-bound controls.... :D
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

LemonParty

  • Jr. Member
  • **
  • Posts: 83
Re: Visual artefact in TDBGrid
« Reply #7 on: February 22, 2024, 03:39:50 pm »
Structure:
Code: Pascal  [Select][+][-]
  1. 'CREATE TABLE CURVE('+
  2. '[Number] INTEGER NOT NULL,'+
  3. 'CurveNumber INTEGER NOT NULL,'+
  4. 'LineNumber INTEGER NOT NULL,'+
  5. 'Absorbance FLOAT,'+
  6. 'Absorbance2 FLOAT,'+
  7. 'Absorbance3 FLOAT,'+
  8. 'Absorbance4 FLOAT,'+
  9. 'Absorbance5 FLOAT,'+
  10. 'Absorbance6 FLOAT,'+
  11. 'Absorbance7 FLOAT,'+
  12. 'Moisture FLOAT,'+
  13. 'CONSTRAINT PK_CURVE PRIMARY KEY ([Number],CurveNumber,LineNumber))'
Query: SELECT * FROM Curve
Database Access, ODBC driver. This is not dublicates in database, when I scroll the table dublicates disappear and replaced by real records. # column is just a counter.

Zvoni

  • Hero Member
  • *****
  • Posts: 2737
Re: Visual artefact in TDBGrid
« Reply #8 on: February 22, 2024, 04:06:56 pm »
Database Access, ODBC driver.
And i'm out and running for the hills.....
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

wp

  • Hero Member
  • *****
  • Posts: 12457
Re: Visual artefact in TDBGrid
« Reply #9 on: February 22, 2024, 04:37:58 pm »
I am attaching a small demo based on your CREATE TABLE. It runs on 32bit and 64bit Windows and does not show any duplicate records in the DBGrid. Please modify it such that the duplicate records appear.

korba812

  • Sr. Member
  • ****
  • Posts: 441
Re: Visual artefact in TDBGrid
« Reply #10 on: February 22, 2024, 04:51:14 pm »
Database Access, ODBC driver. This is not dublicates in database, when I scroll the table dublicates disappear and replaced by real records. # column is just a counter.
Looks like improper buffer management in TSQLQuery/SQLdb? Maybe you have the "UniDirectional" property checked in your TSQLQuery? (edit: probably not because you wouldn't be able to scroll to the top of the DBGrid content)
« Last Edit: February 22, 2024, 05:01:31 pm by korba812 »

LemonParty

  • Jr. Member
  • **
  • Posts: 83
Re: Visual artefact in TDBGrid
« Reply #11 on: February 22, 2024, 05:28:17 pm »
wp, here I reproduced. I built 32-bit application.

wp

  • Hero Member
  • *****
  • Posts: 12457
Re: Visual artefact in TDBGrid
« Reply #12 on: February 22, 2024, 11:43:45 pm »
I see. Seems to be that the duplicate records are caused by the calculated fields. When I exit qCurveCalcFields immediately after the "begin", or when I unhook the OnCalcFields handler altogether, the fields are unique again (this is most easily seen when one of the "*Number" fields is added to the query).

It would be interesting to investigate whether this issue is due to Access/ODBC or due to a bug in the field calculation. Both are not heavily used features in this community... I think there was a bug report about calculated fields sometimes, but I am not sure. I ran the test program also under FPC/main, and the issue remains - this means that this bug has not yet been fixed.

I would recommend to do the calculation within the SELECT SQL, e.g.

Code: [Select]
  qCurve.SQL.Text := 'SELECT Moisture, Moisture*Moisture AS MoistureSquare, Absorbance, (1.0 - Absorbance) AS Residual FROM CURVE';

korba812

  • Sr. Member
  • ****
  • Posts: 441
Re: Visual artefact in TDBGrid
« Reply #13 on: February 22, 2024, 11:56:18 pm »
I noticed that in TSQLQuery you have fewer data fields than those selected in query (SQL select...). Does the problem still occur if you add all data fields or modify query to only retrieve fields corresponding to defined data fields in SQLQuery?

 

TinyPortal © 2005-2018