Changeset 37 for trunk/Application
- Timestamp:
- Mar 8, 2012, 3:11:10 PM (13 years ago)
- Location:
- trunk/Application
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/Clients/UChronisClientMySQL.pas
r34 r37 13 13 14 14 TChronisClientMySQL = class(TChronisClient) 15 protected 16 function GetConnected: Boolean; override; 17 public 15 18 Database: TSqlDatabase; 16 19 procedure ObjectLoad(AObject: TObjectProxy); override; … … 20 23 procedure ListLoad(AList: TListProxy); override; 21 24 procedure ListSave(AList: TListProxy); override; 22 constructor Create; 25 procedure DefineType(AType: TChronisType); override; 26 procedure UndefineType(AType: TChronisType); override; 27 procedure Install; 28 procedure Uninstall; 29 constructor Create; override; 23 30 destructor Destroy; override; 31 procedure Connect; override; 32 procedure Disconnect; override; 24 33 end; 25 34 … … 27 36 28 37 { TChronisClientMySQL } 38 39 function TChronisClientMySQL.GetConnected: Boolean; 40 begin 41 Result := Database.Connected; 42 end; 29 43 30 44 procedure TChronisClientMySQL.ObjectLoad(AObject: TObjectProxy); … … 52 66 DbRows: TDbRows; 53 67 Filter: string; 54 Condition: string;68 DbCondition: string; 55 69 I: Integer; 56 70 NewObject: TObjectProxy; 71 Table: string; 57 72 begin 58 73 try … … 64 79 Delete(Filter, Length(Filter) - 1, 2); 65 80 end else Filter := '*'; 66 if AList.Condition Use then Condition := '`' + AList.ConditionColumn + '` = "' +67 AList.ConditionValue + '"'68 else Condition := '1';69 Database.Query(DbRows, 'SELECT ' + Filter + ' FROM `' + AList.SchemaName + '`.`' +70 AList.ObjectName + '` WHERE ' +Condition);81 if AList.Condition <> '' then DbCondition := ' WHERE ' + AList.Condition 82 else DbCondition := ''; 83 Table := '`' + AList.ObjectName + '`'; 84 if AList.SchemaName <> '' then Table := '`' + AList.SchemaName + '`.' + Table; 85 Database.Query(DbRows, 'SELECT ' + Filter + ' FROM ' + Table + DbCondition); 71 86 AList.Objects.Clear; 72 87 for I := 0 to DbRows.Count - 1 do begin … … 86 101 end; 87 102 103 procedure TChronisClientMySQL.DefineType(AType: TChronisType); 104 var 105 Data: TDictionaryStringString; 106 I: Integer; 107 begin 108 try 109 Data := TDictionaryStringString.Create; 110 Data.Add('Name', AType.Name); 111 Database.Insert('Type', Data); 112 finally 113 Data.Free; 114 end; 115 if AType is TChronisTypeRecord then begin 116 for I := 0 to TChronisTypeRecord(AType).Items.Count - 1 do 117 try 118 Data := TDictionaryStringString.Create; 119 Data.Add('Name', 120 TChronisTypeRecordItem(TChronisTypeRecord(AType).Items[I]).Name); 121 Data.Add('Type', IntToStr( 122 TChronisTypeRecordItem(TChronisTypeRecord(AType).Items[I]).ItemType.OID)); 123 Database.Insert('TypeRecordItem', Data); 124 finally 125 Data.Free; 126 end; 127 end; 128 end; 129 130 procedure TChronisClientMySQL.UndefineType(AType: TChronisType); 131 begin 132 133 end; 134 135 procedure TChronisClientMySQL.Install; 136 begin 137 (* if Tables.IndexOf(InformationTable) = -1 then begin 138 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + InformationTable + '` ( ' + 139 '`Version` varchar(255) NOT NULL,' + 140 '`LastUpdateTime` datetime NOT NULL' + 141 ') ENGINE=InnoDB DEFAULT CHARSET=utf8;'); 142 Database.Query(DbRows, 'INSERT INTO `' + InformationTable + '` (`Version`, `LastUpdateTime`) VALUES ' + 143 '("0.1", "0000-00-00 00:00:00");'); 144 end; 145 Database.Select(DbRows, InformationTable); 146 StructureVersion := DbRows[0].Values['Version'];*) 147 end; 148 149 procedure TChronisClientMySQL.Uninstall; 150 begin 151 152 end; 153 88 154 constructor TChronisClientMySQL.Create; 89 155 begin … … 97 163 end; 98 164 165 procedure TChronisClientMySQL.Connect; 166 begin 167 Database.Port := Port; 168 Database.UserName := User; 169 Database.Password := Password; 170 Database.HostName := Host; 171 Database.Database := Schema; 172 Database.Connect; 173 end; 174 175 procedure TChronisClientMySQL.Disconnect; 176 begin 177 Database.Disconnect; 178 end; 179 99 180 end. 100 181 -
trunk/Application/UChronisClient.pas
r34 r37 19 19 Properties: TDictionaryStringString; 20 20 Client: TChronisClient; 21 ObjectName: string; 22 SchemaName: string; 21 23 procedure Load; 22 24 procedure Save; … … 39 41 ColumnsFilter: TListString; 40 42 ColummsFilterUse: Boolean; 41 ConditionColumn: string; 42 ConditionValue: string; 43 ConditionUse: Boolean; 43 Condition: string; 44 44 ObjectName: string; 45 45 SchemaName: string; 46 46 Objects: TListObject; // TListObject<TObjectProxy> 47 procedure SetCondition(ColumnName: string; Value: string);48 47 procedure Clear; 49 48 constructor Create; … … 53 52 end; 54 53 54 TChronisType = class 55 OID: Integer; 56 Name: string; 57 end; 58 59 TChronisTypeRecordItem = class 60 Name: string; 61 ItemType: TChronisType; 62 end; 63 64 { TChronisTypeRecord } 65 66 TChronisTypeRecord = class(TChronisType) 67 Items: TListObject; // TListObject<TChronisTypeRecordItem> 68 constructor Create; 69 destructor Destroy; override; 70 end; 71 55 72 { TChronisClient } 56 73 57 74 TChronisClient = class 75 protected 76 function GetConnected: Boolean; virtual; 77 public 58 78 Host: string; 59 79 Port: Word; … … 67 87 procedure ListLoad(AList: TListProxy); virtual; abstract; 68 88 procedure ListSave(AList: TListProxy); virtual; abstract; 89 procedure DefineType(AType: TChronisType); virtual; abstract; 90 procedure UndefineType(AType: TChronisType); virtual; abstract; 69 91 constructor Create; virtual; 92 procedure Connect; virtual; abstract; 93 procedure Disconnect; virtual; abstract; 94 property Connected: Boolean read GetConnected; 70 95 end; 71 96 72 97 implementation 98 99 { TChronisTypeRecord } 100 101 constructor TChronisTypeRecord.Create; 102 begin 103 Items := TListObject.Create; 104 end; 105 106 destructor TChronisTypeRecord.Destroy; 107 begin 108 Items.Free; 109 inherited Destroy; 110 end; 73 111 74 112 { TObjectProxy } … … 107 145 { TListProxy } 108 146 109 procedure TListProxy.SetCondition(ColumnName: string; Value: string);110 begin111 ConditionColumn := ColumnName;112 ConditionValue := Value;113 ConditionUse := True;114 end;115 116 147 procedure TListProxy.Clear; 117 148 begin 118 ConditionUse := False;119 149 PageUse := False; 120 150 ColummsFilterUse := False; … … 148 178 { TChronisClient } 149 179 180 function TChronisClient.GetConnected: Boolean; 181 begin 182 Result := False; 183 end; 184 150 185 constructor TChronisClient.Create; 151 186 begin -
trunk/Application/UDataTypes.pas
r23 r37 6 6 7 7 uses 8 Classes, SysUtils, Controls, Spin, StdCtrls, ExtCtrls, MaskEdit, EditBtn; 8 Classes, SysUtils, Controls, Spin, StdCtrls, ExtCtrls, MaskEdit, EditBtn, 9 UChronisClient; 9 10 10 11 type … … 147 148 function GetDataType(ACustomType: Integer): TDataType; 148 149 var 149 DbRows: TDbRows;150 Proxy: TListProxy; 150 151 BaseType: Integer; 151 152 begin 152 153 try 153 DbRows := TDbRows.Create; 154 Core.System.Database.Select(DbRows, CustomTypeTableName, '*', 'Id=' + IntToStr(ACustomType)); 155 BaseType := StrToInt(DbRows[0].Values['Type']); 154 Proxy := TListProxy.Create; 155 Proxy.Client := Core.System.Client; 156 Proxy.ObjectName := CustomTypeTableName; 157 Proxy.Condition := 'Id=' + IntToStr(ACustomType); 158 Proxy.Load; 159 BaseType := StrToInt(TObjectProxy(Proxy.Objects[0]).Properties.Values['Type']); 156 160 finally 157 DbRows.Free;161 Proxy.Free; 158 162 end; 159 163 … … 231 235 procedure TDataTypeRelationMany.LoadDef(ACustomType: Integer); 232 236 var 233 DbRows: TDbRows;237 Proxy: TListProxy; 234 238 BaseType: Integer; 235 239 begin 236 240 try 237 DbRows := TDbRows.Create; 238 Core.System.Database.Select(DbRows, TypeRelationMany, '*', 'CustomType=' + IntToStr(ACustomType)); 239 PropertyID := StrToInt(DbRows[0].Values['ObjectProperty']); 241 Proxy := TListProxy.Create; 242 Proxy.Client := Core.System.Client; 243 Proxy.ObjectName := TypeRelationMany; 244 Proxy.Condition := 'CustomType=' + IntToStr(ACustomType); 245 Proxy.Load; 246 PropertyID := StrToInt(TObjectProxy(Proxy.Objects[0]).Properties.Values['ObjectProperty']); 240 247 finally 241 DbRows.Free;248 Proxy.Free; 242 249 end; 243 250 try 244 DbRows := TDbRows.Create; 245 Core.System.Database.Select(DbRows, PropertyTable, '*', 'Id=' + IntToStr(PropertyID)); 246 ObjectId := StrToInt(DbRows[0].Values['Object']); 247 PropertyName := DbRows[0].Values['ColumnName']; 251 Proxy := TListProxy.Create; 252 Proxy.Client := Core.System.Client; 253 Proxy.ObjectName := PropertyTable; 254 Proxy.Condition := 'Id=' + IntToStr(PropertyID); 255 ObjectId := StrToInt(TObjectProxy(Proxy.Objects[0]).Properties.Values['Object']); 256 PropertyName := TObjectProxy(Proxy.Objects[0]).Properties.Values['ColumnName']; 248 257 finally 249 DbRows.Free;258 Proxy.Free; 250 259 end; 251 260 end; … … 286 295 procedure TDataTypeRelationOne.LoadDef(ACustomType: Integer); 287 296 var 288 DbRows: TDbRows;297 Proxy: TListProxy; 289 298 begin 290 299 try 291 DbRows := TDbRows.Create; 292 Core.System.Database.Select(DbRows, TypeRelationOne, '*', 'CustomType=' + IntToStr(ACustomType)); 293 ObjectId := StrToInt(DbRows[0].Values['Object']); 300 Proxy := TListProxy.Create; 301 Proxy.Client := Core.System.Client; 302 Proxy.ObjectName := TypeRelationOne; 303 Proxy.Condition := 'CustomType=' + IntToStr(ACustomType); 304 Proxy.Load; 305 ObjectId := StrToInt(TObjectProxy(Proxy.Objects[0]).Properties.Values['Object']); 294 306 finally 295 DbRows.Free;307 Proxy.Free; 296 308 end; 297 309 end;
Note:
See TracChangeset
for help on using the changeset viewer.