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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
| ///////////////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2015 by Charta Software B.V. //
// All rights reserved //
// //
// Version: 1.7.0.83525 //
// Web site: https://pascal.chartasoftware.com/ //
// //
// This code and information are provided "as is" without warranty of //
// any kind. Dissemination of this information or reproduction of //
// this material is strictly forbidden unless prior written permission //
// is obtained from Charta Software B.V.. //
// //
///////////////////////////////////////////////////////////////////////////
unit Sql.Statement.DataDefinition.Table.Create;
interface
uses
Boolean,
Collection.List,
Sql.Expression,
Sql.Statement.DataDefinition.Table,
Sql.Statement.ResultSet.Select,
Sql.Table.Column,
Sql.Table.Index,
Sql.Table.Physical,
Text;
type
TSqlCreateTableModifier = (ctmTemporary);
TSqlCreateTableModifiers = set of TSqlCreateTableModifier;
TSqlCreateTableSpecification = class(TSqlExpression)
public
function Copy(): TSqlExpression; override;
function CopyCreateTableSpecification(): TSqlCreateTableSpecification; virtual; abstract;
function ContainsStructuredColumn(): TBoolean; virtual; abstract;
end;
TSqlCreateColumn = class(TSqlCreateTableSpecification)
private
FColumn: TSqlTableColumn;
procedure SetColumn(const Value: TSqlTableColumn);
public
constructor Create(Column: TSqlTableColumn); reintroduce; virtual;
destructor Destroy(); override;
function CopyCreateTableSpecification(): TSqlCreateTableSpecification; override;
function CopyCreateColumn(): TSqlCreateColumn;
function ContainsStructuredColumn(): TBoolean; override;
property Column: TSqlTableColumn read FColumn write SetColumn;
end;
TSqlCreateKey = class(TSqlCreateTableSpecification)
public
Key: TSqlTableKey;
constructor Create(Key: TSqlTableKey); reintroduce; virtual;
function CopyCreateTableSpecification(): TSqlCreateTableSpecification; override;
function CopyCreateKey(): TSqlCreateKey;
function ContainsStructuredColumn(): TBoolean; override;
end;
TSqlCreateTable = class(TSqlTableDefinitionStatement)
private
FTable: TSqlPhysicalTable;
FModifiers: TSqlCreateTableModifiers;
FSpecifications: TList<TSqlCreateTableSpecification>;
FSelect: TSqlSelect;
procedure SetSelect(const Value: TSqlSelect);
function GetIdentifier(): TText;
public
constructor Create(Table: TSqlPhysicalTable; Modifiers: TSqlCreateTableModifiers = []); reintroduce; virtual;
destructor Destroy(); override;
function CopyTableDefinitionStatement(): TSqlTableDefinitionStatement; override;
function CopyCreateTable(): TSqlCreateTable;
property Table: TSqlPhysicalTable read FTable;
property Modifiers: TSqlCreateTableModifiers read FModifiers;
property Specifications: TList<TSqlCreateTableSpecification> read FSpecifications;
property Select: TSqlSelect read FSelect write SetSelect;
property Identifier: TText read GetIdentifier;
end;
implementation
uses
Object_.List,
Object_.Reference.Counter,
Type_.Structured;
{ TSqlCreateTable }
function TSqlCreateTable.CopyCreateTable(): TSqlCreateTable;
var
Specification: TSqlCreateTableSpecification;
begin
Result := TSqlCreateTable.Create(Table, Modifiers);
for Specification in Specifications do
Result.Specifications.Add(Specification.CopyCreateTableSpecification());
if Select <> nil then
Result.Select := Select.CopySelect();
end;
function TSqlCreateTable.CopyTableDefinitionStatement(): TSqlTableDefinitionStatement;
begin
Result := CopyCreateTable();
end;
constructor TSqlCreateTable.Create(Table: TSqlPhysicalTable; Modifiers: TSqlCreateTableModifiers = []);
begin
inherited Create();
FTable := Table;
FModifiers := Modifiers;
FSpecifications := TObjectList<TSqlCreateTableSpecification>.Create();
FSpecifications.ElementManager := TReferenceCounter<TSqlCreateTableSpecification>.Create();
end;
destructor TSqlCreateTable.Destroy();
begin
Specifications.Free();
Select.ReleaseReference();
inherited Destroy();
end;
function TSqlCreateTable.GetIdentifier(): TText;
begin
Result := Table.Identifier;
end;
procedure TSqlCreateTable.SetSelect(const Value: TSqlSelect);
begin
if Value <> Select then
begin
Value.AddReference();
Select.ReleaseReference();
FSelect := Value;
end;
end;
{ TSqlCreateTableSpecification }
function TSqlCreateTableSpecification.Copy(): TSqlExpression;
begin
Result := CopyCreateTableSpecification();
end;
{ TSqlCreateColumn }
function TSqlCreateColumn.ContainsStructuredColumn(): TBoolean;
begin
Result := Column.Type_.GetDecoratedType() is TStructuredType;
end;
function TSqlCreateColumn.CopyCreateColumn(): TSqlCreateColumn;
begin
Result := TSqlCreateColumn.Create(Column);
end;
function TSqlCreateColumn.CopyCreateTableSpecification(): TSqlCreateTableSpecification;
begin
Result := CopyCreateColumn();
end;
constructor TSqlCreateColumn.Create(Column: TSqlTableColumn);
begin
inherited Create();
Self.Column := Column;
end;
destructor TSqlCreateColumn.Destroy();
begin
Column.ReleaseReference();
inherited Destroy();
end;
procedure TSqlCreateColumn.SetColumn(const Value: TSqlTableColumn);
begin
if Value <> Column then
begin
Value.AddReference();
Column.ReleaseReference();
FColumn := Value;
end;
end;
{ TSqlCreateKey }
function TSqlCreateKey.ContainsStructuredColumn(): TBoolean;
var
Columns: TList<TSqlTableColumn>;
begin
Columns := Key.GetTableColumns();
Result := Columns.Contains(TSqlTableColumn.TIsStructured.Create());
Columns.Free();
end;
function TSqlCreateKey.CopyCreateKey(): TSqlCreateKey;
begin
Result := TSqlCreateKey.Create(Key);
end;
function TSqlCreateKey.CopyCreateTableSpecification(): TSqlCreateTableSpecification;
begin
Result := CopyCreateKey();
end;
constructor TSqlCreateKey.Create(Key: TSqlTableKey);
begin
inherited Create();
Self.Key := Key;
end;
end.
|