Changeset 137 for trunk/Packages/CoolWeb/Persistence
- Timestamp:
- Sep 9, 2022, 1:16:58 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/CoolWeb/Persistence/USqlDatabase.pas
r103 r137 1 1 unit USqlDatabase; 2 2 3 {$mode Delphi}{$H+} 4 5 // Modified: 2010-12-24 3 // Modified: 2022-09-08 6 4 7 5 interface 8 6 9 7 uses 10 SysUtils, Classes, Dialogs, mysql50, TypInfo, 11 Specialized Dictionary, SpecializedList;8 SysUtils, Classes, Dialogs, mysql50, TypInfo, SpecializedDictionary, 9 SpecializedList; 12 10 13 11 type … … 61 59 procedure CreateColumn(Table, ColumnName: string; ColumnType: TTypeKind); 62 60 procedure Query(DbRows: TDbRows; Data: string); 63 procedure Select(DbRows: TDbRows; ATable: string; Filter: string = '*'; Condition: string = '1'); 64 procedure Delete(ATable: string; Condition: string = '1'; 61 procedure Select(DbRows: TDbRows; ATable: string; Filter: string = '*'; 62 Condition: string = ''); 63 procedure Delete(ATable: string; Condition: string = ''; 65 64 Schema: string = ''); 66 65 procedure Insert(ATable: string; Data: TDictionaryStringString; 67 66 Schema: string = ''); 68 67 procedure Update(ATable: string; Data: TDictionaryStringString; 69 Condition: string = ' 1'; Schema: string = '');68 Condition: string = ''; Schema: string = ''); 70 69 procedure Replace(ATable: string; Data: TDictionaryStringString; 71 70 Schema: string = ''); … … 100 99 101 100 uses 102 DateUtils , Math;101 DateUtils; 103 102 104 103 resourcestring … … 184 183 Rows: TDbRows; 185 184 begin 186 // mySQLClient1.Connect;187 185 FSession := mysql_init(FSession); 188 // FSession.charset := 'latin2';189 186 NewSession := mysql_real_connect(FSession, PChar(HostName), PChar(UserName), 190 187 PChar(Password), PChar(Database), FPort, nil, CLIENT_LONG_PASSWORD + CLIENT_CONNECT_WITH_DB); … … 250 247 251 248 DbResult := mysql_store_result(FSession); 252 if Assigned(DbResult) then begin 253 DbRows.Count := mysql_num_rows(DbResult); 254 for I := 0 to DbRows.Count - 1 do begin 255 DbRow := mysql_fetch_row(DbResult); 256 DbRows[I] := TDictionaryStringString.Create; 257 with DbRows[I] do begin 258 for II := 0 to mysql_num_fields(DbResult) - 1 do begin 259 Add(mysql_fetch_field_direct(DbResult, II)^.Name, 260 PChar((DbRow + II)^)); 249 try 250 if Assigned(DbResult) then begin 251 DbRows.Count := mysql_num_rows(DbResult); 252 for I := 0 to DbRows.Count - 1 do begin 253 DbRow := mysql_fetch_row(DbResult); 254 DbRows[I] := TDictionaryStringString.Create; 255 with DbRows[I] do begin 256 for II := 0 to mysql_num_fields(DbResult) - 1 do begin 257 Add(mysql_fetch_field_direct(DbResult, II)^.Name, 258 PChar((DbRow + II)^)); 261 259 end; 262 260 end; 263 261 end; 264 end; 265 mysql_free_result(DbResult); 262 end; 263 finally 264 mysql_free_result(DbResult); 265 end; 266 266 end; 267 267 … … 296 296 end; 297 297 298 procedure TSqlDatabase.Select(DbRows: TDbRows; ATable: string; Filter: string = '*'; Condition: string = '1'); 298 procedure TSqlDatabase.Select(DbRows: TDbRows; ATable: string; Filter: string = '*'; Condition: string = ''); 299 var 300 QueryText: string; 299 301 begin 300 302 LastUsedTable := ATable; 301 Query(DbRows, 'SELECT ' + Filter + ' FROM `' + ATable + '` WHERE ' + Condition); 303 QueryText := 'SELECT ' + Filter + ' FROM `' + ATable + '`'; 304 if Condition <> '' then QueryText := QueryText + ' WHERE ' + Condition; 305 Query(DbRows, QueryText); 302 306 end; 303 307 304 308 procedure TSqlDatabase.Update(ATable: string; Data: TDictionaryStringString; 305 Condition: string = '1'; Schema: string = ''); 306 var 309 Condition: string = ''; Schema: string = ''); 310 var 311 QueryText: string; 307 312 DbValues: string; 308 313 Value: string; … … 322 327 DbResult := TDbRows.Create; 323 328 if Schema <> '' then Schema := '`' + Schema + '`.'; 324 Query(DbResult, 'UPDATE ' + Schema + '`' + ATable + '` SET ' + DbValues + ' WHERE ' + Condition); 329 QueryText := 'UPDATE ' + Schema + '`' + ATable + '` SET ' + DbValues; 330 if Condition <> '' then QueryText := QueryText + ' WHERE ' + Condition; 331 Query(DbResult, QueryText); 325 332 finally 326 333 DbResult.Free; … … 333 340 end; 334 341 335 procedure TSqlDatabase.Delete(ATable: string; Condition: string = ' 1';342 procedure TSqlDatabase.Delete(ATable: string; Condition: string = ''; 336 343 Schema: string = ''); 337 344 var 345 QueryText: string; 338 346 DbResult: TDbRows; 339 347 begin … … 342 350 DbResult := TDbRows.Create; 343 351 if Schema <> '' then Schema := '`' + Schema + '`.'; 344 Query(DbResult, 'DELETE FROM ' + Schema + '`' + ATable + '` WHERE ' + Condition); 352 QueryText := 'DELETE FROM ' + Schema + '`' + ATable + '`'; 353 if Condition <> '' then QueryText := QueryText + ' WHERE ' + Condition; 354 Query(DbResult, QueryText); 345 355 finally 346 356 DbResult.Free; … … 497 507 end. 498 508 499
Note:
See TracChangeset
for help on using the changeset viewer.