- Timestamp:
- Mar 8, 2012, 3:11:10 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 9 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; -
trunk/Forms/UItemAdd.pas
r31 r37 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, 9 9 StdCtrls, Spin, EditBtn, MaskEdit, USqlDatabase, USystem, 10 SpecializedDictionary, SpecializedList ;10 SpecializedDictionary, SpecializedList, UChronisClient; 11 11 12 12 type … … 53 53 var 54 54 Data: TDictionaryStringString; 55 NewProxy: TObjectProxy; 55 56 I: Integer; 56 57 DataType: TDataType; … … 59 60 try 60 61 Data := TDictionaryStringString.Create; 62 NewProxy := TObjectProxy.Create; 63 NewProxy.Client := Client; 64 NewProxy.ObjectName := SelectedObject.Table; 65 NewProxy.SchemaName := SelectedObject.Schema; 61 66 for I := 0 to Report.Columns.Count - 1 do 62 67 if not (TReportColumn(Report.Columns[I]).CustomType is TDataTypeRelationMany) then 63 68 if TReportColumn(Report.Columns[I]).ColumnName <> SelectedObject.PrimaryKey then begin 64 69 DataType := TReportColumn(Report.Columns[I]).CustomType; 65 Data.Add(TReportColumn(Report.Columns[I]).ColumnName,70 NewProxy.Properties.Add(TReportColumn(Report.Columns[I]).ColumnName, 66 71 DataType.GetControlValue(TWinControl(TReportColumn(Report.Columns[I]).Control))); 67 72 end; 68 Database.Insert(SelectedObject.Table, Data, SelectedObject.Schema);73 NewProxy.Save; 69 74 finally 70 75 Data.Free; 76 NewProxy.Free; 71 77 end; 72 78 //MainForm.LoadItemList; -
trunk/Forms/UItemEdit.pas
r31 r37 1 1 unit UItemEdit; 2 2 3 {$mode objfpc}{$H+}3 {$mode Delphi}{$H+} 4 4 5 5 interface … … 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, 9 9 StdCtrls, Spin, EditBtn, USqlDatabase, MaskEdit, ComCtrls, USystem, 10 SpecializedList, SpecializedDictionary ;10 SpecializedList, SpecializedDictionary, UChronisClient; 11 11 12 12 type … … 119 119 procedure TItemEditForm.ButtonSaveClick(Sender: TObject); 120 120 var 121 Data: TDictionaryStringString;121 Proxy: TObjectProxy; 122 122 I: Integer; 123 123 DataType: TDataType; … … 125 125 with Core.System do 126 126 try 127 Data := TDictionaryStringString.Create; 127 Proxy := TObjectProxy.Create; 128 Proxy.Client := Client; 129 Proxy.ObjectName := SelectedObject.Table; 130 Proxy.SchemaName := SelectedObject.Schema; 131 Proxy.Id := SelectedItemId; 128 132 for I := 0 to Report.Columns.Count - 1 do 129 133 if not (TReportColumn(Report.Columns[I]).CustomType is TDataTypeRelationMany) then 130 134 if TReportColumn(Report.Columns[I]).ColumnName <> SelectedObject.PrimaryKey then begin 131 135 DataType := TReportColumn(Report.Columns[I]).CustomType; 132 Data.Add(TReportColumn(Report.Columns[I]).ColumnName,136 Proxy.Properties.Add(TReportColumn(Report.Columns[I]).ColumnName, 133 137 DataType.GetControlValue(TWinControl(TReportColumn(Report.Columns[I]).Control))); 134 138 end; 135 Database.Update(SelectedObject.Table, Data, 136 '`' + SelectedObject.PrimaryKey + '` = ' + IntToStr(SelectedItemId), SelectedObject.Schema); 139 Proxy.Save; 137 140 finally 138 Data.Free;141 Proxy.Free; 139 142 end; 140 143 if (SelectedObject.Table = ObjectGroupTable) or -
trunk/Forms/UMainForm.pas
r36 r37 148 148 procedure TMainForm.UpdateInterface; 149 149 begin 150 ADisconnect.Enabled := Core.System. Database.Connected;151 AConnect.Enabled := not Core.System. Database.Connected;152 AImportStructure.Enabled := Core.System. Database.Connected;150 ADisconnect.Enabled := Core.System.Client.Connected; 151 AConnect.Enabled := not Core.System.Client.Connected; 152 AImportStructure.Enabled := Core.System.Client.Connected; 153 153 if Assigned(MainPanelForm) then 154 154 Caption := MainPanelForm.Caption + ' - ' + ApplicationInfo.Name … … 257 257 if LoginForm.ShowModal = mrOK then begin 258 258 with TConnectProfile(Core.Profiles[Core.LastProfile]) do begin 259 Core.System. Database.HostName:= HostName;260 Core.System. Database.Database:= Database;261 Core.System. Database.UserName:= Core.LastUserName;262 Core.System. Database.Password := Core.LastPassword;263 Core.System. Database.Port := Port;259 Core.System.Client.Host := HostName; 260 Core.System.Client.Schema := Database; 261 Core.System.Client.User := Core.LastUserName; 262 Core.System.Client.Password := Core.LastPassword; 263 Core.System.Client.Port := Port; 264 264 if Protocol = cpDirect then Core.Client := TChronisClientDirect.Create; 265 265 end; 266 266 try 267 Core.System. Database.Connect;267 Core.System.Client.Connect; 268 268 if Core.System.IsDatabaseEmpty then Core.System.ModuleSystem.Install; 269 269 Core.System.LoadTypes; … … 277 277 procedure TMainForm.ADisconnectExecute(Sender: TObject); 278 278 begin 279 if Core.System. Database.Connected then begin280 Core.System. Database.Disconnect;279 if Core.System.Client.Connected then begin 280 Core.System.Client.Disconnect; 281 281 TreeView1.Items.Clear; 282 282 Core.System.Types.Clear; … … 361 361 Groups.Client := Core.System.Client; 362 362 Groups.ObjectName := ObjectGroupTable; 363 Groups.SchemaName := Core.System. Database.Database;363 Groups.SchemaName := Core.System.Client.Schema; 364 364 Groups.Load; 365 365 for I := 0 to Groups.Objects.Count - 1 do begin … … 373 373 Objects.Client := Core.System.Client; 374 374 Objects.ObjectName := ObjectTable; 375 Objects.SchemaName := Core.System. Database.Database;376 Objects. SetCondition('Group', Obj.Properties.Values['Id']);375 Objects.SchemaName := Core.System.Client.Schema; 376 Objects.Condition := '`Group`="' + Obj.Properties.Values['Id'] + '"'; 377 377 Objects.Load; 378 378 for O := 0 to Objects.Objects.Count - 1 do begin -
trunk/Module/UModuleSystem.pas
r29 r37 26 26 27 27 uses 28 USystem, USqlDatabase ;28 USystem, USqlDatabase, UChronisClient; 29 29 30 30 { TModuleSystem } … … 86 86 GroupId := AddObjectGroup('System'); 87 87 88 ObjectGroupId := AddObject('Object groups', 'ObjectGroup', Database.Database, GroupId);88 ObjectGroupId := AddObject('Object groups', 'ObjectGroup', Client.Schema, GroupId); 89 89 AddPropertyNumber(ObjectGroupId, 'Id', 'Id', False); 90 90 AddPropertyString(ObjectGroupId, 'Name', 'Name', True); 91 91 ObjectGroupParentId := AddPropertyRelationOne(ObjectGroupId, 'Parent', 'Parent', True, ObjectGroupId); 92 92 93 ObjectId := AddObject('Objects', 'Object', Database.Database, GroupId);93 ObjectId := AddObject('Objects', 'Object', Client.Schema, GroupId); 94 94 AddPropertyNumber(ObjectId, 'Id', 'Id', False); 95 95 AddPropertyString(ObjectId, 'Name', 'Name', True); … … 100 100 AddPropertyNumber(ObjectId, 'Sequence', 'Sequence', True); 101 101 102 PropertyTypeId := AddObject('Property types', 'Type', Database.Database, GroupId);102 PropertyTypeId := AddObject('Property types', 'Type', Client.Schema, GroupId); 103 103 AddPropertyNumber(PropertyTypeId, 'Id', 'Id', False); 104 104 AddPropertyString(PropertyTypeId, 'Name', 'Name', True); … … 106 106 //AddPropertyNumber(ObjectId, 'Parent', 'Parent'); 107 107 108 CustomTypeId := AddObject('Custom types', 'TypeCustom', Database.Database, GroupId);108 CustomTypeId := AddObject('Custom types', 'TypeCustom', Client.Schema, GroupId); 109 109 AddPropertyNumber(CustomTypeId, 'Id', 'Id', False); 110 110 CustomTypeIdType := AddPropertyRelationOne(CustomTypeId, 'Type', 'Type', True, PropertyTypeId); 111 111 112 ObjectPropertyGroupId := AddObject('Property groups', 'PropertyGroup', Database.Database, GroupId);112 ObjectPropertyGroupId := AddObject('Property groups', 'PropertyGroup', Client.Schema, GroupId); 113 113 AddPropertyNumber(ObjectPropertyGroupId, 'Id', 'Id', False); 114 114 115 ObjectPropertyId := AddObject('Properties', 'Property', Database.Database, GroupId);115 ObjectPropertyId := AddObject('Properties', 'Property', Client.Schema, GroupId); 116 116 AddPropertyNumber(ObjectPropertyId, 'Id', 'Id', False); 117 117 AddPropertyString(ObjectPropertyId, 'Name', 'Name', True); … … 127 127 AddPropertyRelationMany(ObjectPropertyGroupId, 'Properties', 'Properties', True, ObjectPropertyIdGroup); 128 128 AddPropertyRelationMany(PropertyTypeId, 'Custom types', 'CustomTypes', True, CustomTypeIdType); 129 ModuleId := AddObject('Modules', 'Module', Database.Database, GroupId); 129 130 ModuleId := AddObject('Modules', 'Module', Client.Schema, GroupId); 130 131 AddPropertyNumber(ModuleId, 'Id', 'Id', False); 131 132 AddPropertyString(ModuleId, 'Name', 'Name', True); … … 149 150 procedure TModuleSystem.InitStructure; 150 151 var 151 DbRows: TDbRows;152 DbRows2: TDbRows;153 152 StructureVersion: string; 154 153 Data: TDictionaryStringString; … … 156 155 Tables: TListString; 157 156 I: Integer; 157 NewProxy: TListProxy; 158 158 begin 159 159 with TChronisBase(System) do 160 160 try 161 DbRows := TDbRows.Create;162 161 Tables := TListString.Create; 163 162 Data := TDictionaryStringString.Create; 164 163 165 Database.Query(DbRows, 'SHOW TABLES'); 166 Tables.Count := DbRows.Count; 167 for I := 0 to DbRows.Count - 1 do 168 Tables[I] := DbRows[I].Items[0].Value; 169 170 if Tables.IndexOf(InformationTable) = -1 then begin 171 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + InformationTable + '` ( ' + 172 '`Version` varchar(255) NOT NULL,' + 173 '`LastUpdateTime` datetime NOT NULL' + 174 ') ENGINE=InnoDB DEFAULT CHARSET=utf8;'); 175 Database.Query(DbRows, 'INSERT INTO `' + InformationTable + '` (`Version`, `LastUpdateTime`) VALUES ' + 176 '("0.1", "0000-00-00 00:00:00");'); 177 end; 178 Database.Select(DbRows, InformationTable); 179 StructureVersion := DbRows[0].Values['Version']; 180 181 if Tables.IndexOf(ObjectTable) = -1 then begin 164 NewProxy := TListProxy.Create; 165 NewProxy.SchemaName := 'information_schema'; 166 NewProxy.ObjectName := 'TABLES'; 167 NewProxy.Condition := 'TABLE_SCHEMA = "' + Client.Schema + '"'; 168 NewProxy.Load; 169 //Database.Query(DbRows, 'SHOW TABLES'); 170 Tables.Count := NewProxy.Objects.Count; 171 for I := 0 to NewProxy.Objects.Count - 1 do 172 Tables[I] := TObjectProxy(NewProxy.Objects[I]).Properties.Values['TABLE']; 173 174 (* if Tables.IndexOf(ObjectTable) = -1 then begin 182 175 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + ObjectTable + '` ( ' + 183 176 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + … … 372 365 'PRIMARY KEY (`Id`)' + 373 366 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 374 end; 367 end; *) 375 368 finally 376 369 Tables.Free; 377 370 Data.Free; 378 DbRows.Free;371 NewProxy.Free; 379 372 end; 380 373 end; -
trunk/UCore.pas
r33 r37 55 55 LoadFromRegistry; 56 56 System := TChronisBase.Create; 57 System.Database := SqlDatabase1;58 57 System.Client := TChronisClientMySQL.Create; 59 58 TChronisClientMySQL(System.Client).Database := SqlDatabase1; -
trunk/USystem.pas
r35 r37 106 106 Types: TChronisTypeList; 107 107 Client: TChronisClient; 108 Database: TSqlDatabase;108 //Database: TSqlDatabase; 109 109 Modules: TListObject; // TListObject<TChronisModule> 110 110 ModuleSystem: TChronisModule; … … 207 207 Properties.Client := Base.Client; 208 208 Properties.ObjectName := PropertyTable; 209 Properties.SchemaName := Base. Database.Database;210 Properties. SetCondition('Object', IntToStr(Obj.Id));209 Properties.SchemaName := Base.Client.Schema; 210 Properties.Condition := 'Object="' + IntToStr(Obj.Id) + '"'; 211 211 Properties.Load; 212 212 Columns.Clear; … … 262 262 function TChronisBase.AddType(Name, DataType: string; TypeIndex: TDbValueType): Integer; 263 263 var 264 DbRows: TDbRows; 265 Data: TDictionaryStringString; 266 begin 267 try 268 DbRows := TDbRows.Create; 269 Data := TDictionaryStringString.Create; 270 Data.Add('Name', Name); 271 Data.Add('DbType', DataType); 272 Data.Add('Id', IntToStr(Integer(TypeIndex))); 273 Database.Insert(PropertyTypeTable, Data); 274 Result := Database.LastInsertId; 275 finally 276 Data.Free; 277 DbRows.Free; 264 Proxy: TObjectProxy; 265 begin 266 try 267 Proxy := TObjectProxy.Create; 268 Proxy.Client := Client; 269 Proxy.ObjectName := PropertyTypeTable; 270 Proxy.Properties.Add('Name', Name); 271 Proxy.Properties.Add('DbType', DataType); 272 Proxy.Properties.Add('Id', IntToStr(Integer(TypeIndex))); 273 Proxy.Save; 274 Result := Proxy.Id; 275 finally 276 Proxy.Free; 278 277 end; 279 278 end; … … 281 280 function TChronisBase.AddGroup(Name: string; ParentGroupId: Integer): Integer; 282 281 var 283 DbRows: TDbRows; 284 Data: TDictionaryStringString; 285 begin 286 try 287 DbRows := TDbRows.Create; 288 Data := TDictionaryStringString.Create; 289 Data.Add('Name', Name); 290 Data.Add('Parent', IntToStr(ParentGroupId)); 291 Database.Insert(ObjectGroupTable, Data); 292 Result := Database.LastInsertId; 293 finally 294 Data.Free; 295 DbRows.Free; 282 Proxy: TObjectProxy; 283 begin 284 try 285 Proxy := TObjectProxy.Create; 286 Proxy.Client := Client; 287 Proxy.ObjectName := ObjectGroupTable; 288 Proxy.Properties.Add('Name', Name); 289 Proxy.Properties.Add('Parent', IntToStr(ParentGroupId)); 290 Proxy.Save; 291 Result := Proxy.Id; 292 finally 293 Proxy.Free; 296 294 end; 297 295 end; … … 300 298 GroupId: Integer): Integer; 301 299 var 302 DbRows: TDbRows; 303 Data: TDictionaryStringString; 304 begin 305 try 306 DbRows := TDbRows.Create; 307 Data := TDictionaryStringString.Create; 308 Data.Add('Name', Name); 309 Data.Add('Schema', Schema); 310 Data.Add('Table', TableName); 311 Data.Add('Group', IntToStr(GroupId)); 312 Database.Insert(ObjectTable, Data); 313 Result := Database.LastInsertId; 314 finally 315 Data.Free; 316 DbRows.Free; 300 Proxy: TObjectProxy; 301 begin 302 try 303 Proxy := TObjectProxy.Create; 304 Proxy.Client := Client; 305 Proxy.ObjectName := ObjectTable; 306 Proxy.Properties.Add('Name', Name); 307 Proxy.Properties.Add('Schema', Schema); 308 Proxy.Properties.Add('Table', TableName); 309 Proxy.Properties.Add('Group', IntToStr(GroupId)); 310 Proxy.Save; 311 Result := Proxy.Id; 312 finally 313 Proxy.Free; 317 314 end; 318 315 end; … … 321 318 CustomType: Integer; Editable: Boolean): Integer; 322 319 var 323 DbRows: TDbRows; 324 Data: TDictionaryStringString; 325 begin 326 try 327 DbRows := TDbRows.Create; 328 Data := TDictionaryStringString.Create; 329 Data.Add('Name', Name); 330 Data.Add('Object', IntToStr(ObjectId)); 331 Data.Add('ColumnName', ColumnName); 332 Data.Add('CustomType', IntToStr(CustomType)); 333 Data.Add('Editable', IntToStr(Integer(Editable))); 334 Database.Insert(PropertyTable, Data); 335 Result := Database.LastInsertId; 336 finally 337 Data.Free; 338 DbRows.Free; 320 Proxy: TObjectProxy; 321 begin 322 try 323 Proxy := TObjectProxy.Create; 324 Proxy.Client := Client; 325 Proxy.ObjectName := PropertyTable; 326 Proxy.Properties.Add('Name', Name); 327 Proxy.Properties.Add('Object', IntToStr(ObjectId)); 328 Proxy.Properties.Add('ColumnName', ColumnName); 329 Proxy.Properties.Add('CustomType', IntToStr(CustomType)); 330 Proxy.Properties.Add('Editable', IntToStr(Integer(Editable))); 331 Proxy.Save; 332 Result := Proxy.Id; 333 finally 334 Proxy.Free; 339 335 end; 340 336 end; … … 344 340 Max: Integer = High(Integer)): Integer; 345 341 var 346 DbRows: TDbRows; 347 Data: TDictionaryStringString; 342 Proxy: TObjectProxy; 348 343 CustomTypeId: Integer; 349 344 begin 350 345 try 351 DbRows := TDbRows.Create; 352 Data := TDictionaryStringString.Create; 353 354 Data.Clear; 355 Data.Add('Type', IntToStr(Integer(vtInteger))); 356 Database.Insert(CustomTypeTableName, Data); 357 CustomTypeId := Database.LastInsertId; 358 359 Data.Clear; 360 Data.Add('CustomType', IntToStr(CustomTypeId)); 361 Data.Add('Min', IntToStr(Min)); 362 Data.Add('Max', IntToStr(Max)); 363 Data.Add('Default', IntToStr(Default)); 364 Database.Insert(TypeNumber, Data); 346 Proxy := TObjectProxy.Create; 347 Proxy.Client := Client; 348 Proxy.ObjectName := CustomTypeTableName; 349 Proxy.Properties.Add('Type', IntToStr(Integer(vtInteger))); 350 CustomTypeId := Proxy.Id; 351 352 Proxy.ObjectName := TypeNumber; 353 Proxy.Properties.Clear; 354 Proxy.Properties.Add('CustomType', IntToStr(CustomTypeId)); 355 Proxy.Properties.Add('Min', IntToStr(Min)); 356 Proxy.Properties.Add('Max', IntToStr(Max)); 357 Proxy.Properties.Add('Default', IntToStr(Default)); 358 Proxy.Save; 365 359 //CustomTypeId := Database.LastInsertId; 366 360 367 361 Result := AddProperty(ObjectId, Name, ColumnName, CustomTypeId, Editable); 368 finally369 Data.Free;370 DbRows.Free;362 Result := Proxy.Id; 363 finally 364 Proxy.Free; 371 365 end; 372 366 end; … … 375 369 ColumnName: string; Editable: Boolean; Default: Double; Min: Double; Max: Double): Integer; 376 370 var 377 DbRows: TDbRows; 378 Data: TDictionaryStringString; 371 Proxy: TObjectProxy; 379 372 CustomTypeId: Integer; 380 373 begin 381 374 try 382 DbRows := TDbRows.Create; 383 Data := TDictionaryStringString.Create; 384 385 Data.Clear; 386 Data.Add('Type', IntToStr(Integer(vtFloat))); 387 Database.Insert(CustomTypeTableName, Data); 388 CustomTypeId := Database.LastInsertId; 389 390 Data.Clear; 391 Data.Add('CustomType', IntToStr(CustomTypeId)); 392 Data.Add('Min', MySQLFloatToStr(Min)); 393 Data.Add('Max', MySQLFloatToStr(Max)); 394 Data.Add('Default', MySQLFloatToStr(Default)); 395 Database.Insert(TypeFloat, Data); 375 Proxy := TObjectProxy.Create; 376 Proxy.Client := Client; 377 Proxy.ObjectName := CustomTypeTableName; 378 Proxy.Properties.Add('Type', IntToStr(Integer(vtFloat))); 379 CustomTypeId := Proxy.Id; 380 381 Proxy.ObjectName := TypeFloat; 382 Proxy.Properties.Clear; 383 Proxy.Properties.Add('CustomType', IntToStr(CustomTypeId)); 384 Proxy.Properties.Add('Min', MySQLFloatToStr(Min)); 385 Proxy.Properties.Add('Max', MySQLFloatToStr(Max)); 386 Proxy.Properties.Add('Default', MySQLFloatToStr(Default)); 387 Proxy.Save; 396 388 //CustomTypeId := Database.LastInsertId; 397 389 398 390 Result := AddProperty(ObjectId, Name, ColumnName, CustomTypeId, Editable); 399 391 finally 400 Data.Free; 401 DbRows.Free; 392 Proxy.Free; 402 393 end; 403 394 end; … … 407 398 ): Integer; 408 399 var 409 DbRows: TDbRows; 410 Data: TDictionaryStringString; 400 Proxy: TObjectProxy; 411 401 CustomTypeId: Integer; 412 402 begin 413 403 try 414 DbRows := TDbRows.Create;415 Data := TDictionaryStringString.Create;416 417 Data.Clear;418 Data.Add('Type', IntToStr(Integer(vtDateTime)));419 Database.Insert(CustomTypeTableName, Data);420 CustomTypeId := Database.LastInsertId; 421 422 Data.Clear;423 Data.Add('CustomType', IntToStr(CustomTypeId));424 Data.Add('Min', DateTimeToSQL(Min));425 Data.Add('Max', DateTimeToSQL(Max));426 Data.Add('Default', DateTimeToSQL(Default));427 Database.Insert(TypeDateTime, Data);404 Proxy := TObjectProxy.Create; 405 Proxy.Client := Client; 406 Proxy.ObjectName := CustomTypeTableName; 407 Proxy.Properties.Add('Type', IntToStr(Integer(vtDateTime))); 408 Proxy.Save; 409 CustomTypeId := Proxy.Id; 410 411 Proxy.ObjectName := TypeDateTime; 412 Proxy.Properties.Clear; 413 Proxy.Properties.Add('CustomType', IntToStr(CustomTypeId)); 414 Proxy.Properties.Add('Min', DateTimeToSQL(Min)); 415 Proxy.Properties.Add('Max', DateTimeToSQL(Max)); 416 Proxy.Properties.Add('Default', DateTimeToSQL(Default)); 417 Proxy.Save; 428 418 //CustomTypeId := Database.LastInsertId; 429 419 430 420 Result := AddProperty(ObjectId, Name, ColumnName, CustomTypeId, Editable); 431 421 finally 432 Data.Free; 433 DbRows.Free; 422 Proxy.Free; 434 423 end; 435 424 end; … … 438 427 ColumnName: string; Editable: Boolean; Default: string = ''; MaxLength: Integer = 255): Integer; 439 428 var 440 DbRows: TDbRows; 441 Data: TDictionaryStringString; 429 Proxy: TObjectProxy; 442 430 CustomTypeId: Integer; 443 431 begin 444 432 try 445 DbRows := TDbRows.Create;446 Data := TDictionaryStringString.Create;447 448 Data.Clear;449 Data.Add('Type', IntToStr(Integer(vtString)));450 Database.Insert(CustomTypeTableName, Data);451 CustomTypeId := Database.LastInsertId; 452 453 Data.Clear;454 Data.Add('CustomType', IntToStr(CustomTypeId));455 Data.Add('MaxLength', IntToStr(MaxLength));456 Data.Add('Default', Default);457 Database.Insert(TypeString, Data);433 Proxy := TObjectProxy.Create; 434 Proxy.Client := Client; 435 Proxy.ObjectName := CustomTypeTableName; 436 Proxy.Properties.Add('Type', IntToStr(Integer(vtString))); 437 Proxy.Save; 438 CustomTypeId := Proxy.Id; 439 440 Proxy.ObjectName := TypeString; 441 Proxy.Properties.Clear; 442 Proxy.Properties.Add('CustomType', IntToStr(CustomTypeId)); 443 Proxy.Properties.Add('MaxLength', IntToStr(MaxLength)); 444 Proxy.Properties.Add('Default', Default); 445 Proxy.Save; 458 446 //CustomTypeId := Database.LastInsertId; 459 447 460 448 Result := AddProperty(ObjectId, Name, ColumnName, CustomTypeId, Editable); 461 449 finally 462 Data.Free; 463 DbRows.Free; 450 Proxy.Free; 464 451 end; 465 452 end; … … 468 455 ColumnName: string; Editable: Boolean; Default: string): Integer; 469 456 var 470 DbRows: TDbRows; 471 Data: TDictionaryStringString; 457 Proxy: TObjectProxy; 472 458 CustomTypeId: Integer; 473 459 begin 474 460 try 475 DbRows := TDbRows.Create;476 Data := TDictionaryStringString.Create;477 478 Data.Clear;479 Data.Add('Type', IntToStr(Integer(vtText)));480 Database.Insert(CustomTypeTableName, Data);481 CustomTypeId := Database.LastInsertId; 482 483 Data.Clear;484 Data.Add('CustomType', IntToStr(CustomTypeId));485 Data.Add('Default', Default);486 Database.Insert(TypeString, Data);461 Proxy := TObjectProxy.Create; 462 Proxy.Client := Client; 463 Proxy.ObjectName := CustomTypeTableName; 464 Proxy.Properties.Add('Type', IntToStr(Integer(vtText))); 465 Proxy.Save; 466 CustomTypeId := Proxy.Id; 467 468 Proxy.ObjectName := TypeString; 469 Proxy.Properties.Clear; 470 Proxy.Properties.Add('CustomType', IntToStr(CustomTypeId)); 471 Proxy.Properties.Add('Default', Default); 472 Proxy.Save; 487 473 //CustomTypeId := Database.LastInsertId; 488 474 489 475 Result := AddProperty(ObjectId, Name, ColumnName, CustomTypeId, Editable); 490 476 finally 491 Data.Free; 492 DbRows.Free; 477 Proxy.Free; 493 478 end; 494 479 end; … … 497 482 ColumnName: string; Editable: Boolean; ReferedObject: Integer): Integer; 498 483 var 499 DbRows: TDbRows; 500 Data: TDictionaryStringString; 484 Proxy: TObjectProxy; 501 485 CustomTypeId: Integer; 502 486 begin 503 487 try 504 DbRows := TDbRows.Create;505 Data := TDictionaryStringString.Create;506 507 Data.Clear;508 Data.Add('Type', IntToStr(Integer(vtRelationOne)));509 Database.Insert(CustomTypeTableName, Data);510 CustomTypeId := Database.LastInsertId; 511 512 Data.Clear;513 Data.Add('CustomType', IntToStr(CustomTypeId));514 Data.Add('Object', IntToStr(ReferedObject));515 Database.Insert(TypeRelationOne, Data);488 Proxy := TObjectProxy.Create; 489 Proxy.Client := Client; 490 Proxy.ObjectName := CustomTypeTableName; 491 Proxy.Properties.Add('Type', IntToStr(Integer(vtRelationOne))); 492 Proxy.Save; 493 CustomTypeId := Proxy.Id; 494 495 Proxy.ObjectName := TypeRelationOne; 496 Proxy.Properties.Clear; 497 Proxy.Properties.Add('CustomType', IntToStr(CustomTypeId)); 498 Proxy.Properties.Add('Object', IntToStr(ReferedObject)); 499 Proxy.Save; 516 500 //CustomTypeId := Database.LastInsertId; 517 501 518 502 Result := AddProperty(ObjectId, Name, ColumnName, CustomTypeId, Editable); 519 503 finally 520 Data.Free; 521 DbRows.Free; 504 Proxy.Free; 522 505 end; 523 506 end; … … 526 509 ColumnName: string; Editable: Boolean; ReferedObjectProperty: Integer): Integer; 527 510 var 528 DbRows: TDbRows; 529 Data: TDictionaryStringString; 511 Proxy: TObjectProxy; 530 512 CustomTypeId: Integer; 531 513 begin 532 514 try 533 DbRows := TDbRows.Create; 534 Data := TDictionaryStringString.Create; 535 536 Data.Clear; 537 Data.Add('Type', IntToStr(Integer(vtRelationMany))); 538 Database.Insert(CustomTypeTableName, Data); 539 CustomTypeId := Database.LastInsertId; 540 541 Data.Clear; 542 Data.Add('CustomType', IntToStr(CustomTypeId)); 543 Data.Add('ObjectProperty', IntToStr(ReferedObjectProperty)); 544 Database.Insert(TypeRelationMany, Data); 515 Proxy := TObjectProxy.Create; 516 Proxy.Client := Client; 517 Proxy.ObjectName := CustomTypeTableName; 518 519 Proxy.Properties.Clear; 520 Proxy.Properties.Add('Type', IntToStr(Integer(vtRelationMany))); 521 Proxy.Save; 522 CustomTypeId := Proxy.Id; 523 524 Proxy.ObjectName := TypeRelationMany; 525 Proxy.Properties.Clear; 526 Proxy.Properties.Add('CustomType', IntToStr(CustomTypeId)); 527 Proxy.Properties.Add('ObjectProperty', IntToStr(ReferedObjectProperty)); 528 Proxy.Save; 545 529 //CustomTypeId := Database.LastInsertId; 546 530 547 531 Result := AddProperty(ObjectId, Name, ColumnName, CustomTypeId, Editable); 548 532 finally 549 Data.Free; 550 DbRows.Free; 533 Proxy.Free; 551 534 end; 552 535 end; … … 554 537 function TChronisBase.AddObjectGroup(Name: string): Integer; 555 538 var 556 DbRows: TDbRows; 557 Data: TDictionaryStringString; 558 begin 559 try 560 DbRows := TDbRows.Create; 561 Data := TDictionaryStringString.Create; 562 Data.Add('Name', Name); 563 Database.Insert(ObjectGroupTable, Data); 564 Result := Database.LastInsertId; 565 finally 566 Data.Free; 567 DbRows.Free; 539 Proxy: TObjectProxy; 540 begin 541 try 542 Proxy := TObjectProxy.Create; 543 Proxy.Client := Client; 544 Proxy.ObjectName := ObjectGroupTable; 545 Proxy.Properties.Add('Name', Name); 546 Proxy.Save; 547 Result := Proxy.Id; 548 finally 549 Proxy.Free; 568 550 end; 569 551 end; … … 571 553 function TChronisBase.AddEnumeration(Name: string): Integer; 572 554 var 573 DbRows: TDbRows; 574 Data: TDictionaryStringString; 575 begin 576 try 577 DbRows := TDbRows.Create; 578 Data := TDictionaryStringString.Create; 579 Data.Add('Name', Name); 580 Database.Insert(Enumeration, Data); 581 Result := Database.LastInsertId; 582 finally 583 Data.Free; 584 DbRows.Free; 555 Proxy: TObjectProxy; 556 begin 557 try 558 Proxy := TObjectProxy.Create; 559 Proxy.Client := Client; 560 Proxy.ObjectName := Enumeration; 561 Proxy.Properties.Add('Name', Name); 562 Proxy.Save; 563 Result := Proxy.Id; 564 finally 565 Proxy.Free; 585 566 end; 586 567 end; … … 589 570 ): Integer; 590 571 var 591 DbRows: TDbRows; 592 Data: TDictionaryStringString; 593 begin 594 try 595 DbRows := TDbRows.Create; 596 Data := TDictionaryStringString.Create; 597 Data.Add('Enumeration', IntToStr(Enum)); 598 Data.Add('Name', Name); 599 Database.Insert(EnumerationState, Data); 600 Result := Database.LastInsertId; 601 finally 602 Data.Free; 603 DbRows.Free; 572 Proxy: TObjectProxy; 573 begin 574 try 575 Proxy := TObjectProxy.Create; 576 Proxy.Client := Client; 577 Proxy.ObjectName := EnumerationState; 578 Proxy.Properties.Add('Enumeration', IntToStr(Enum)); 579 Proxy.Properties.Add('Name', Name); 580 Proxy.Save; 581 Result := Proxy.Id; 582 finally 583 Proxy.Free; 604 584 end; 605 585 end; … … 608 588 License: string): Integer; 609 589 var 610 DbRows: TDbRows; 611 Data: TDictionaryStringString; 612 begin 613 try 614 DbRows := TDbRows.Create; 615 Data := TDictionaryStringString.Create; 616 Data.Add('Name', Name); 617 Data.Add('Author', Author); 618 Data.Add('Website', Website); 619 Data.Add('Version', Version); 620 Data.Add('Description', Description); 621 Data.Add('License', License); 622 Database.Insert(ModuleTable, Data); 623 Result := Database.LastInsertId; 624 finally 625 Data.Free; 626 DbRows.Free; 590 Proxy: TObjectProxy; 591 begin 592 try 593 Proxy := TObjectProxy.Create; 594 Proxy.Client := Client; 595 Proxy.ObjectName := ModuleTable; 596 Proxy.Properties.Add('Name', Name); 597 Proxy.Properties.Add('Author', Author); 598 Proxy.Properties.Add('Website', Website); 599 Proxy.Properties.Add('Version', Version); 600 Proxy.Properties.Add('Description', Description); 601 Proxy.Properties.Add('License', License); 602 Proxy.Save; 603 Result := Proxy.Id; 604 finally 605 Proxy.Free; 627 606 end; 628 607 end; … … 630 609 procedure TChronisBase.LoadTypes; 631 610 var 632 DbRows: TDbRows;611 Proxy: TListProxy; 633 612 I: Integer; 634 613 begin 635 614 try 636 DbRows := TDbRows.Create; 615 Proxy := TListProxy.Create; 616 Proxy.Client := Client; 617 Proxy.ObjectName := PropertyTypeTable; 618 Proxy.Load; 637 619 Types.Clear; 638 Database.Select(DbRows, PropertyTypeTable); 639 for I := 0 to DbRows.Count - 1 do begin 620 for I := 0 to Proxy.Objects.Count - 1 do begin 640 621 with TChronisType(Types.AddNew(TChronisType.Create)) do 641 with DbRows[I]do begin642 Id := StrToInt( Values['Id']);643 DbType := Values['DbType'];644 //Parent := StrToInt( Values['Parent']);622 with TObjectProxy(Proxy.Objects[I]) do begin 623 Id := StrToInt(Properties.Values['Id']); 624 DbType := Properties.Values['DbType']; 625 //Parent := StrToInt(Properties.Values['Parent']); 645 626 end; 646 627 end; 647 628 finally 648 DbRows.Free;629 Proxy.Free; 649 630 end; 650 631 end; … … 652 633 function TChronisBase.IsDatabaseEmpty: Boolean; 653 634 var 654 DbRows: TDbRows; 655 begin 656 try 657 DbRows := TDbRows.Create; 658 Database.Query(DbRows, 'SELECT 1 FROM information_schema.tables WHERE table_name = "Information" AND table_schema = "' + 659 Database.Database + '"'); 660 Result := DbRows.Count = 0; 661 finally 662 DbRows.Free; 635 Proxy: TListProxy; 636 begin 637 try 638 Proxy := TListProxy.Create; 639 Proxy.Client := Client; 640 Proxy.SchemaName := 'information_schema'; 641 Proxy.ObjectName := 'tables'; 642 Proxy.Condition := 'table_name = "Information" AND table_schema = "' + 643 Client.Schema + '"'; 644 Proxy.Load; 645 Result := Proxy.Objects.Count = 0; 646 finally 647 Proxy.Free; 663 648 end; 664 649 end; … … 718 703 List.Client := Core.System.Client; 719 704 List.ObjectName := ObjectTable; 720 List.SchemaName := Core.System. Database.Database;721 List. SetCondition('Id', IntToStr(ObjectId));705 List.SchemaName := Core.System.Client.Schema; 706 List.Condition := 'Id=' + IntToStr(ObjectId); 722 707 List.Load; 723 708 if List.Objects.Count = 1 then begin
Note:
See TracChangeset
for help on using the changeset viewer.