-
Notifications
You must be signed in to change notification settings - Fork 1
/
Netezza.fet
1527 lines (1435 loc) · 45.7 KB
/
Netezza.fet
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
SPItemBegin [keep format] = Alter Attribute
/* DESCRIPTION: Alter an attribute during alter script generation. */
/* Assumes the context object is an attribute. */
/* Context Object is Attribute */
[
@if( IsModified )
{
PushTopLevelObject
[
[
[ Execute( "Generate " ObjectType ) ]
]
]
Pop
}
]
SPItemEnd
SPItemBegin [keep format] = Alter Check_Constraint_Usage
[ /* No Operation*/ ]
SPItemEnd
SPItemBegin [keep format] = Alter Default
/* DESCRIPTION: Alter a Default during alter script generation. */
/* Assumes the context object is a Default. */
[
/* For each referring oDefaultConstraintUsage object */
/* drop and recreate the entire table. */
ForEachReference( "Dependent_Objects_Ref" )
{
[
Execute("Alter Default_Constraint_Usage")
]
}
]
SPItemEnd
SPItemBegin [keep format] = Alter Default_Constraint_Usage
[ /* No Operation*/ ]
SPItemEnd
SPItemBegin [keep format] = Alter Entity
/* DESCRIPTION: Alter an entity during alter script generation. */
/* Assumes the context object is an entity. */
/* Process the (EMXTypes::pPhysicalOrderList) property of the Entity. */
[
IsPropertyModified("Physical_Columns_Order_Ref")
[
FE::Option("ColumnPhysicalOrder")
[
IsPropertyReordered("Physical_Columns_Order_Ref", "existing_only")
[
Execute("Generate Entity")
]
]
]
]
/* Process the (EMXTypes::pColumnOrderList) property of the Entity. */
[
IsPropertyModified("Columns_Order_Ref")
[
FE::Option("!ColumnPhysicalOrder")
IsPropertyReordered("Columns_Order_Ref", "existing_only")
[
Execute("Generate Entity")
]
]
]
[
/* Is any property other than the Physical Order List,Column Order List or Attribute Order List above was modified? */
@if(IsModified( "Physical_Columns_Order_Ref", "Columns_Order_Ref","Attributes_Order_Ref") )
{
Execute("Generate Entity")
}
]
SPItemEnd
SPItemBegin [keep format] = Alter Generic Create Object
/* DESCRIPTION: Create an object during alter script generation. */
/* The context can be any model object like entity, attribute etc. */
[
[
Execute( "Create " ObjectType )
SetLocalFlag( "Template Found" )
]
@ifnot ( IsLocalFlagSet ( "Template Found" ) )
{
PushTopLevelObject
@if ( IsCreated )
{
Execute( "Create " ObjectType )
}
@else
{
Execute( "Generate " ObjectType )
}
Pop
}
@else
{
ClearLocalFlag( "Template Found" )
}
]
SPItemEnd
SPItemBegin [keep format] = Alter Generic Drop Object
/* DESCRIPTION: Drop an object during alter script generation. */
/* The context can be any model object like entity, attribute etc. */
[
[
Execute( "Drop " ObjectType )
SetLocalFlag( "Template Found" )
]
@ifnot ( IsLocalFlagSet( "Template Found" ) )
{
PushTopLevelObject
@if ( IsDeleted )
{
Execute( "Drop " ObjectType )
}
@else
{
Execute( "Generate " ObjectType )
}
Pop
}
@else
{
ClearLocalFlag( "Template Found" )
}
]
SPItemEnd
SPItemBegin [keep format] = Alter Generic Modify Object
/* DESCRIPTION: Modify an object during alter script generation. */
/* The context can be any model object like entity, attribute etc. */
[
[
Execute( "Alter " ObjectType )
SetLocalFlag( "Template Found" )
]
@ifnot( IsLocalFlagSet( "Template Found" ) )
{
PushTopLevelObject
[ Execute( "Generate " ObjectType ) ]
Pop
}
@else
{
ClearLocalFlag( "Template Found" )
}
]
SPItemEnd
SPItemBegin [keep format] = Alter Key_Group
/* DESCRIPTION: Alter Index during alter scrpit generation. */
/* Assumes the context object is an key group. */
[
/* Is any other property other than Key Group Member Order List is modified */
@if( IsModified("Key_Group_Members_Order_Ref") )
{
Execute("Generate Key_Group")
}
]
SPItemEnd
SPItemBegin [keep format] = Alter Relationship
[ /* No Operation*/ ]
SPItemEnd
SPItemBegin [keep format] = Alter Table Check Constraint Usage
/* DESCRIPTION: Alter a Table Check Constraint Usage during alter script generation. */
Execute("Generate Table Check Constraint Usage")
SPItemEnd
SPItemBegin [keep format] = Alter Validation_Rule
/* DESCRIPTION: Alter a validation rule during alter script generation. */
/* Assumes the context object is a validation rule. */
[
/* For each referring oCheckConstraintUsage object. */
ForEachReference("Dependent_Objects_Ref")
{
[
/* Push an Entity Or an Attribute */
/* If It is an Attribute Execute Alter Check Constraint Usage */
/* If It is an Entity Execute Alter Table Check Constraint Usage */
PushOwner
Pop
@if( Equal(ObjectType,"Attribute") )
{
Execute("Alter Check_Constraint_Usage")
}
@else
{
@if( Equal(ObjectType,"Entity") )
{
Execute("Alter Table Check Constraint Usage")
}
}
]
}
]
SPItemEnd
SPItemBegin [keep format] = Clause: Define Column
/* For Displaying code For Creation Of Columns */
/* Columns. We have to check sort order as some user don't bother */
/* with physical order and always generate using column order. */
ListSeparator( ",\n" )
/* DESCRIPTION: Emit the column definition. */
/* Assumes the context object is a column.*/
"\t" Pad( QuotedName , 20 )
" " Property( "Physical_Data_Type" )
[" " EnumProperty( "Null_Option_Type" , "NULL" , "NOT NULL" ) ]
/* If generation of column defaults is turned on, emit it. */
[
FE::Option( "ColumnDefaultValue" )
ForEachOwnee( "Default_Constraint_Usage" )
{
PushReference( "Default_Ref" )
[
ShouldGenerate " DEFAULT "
FE::ExpandERwinMacro( "Server_Value" )
]
Pop
}
/* If generation of column check constraints is on, emit it. */
[
FE::Option( "ColumnCheckConstraint" )
[
" CONSTRAINT "
FE::Option( "ConstraintName" )
QuotedName
]
<ForEachOwnee( "Check_Constraint_Usage" )
{
[
/* Use a propagating block so that we fail the entire thing if either */
/* we can't retrieve the server value. */
PushReference("Validation_Rule_Ref")
[
ShouldGenerate
" CHECK ( "
FE::ExpandERwinMacro( "Server_Value" )
" )"
]
Pop
]
}>
]
]
Remove( "Column Order" )
SPItemEnd
SPItemBegin [keep format] = Clause: FKConstraint
/* DESCRIPTION: Emit the FK constraint clause. */
/* Assumes the context object is a key group. */
[
/* Generate it once */
OnceForObject( "Constraint" )
/* Are we naming the contraints? */
[ "CONSTRAINT "
FE::Option( "ConstraintName" )
/* Suppress default relationship names for subtypes. */
[
PushReference( "Relationship_Ref" )
[
<Equal( QuotedName, "is_a" )
[
PushReference( "Parent_Entity_Ref" )
[
Equal( ObjectType, "Subtype_Symbol" )
SetLocalFlag( "Suppress Constraint Name","2" )
]
Pop
]>
]
Pop
]
@ifnot( IsLocalFlagSet( "Suppress Constraint Name" ) )
{
QuotedNameThrough( "Relationship_Ref") " "
}
@else
{
ClearLocalFlag( "Suppress Constraint Name" )
}
/* Emit the key group type. */
"FOREIGN KEY "
]
/* Emit the index members. */
"("
ForEachFKColumn
{
ListSeparator( ", " )
QuotedName
}
")"
/* Emit the referenced table. */
" REFERENCES "
PushReference( "Relationship_Ref" )
PushReference( "Parent_Entity_Ref" )
Switch( ObjectType )
{
/* If the parent is an entity, just emit the name. */
Choose( "Entity" )
{
[ FE::OwnerOverride( "true" ) "." ] QuotedName " "
}
/* Subtypes, however, require a jump through the second relationship. */
Choose( "Subtype_Symbol" )
{
ForEachReference( "Child_Relationships_Ref" )
{
PushReference( "Parent_Entity_Ref" )
[ FE::OwnerOverride( "true" ) "." ] QuotedName
Pop
}
}
}
Pop
Pop
/* Emit the columns. */
"("
ForEachMigratingColumn
{
ListSeparator( ", " )
QuotedName
}
")"
[
PushReference("Relationship_Ref")
[
FE::Option("OnDeleteFKConstraint")
"\n\t\t"
"ON DELETE "
LookupProperty( "Parent_Delete_Rule",
"10005", "CASCADE")
]
Pop
]
]
SPItemEnd
SPItemBegin [keep format] = Clause: PKConstraint
/* DESCRIPTION: Emit the PK constraint clause. */
/* Assumes the context object is a key group. */
Equal( Left( Property( "Key_Group_Type" ), "2" ), "PK" )
/* Primary Index property indicates that the key group must be */
/* generated as PK index only. Make sure it is set to false. */
IsPropertyFalse( "Is_Primary_Index" )
/* Generate it once */
OnceForObject( "Constraint" )
"PRIMARY KEY "
"("
<
ForEachReference( "Index_Members_Order_Ref" )
{
ListSeparator( "," )
QuotedName
}
>
")"
SPItemEnd
SPItemBegin [keep format] = Create Attribute
/* DESCRIPTION: Alter table to add an attribute during alter script generation. */
/* Assumes the context object is an attribute. */
[
PushOwner
@if ( Equal( ObjectType, "Entity" ) )
{
Pop
/* Current context is an attribute. */
/* Determine if we can add column by altering table */
@if ( FE::Option( "AlterStatements" ) )
{
/* User requested alter statement. */
SetLocalFlag( "Use Alter To Add Column" )
}
@else
{
[
/* Make sure we are adding at the end. */
FE::IsLastColumn
@ifnot ( IsPropertyEqual( "Null_Option_Type", "1" ) )
{
/* The column null option is NULL. */
SetLocalFlag( "Use Alter To Add Column" )
}
@else
{
/* The column null option is NOT NULL, check if there is a default. */
[
ForEachOwnee( "Default_Constraint_Usage" ) /* there is only one */
{
SetLocalFlag( "Use Alter To Add Column","1" )
}
]
}
]
}
@if ( IsLocalFlagSet ( "Use Alter To Add Column" ) )
{
FE::Bucket( "85" )
PushOwner
FE::RecordAlter
"ALTER TABLE " [ FE::OwnerOverride( "true" ) "." ] QuotedName
Pop
" (ADD " QuotedName " " Property( "Physical_Data_Type") ")"
FE::EndOfStatement
ClearLocalFlag( "Use Alter To Add Column" )
}
@else
{
/* We have to recreate the entity. */
PushOwner
[ Execute( "Generate Entity" ) ]
Pop
}
}
@elseif ( Equal( ObjectType, "View" ) )
{
/* It's a view attibute, recreate the view. */
Pop
PushTopLevelObject
Execute( "Generate " ObjectType )
Pop
}
@else
{
Pop
}
]
SPItemEnd
SPItemBegin [keep format] = Create Check_Constraint_Usage
[ /* No Operation*/ ]
SPItemEnd
SPItemBegin [keep format] = Create Default_Constraint_Usage
[ /* No Operation*/ ]
SPItemEnd
SPItemBegin [keep format] = Create Entity
/* DESCRIPTION: Create an entity during schema generation. */
/* Assumes the context object is an entity. */
[
ShouldGenerate
/* Make sure that Create Entity is executed only once. */
OnceForObject( "Create Entity" )
/* Is the "TablePreScript" option turned on? */
[
FE::Option( "TablePreScript" )
ForEachReference( "Script_Templates_Ref" )
{
[
ShouldGenerate
IsPropertyTrue( "Generate_As_Pre_Script" )
FE::Bucket( "90" )
FE::ExpandERwinMacro( "Template_Code" )
FE::EndOfStatement("true")
]
}
]
/* Is "CreateTable" option turned on? */
[
FE::Option( "CreateTable" )
/* We need to set this flag to indicate to the internal post process */
/* that the entity has been created. Post process uses this flag to */
/* determine whether alter statements have been superceded by this */
/* create statement. */
FE::RecordCreate
FE::Bucket( "90" )
"CREATE "
"TABLE "
[FE::OwnerOverride( "true" ) "." ]
QuotedName
"\n("
/* Columns. We have to check sort order as some user don't bother */
/* with physical order and always generate using column order. */
@if ( FE::Option( "ColumnPhysicalOrder" ) )
{
Set( "Column Order", "Physical_Columns_Order_Ref" )
}
@else
{
Set( "Column Order", "Columns_Order_Ref" )
}
"\n"
<ForEachReference( Value( "Column Order" ) )
{
< Execute("Clause: Define Column") >
}>
/* Are we generating PK constraints in the CREATE? */
[
FE::Option( "PKConstraintInCreate" )
ForEachOwnee( "Key_Group", "Physical_Name" )
{
[
Equal( Left( Property( "Key_Group_Type" ), "2" ), "PK" )
",\n\t" < Execute( "Clause: PKConstraint" ) >
]
}
]
/* Are we generating FKs in the CREATE? */
[
FE::Option( "FKConstraintInCreate" )
ForEachOwnee( "Key_Group", "Physical_Name" )
{
[
Equal( Left( Property( "Key_Group_Type" ), "2" ), "IF" )
",\n\t"
< Execute( "Clause: FKConstraint" ) >
]
}
]
/* Table level check constraints in create. */
[
FE::Option( "TableCheckConstraint" )
FE::Option("TableConstraintInCreate")
ForEachOwnee( "Check_Constraint_Usage" )
{
",\n\t"
<
[
"CONSTRAINT "
FE::Option( "ConstraintName" )
QuotedName " "
]
[
PushReference("Validation_Rule_Ref")
"CHECK "
"( " FE::ExpandERwinMacro( "Server_Value" ) " )"
Pop
]
>
}
]
"\n) distribute on "
Switch( Property("Entity.Physical.DistributionKey") )
{
Choose ("Random")
{
"RANDOM"
}
Choose ("random")
{
"RANDOM"
}
Default
{
"(" Property("Entity.Physical.DistributionKey") ")"
}
}
""
FE::EndOfStatement
]
/* Are we generating PKs in an ALTER? */
[
ForEachOwnee("Key_Group", "Physical_Name" )
{
[
Equal ( Left( Property( "Key_Group_Type" ), "2" ) , "PK" )
[
FE::Bucket("90")
Execute("Create Key_Group")
]
[
FE::Option("PKConstraintInAlter")
Equal( Left( Property( "Key_Group_Type" ), "2" ), "PK" )
FE::Bucket( "90" )
PushOwner
"ALTER TABLE " [ FE::OwnerOverride( "true" ) "." ] QuotedName
Pop
"\nADD "
< Execute( "Clause: PKConstraint" ) >
FE::EndOfStatement
]
]
}
]
/* Are we generating FKs in an ALTER? */
[
ForEachOwnee("Key_Group", "Physical_Name" )
{
[
Equal ( Left( Property( "Key_Group_Type" ), "2" ) , "IF" )
[
FE::Bucket("90")
Execute("Create Key_Group")
]
[
/* Are we generating FK constraints? */
FE::Option("FKConstraintInAlter")
Equal( Left( Property( "Key_Group_Type" ), "2" ), "IF" )
/* Check if the relationship is set to generate. */
SetLocalFlag( "FK Should Generate" )
PushReference( "Relationship_Ref" )
@if ( ShouldGenerate )
{
PushReference( "Parent_Entity_Ref" )
@ifnot ( FE::IsEntityInSubjectArea )
{
ClearLocalFlag( "FK Should Generate", "2" )
}
Pop
}
@else
{
ClearLocalFlag( ""FK Should Generate"", "1" )
}
Pop
@if ( IsLocalFlagSet( "FK Should Generate" ) )
{
FE::Bucket( "94" )
PushOwner
"ALTER TABLE " [ FE::OwnerOverride( "true" ) "." ] QuotedName
Pop
"\nADD "
< Execute( "Clause: FKConstraint" ) >
FE::EndOfStatement
}
]
]
}
]
/* Are We Generating AK Or IE indexes */
[
ForEachOwnee("Key_Group", "Physical_Name" )
{
[
NotEqual ( Left( Property( "Key_Group_Type" ), "2" ) , "PK" )
[
NotEqual ( Left( Property( "Key_Group_Type" ), "2" ) , "IF" )
[
FE::Bucket("90")
Execute("Create Key_Group")
]
]
]
}
]
/* Stored procedures. */
[
FE::Bucket("105")
ForEachReference("Stored_Procedures_Ref")
{
ShouldGenerate
Equal( Property( "Type" ), "Table Level" )
[
FE::Option("TableDropProcedure" )
Execute("Drop Stored_Procedure")
]
[
FE::Option("TableCreateProcedure" )
Execute("Create Stored_Procedure")
]
}
]
/* Table post script. */
[
FE::Option("TablePostScript")
ForEachReference( "Script_Templates_Ref" )
{
[
ShouldGenerate
IsPropertyFalse( "Generate_As_Pre_Script" )
FE::Bucket("90")
FE::ExpandERwinMacro( "Template_Code" )
FE::EndOfStatement("true")
]
}
]
]
SPItemEnd
SPItemBegin [keep format] = Create Key_Group
/* DESCRIPTION: Create an index during schema generation. */
/* Assumes the context object is a key group. */
[
/* Owner type is an entity. */
Set( "Owner Type", [ PushOwner ObjectType Pop ] )
[
ShouldGenerate
/* Make sure that the appropriate FE index option is selected. */
Set( "Key_Group_Type", Left( Property( "Key_Group_Type" ), "2" ) )
[
Equal( Value( "Owner Type" ), "Entity" )
[
Equal( Left( Property( "Key_Group_Type" ), "2" ), "PK" )
FE::Option("CreatePKIndex")
SetLocalFlag( "Should Generate" )
]
[
Equal( Left( Property( "Key_Group_Type" ), "2" ), "AK" )
FE::Option("CreateAKIndex")
SetLocalFlag( "Should Generate" )
]
[
Equal( Left( Property( "Key_Group_Type" ), "2" ), "IF" )
FE::Option("CreateFKIndex")
SetLocalFlag( "Should Generate" )
]
[
Equal( Left( Property( "Key_Group_Type" ), "2" ), "IE" )
FE::Option("CreateIEIndex")
SetLocalFlag( "Should Generate" )
]
]
Remove( "Key_Group_Type" )
Remove( "Owner Type" )
/* Check for duplicate indexes. */
@ifnot( Execute("Is Duplicate Index") )
{
Set( "Key Group Members", Execute( "Key Group Members" ) )
PushOwner
SetGlobalFlag( "IndexCreated" Value( "Key Group Members" )ObjectId )
Pop
Remove( "Key Group Members" )
}
@if ( IsLocalFlagSet( "Should Generate" ) )
{
OnceForObject( "Create Key_Group" )
FE::RecordCreate
FE::Bucket( "90" )
/* Regular indexes. */
"CREATE "
[ IsPropertyTrue( "Is_Unique" ) "UNIQUE " ]
"INDEX " QuotedName " ON "
PushOwner
QuotedName
Pop
"\n(\n"
<ForEachReference( "Index_Members_Order_Ref" )
{
ListSeparator( "," )
"\t" < QuotedName >
}>
"\n)"
ClearLocalFlag( "Should Generate" )
FE::EndOfStatement
}
]
]
SPItemEnd
SPItemBegin [keep format] = Create Stored_Procedure
/* DESCRIPTION: Create Stored Procedure during schema generation. */
/* Assumes the context object is a Stored Procedure. */
[
FE::ExpandERwinMacro("Template_Code")
FE::EndOfStatement
]
SPItemEnd
SPItemBegin [keep format] = Create Table Check Constraint Usage
[ /* No Operation*/ ]
SPItemEnd
SPItemBegin [keep format] = Create View
/* DESCRIPTION: Create a view during schema generation. */
/* Assumes the context object is a view. */
[
ShouldGenerate
OnceForObject( "Create View" )
[
/* Check Whether PreScript Option is Turned On? */
FE::Option("ViewPreScript")
ForEachReference("Script_Templates_Ref")
{
[
ShouldGenerate
IsPropertyTrue( "Generate_As_Pre_Script" )
Bucket("90")
FE::ExpandERwinMacro("Template_Code")
FE::EndOfStatement("true")
]
}
]
[
/* Is "CreateView" option turned on? */
FE::Option( "CreateView" )
FE::RecordCreate
FE::Bucket( "90" )
@if ( IsPropertyNotNull( "User_Defined_SQL" ) )
{
/* User defined view. Emit the view SQL. */
Property( "User_Defined_SQL" )
FE::EndOfStatement
}
@else
{
/* Erwin generated view. */
[
"CREATE "
"VIEW "
[ FE::OwnerOverride( "true" ) "." ] QuotedName
/* View columns. */
" ( "
<
ForEachReference( "Physical_Columns_Order_Ref" )
{
ShouldGenerate
ListSeparator( "," )
QuotedName
}
>
" ) AS "
/* View select statement. */
"\n\tSELECT "
[ LookupProperty( "Select_Type", "2", " DISTINCT" ) ]
<
ForEachReference( "Physical_Columns_Order_Ref" )
{
ShouldGenerate
ListSeparator( "," )
[
PushReference( "Parent_Relationship_Ref" )
@if ( IsPropertyNotNull( "Alias_Name" ) )
{
Property( "Alias_Name" ) "."
}
@else
{
PushReference( "Parent_Entity_Ref" )
[
[ FE::OwnerOverride( "true" ) "." ]
QuotedName "."
]
Pop
}
Pop
PushReference( "Parent_Attribute_Ref" )
[
PushOwner
@if ( Equal( ObjectType, "Entity" ) )
{
/* Entity attribute. */
Pop
QuotedName
}
@else
{
/* View Attribute. */
Pop
QuotedName
}
]
Pop
]
[ Property( "View_Expression" ) ]
}
>
/* View select statement clauses. */
"\n\t\t" "FROM "
<
ForEachReference( "Child_Relationships_Ref" )
{
ShouldGenerate
ListSeparator( "," )
[
PushReference( "Parent_Entity_Ref" )
[
FE::OwnerOverride( "true" ) "."
]
QuotedName
Pop
]
[ " " Property( "Alias_Name" ) ]
}
>
[ "\n\t\t" "WHERE " Property( "Where_Clause" ) ]
[ "\n\t\t" "GROUP BY " Property( "Group_By_Clause") ]
[ "\n\t\t" "HAVING " Property( "Having_Clause" ) ]
[ Equal ( Property( "Restriction_Type", "no_translate" ), "1" ) "\n\t\tWITH CHECK OPTION" ]
[ "\n\t\t" "ORDER BY " Property( "Order_By_Clause" ) ]
FE::EndOfStatement
]
}
]
/* Stored procedures. */
[
ForEachReference( "Stored_Procedures_Ref" )
{
/* Make sure they should generate and that they are a table-level procedure. */
[
ShouldGenerate
Equal( Property( "Type" ), "Table Level" )
FE::Bucket( "105" )
[
FE::Option( "ViewDropStoredProcedure" )
Execute( "Drop Stored_Procedure" )
]
[
FE::Option( "ViewCreateStoredProcedure" )
Execute( "Create Stored_Procedure")
]
]
}
]
/* View post script. */
[ FE::Option("ViewPostScript")
ForEachReference( "Script_Templates_Ref" )
{
[
ShouldGenerate
IsPropertyFalse( "Generate_As_Pre_Script" )
FE::Bucket("90")
FE::ExpandERwinMacro( "Template_Code" )
FE::EndOfStatement("true")
]
}
]
/* During alter script generation, recreate dependent views. */
[
FE::IsAlterScriptGeneration
ForEachReference( "Parent_Relationships_Ref" )
{
PushReference( "Child_Entity_Ref" )
[
Equal( ObjectType, "View" )
@ifnot ( IsDeleted )
{
Execute( "Create View" )
}
]
Pop
}
]
]
SPItemEnd
SPItemBegin [keep format] = Drop Attribute
/* DESCRIPTION: Drop an attribute during schema generation. */
/* Assumes the context object is an attribute. */
[
PushOwner
@if( Equal( ObjectType, "Entity" ) )
{
Pop
SetGlobalFlag("Drop Attribute")
/* Current context is an attribute. */
FE::Bucket( "40" )
PushOwner
FE::RecordAlter
"ALTER TABLE " [ FE::OwnerOverride( "true" ) "." ] QuotedName
Pop
" DROP "
< Execute( "Previous Physical Name" ) >
FE::EndOfStatement
}
]
SPItemEnd
SPItemBegin = Drop Check_Constraint_Usage
[ /* No Operation*/ ]
SPItemEnd
SPItemBegin = Drop Default_Constraint_Usage
[ /* No Operation*/ ]
SPItemEnd
SPItemBegin [keep format] = Drop Entity
/* DESCRIPTION: Drop an entity during schema generation. */
/* Assumes the context object is an entity. */
[