emin Posted January 18, 2021 Share Posted January 18, 2021 I need to delete some record on a database on every 30 minutes. I added a unithreadtimer on servermodule and used below code. But when I check the database it seems that unithreadtimer doesn't work. My code: procedure TUniServerModule.UniGUIServerModuleServerStartup(Sender: TObject); begin unithreadtimer1.Enabled:=true; end; procedure TUniServerModule.UniThreadTimer1Timer(Sender: TObject); begin UniThreadTimer1.Lock; try with unimainmodule.servermodulesql do begin close; sql.Text:='DELETE from kilitlipoliceler where ROUND(TIME_TO_SEC(timediff(CURRENT_TIME,kilitlemesaati))/60)>30' execsql; end; finally UniThreadTimer1.Release; end; end; Quote Link to comment Share on other sites More sharing options...
alfr Posted January 18, 2021 Share Posted January 18, 2021 Hi, There is no mainmodule created/linked to the server module, so all objects needs to be located for it in the server module itself. (ie the connection to the db.) //Alf Quote Link to comment Share on other sites More sharing options...
emin Posted January 18, 2021 Author Share Posted January 18, 2021 I added unithreadtimer on mainmodule but nothing changed Quote Link to comment Share on other sites More sharing options...
alfr Posted January 18, 2021 Share Posted January 18, 2021 1 hour ago, emin said: with unimainmodule.servermodulesql do What i meant was that you can’t call anything in the mainmodule from the servermodule. The mainmodule is linked to a specific user, the servermodule is not (singleton). So the sql and the db connection in the servermodule usually needs to be created in the servermodule. Quote Link to comment Share on other sites More sharing options...
emin Posted January 18, 2021 Author Share Posted January 18, 2021 Ok. I add a TFDConnection, TFDQuery and TUniThreadTimer on server module. And I created another connection which is independant from mainmodule connection But the result was the same. Nothing changed on the database. Quote Link to comment Share on other sites More sharing options...
alfr Posted January 18, 2021 Share Posted January 18, 2021 So if you put a breakpoint in the code and step it line by line, everyting works as expected, but not the query? Quote Link to comment Share on other sites More sharing options...
emin Posted January 19, 2021 Author Share Posted January 19, 2021 You are right. Actually there is no problem with running unithreadtimer. My problem is that I could not manage how to run a query on server to handle backup operation. I checked demos related to unithreadtimer, but non of them use query. I don't want to use unitimer instead of unithreadtimer and run the same query many times. Quote Link to comment Share on other sites More sharing options...
emin Posted January 20, 2021 Author Share Posted January 20, 2021 Finally I've solved the problem. I set unithreadtimer interval as 600000 and started unithreadtimer when server module create. It worked. On the other hand I'm not sure is it right to use two fdconnetcion one on mainmodule, onether on servermodule Quote Link to comment Share on other sites More sharing options...
Wilton Ergon Posted January 20, 2021 Share Posted January 20, 2021 yes, the correct one and as already explained, and you create a new connection independent of your database, make the connection at the beginning, and at the end disconnect. UniThreadTimer1.enabled :=false; try db :=tfdconnection.create(self); db.... you parameters connection load ini .... db.open; db.execsql('your DELETE....'); finally begin db.close; Freeandnil(db); UniThreadTimer1.enabled :=true; end; end; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.