Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » DBISAM Technical Support » Support Forums » DBISAM General » View Thread |
Messages 1 to 7 of 7 total |
Is code thread safe |
Tue, May 20 2008 10:30 AM | Permanent Link |
Tomas | Hello,
Is code below thread safe? I have tried to follow DBISAM thread safe rules and I am not sure if I understood everything correct. function ExecSQL(SQL: string): Integer; var s: TDBISAMSession; db: TDBISAMDatabase; q: TDBISAMQuery; ADynamicSessionName:String; begin s := TDBISAMSession.Create(nil); db := TDBISAMDatabase.Create(nil); q := TDBISAMQuery.Create(nil); try s.RemoteAddress := ADBServerIP; s.RemotePort := StrToInt(ADBServerPort); s.RemoteUser := ADBUser; s.RemotePassword := ADBPass; db.RemoteDatabase := ADBDatabase; s.SessionType:=stRemote; s.AutoSessionName:=true; s.PrivateDir := Path_UserTemp; s.Active:=true; ADynamicSessionName:=s.SessionName; db.DatabaseName := ADynamicSessionName; db.SessionName:=ADynamicSessionName; q.DatabaseName := db.DatabaseName; q.SessionName:=ADynamicSessionName; q.RequestLive:=true; q.Close; q.SQL.Text := SQL; q.ExecSQL; result := q.RowsAffected; finally db.Close; s.Active:=false; s.Free; db.Free; q.Free; end; end; Regards, Tomas |
Tue, May 20 2008 11:47 AM | Permanent Link |
Fernando Dias Team Elevate | Tomas,
There is a problem with your session names: you can't assign a value to SessionName when AutoSessionName=True. You must set AutoSessionName to false and generate a unique name for the session yourself. One method to get a unique session name in each thread is to use ThreadID as part of the name, for example: SessionName := 'S_'+IntToStr(ThreadID); -- Fernando Dias [Team Elevate] |
Tue, May 20 2008 12:18 PM | Permanent Link |
Tomas | I am not assigning TDBISAM.SessionName manually, I set AutoSessionName:=true and as I understand from DBISAM manual, DBISAM will
generate unique ID for TDBISAM.SessionName. Right? "Fernando Dias [Team Elevate]" <fernandodias.removthis@easygate.com.pt> wrote: Tomas, There is a problem with your session names: you can't assign a value to SessionName when AutoSessionName=True. You must set AutoSessionName to false and generate a unique name for the session yourself. One method to get a unique session name in each thread is to use ThreadID as part of the name, for example: SessionName := 'S_'+IntToStr(ThreadID); -- Fernando Dias [Team Elevate] |
Tue, May 20 2008 1:15 PM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Tomas
>I am not assigning TDBISAM.SessionName manually, I set AutoSessionName:=true and as I understand from DBISAM manual, DBISAM will >generate unique ID for TDBISAM.SessionName. Right? From your code q.SessionName:=ADynamicSessionName; Just remove it and you're right Roy Lambert [Team Elevate] |
Tue, May 20 2008 1:41 PM | Permanent Link |
Tomas | q is Query, I assing Auto Generated Session ID to DBISAM query session property.
Roy Lambert <roy.lambert@skynet.co.uk> wrote: Tomas >I am not assigning TDBISAM.SessionName manually, I set AutoSessionName:=true and as I understand from DBISAM manual, DBISAM will >generate unique ID for TDBISAM.SessionName. Right? From your code q.SessionName:=ADynamicSessionName; Just remove it and you're right Roy Lambert [Team Elevate] |
Tue, May 20 2008 2:15 PM | Permanent Link |
Fernando Dias Team Elevate | Tomas,
> I am not assigning TDBISAM.SessionName manually, I set AutoSessionName:=true and as I understand from DBISAM manual, DBISAM will > generate unique ID for TDBISAM.SessionName. Right? Yes, sorry - my mistake. I misread your code and, as Roy, I interpreted q.SessionName as an assignement to the Session name. -- Fernando Dias [Team Elevate] |
Wed, May 21 2008 12:16 PM | Permanent Link |
Rolf Frei eicom GmbH | Yes, you are right.
q.SessionName := s.SessionName This is correct in your code. This way you assign the query to the unique Session instance. Your code looks absolutly correct to me. Regards Rolf "Tomas" <tomas@baltsoft.com> schrieb im Newsbeitrag news:79C622AE-35A8-45AB-9E52-688E67A04473@news.elevatesoft.com... >q is Query, I assing Auto Generated Session ID to DBISAM query session >property. > > > > > Roy Lambert <roy.lambert@skynet.co.uk> wrote: > > Tomas > >>I am not assigning TDBISAM.SessionName manually, I set >>AutoSessionName:=true and as I understand from DBISAM manual, DBISAM will >>generate unique ID for TDBISAM.SessionName. Right? > > From your code > q.SessionName:=ADynamicSessionName; > > Just remove it and you're right > > Roy Lambert [Team Elevate] > |
This web page was last updated on Friday, March 29, 2024 at 03:30 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |