Search the Community
Showing results for tags 'sql'.
-
Sometimes, we want to run a store procedure in the server, which takes a lot of time, and in this case, the page even gets disconnected. To solve this problem, it is enough to create a Thread in the program and only monitor its execution Here I present the solution I created for myself and I will be happy if you help to improve it 1- create a temp table for list of process DMt.ProccessTable:='_X_'+DMt.CurrentPreName; DMt.Exec_SQLClient('If Not Object_Id('+QuotedStr(DMt.ProccessTable)+') is Null Drop Table '+DMt.ProccessTable); DMt.Exec_SQLClient(' Create Table '+DMt.ProccessTable+' ([StartDT] datetime DEFAULT (getdate()),[PName] NChar(50) ,[PID] int )'); 2- define type Type TSQLQueryThread = class(TThread) private FID: Integer; FQuery: string; FTempTable : String; FConnection: TMSConnection; protected procedure Execute; override; public constructor Create(const AID: Integer; const AQuery: string; AConnection: TMSConnection;ATempTable:String); property ID: Integer read FID; end; 2- functions for Thread procedure TSQLQueryThread.Execute; var Query: TMSQuery; begin Query := TMSQuery.Create(nil); try Query.Connection := FConnection; Query.SQL.Text := FQuery; Query.Execute; finally Query.Free; end; end; constructor TSQLQueryThread.Create(const AID: Integer; const AQuery: string; AConnection: TMSConnection;ATempTable:String); begin inherited Create(False); FID := AID; FQuery := AQuery; FConnection := AConnection; FTempTable:=ATempTable; end; procedure TDMT.TH_QueryThreadTerminated(Sender: TObject); Var FinalQ : TMSQuery; begin FinalQ := TMSQuery.Create(nil); try FinalQ.Connection := TSQLQueryThread(Sender).FConnection; FinalQ.SQL.Text := 'Delete From '+TSQLQueryThread(Sender).FTempTable+' Where PID='+TSQLQueryThread(Sender).FID.ToString; FinalQ.Execute; finally FinalQ.Free; end; end; 4-main procedure for call Procedure TDMT.TH_Execute(Titr,SQLCMD:String); var SQLQueryThread: TSQLQueryThread; begin Inc(FQueryCounter); DMt.Exec_SQLClient('Insert Into '+Dmt.ProccessTable+'(PName,PId) Values ('+QuotedStr(Titr)+','+FQueryCounter.ToString+')'); SQLQueryThread := TSQLQueryThread.Create(FQueryCounter, SQLCMD, ClientConnection,DMt.ProccessTable); SQLQueryThread.OnTerminate := TH_QueryThreadTerminated; SQLQueryThread.FreeOnTerminate := True; end; 5- Now We are ready to call it DMT.TH_Execute(' any title ','Exec ..........'); 6- You can use the following command to display the list of running processes and their duration SQL.Text:='SELECT PID,Pname, Trim(CONVERT(CHAR,DATEDIFF(mi, StartDT, GETDATE())))+'':''+CONVERT(CHAR,DATEDIFF(ss, StartDT, GETDATE())% 60) Dis FROM '+DMt.ProccessTable; and finally we have controller for our program
-
Hii, first, my english is not so good (i'm from germany) i want develop an onlineshop with mySQL. My problem is, The Connection / Session broken very fast... "EUniSessionException: 'Invalid session or session Timeout'" I working with Delphi XE8 and UniGui (Version 0.99.10.1182) ... I use the vcl DAC for MySQL. How can i this incease? Have you an idea?