Changeset 21
- Timestamp:
- Mar 23, 2018, 3:06:47 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DbEngines/UEngineMySQL.pas
r20 r21 19 19 public 20 20 SqlDatabase: TSqlDatabase; 21 procedure Query( DbRows: TDbRows; Text: string); override;21 procedure Query(Text: string; DbRows: TDbRows = nil); override; 22 22 constructor Create; override; 23 23 destructor Destroy; override; … … 87 87 if DbRows2.Count > 0 then begin 88 88 TypeName := TDictionaryStringString(DbRows2[0]).Values['Name']; 89 NewField.DataType := Table.DbClient.ClientType.DataTypes. FindByName(TypeName);89 NewField.DataType := Table.DbClient.ClientType.DataTypes.SearchByName(TypeName); 90 90 if not Assigned(NewField.DataType) then 91 NewField.DataType := Table.DbClient.ClientType.DataTypes. FindByType(ftString);91 NewField.DataType := Table.DbClient.ClientType.DataTypes.SearchByType(ftString); 92 92 end else begin 93 93 // Use string as default 94 NewField.DataType := Table.DbClient.ClientType.DataTypes. FindByType(ftString);94 NewField.DataType := Table.DbClient.ClientType.DataTypes.SearchByType(ftString); 95 95 end; 96 96 Table.Fields.Add(NewField); … … 125 125 end; 126 126 127 procedure TDatabaseMySQL.Query( DbRows: TDbRows; Text: string);127 procedure TDatabaseMySQL.Query(Text: string; DbRows: TDbRows = nil); 128 128 begin 129 129 SqlDatabase.Query(DbRows, Text); -
trunk/DbEngines/UEngineXML.pas
r20 r21 30 30 procedure LoadFromFile(FileName: string); 31 31 procedure SaveToFile(FileName: string); 32 function GetNextPart(var Text: string ): string;32 function GetNextPart(var Text: string; Separator: string = ' '): string; 33 33 protected 34 34 public 35 procedure Query( DbRows: TDbRows; Text: string); override;35 procedure Query(Text: string; DbRows: TDbRows = nil); override; 36 36 procedure LoadTables(Tables: TTables); override; 37 37 procedure Load; override; … … 158 158 begin 159 159 Field.Name := ReadString(Node, 'Name', ''); 160 Field.DataType := Field.Table.DbClient.ClientType.DataTypes. FindByType(TFieldType(ReadInteger(Node, 'Type', 0)));160 Field.DataType := Field.Table.DbClient.ClientType.DataTypes.SearchByType(TFieldType(ReadInteger(Node, 'Type', 0))); 161 161 Field.TextBefore := ReadString(Node, 'TextBefore', ''); 162 162 Field.TextAfter := ReadString(Node, 'TextAfter', ''); … … 296 296 SaveNodeTables(Tables, NewNode); 297 297 end; 298 ForceDirectories(ExtractFileDir(FileName)); 298 if Pos(DirectorySeparator, FileName) > 0 then 299 ForceDirectories(ExtractFileDir(FileName)); 299 300 WriteXMLFile(Doc, FileName); 300 301 finally … … 303 304 end; 304 305 305 function TDatabaseXML.GetNextPart(var Text: string ): string;306 begin 307 if Pos( ' ', Text) > 0 then begin308 Result := Trim(Copy(Text, 1, Pos( ' ', Text) - 1));309 Delete(Text, 1, Pos( ' ', Text));306 function TDatabaseXML.GetNextPart(var Text: string; Separator: string = ' '): string; 307 begin 308 if Pos(Separator, Text) > 0 then begin 309 Result := Trim(Copy(Text, 1, Pos(Separator, Text) - Length(Separator))); 310 Delete(Text, 1, Pos(Separator, Text)); 310 311 end else begin 311 312 Result := Text; … … 314 315 end; 315 316 316 procedure TDatabaseXML.Query( DbRows: TDbRows; Text: string);317 procedure TDatabaseXML.Query(Text: string; DbRows: TDbRows = nil); 317 318 var 318 319 Command: string; … … 348 349 end else raise Exception.Create('Unsupported columns ' + Columns + ' specification'); 349 350 end else raise Exception.Create('Table ' + TableName + ' not found.'); 350 end else raise Exception.Create('Unsupported SQL command ' + Command); 351 end else 352 if Command = 'CREATE' then begin 353 Command := GetNextPart(Text); 354 if Command = 'TABLE' then begin 355 TableName := GetNextPart(Text); 356 Table := TTable.Create; 357 Table.Name := TableName; 358 Table.DbClient := Self; 359 Tables.Add(Table);; 360 end else raise Exception.Create('TABLE keyword expected'); 361 end else 362 if Command = 'DROP' then begin 363 Command := GetNextPart(Text); 364 if Command = 'TABLE' then begin 365 TableName := GetNextPart(Text); 366 Table := Tables.SearchByName(TableName); 367 if Assigned(Table) then Tables.Remove(Table) 368 else raise Exception.Create('Table ' + TableName + ' not found'); 369 end else raise Exception.Create('TABLE keyword expected'); 370 end else 371 raise Exception.Create('Unsupported SQL command ' + Command); 351 372 end; 352 373 353 374 procedure TDatabaseXML.LoadTables(Tables: TTables); 354 375 begin 355 inherited; 356 376 Tables.Assign(Self.Tables); 357 377 end; 358 378 359 379 procedure TDatabaseXML.Load; 360 380 begin 381 FileName := TDbConnectParamsXml(ConnectProfile.Params).FileName; 361 382 if FileExists(FileName) then 362 383 LoadFromFile(FileName); -
trunk/Forms/UFormTables.lfm
r20 r21 10 10 OnActivate = FormActivate 11 11 OnClose = FormClose 12 OnCreate = FormCreate 13 OnDestroy = FormDestroy 12 14 OnShow = FormShow 13 15 LCLVersion = '1.8.0.6' -
trunk/Forms/UFormTables.pas
r20 r21 40 40 procedure FormActivate(Sender: TObject); 41 41 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 42 procedure FormCreate(Sender: TObject); 43 procedure FormDestroy(Sender: TObject); 42 44 procedure FormShow(Sender: TObject); 43 45 procedure ListView1Data(Sender: TObject; Item: TListItem); … … 45 47 Selected: Boolean); 46 48 private 49 FDbClient: TDbClient; 47 50 FTables: TTables; 48 procedure Set Tables(AValue: TTables);51 procedure SetDbClient(AValue: TDbClient); 49 52 public 50 property Tables: TTables read FTables write SetTables; 53 property DbClient: TDbClient read FDbClient write SetDbClient; 54 property Tables: TTables read FTables; 51 55 procedure UpdateInterface; 52 56 procedure ReloadList; … … 87 91 end; 88 92 89 procedure TFormTables.SetTables(AValue: TTables); 90 begin 91 if FTables = AValue then Exit; 92 FTables := AValue; 93 procedure TFormTables.SetDbClient(AValue: TDbClient); 94 begin 95 if FDbClient = AValue then Exit; 96 FDbClient := AValue; 97 FTables.DbClient := AValue; 93 98 ReloadList; 94 99 end; … … 114 119 if FormTable.ShowModal = mrOk then begin 115 120 FormTable.Save(NewTable); 116 Tables. Add(NewTable);121 Tables.DbClient.Query('CREATE TABLE ' + NewTable.Name + ' (ID INTEGER)'); 117 122 ReloadList; 118 123 end else NewTable.Free; … … 135 140 if MessageDlg(SRemoveTable, Format(SRemoveTableConfirm, [TTable(ListView1.Selected.Data).Name]), 136 141 mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin 137 Tables. Remove(ListView1.Selected.Data);142 Tables.DbClient.Query('DROP TABLE ' + TTable(ListView1.Selected.Data).Name); 138 143 ReloadList; 139 144 end; … … 201 206 procedure TFormTables.FormClose(Sender: TObject; var CloseAction: TCloseAction); 202 207 begin 203 //Tables.DbClient.Save; 208 end; 209 210 procedure TFormTables.FormCreate(Sender: TObject); 211 begin 212 FTables := TTables.Create; 213 end; 214 215 procedure TFormTables.FormDestroy(Sender: TObject); 216 begin 217 FTables.Free; 204 218 end; 205 219 … … 208 222 I: Integer; 209 223 begin 224 ReloadList; 210 225 for I := 0 to ToolBar1.ButtonCount - 1 do 211 226 ToolBar1.Buttons[I].Hint := ToolBar1.Buttons[I].Caption; … … 217 232 I: Integer; 218 233 begin 234 if Assigned(DbClient) then DbClient.LoadTables(Tables) 235 else Tables.Clear; 219 236 for I := 0 to Tables.Count - 1 do 220 237 TTable(Tables[I]).LoadRecordsCount; -
trunk/UCore.pas
r20 r21 87 87 88 88 procedure TCore.ADatabaseConnectExecute(Sender: TObject); 89 var90 NewClient: TDbClient;91 89 begin 92 90 if FormDatabases.ShowModal = mrOk then begin 93 91 DbClient := nil; 94 NewClient := FormDatabases.SelectedProfile.ClientType.DatabaseClientClass.Create; 95 NewClient.ConnectProfile := FormDatabases.SelectedProfile; 96 DbClient := NewClient; 92 DbClient := FormDatabases.SelectedProfile.GetClient; 97 93 end; 98 94 end; … … 134 130 DbClient.Load; 135 131 Preferences.LastDatabaseName := FDbClient.ConnectProfile.Name; 136 if not Assigned(FormTables.Tables) then 137 FormTables.Tables := TTables.Create; 138 DbClient.LoadTables(FormTables.Tables); 132 FormTables.DbClient := DbClient; 139 133 end; 140 134 UpdateInterface; … … 186 180 UpdateInterface; 187 181 if Preferences.RememberDatabase then begin 188 ConnectProfile := DbManager.ConnectProfiles.FindByName(Preferences.LastDatabaseName); 189 if Assigned(ConnectProfile) then 190 DbClient := ConnectProfile.ClientType.DatabaseClientClass.Create; 182 ConnectProfile := DbManager.ConnectProfiles.SearchByName(Preferences.LastDatabaseName); 183 if Assigned(ConnectProfile) then begin 184 DbClient := ConnectProfile.GetClient; 185 end; 191 186 end else ADatabaseConnect.Execute; 192 187 end; … … 196 191 begin 197 192 SaveConfig; 193 DbClient := nil; 198 194 end; 199 195 -
trunk/UDatabase.pas
r20 r21 143 143 Name: string; 144 144 Params: TDbConnectParams; 145 destructor Destroy; override; 146 function GetClient: TDbClient; 145 147 property ClientType: TDbClientType read FClientType write SetClientType; 146 148 end; … … 152 154 procedure LoadFromRegistry(Context: TRegistryContext); 153 155 procedure SaveToRegistry(Context: TRegistryContext); 154 function FindByName(Name: string): TDbConnectProfile;156 function SearchByName(Name: string): TDbConnectProfile; 155 157 end; 156 158 … … 170 172 function RegisterType(Id: Integer; Name, Title: string; 171 173 FieldType: TFieldType; FieldTypeClass: TFieldTypeSpecificClass): TDataType; 172 function FindByType(FieldType: TFieldType): TDataType;173 function FindByName(Name: string): TDataType;174 function SearchByType(FieldType: TFieldType): TDataType; 175 function SearchByName(Name: string): TDataType; 174 176 end; 175 177 … … 183 185 procedure SetConnectProfile(AValue: TDbConnectProfile); virtual; 184 186 public 185 procedure Query( DbRows: TDbRows; Text: string); virtual;187 procedure Query(Text: string; DbRows: TDbRows = nil); virtual; 186 188 procedure LoadTables(Tables: TTables); virtual; 187 189 constructor Create; virtual; … … 373 375 end; 374 376 375 function TDbConnectProfiles. FindByName(Name: string): TDbConnectProfile;377 function TDbConnectProfiles.SearchByName(Name: string): TDbConnectProfile; 376 378 var 377 379 I: Integer; … … 389 391 if FClientType = AValue then Exit; 390 392 if Assigned(FClientType) then begin 391 Params.Free;393 FreeAndNil(Params); 392 394 end; 393 395 FClientType := AValue; … … 395 397 Params := FClientType.ConnectParmasClass.Create; 396 398 end; 399 end; 400 401 destructor TDbConnectProfile.Destroy; 402 begin 403 ClientType := nil; 404 if Assigned(Params) then Params.Free; 405 inherited Destroy; 406 end; 407 408 function TDbConnectProfile.GetClient: TDbClient; 409 begin 410 Result := ClientType.DatabaseClientClass.Create; 411 Result.ConnectProfile := Self; 397 412 end; 398 413 … … 422 437 end; 423 438 424 procedure TDbClient.Query( DbRows: TDbRows; Text: string);439 procedure TDbClient.Query(Text: string; DbRows: TDbRows = nil); 425 440 begin 426 441 end; … … 482 497 end; 483 498 484 function TDataTypes. FindByType(FieldType: TFieldType): TDataType;499 function TDataTypes.SearchByType(FieldType: TFieldType): TDataType; 485 500 var 486 501 I: Integer; … … 492 507 end; 493 508 494 function TDataTypes. FindByName(Name: string): TDataType;509 function TDataTypes.SearchByName(Name: string): TDataType; 495 510 var 496 511 I: Integer; … … 510 525 DataTypes.Clear; 511 526 for I := Low(TFieldType) to High(TFieldType) do 512 if I in Types then DataTypes.Add(ADataTypes. FindByType(I));527 if I in Types then DataTypes.Add(ADataTypes.SearchByType(I)); 513 528 end; 514 529 … … 698 713 Records.Clear; 699 714 DbRows := TDbRows.Create; 700 DbClient.Query( DbRows, 'SELECT * FROM ' + Name);715 DbClient.Query('SELECT * FROM ' + Name, DbRows); 701 716 for I := 0 to DbRows.Count - 1 do begin 702 717 NewRecord := TRecord.Create; … … 723 738 Records.Clear; 724 739 DbRows := TDbRows.Create; 725 DbClient.Query( DbRows, 'SELECT COUNT(*) FROM ' + Name);740 DbClient.Query('SELECT COUNT(*) FROM ' + Name, DbRows); 726 741 if DbRows.Count = 1 then begin 727 742 RecordsCount := StrToInt(TDictionaryStringString(DbRows[0]).Items[0].Value);
Note:
See TracChangeset
for help on using the changeset viewer.