Changeset 33 for trunk/WebServer/UHTTPSessionMySQL.pas
- Timestamp:
- Sep 13, 2010, 11:20:24 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 2 2 UConfig.pas 3 3 bin 4 lib
-
- Property svn:ignore
-
trunk/WebServer/UHTTPSessionMySQL.pas
r32 r33 12 12 { TFileHTTPSessionStorage } 13 13 14 T MySQLHTTPSessionStorage= class(THTTPSessionStorage)14 THTTPSessionStorageMySQL = class(THTTPSessionStorage) 15 15 private 16 16 Lock: TCriticalSection; … … 32 32 { THTTPSession } 33 33 34 function T MySQLHTTPSessionStorage.GetNewSessionId: string;34 function THTTPSessionStorageMySQL.GetNewSessionId: string; 35 35 var 36 36 DbRows: TDbRows; 37 Found: Boolean; 37 38 begin 38 DbRows := nil;39 Result := BinToHexString(SHA1(FloatToStr(Now)));40 39 repeat 41 if Assigned(DbRows) then DbRows.Destroy; 42 DbRows := SqlDatabase.Query('SELECT * FROM Session WHERE Identification="' + 43 Result + '"'); 44 if DbRows.Count > 0 then Result := BinToHexString(SHA1(FloatToStr(Now))); 45 until DbRows.Count > 0; 46 DbRows.Destroy; 40 Result := BinToHexString(SHA1(FloatToStr(Now))); 41 try 42 DbRows := SqlDatabase.Query('SELECT * FROM `HTTPSession` WHERE `Identification`="' + 43 Result + '"'); 44 Found := DbRows.Count > 0; 45 finally 46 DbRows.Free; 47 end; 48 until not Found; 47 49 end; 48 50 49 procedure T MySQLHTTPSessionStorage.GetSessionId(HandlerData: THTTPHandlerData);51 procedure THTTPSessionStorageMySQL.GetSessionId(HandlerData: THTTPHandlerData); 50 52 begin 51 53 with HandlerData do begin … … 54 56 end else begin 55 57 SessionId := GetNewSessionId; 56 Response.Cookies.Values[SessionIdCookieName] := SessionId;57 58 end; 58 59 end; 59 60 end; 60 61 61 procedure T MySQLHTTPSessionStorage.Load(HandlerData: THTTPHandlerData);62 procedure THTTPSessionStorageMySQL.Load(HandlerData: THTTPHandlerData); 62 63 var 63 64 DbRows: TDbRows; … … 66 67 try 67 68 Lock.Acquire; 68 DbRows := SqlDatabase.Query('SELECT * FROM Session WHERE Identification="' +69 DbRows := SqlDatabase.Query('SELECT * FROM `HTTPSession` WHERE `Identification`="' + 69 70 HandlerData.SessionId + '"'); 70 71 if DbRows.Count > 0 then begin … … 73 74 HandlerData.SessionId := GetNewSessionId; 74 75 end; 75 DbRows.Destroy;76 76 finally 77 DbRows.Free; 77 78 Lock.Release; 78 79 end; … … 80 81 end; 81 82 82 procedure T MySQLHTTPSessionStorage.Save(HandlerData: THTTPHandlerData);83 procedure THTTPSessionStorageMySQL.Save(HandlerData: THTTPHandlerData); 83 84 var 84 85 DbRows: TDbRows; … … 87 88 try 88 89 Lock.Acquire; 89 DbRows := SqlDatabase.Query('SELECT * FROM Session WHERE Identification="' +90 DbRows := SqlDatabase.Query('SELECT * FROM `HTTPSession` WHERE `Identification`="' + 90 91 HandlerData.SessionId + '"'); 91 92 if DbRows.Count > 0 then 92 DbRows2 := SqlDatabase.Query('UPDATE Session SET Variables="' + HandlerData.Session.Text 93 + '" WHERE Identification="' + HandlerData.SessionId + '"') 94 else DbRows2 := SqlDatabase.Query('REPLACE Session SET Variables="' + HandlerData.Session.Text 95 + '" WHERE Identification="' + HandlerData.SessionId + '"'); 96 DbRows2.Destroy; 97 DbRows.Destroy; 93 DbRows2 := SqlDatabase.Query('UPDATE `HTTPSession` SET `Variables`="' + HandlerData.Session.Text 94 + '" WHERE `Identification`="' + HandlerData.SessionId + '", `Time` = NOW()') 95 else DbRows2 := SqlDatabase.Query('INSERT INTO `HTTPSession` (`Time`, `Variables`, `Identification`) VALUES (' + 96 'NOW(), "' + HandlerData.Session.Text + '", "' + HandlerData.SessionId + '")'); 98 97 HandlerData.Response.Cookies.Values[SessionIdCookieName] := HandlerData.SessionId; 99 98 finally 99 DbRows2.Free; 100 DbRows.Free; 100 101 Lock.Release; 101 102 end; … … 103 104 end; 104 105 105 constructor T MySQLHTTPSessionStorage.Create;106 constructor THTTPSessionStorageMySQL.Create; 106 107 begin 107 108 inherited Create; … … 109 110 Sessions := TStringList.Create; 110 111 SessionIdCookieName := 'SessionId'; 111 SqlDatabase := TSqlDatabase.Create;112 112 Timeout := 3600; 113 113 end; 114 114 115 destructor T MySQLHTTPSessionStorage.Destroy;115 destructor THTTPSessionStorageMySQL.Destroy; 116 116 begin 117 SqlDatabase.Destroy; 118 Sessions.Destroy; 119 Lock.Destroy; 117 Sessions.Free; 118 Lock.Free; 120 119 inherited Destroy; 121 120 end;
Note:
See TracChangeset
for help on using the changeset viewer.