From 2955c1d4a9b414e754712ac931017ba9ff13ad87 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Wed, 15 Dec 2021 09:38:33 +0000 Subject: [PATCH] TvPlanIt: Fix sqlite3 datastore duplicating dragged events sometimes. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8180 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/tvplanit/source/vpdayview.pas | 5 +-- components/tvplanit/source/vpsqlite3ds.pas | 48 +++++++++------------- 2 files changed, 20 insertions(+), 33 deletions(-) diff --git a/components/tvplanit/source/vpdayview.pas b/components/tvplanit/source/vpdayview.pas index e73cf77ec..3e252f492 100644 --- a/components/tvplanit/source/vpdayview.pas +++ b/components/tvplanit/source/vpdayview.pas @@ -1688,6 +1688,7 @@ begin according to how far the event was dragged } Event.StartTime := Event.StartTime + (DragToTime - DvDragStartTime); Event.EndTime := Event.StartTime + Duration; + DataStore.PostEvents; { Force a repaint. This will update the rectangles for the event } @@ -1704,12 +1705,8 @@ begin Break; end; end; - - { Invalidate; } end; -// TVpEventDragObject(Source).EndDrag(False); end; -{=====} function TVpDayView.dvCalcRowHeight(Scale: Extended; UseGran: TVpGranularity): Integer; diff --git a/components/tvplanit/source/vpsqlite3ds.pas b/components/tvplanit/source/vpsqlite3ds.pas index de78c0b05..c99232ad1 100644 --- a/components/tvplanit/source/vpsqlite3ds.pas +++ b/components/tvplanit/source/vpsqlite3ds.pas @@ -9,6 +9,9 @@ uses VpBaseDS, VpDBDS; type + + { TVpSqlite3Datastore } + TVpSqlite3Datastore = class(TVpCustomDBDatastore) private FConnection: TSqlite3Connection; @@ -38,12 +41,10 @@ type public constructor Create(AOwner: TComponent); override; + destructor Destroy; override; + procedure CreateTables; function GetNextID(TableName: string): integer; override; - procedure PostEvents; override; - procedure PostContacts; override; - procedure PostTasks; override; - procedure PostResources; override; property ResourceTable; property EventsTable; @@ -80,15 +81,28 @@ begin FContactsTable := TSQLQuery.Create(self); FContactsTable.SQL.Add('SELECT * FROM Contacts'); + FContactsTable.Options := FContactsTable.Options + [sqoAutoApplyUpdates]; FEventsTable := TSQLQuery.Create(Self); FEventsTable.SQL.Add('SELECT * FROM Events'); + FEventsTable.Options := FEventsTable.Options + [sqoAutoApplyUpdates]; FResourceTable := TSQLQuery.Create(self); FResourceTable.SQL.Add('SELECT * FROM Resources'); + FResourceTable.Options := FResourceTable.Options + [sqoAutoApplyUpdates]; FTasksTable := TSQLQuery.Create(self); - FTasksTable.SQL.Add('SELECT * FROM Tasks'); + FTasksTable.SQL.Add('SELECT * FROM Tasks'); + FTaskstable.Options := FTasksTable.Options + [sqoAutoApplyUpdates]; +end; + +destructor TVpSqlite3Datastore.Destroy; +begin + FContactsTable.Close; + FEventsTable.Close; + FTasksTable.Close; + FResourceTable.Close; + inherited; end; procedure TVpSqlite3Datastore.AddField(ATableName, AFieldName: String; @@ -537,30 +551,6 @@ begin FTasksTable.Open; end; -procedure TVpSqlite3Datastore.PostContacts; -begin - inherited; - FContactsTable.ApplyUpdates; -end; - -procedure TVpSqlite3Datastore.PostEvents; -begin - inherited; - FEventsTable.ApplyUpdates; -end; - -procedure TVpSqlite3Datastore.PostResources; -begin - inherited; - FResourceTable.ApplyUpdates; -end; - -procedure TVpSqlite3Datastore.PostTasks; -begin - inherited; - FTasksTable.ApplyUpdates; -end; - procedure TVpSqlite3Datastore.SetConnected(const AValue: Boolean); begin if (FConnection = nil) or (FConnection.Transaction = nil) then