Changeset 44 for trunk/Application/UChronisClient.pas
- Timestamp:
- Mar 9, 2012, 3:02:00 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/UChronisClient.pas
r43 r44 7 7 uses 8 8 Classes, SysUtils, SpecializedList, SpecializedDictionary; 9 10 const 11 SystemVersionObject = 'SystemVersion'; 9 12 10 13 type … … 26 29 procedure Save; 27 30 procedure Delete; 28 procedure Add;29 31 constructor Create; 30 32 destructor Destroy; override; … … 81 83 protected 82 84 procedure InitSystemTypes; virtual; 85 procedure Init; virtual; 83 86 function GetConnected: Boolean; virtual; 84 87 public … … 89 92 Password: string; 90 93 Types: TChronisTypeList; 94 Version: string; 91 95 procedure ObjectLoad(AObject: TObjectProxy); virtual; abstract; 92 96 procedure ObjectSave(AObject: TObjectProxy); virtual; abstract; 93 procedure ObjectAdd(AObject: TObjectProxy); virtual; abstract;94 97 procedure ObjectDelete(AObject: TObjectProxy); virtual; abstract; 95 98 procedure ListLoad(AList: TListProxy); virtual; abstract; … … 98 101 procedure TypeUndefine(AType: TChronisType); virtual; abstract; 99 102 procedure CheckTypes; 103 function TypeExists(Name: string): Boolean; virtual; abstract; 100 104 constructor Create; virtual; 101 105 destructor Destroy; override; 102 procedure Connect; virtual; abstract; 103 procedure Disconnect; virtual; abstract; 106 procedure Connect; virtual; 107 procedure Disconnect; virtual; 108 procedure Install; virtual; 109 procedure Uninstall; virtual; 110 procedure Update; virtual; 104 111 property Connected: Boolean read GetConnected; 105 112 end; … … 110 117 resourcestring 111 118 SClientNotSet = 'Client not set'; 119 SNotSupported = 'Not supported'; 120 SVersionMismatch = 'Version mismatch, client: %0:s, server: %1:s. Please upgrade database.'; 121 112 122 113 123 { TChronisTypeList } … … 174 184 end; 175 185 176 procedure TObjectProxy.Add;177 begin178 if Assigned(Client) then Client.ObjectAdd(Self)179 else raise EClientNotSet.Create(SClientNotSet);180 end;181 182 186 constructor TObjectProxy.Create; 183 187 begin … … 230 234 procedure TChronisClient.InitSystemTypes; 231 235 begin 236 end; 237 238 procedure TChronisClient.Init; 239 var 240 NewProxy: TListProxy; 241 NewType: TChronisType; 242 NewObject: TObjectProxy; 243 DbVersion: string; 244 begin 245 NewProxy := TListProxy.Create; 246 NewProxy.Client := Self; 247 NewProxy.SchemaName := 'information_schema'; 248 NewProxy.ObjectName := 'TABLES'; 249 NewProxy.Condition := '(TABLE_SCHEMA = "' + Schema + 250 '") AND (TABLE_NAME = "' + SystemVersionObject + '")'; 251 NewProxy.Load; 252 if NewProxy.Objects.Count > 0 then begin 253 DbVersion := TObjectProxy(NewProxy.Objects[0]).Properties.Values['Version']; 254 if Version <> DbVersion then 255 raise Exception.Create(Format(SVersionMismatch, [Version, DbVersion])); 256 end else begin 257 NewType := TChronisType.Create; 258 NewType.Client := Self; 259 NewType.Name := SystemVersionObject; 260 NewType.Properties.Add('Version', 'String'); 261 NewType.Properties.Add('Time', 'DateTime'); 262 NewType.Define; 263 264 NewObject := TObjectProxy.Create; 265 NewObject.Client := Self; 266 NewObject.SchemaName := Schema; 267 NewObject.ObjectName := SystemVersionObject; 268 NewObject.Properties.Add('Version', Version); 269 NewObject.Properties.Add('Time', 'NOW()'); 270 NewObject.Save; 271 272 Install; 273 end; 232 274 end; 233 275 … … 287 329 end; 288 330 331 procedure TChronisClient.Connect; 332 begin 333 raise Exception.Create(SNotSupported); 334 end; 335 336 procedure TChronisClient.Disconnect; 337 begin 338 raise Exception.Create(SNotSupported); 339 end; 340 341 procedure TChronisClient.Install; 342 begin 343 344 end; 345 346 procedure TChronisClient.Uninstall; 347 begin 348 349 end; 350 351 procedure TChronisClient.Update; 352 begin 353 354 end; 355 289 356 end. 290 357
Note:
See TracChangeset
for help on using the changeset viewer.