Changeset 250 for Network/CoolWeb/Persistence
- Timestamp:
- Jun 13, 2011, 8:00:17 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Network/CoolWeb/Persistence/USqlDatabase.pas
r238 r250 20 20 21 21 TSetClientCapabilities = set of TClientCapabilities; 22 23 TLogEvent = procedure(Sender: TObject; Text: string) of object; 22 24 23 25 TDbRows = class(TListObject) … … 41 43 FDatabase: string; 42 44 FUserName: string; 45 FOnLogQuery: TLogEvent; 43 46 procedure mySQLClient1ConnectError(Sender: TObject; Msg: String); 44 47 function GetConnected: Boolean; … … 56 59 procedure Query(DbRows: TDbRows; Data: string); 57 60 procedure Select(DbRows: TDbRows; ATable: string; Filter: string = '*'; Condition: string = '1'); 58 procedure Delete(ATable: string; Condition: string = '1'); 59 procedure Insert(ATable: string; Data: TDictionaryStringString); 60 procedure Update(ATable: string; Data: TDictionaryStringString; Condition: string = '1'); 61 procedure Replace(ATable: string; Data: TDictionaryStringString); 61 procedure Delete(ATable: string; Condition: string = '1'; 62 Schema: string = ''); 63 procedure Insert(ATable: string; Data: TDictionaryStringString; 64 Schema: string = ''); 65 procedure Update(ATable: string; Data: TDictionaryStringString; 66 Condition: string = '1'; Schema: string = ''); 67 procedure Replace(ATable: string; Data: TDictionaryStringString; 68 Schema: string = ''); 62 69 procedure Connect; 63 70 procedure Disconnect; … … 75 82 property Password: string read FPassword write FPassword; 76 83 property Encoding: string read FEncoding write FEncoding; 84 property OnLogQuery: TLogEvent read FOnLogQuery write FOnLogQuery; 77 85 end; 78 86 … … 193 201 end; 194 202 195 procedure TSqlDatabase.Insert(ATable: string; Data: TDictionaryStringString); 203 procedure TSqlDatabase.Insert(ATable: string; Data: TDictionaryStringString; 204 Schema: string); 196 205 var 197 206 DbNames: string; … … 215 224 try 216 225 DbResult := TDbRows.Create; 217 Query(DbResult, 'INSERT INTO `' + ATable + '` (' + DbNames + ') VALUES (' + DbValues + ')'); 226 if Schema <> '' then Schema := '`' + Schema + '`.'; 227 Query(DbResult, 'INSERT INTO ' + Schema + '`' + ATable + '` (' + DbNames + ') VALUES (' + DbValues + ')'); 218 228 finally 219 229 DbResult.Free; … … 228 238 begin 229 239 DbRows.Clear; 230 //DebugLog('SqlDatabase query: '+Data);240 if Assigned(FOnLogQuery) then FOnLogQuery(Self, Data); 231 241 LastQuery := Data; 232 242 mysql_query(FSession, PChar(Data)); … … 252 262 end; 253 263 254 procedure TSqlDatabase.Replace(ATable: string; Data: TDictionaryStringString); 264 procedure TSqlDatabase.Replace(ATable: string; Data: TDictionaryStringString; 265 Schema: string = ''); 255 266 var 256 267 DbNames: string; … … 274 285 try 275 286 DbResult := TDbRows.Create; 276 Query(DbResult, 'REPLACE INTO `' + ATable + '` (' + DbNames + ') VALUES (' + DbValues + ')'); 287 if Schema <> '' then Schema := '`' + Schema + '`.'; 288 Query(DbResult, 'REPLACE INTO ' + Schema + '`' + ATable + '` (' + DbNames + ') VALUES (' + DbValues + ')'); 277 289 finally 278 290 DbResult.Free; … … 286 298 end; 287 299 288 procedure TSqlDatabase.Update(ATable: string; Data: TDictionaryStringString; Condition: string = '1'); 300 procedure TSqlDatabase.Update(ATable: string; Data: TDictionaryStringString; 301 Condition: string = '1'; Schema: string = ''); 289 302 var 290 303 DbValues: string; … … 304 317 try 305 318 DbResult := TDbRows.Create; 306 Query(DbResult, 'UPDATE `' + ATable + '` SET (' + DbValues + ') WHERE ' + Condition); 319 if Schema <> '' then Schema := '`' + Schema + '`.'; 320 Query(DbResult, 'UPDATE ' + Schema + '`' + ATable + '` SET (' + DbValues + ') WHERE ' + Condition); 307 321 finally 308 322 DbResult.Free; … … 315 329 end; 316 330 317 procedure TSqlDatabase.Delete(ATable: string; Condition: string = '1'); 331 procedure TSqlDatabase.Delete(ATable: string; Condition: string = '1'; 332 Schema: string = ''); 318 333 var 319 334 DbResult: TDbRows; … … 322 337 try 323 338 DbResult := TDbRows.Create; 324 Query(DbResult, 'DELETE FROM `' + ATable + '` WHERE ' + Condition); 339 if Schema <> '' then Schema := '`' + Schema + '`.'; 340 Query(DbResult, 'DELETE FROM ' + Schema + '`' + ATable + '` WHERE ' + Condition); 325 341 finally 326 342 DbResult.Free;
Note:
See TracChangeset
for help on using the changeset viewer.