Changeset 13 for trunk/UDatabase.pas
- Timestamp:
- Mar 17, 2015, 12:09:11 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UDatabase.pas
r12 r13 6 6 7 7 uses 8 Classes, SysUtils, Contnrs, ExtCtrls, StdCtrls, EditBtn, dialogs; 8 Classes, SysUtils, Contnrs, ExtCtrls, StdCtrls, EditBtn, dialogs, USqlDatabase, 9 SpecializedDictionary; 9 10 10 11 type … … 23 24 procedure Assign(Source: TValue); virtual; 24 25 function GetString: string; virtual; 26 function SetString(Value: string): string; virtual; 25 27 end; 26 28 … … 94 96 95 97 TTable = class 98 Id: Integer; 96 99 Name: string; 97 100 Caption: string; … … 99 102 Fields: TFields; 100 103 Database: TDatabase; 104 RecordsCount: Integer; 105 procedure LoadRecords; 106 procedure LoadRecordsCount; 101 107 procedure Assign(Source: TTable); 102 108 constructor Create; … … 104 110 end; 105 111 112 { TTables } 113 106 114 TTables = class(TObjectList) 107 115 Database: TDatabase; 116 function SearchByName(Name: string): TTable; 108 117 end; 109 118 … … 140 149 141 150 TDataType = class 151 Id: Integer; 142 152 Name: string; 143 153 FieldType: TFieldType; … … 148 158 149 159 TDataTypes = class(TObjectList) 150 function RegisterType( Name: string; FieldType: TFieldType; FieldTypeClass: TFieldTypeSpecificClass): TDataType;160 function RegisterType(Id: Integer; Name: string; FieldType: TFieldType; FieldTypeClass: TFieldTypeSpecificClass): TDataType; 151 161 function FindByType(FieldType: TFieldType): TDataType; 152 162 end; … … 156 166 TDatabaseClient = class 157 167 Database: TDatabase; 168 procedure Query(DbRows: TDbRows; Text: string); virtual; 158 169 constructor Create; virtual; 159 170 procedure Load; virtual; … … 194 205 UDataTypes; 195 206 207 { TTables } 208 209 function TTables.SearchByName(Name: string): TTable; 210 var 211 I: Integer; 212 begin 213 I := 0; 214 while (I < Count) and (TTable(Items[I]).Name <> Name) do Inc(I); 215 if I < Count then Result := TTable(Items[I]) 216 else Result := nil; 217 end; 218 196 219 { TDatabases } 197 220 … … 208 231 { TDatabaseClient } 209 232 233 procedure TDatabaseClient.Query(DbRows: TDbRows; Text: string); 234 begin 235 end; 236 210 237 constructor TDatabaseClient.Create; 211 238 begin … … 245 272 { TDataTypes } 246 273 247 function TDataTypes.RegisterType( Name: string; FieldType: TFieldType;274 function TDataTypes.RegisterType(Id: Integer; Name: string; FieldType: TFieldType; 248 275 FieldTypeClass: TFieldTypeSpecificClass): TDataType; 249 276 begin 250 277 Result := TDataType.Create; 278 Result.Id := Id; 251 279 Result.Name := Name; 252 280 Result.FieldType := FieldType; … … 380 408 end; 381 409 410 function TValue.SetString(Value: string): string; 411 begin 412 413 end; 414 382 415 { TFieldTypeSpecific } 383 416 … … 430 463 { TTable } 431 464 465 procedure TTable.LoadRecords; 466 var 467 DbRows: TDbRows; 468 I: Integer; 469 F: Integer; 470 NewRecord: TRecord; 471 NewValue: TValue; 472 begin 473 Records.Clear; 474 DbRows := TDbRows.Create; 475 Database.Client.Query(DbRows, 'SELECT * FROM ' + Name); 476 for I := 0 to DbRows.Count - 1 do begin 477 NewRecord := TRecord.Create; 478 for F := 0 to Fields.Count - 1 do begin 479 NewValue := TField(Fields[F]).GetValueClass.Create; 480 NewValue.SetString(TDictionaryStringString(DbRows[I]).Values[TField(Fields[F]).Name]); 481 NewRecord.Values.Add(NewValue); 482 end; 483 Records.Add(NewRecord); 484 end; 485 DbRows.Free; 486 end; 487 488 procedure TTable.LoadRecordsCount; 489 var 490 DbRows: TDbRows; 491 I: Integer; 492 F: Integer; 493 NewRecord: TRecord; 494 NewValue: TValue; 495 begin 496 Records.Clear; 497 DbRows := TDbRows.Create; 498 Database.Client.Query(DbRows, 'SELECT COUNT(*) FROM ' + Name); 499 if DbRows.Count = 1 then begin 500 RecordsCount := StrToInt(TDictionaryStringString(DbRows[0]).Items[0].Value); 501 end else RecordsCount := 0; 502 DbRows.Free; 503 end; 504 432 505 procedure TTable.Assign(Source: TTable); 433 506 begin
Note:
See TracChangeset
for help on using the changeset viewer.