Changeset 142 for devel/web/UDatabase.pas
- Timestamp:
- Jan 22, 2009, 9:20:15 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
devel/web/UDatabase.pas
r139 r142 9 9 10 10 type 11 TDatabase = class; 11 12 12 13 { TDbObject } … … 14 15 TDbObject = class 15 16 Id: Integer; 17 Loaded: Boolean; 18 Database: TDatabase; 16 19 procedure Store; virtual; 20 procedure Load; virtual; 17 21 procedure Delete; 22 constructor Create; 23 destructor Destroy; override; 18 24 end; 25 26 TDbObjectClass = class of TDbObject; 19 27 20 28 { TDbList } 21 29 22 30 TDbList = class 31 Id: Integer; 32 Database: TDatabase; 33 ItemClassType: TDbObjectClass; 23 34 Items: TList; 24 35 constructor Create; 25 36 destructor Destroy; override; 37 function Add: TDbObject; 38 procedure Store; 39 procedure Load; 26 40 end; 27 41 … … 35 49 { TDatabase } 36 50 37 TDatabase = class 38 SqlDatabase: TSqlDatabase; 39 procedure Open; 40 procedure Close; 51 TDatabase = class(TSqlDatabase) 52 BaseObject: TDbObject; 53 constructor Create; 54 destructor Destroy; override; 55 procedure Init; 41 56 end; 42 57 … … 48 63 end; 49 64 65 procedure TDbObject.Load; 66 begin 67 68 end; 69 50 70 procedure TDbObject.Delete; 51 71 begin 52 72 73 end; 74 75 constructor TDbObject.Create; 76 begin 77 end; 78 79 destructor TDbObject.Destroy; 80 begin 81 inherited Destroy; 53 82 end; 54 83 … … 70 99 end; 71 100 101 function TDbList.Add: TDbObject; 102 var 103 Data: TAssocArray; 104 begin 105 Result := ItemClassType.Create; 106 Data := TAssocArray.Create; 107 Data.AddKeyValue('id', ''); 108 Database.Insert(ClassName, Data); 109 Result.Id := Database.LastInsertId;; 110 Items.Add(Result); 111 end; 112 113 procedure TDbList.Store; 114 var 115 I: Integer; 116 Data: TAssocArray; 117 begin 118 Data := TAssocArray.Create; 119 Database.Insert(ClassName, Data); 120 for I := 0 to Items.Count - 1 do begin 121 Database.Insert(ClassName, Data); 122 end; 123 end; 124 125 procedure TDbList.Load; 126 begin 127 128 end; 129 72 130 { TDbResultSet } 73 131 … … 83 141 { TDatabase } 84 142 85 procedure TDatabase.Open;143 constructor TDatabase.Create; 86 144 begin 87 145 BaseObject := TDbObject.Create;; 88 146 end; 89 147 90 procedure TDatabase.Close;148 destructor TDatabase.Destroy; 91 149 begin 150 BaseObject.Free; 151 end; 92 152 153 procedure TDatabase.Init; 154 begin 155 BaseObject.Id := 1; 156 BaseObject.Database := Self; 157 BaseObject.Load; 93 158 end; 94 159
Note:
See TracChangeset
for help on using the changeset viewer.