Changeset 20 for trunk/DbEngines
- Timestamp:
- Mar 23, 2018, 1:59:25 PM (7 years ago)
- Location:
- trunk/DbEngines
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DbEngines/UEngineMySQL.pas
r15 r20 12 12 { TDatabaseMySQL } 13 13 14 TDatabaseMySQL = class(TD atabaseClient)14 TDatabaseMySQL = class(TDbClient) 15 15 private 16 16 procedure LoadFields(Table: TTable); 17 procedure LoadTables; 17 protected 18 procedure LoadTables(Tables: TTables); override; 18 19 public 19 20 SqlDatabase: TSqlDatabase; … … 25 26 end; 26 27 28 { TDbConnectParamsMySQL } 29 30 TDbConnectParamsMySQL = class(TDbConnectParams) 31 protected 32 function GetConnectionString: string; override; 33 procedure SetConnectionString(AValue: string); override; 34 public 35 Host: string; 36 Port: Word; 37 end; 38 39 27 40 implementation 41 42 { TDbConnectParamsMySQL } 43 44 function TDbConnectParamsMySQL.GetConnectionString: string; 45 begin 46 Result := 'mysql://' + Host + ':' + IntToStr(Port); 47 end; 48 49 procedure TDbConnectParamsMySQL.SetConnectionString(AValue: string); 50 var 51 URL: TURL; 52 begin 53 URL := TURL.Create; 54 try 55 URL.AsString := AValue; 56 if (URL.Scheme <> 'mysql') and (AValue <> '') then 57 raise Exception.Create('Wrong connection string. Required mysql scheme.'); 58 Host := URL.Host.AsString; 59 Port := URL.Port; 60 finally 61 URL.Free; 62 end; 63 end; 28 64 29 65 { TDatabaseMySQL } … … 51 87 if DbRows2.Count > 0 then begin 52 88 TypeName := TDictionaryStringString(DbRows2[0]).Values['Name']; 53 NewField.DataType := Table.D atabase.Engine.DataTypes.FindByName(TypeName);89 NewField.DataType := Table.DbClient.ClientType.DataTypes.FindByName(TypeName); 54 90 if not Assigned(NewField.DataType) then 55 NewField.DataType := Table.D atabase.Engine.DataTypes.FindByType(ftString);91 NewField.DataType := Table.DbClient.ClientType.DataTypes.FindByType(ftString); 56 92 end else begin 57 93 // Use string as default 58 NewField.DataType := Table.D atabase.Engine.DataTypes.FindByType(ftString);94 NewField.DataType := Table.DbClient.ClientType.DataTypes.FindByType(ftString); 59 95 end; 60 96 Table.Fields.Add(NewField); … … 66 102 end; 67 103 68 procedure TDatabaseMySQL.LoadTables ;104 procedure TDatabaseMySQL.LoadTables(Tables: TTables); 69 105 var 70 106 DbRows: TDbRows; … … 78 114 NewTable := TTable.Create; 79 115 NewTable.Id := StrToInt(TDictionaryStringString(DbRows[I]).Values['Id']); 80 NewTable.D atabase := Database;116 NewTable.DbClient := Self; 81 117 NewTable.Name := TDictionaryStringString(DbRows[I]).Values['Name']; 82 118 NewTable.Caption := TDictionaryStringString(DbRows[I]).Values['Title']; 83 119 LoadFields(NewTable); 84 Database.Tables.Add(NewTable);120 Tables.Add(NewTable); 85 121 end; 86 122 finally … … 112 148 URL := TURL.Create; 113 149 try 114 URL.AsString := Database.ConnectionString;150 URL.AsString := ConnectProfile.Params.ConnectionString; 115 151 if URL.Scheme <> 'mysql' then 116 152 raise Exception.Create('Wrong connection string. Required mysql protocol.'); … … 124 160 SqlDatabase.Database := Copy(URL.Path, 2, High(Integer)); 125 161 SqlDatabase.Connect; 126 LoadTables;127 162 finally 128 163 URL.Free; -
trunk/DbEngines/UEngineSQLite.pas
r7 r20 9 9 10 10 type 11 TDatabaseSQLite = class(TD atabaseClient)11 TDatabaseSQLite = class(TDbClient) 12 12 13 13 end; 14 15 TDbConnectParamsSQLite = class(TDbConnectParams) 16 17 end; 18 14 19 15 20 implementation -
trunk/DbEngines/UEngineXML.pas
r17 r20 12 12 { TDatabaseXML } 13 13 14 TDatabaseXML = class(TD atabaseClient)14 TDatabaseXML = class(TDbClient) 15 15 private 16 function GetFileName: string; 16 FFileName: string; 17 Tables: TTables; 17 18 procedure LoadNodeRecord(Row: TRecord; Node: TDOMNode); 18 19 procedure SaveNodeRecord(Row: TRecord; Node: TDOMNode); … … 30 31 procedure SaveToFile(FileName: string); 31 32 function GetNextPart(var Text: string): string; 33 protected 32 34 public 33 35 procedure Query(DbRows: TDbRows; Text: string); override; 36 procedure LoadTables(Tables: TTables); override; 34 37 procedure Load; override; 35 38 procedure Save; override; 36 property FileName: string read GetFileName; 39 constructor Create; override; 40 destructor Destroy; override; 41 property FileName: string read FFileName write FFileName; 42 end; 43 44 { TDbConnectParamsXml } 45 46 TDbConnectParamsXml = class(TDbConnectParams) 47 protected 48 function GetConnectionString: string; override; 49 procedure SetConnectionString(AValue: string); override; 50 public 51 FileName: string; 37 52 end; 38 53 … … 46 61 SWrongFileFormat = 'Wrong file format'; 47 62 48 { TDatabaseXML } 49 50 function TDatabaseXML.GetFileName: string; 63 { TDbConnectParamsXml } 64 65 function TDbConnectParamsXml.GetConnectionString: string; 66 begin 67 Result := 'file:///' + FileName; 68 end; 69 70 procedure TDbConnectParamsXml.SetConnectionString(AValue: string); 51 71 var 52 72 URL: TURL; … … 54 74 URL := TURL.Create; 55 75 try 56 URL.AsString := Database.ConnectionString;57 if URL.Scheme <> 'file'then76 URL.AsString := AValue; 77 if (URL.Scheme <> 'file') and (AValue <> '') then 58 78 raise Exception.Create('Wrong connection string. Required file scheme.'); 59 60 Result := URL.Path 79 FileName := Copy(URL.Path, 2, Length(URL.Path)); 61 80 finally 62 81 URL.Free; 63 82 end; 64 83 end; 84 85 { TDatabaseXML } 65 86 66 87 procedure TDatabaseXML.LoadNodeRecord(Row: TRecord; Node: TDOMNode); … … 137 158 begin 138 159 Field.Name := ReadString(Node, 'Name', ''); 139 Field.DataType := Field.Table.D atabase.Engine.DataTypes.FindByType(TFieldType(ReadInteger(Node, 'Type', 0)));160 Field.DataType := Field.Table.DbClient.ClientType.DataTypes.FindByType(TFieldType(ReadInteger(Node, 'Type', 0))); 140 161 Field.TextBefore := ReadString(Node, 'TextBefore', ''); 141 162 Field.TextAfter := ReadString(Node, 'TextAfter', ''); … … 219 240 while Assigned(Node2) and (Node2.NodeName = 'Table') do begin 220 241 NewTable := TTable.Create; 221 NewTable.D atabase := Tables.Database;242 NewTable.DbClient := Tables.DbClient; 222 243 LoadNodeTable(NewTable, Node2); 223 244 Tables.Add(NewTable); … … 252 273 NewNode := FindNode('Tables'); 253 274 if Assigned(NewNode) then 254 LoadNodeTables( Database.Tables, NewNode);275 LoadNodeTables(Tables, NewNode); 255 276 end; 256 277 finally … … 273 294 NewNode := OwnerDocument.CreateElement('Tables'); 274 295 AppendChild(NewNode); 275 SaveNodeTables( Database.Tables, NewNode);296 SaveNodeTables(Tables, NewNode); 276 297 end; 277 298 ForceDirectories(ExtractFileDir(FileName)); … … 310 331 TableName := GetNextPart(Text); 311 332 end else raise Exception.Create('No table specified with FROM'); 312 Table := Database.Tables.SearchByName(TableName);333 Table := Tables.SearchByName(TableName); 313 334 if Assigned(Table) then begin 314 335 DbRows.Count := 0; … … 330 351 end; 331 352 353 procedure TDatabaseXML.LoadTables(Tables: TTables); 354 begin 355 inherited; 356 357 end; 358 332 359 procedure TDatabaseXML.Load; 333 360 begin … … 341 368 end; 342 369 370 constructor TDatabaseXML.Create; 371 begin 372 Tables := TTables.Create; 373 inherited Create; 374 end; 375 376 destructor TDatabaseXML.Destroy; 377 begin 378 Tables.Free; 379 inherited Destroy; 380 end; 381 343 382 344 383 end.
Note:
See TracChangeset
for help on using the changeset viewer.