Changeset 43 for trunk/Application/Clients/UChronisClientMySQL.pas
- Timestamp:
- Mar 9, 2012, 1:09:52 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/Clients/UChronisClientMySQL.pas
r40 r43 14 14 TChronisClientMySQL = class(TChronisClient) 15 15 protected 16 procedure InitSystemTypes; override; 16 17 function GetConnected: Boolean; override; 17 18 public … … 23 24 procedure ListLoad(AList: TListProxy); override; 24 25 procedure ListSave(AList: TListProxy); override; 25 procedure DefineType(AType: TChronisType); override;26 procedure UndefineType(AType: TChronisType); override;26 procedure TypeDefine(AType: TChronisType); override; 27 procedure TypeUndefine(AType: TChronisType); override; 27 28 procedure Install; 28 29 procedure Uninstall; … … 35 36 implementation 36 37 38 39 resourcestring 40 SMissingBaseType = 'Missing base typ for %s'; 41 SUndefinedType = 'Undefinned type %s'; 42 43 37 44 { TChronisClientMySQL } 45 46 procedure TChronisClientMySQL.InitSystemTypes; 47 begin 48 inherited InitSystemTypes; 49 Types.AddType('Integer', 'int(11)'); 50 Types.AddType('String', 'varchar(255)'); 51 Types.AddType('RelationOne', 'int(11)'); 52 Types.AddType('Double', 'double'); 53 Types.AddType('DateTime', 'datetime'); 54 Types.AddType('Date', 'date'); 55 Types.AddType('Time', 'time'); 56 Types.AddType('Text', 'text'); 57 Types.AddType('Boolean', 'bool'); 58 end; 38 59 39 60 function TChronisClientMySQL.GetConnected: Boolean; … … 103 124 end; 104 125 105 procedure TChronisClientMySQL. DefineType(AType: TChronisType);126 procedure TChronisClientMySQL.TypeDefine(AType: TChronisType); 106 127 var 107 D ata: TDictionaryStringString;128 DbRows: TDbRows; 108 129 I: Integer; 130 Query: string; 131 RefType: TChronisType; 109 132 begin 110 133 try 111 Data := TDictionaryStringString.Create; 112 Data.Add('Name', AType.Name); 113 Database.Insert('Type', Data); 134 DbRows := TDbRows.Create; 135 Query := 'CREATE TABLE IF NOT EXISTS `' + AType.Name + '` ( ' + 136 '`Id` int(11) NOT NULL AUTO_INCREMENT,'; 137 for I := 0 to AType.Properties.Count - 1 do 138 with AType.Properties do begin 139 RefType := Types.SearchByName(Items[I].Value); 140 if not Assigned(RefType) then 141 raise Exception.Create(Format(SUndefinedType, [Items[I].Value])); 142 if RefType.DbType = '' then 143 raise Exception.Create(Format(SMissingBaseType, [RefType.Name])); 144 145 Query := Query + '`' + Items[I].Key + '` ' + RefType.DbType + ' NOT NULL,'; 146 end; 147 Query := Query + 'PRIMARY KEY (`Id`)' + 148 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'; 149 Database.Query(DbRows, Query); 114 150 finally 115 Data.Free; 116 end; 117 if AType is TChronisTypeRecord then begin 118 for I := 0 to TChronisTypeRecord(AType).Items.Count - 1 do 119 try 120 Data := TDictionaryStringString.Create; 121 Data.Add('Name', 122 TChronisTypeRecordItem(TChronisTypeRecord(AType).Items[I]).Name); 123 Data.Add('Type', IntToStr( 124 TChronisTypeRecordItem(TChronisTypeRecord(AType).Items[I]).ItemType.OID)); 125 Database.Insert('TypeRecordItem', Data); 126 finally 127 Data.Free; 128 end; 129 end; 130 end; 131 132 procedure TChronisClientMySQL.UndefineType(AType: TChronisType); 151 DbRows.Free; 152 end; 153 end; 154 155 procedure TChronisClientMySQL.TypeUndefine(AType: TChronisType); 133 156 begin 134 157 … … 156 179 constructor TChronisClientMySQL.Create; 157 180 begin 181 inherited; 158 182 Database := TSqlDatabase.Create(nil); 159 183 end;
Note:
See TracChangeset
for help on using the changeset viewer.