View Issue Details

IDProjectCategoryView StatusLast Update
0035887FPCDatabasepublic2019-09-07 16:26
ReporterAndrei Assigned ToMichael Van Canneyt  
Status resolvedResolutionreopened 
Product Version3.2.0 
Fixed in Version3.3.1 
Summary0035887: TSQLQuery.ServerFilter exception on filter change
DescriptionTSQLQuery.ServerFilter fails when it is is changed after it was set to a default filters that would return around 250 rows or more. If the initial filter doesn't return records, the filter change is not throwing this exception.

The exception is the following:

An unhandled exception occurred at $00000000004B4F0C:
EAccessViolation: Access violation

This issue doesn't exist in Free Pascal 3.0.4; it is present in trunk.
Steps To Reproduce    qQuery.SQL.Text := ' select from test_table a where 1=1 ';
    qQuery.ServerFiltered := True;
    qQuery.ServerFilter := ' name=''test value'' ';
    qQuery.ServerFilter := ' name=''another value'' '; // <-------- here it will fail

I attached a project with a small sqlite3 test database.
TagsNo tags attached.
Fixed in Revision42933
Attached Files



2019-07-25 21:32



2019-07-26 09:32

developer   ~0117405

Last edited: 2019-07-26 09:36

View 2 revisions

AV happens in call to procedure TCustomBufDataset.InternalCreateIndex, where is:
 if Active and not Refreshing then
    FetchAll; <--- HERE AV, because CurrentIndexBuf was released in prior InternalClose call (because of DiscardOnClose)

Probably simpliest would be modify TCustomSQLQuery.ApplyFilter method and use there Close+Open instead of InternalClose+InternalOpen


2019-07-26 14:17

developer   ~0117417

Last edited: 2019-07-26 14:19

View 2 revisions

I have added test for this bug in revision: 42497
(please if you fix this, backport also to 3.2, because this is regression)

Michael Van Canneyt

2019-08-26 20:34

administrator   ~0117850

Fixed as suggested.


2019-09-04 09:46

reporter   ~0117948

Closing and reopening the TSQLQuery while applying a filter will reset the settings applied to components which are using TSQLQuery as a dataset.

Example using a TDbGrid which doesn't have the columns predefined:

dsExDataSource.DataSet := sqlQuery;
dbgGrid.DataSource := dsExDataSource;
dbgGrid.Columns[0].Width := 60;
dbgGrid.Columns[1].Width := 500;
dbgGrid.Columns[2].Visible := False;
sqlQuery.ServerFilter := ' table.field = "value" ';

After the fix, when you are changing the ServerFilter field, the grid columns will lose all their settings, unless you are explicitely defining them for that TDBGrid in designer. I am not sure if this is the desirable behaviour, since it will force you to explicitly define all the columns and their settings for that grid, and the functionality of dynamically adding the fiends to grid based on the dataset is becoming useless, since filtering is only changing the result set, not the number or the data types of the row fields.

In the stable version (fpc 3.0.4/Lazarus 2.0.2) all these work well, so this fix will change the current behaviour.

Michael Van Canneyt

2019-09-04 10:04

administrator   ~0117949

* I would rather remove the serverfilter property completely.
* I think you should always define the grid columns.

I will think about it. But if you have a working patch, feel free to supply it.

Michael Van Canneyt

2019-09-07 16:26

administrator   ~0117971

Applied a proper fix in 42933. In essence, the applying of a new filter works as a refresh, So I call InternalRefresh, which sets the refreshing flag.

Issue History

Date Modified Username Field Change
2019-07-25 21:32 Andrei New Issue
2019-07-25 21:32 Andrei File Added:
2019-07-26 08:17 LacaK Assigned To => LacaK
2019-07-26 08:17 LacaK Status new => assigned
2019-07-26 08:18 LacaK Summary TSQLQuery.SelectFilter exception on filter change => TSQLQuery.ServerFilter exception on filter change
2019-07-26 08:18 LacaK Description Updated View Revisions
2019-07-26 08:18 LacaK Steps to Reproduce Updated View Revisions
2019-07-26 08:18 LacaK FPCTarget => -
2019-07-26 09:32 LacaK Note Added: 0117405
2019-07-26 09:36 LacaK Note Edited: 0117405 View Revisions
2019-07-26 09:37 LacaK Assigned To LacaK => Michael Van Canneyt
2019-07-26 14:17 LacaK Note Added: 0117417
2019-07-26 14:19 LacaK Note Edited: 0117417 View Revisions
2019-08-26 20:34 Michael Van Canneyt Status assigned => resolved
2019-08-26 20:34 Michael Van Canneyt Resolution open => fixed
2019-08-26 20:34 Michael Van Canneyt Fixed in Version => 3.3.1
2019-08-26 20:34 Michael Van Canneyt Fixed in Revision => 42831
2019-08-26 20:34 Michael Van Canneyt FPCTarget - => 3.2.0
2019-08-26 20:34 Michael Van Canneyt Note Added: 0117850
2019-09-04 09:46 Andrei Status resolved => feedback
2019-09-04 09:46 Andrei Resolution fixed => reopened
2019-09-04 09:46 Andrei Note Added: 0117948
2019-09-04 10:04 Michael Van Canneyt Note Added: 0117949
2019-09-07 16:26 Michael Van Canneyt Status feedback => resolved
2019-09-07 16:26 Michael Van Canneyt Fixed in Revision 42831 => 42933
2019-09-07 16:26 Michael Van Canneyt Note Added: 0117971