File: frasqldbfullrestschemaaditor.pp

package info (click to toggle)
lazarus 2.2.6%2Bdfsg2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 219,980 kB
  • sloc: pascal: 1,944,919; xml: 357,634; makefile: 270,608; cpp: 57,115; sh: 3,249; java: 609; perl: 297; sql: 222; ansic: 137
file content (173 lines) | stat: -rw-r--r-- 4,727 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
unit frasqldbfullrestschemaaditor;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, ExtCtrls, PropertyStorage, fraconnections, sqldb, sqldbrestschema, sqldbschemaedittools,
  fraSQLDBRestSchemaEditor, sqldbrestbridge;

type

  { TSchemaEditorFrame }

  TSchemaEditorFrame = class(TFrame)
    fraConn: TfraConnections;
    splConnection: TSplitter;
    fraSchema: TSQLDBRestSchemaEditorFrame;
  private
    FOnSchemaChanged: TNotifyEvent;
    procedure DoImportSchema(Sender: TObject);
    procedure DoSchemaChanged(Sender: TObject);
    function GetConnections: TSQLDBRestConnectionList;
    function GetConnectionsFileName: String;
    function GetConnectionsModified: Boolean;
    function GetModified: Boolean;
    function GetSchema: TSQLDBRestSchema;
    procedure SetConnections(AValue: TSQLDBRestConnectionList);
    procedure SetSchema(AValue: TSQLDBRestSchema);
  public
     Constructor Create(aOwner : TComponent);override;
     Procedure ClearSchema;
     Function CheckSave : Boolean;
     Procedure LoadSchema(Const aFileName : String);
     Procedure SaveSchema(Const aFileName : String);
     Procedure LoadConnections(Const aFileName : String);
     Procedure SaveConnections(Const aFileName : String);
     Procedure LoadSession(aStorage : TCustomPropertyStorage);
     Procedure SaveSession(aStorage : TCustomPropertyStorage);
     Property ConnectionsFileName : String Read GetConnectionsFileName;
     Property SchemaModified : Boolean Read GetModified;
     Property ConnectionsModified : Boolean Read GetConnectionsModified;
     Property OnSchemaChanged : TNotifyEvent Read FOnSchemaChanged Write FOnSchemaChanged;
     Property Schema : TSQLDBRestSchema Read GetSchema Write SetSchema;
     Property Connections : TSQLDBRestConnectionList Read GetConnections Write SetConnections;
  end;

implementation

uses dlgrestfieldoptions;

{$R *.lfm}

{ TSchemaEditorFrame }

procedure TSchemaEditorFrame.DoImportSchema(Sender: TObject);

Var
  RFO : TRestFieldOptions;
  Conn : TSQLConnection;

begin
  Conn:=(Sender as TMySQLDBRestConnection).MyConnection;
  RFO:=fraSchema.ImportOpts;
  if GetRestFieldOptions(RFO) then
    FraSchema.Schema.PopulateResources(Conn,Nil,RFO);
end;

procedure TSchemaEditorFrame.DoSchemaChanged(Sender: TObject);
begin
  if Assigned(FOnSchemaChanged) then
    FOnSchemaChanged(Sender);
end;

function TSchemaEditorFrame.GetConnections: TSQLDBRestConnectionList;
begin
  Result:=fraConn.Connections;
end;

function TSchemaEditorFrame.GetConnectionsFileName: String;
begin
  Result:=fraConn.FileName;
end;

function TSchemaEditorFrame.GetConnectionsModified: Boolean;
begin
  Result:=fraConn.Modified
end;

function TSchemaEditorFrame.GetModified: Boolean;
begin
  Result:=fraSchema.Modified;
end;

function TSchemaEditorFrame.GetSchema: TSQLDBRestSchema;
begin
  Result:=fraSchema.Schema;
end;

procedure TSchemaEditorFrame.SetConnections(AValue: TSQLDBRestConnectionList);
begin
  FraConn.Connections:=aValue;
end;

procedure TSchemaEditorFrame.SetSchema(AValue: TSQLDBRestSchema);
begin
  if Assigned(aValue) then
    begin
    Schema.Name:=aValue.Name;
    Schema.Resources.Assign(aValue.Resources);
    fraSchema.ShowResources;
    end;
end;


constructor TSchemaEditorFrame.Create(aOwner: TComponent);
begin
  inherited Create(aOwner);
  fraConn.OnImportSchema:=@DoImportSchema;
  fraSchema.ConnectionPane:=fraConn;
  fraSchema.Connections:=fraConn.Connections;
  fraSchema.OnChanged:=@DoSchemaChanged;
end;

procedure TSchemaEditorFrame.ClearSchema;
begin
  FraSchema.ClearSchema;
end;

function TSchemaEditorFrame.CheckSave: Boolean;
begin
  Result:=FraSchema.CheckSave;
end;

procedure TSchemaEditorFrame.LoadSchema(const aFileName: String);
begin
  fraSchema.LoadFromFile(aFileName);
end;

procedure TSchemaEditorFrame.SaveSchema(const aFileName: String);
begin
  fraSchema.SaveToFile(aFileName);
end;

procedure TSchemaEditorFrame.LoadConnections(const aFileName: String);
begin
  fraConn.LoadConnections(aFileName);
end;

procedure TSchemaEditorFrame.SaveConnections(const aFileName: String);
begin
  fraConn.SaveConnections(aFileName);
end;

procedure TSchemaEditorFrame.LoadSession(aStorage: TCustomPropertyStorage);

begin
  fraConn.Width:=aStorage.ReadInteger('Connections_Width',fraConn.Width);
  fraConn.Visible:=aStorage.ReadBoolean('Connections_Visible',fraConn.Visible);
  fraConn.LoadSession(aStorage);
  fraSchema.LoadSession(aStorage);
end;

procedure TSchemaEditorFrame.SaveSession(aStorage: TCustomPropertyStorage);
begin
  aStorage.WriteInteger('Connections_Width',fraConn.Width);
  aStorage.WriteBoolean('Connections_Visible',fraConn.Visible);
  fraConn.SaveSession(aStorage);
  fraSchema.SaveSession(aStorage);
end;

end.