-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathD2_99_EDSIZE.TPW
2101 lines (2067 loc) · 100 KB
/
D2_99_EDSIZE.TPW
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
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#! File Name: D2EdSize.tpw
#! Purpose: DCT to SYBASE creation script
#! Author: Copyright © 1999-2999 by Roberto Artigas Jr
#! All rights reserved world wide.
#! Changes:
#! 2006 09 20 Eddie Sizemore
#! * Added Support assign a name to a foreign key in the script. Needed when using a pk as the linking side
#! * of a file relationship so the script does not try to create the pk and fk with the same name.
#! * RASQL(,relation name,,) Foreign Key Name
#! 2006 08 07 Eddie Sizemore
#! Added Support to keep a history (99) of the old files
#! 2006 03 18 Eddie Sizemore
#! Added Support for naming of primary keys ie CONSTRAINT "pkTimeTest" PRIMARY KEY CLUSTERED ( "SysID" )
#! Added Support to Drop the pk in the drop script
#! 2006 02 03 Eddie Sizemore
#! Added Support for ULONG and USHORT Will create UNSIGNED INTEGER and UNSIGNED SMALLINT
#! Added Support for SREAL and REAL
#! 2005 12 30 Eddie Sizemore
#! * Added support to override PKClustered flag per file in file user option 2
#! * And set another key as clustered using the key user option 2.
#! * RASQL(,NC,,) File option 2 [NC] Override global flag set primary key clustered
#! * RASQL(,C,,) Key option 2 [C] Set this key as Clustered only one per table
#! 2005 10 07 Eddie Sizemore
#! * Changed the comment delimiter from ' to "
#! 2005 06 01 Eddie Sizemore
#! * Added Constraints to column validations. The db error message will include this text in the error message
#! 2003 09.16 Eddie Sizemore
#! * Changed Database Options to IncludeDctComments As Script
#! Allows you to place SQL script in the Dct
#! comments and it will be included after all
#! the tables and indexes are created
#! 2003 05.31 Eddie Sizemore
#! * Added support for GLOBAL TEMPORARY TABLE in File User Options
#! * RASQL(,,GT,) GLOBAL TEMPORARY TABLE
#! * RASQL(,,PR,) GLOBAL TEMPORARY TABLE ON COMMIT PRESERVE ROWS
#! * RASQL(,,,IC) Include Table Comment as script
#! Allows you to place SQL script in the table
#! comments and it will be included after the
#! table and indexes are created
#! * Added support for additional defaults
#! * RASQL(,,LU,) Default Last User
#! Changes:
#! 2003 03.16 Eddie Sizemore
#! * Added support for additional defaults
#! * RASQL(,,CP,) Default Current Publisher
#! * RASQL(,,CDB,) Default Current DataBase
#! * RASQL(,,CUTS,) Default Current UTC TimeStamp
#! * RASQL(,,CTS,) Default Current TimeStamp
#! * RASQL(,,CD,) Default Current Date
#! * RASQL(,,CT,) Default Current Time
#! * RASQL(,,CU,) Default Current User
#! * RASQL(,,UTS,) Default UTC TimeStamp
#! * RASQL(,,TS,) Default TimeStamp
#! 2003.01.24 Eddie Sizemore
#! * Added TempTable
#! * Added Database Options
#! 2003.01.05 Roberto Artigas Jr
#! * Added NOTEPAD show of the script at generation end.
#! 2003.01.03 Eddie Sizemore
#! * Changed to process tables in alphbetical order
#! * Changed the Table format
#! * Added support for defaults including AutoInc and Global AutoInc
#! * RASQL(,,A,) Default AutoIncrement
#! * RASQL(,,G,) Default Global AutoIncrement
#! * RASQL(,,G,1024) Default Global AutoIncrement Partition Size
#! * Added quote toggle
#! * Added flag to turn off reserved words check
#! * Added column constriants
#! * Added table owner
#! * Added primary key def in table
#! * Added Table & Column Comments
#! * Added Drop Table, FK, and Index
#! * Added automatic conversion of timestamp fields
#! * Added Combined Script
#! * Added Flag to Add Clustered to the primary Key
#! * My changes do not support the use of arrays!
#! 2002.12.02 Roberto Artigas Jr
#! * Created skeleton for the Sybase variant.
#!---------------------------------------------------------------------
#UTILITY(Dct2SYBASE_EddieSizemore, '2016.02.17: Dictionary to SYBASE script')
#!---------------------------------------------------------------------
#BOXED('Hidden Variables'),HIDE
#PROMPT('DictName: ' ,@S40 ),%DictName
#PROMPT('DictPath: ' ,@S80 ),%DictPath
#PROMPT('nLoc1: ' ,@N4 ),%nLoc1
#PROMPT('nLoc2: ' ,@N4 ),%nLoc2
#PROMPT('OutCombinedName:',@S120),%OutCombinedName
#PROMPT('OutTableName: ' ,@S120),%OutTableName
#PROMPT('OutDropName: ' ,@S120),%OutDropName
#PROMPT('OutGrantName: ' ,@S120),%OutGrantName
#PROMPT('OutIndexName: ' ,@S120),%OutIndexName
#PROMPT('OutRelatName: ' ,@S120),%OutRelatName
#ENDBOXED
#!
#SHEET,HSCROLL
#TAB('General')
#BOXED('')
#DISPLAY('The SYBASE Script Creator.')
#DISPLAY('Copyright 2002-2003 © by Roberto Artigas Jr.')
#DISPLAY('All Rights Reserved World Wide.')
#DISPLAY('')
#PROMPT('Directory:' ,@S80 ),%SQLDirectory,AT(52,,130)
#DISPLAY('')
#PROMPT('Combine Scripts into 1?',CHECK),%SQLCombined,DEFAULT(%TRUE),AT(10) #! ES 2003.01.03
#PROMPT('Combined Script:',@S40),%SQLCombinedName,AT(82,,100) #! ES 2003.01.03
#DISPLAY('')
#PROMPT('Generate CREATE?',CHECK),%SQLTable,DEFAULT(%TRUE),AT(10)
#PROMPT('CREATE Script:',@S40),%SQLTableName,AT(82,,100)
#DISPLAY('')
#PROMPT('Generate DROP?',CHECK),%SQLDrop,DEFAULT(%TRUE),AT(10) #! ES 2003.01.03
#PROMPT('DROP Script:',@S40),%SQLDropName,AT(82,,100) #! ES 2003.01.03
#DISPLAY('')
#PROMPT('Generate Indexs?',CHECK),%SQLIndex,DEFAULT(%TRUE),AT(10)
#PROMPT('Index Script:',@S40),%SQLIndexName,AT(82,,100)
#DISPLAY('')
#PROMPT('Generate FK?',CHECK),%SQLRelat,DEFAULT(%TRUE),AT(10)
#PROMPT('FK Script:',@S40),%SQLRelatName,AT(82,,100)
#DISPLAY('')
#PROMPT('Generate GRANT?',CHECK),%SQLGrant,DEFAULT(%FALSE),AT(10)
#PROMPT('GRANT Script:',@S40),%SQLGrantName,AT(82,,100)
#ENDBOXED
#ENDTAB
#TAB('Options')
#BOXED('')
#PROMPT('Table Owner:' ,@S20 ),%SQLPrefix,AT(82,,100),DEFAULT('DBA') #! ES 2003.01.03
#PROMPT('Grant User:' ,@S20 ),%GrantUser,AT(82,,100),DEFAULT('GSIUser') #! ES 2003.01.03
#PROMPT('Keep History Files:',CHECK),%KeepHistoryFiles,AT(10),DEFAULT(%True) #! ES 2006.08.07
#PROMPT('Use Quotes on Table and Column Names:',CHECK),%UseQuotes,AT(10),DEFAULT(%True) #! ES 2003.01.03
#PROMPT('Declare Primary Key in Table:',CHECK),%PKInTable,AT(10),DEFAULT(%True) #! ES 2003.01.03
#PROMPT('Declare Primary Key as Clustered:',CHECK),%PKClustered,AT(10),DEFAULT(%True) #! ES 2003.01.03
#PROMPT('Declare Primary Key as Constraint:',CHECK),%PKConstraint,AT(10),DEFAULT(%True) #! ES 2006.03.18
#PROMPT('DROP Primary Key in Drop Script',CHECK),%DropPK,AT(10),DEFAULT(%False) #! ES 2006 03 18
#PROMPT('Check Reserved Words:',CHECK),%CheckReserved,AT(10),DEFAULT(%False) #! ES 2003.01.03
#PROMPT('Add TempTable to Script:',CHECK),%AddTempTable,AT(10),DEFAULT(%False) #! ES 2003.01.24
#PROMPT('Add DataBase Options to Script:',CHECK),%IncludeDctComments,AT(10),DEFAULT(%True) #! ES 2003.01.24
#DISPLAY('')
#ENDBOXED
#ENDTAB
#TAB('Arrays')
#BOXED('')
#DISPLAY('There are two ways to handle arrays:')
#DISPLAY('')
#DISPLAY('1) You defined a group with all the fields of the array')
#DISPLAY('inside this group. Then you put the array OVER the')
#DISPLAY('group. If you set up your arrays in this manner, then')
#DISPLAY('LEAVE the checkbox bellow OFF.')
#DISPLAY('')
#DISPLAY('2) You define your arrays as actual fields using no')
#DISPLAY('groups whatsoever. If you set up your arrays this way,')
#DISPLAY('then TURN ON the checkbox bellow.')
#DISPLAY('')
#DISPLAY('')
#PROMPT('I DO NOT HAVE ARRAYS OVER GROUPS. ',CHECK),%NoArrayOver,AT(10),DEFAULT(1)
#DISPLAY('')
#DISPLAY('')
#DISPLAY('')
#DISPLAY('')
#DISPLAY('')
#ENDBOXED
#ENDTAB
#! #TAB('Standardize')
#! #BOXED('')
#! #PROMPT('Generate script comments? ',CHECK),%DoComments,AT(10),DEFAULT(0)
#! #PROMPT('Force BOOLEAN validation to [Y,N] choices? ',CHECK),%ForceBoolYN,AT(10),DEFAULT(1)
#! #PROMPT('Prefix tables and rows with file prefix? ',CHECK),%UsePrefix,AT(10),DEFAULT(0)
#! #PROMPT('Do KEYFIELD-FILE list to create relations? ',CHECK),%DoFieldFile,AT(10),DEFAULT(0)
#! #DISPLAY('')
#! #DISPLAY('')
#! #DISPLAY('')
#! #DISPLAY('')
#! #DISPLAY('')
#! #DISPLAY('')
#! #DISPLAY('')
#! #DISPLAY('')
#! #DISPLAY('')
#! #DISPLAY('')
#! #ENDBOXED
#! #BOXED('')
#! #PROMPT('True Value (Y,T,1): ',@S1),%TrueValue,REQ,DEFAULT('Y')
#! #PROMPT('False Value (N,F,0): ',@S1),%FalseValue,REQ,DEFAULT('N')
#! #ENDBOXED
#! #ENDTAB
#ENDSHEET
#BOXED('Hidden Variables'),HIDE
#PROMPT('Generate script comments? ',CHECK),%DoComments,AT(10),DEFAULT(0)
#PROMPT('Force BOOLEAN validation to [Y,N] choices? ',CHECK),%ForceBoolYN,AT(10),DEFAULT(0)
#PROMPT('Prefix tables and rows with file prefix? ',CHECK),%UsePrefix,AT(10),DEFAULT(0)
#PROMPT('Do KEYFIELD-FILE list to create relations? ',CHECK),%DoFieldFile,AT(10),DEFAULT(0)
#PROMPT('True Value (Y,T,1): ',@S1),%TrueValue,REQ,DEFAULT('1')
#PROMPT('False Value (N,F,0): ',@S1),%FalseValue,REQ,DEFAULT('0')
#ENDBOXED
#!---------------------------------------------------------------------
#PREPARE
#!
#SET(%nLoc1,INSTRING('\',%DictionaryFile,1,1))
#LOOP,WHILE(%nLoc1)
#SET(%nLoc2,%nLoc1)
#SET(%nLoc1,INSTRING('\',%DictionaryFile,1,%nLoc1+1))
#ENDLOOP
#SET(%DictName,UPPER(SUB(%DictionaryFile,%nLoc2+1,LEN(%DictionaryFile)-%nLoc2-4)))
#SET(%DictPath,UPPER(SUB(%DictionaryFile,1,%nLoc2)))
#!
#SET(%SQLDirectory,%DictPath)
#SET(%SQLCombinedName,%DictName & '.SY.SQL')
#SET(%SQLTableName,%DictName & '.T_SY.SQL')
#SET(%SQLDropName,%DictName & '.D_SY.SQL')
#SET(%SQLGrantName,%DictName & '.G_SY.SQL')
#SET(%SQLIndexName,%DictName & '.I_SY.SQL')
#SET(%SQLRelatName,%DictName & '.F_SY.SQL')
#!
#ENDPREPARE
#!---------------------------------------------------------------------
#MESSAGE('The SYBASE Script Creator',0)
#DECLARE(%NFileUser) #! File user options [RASQL]
#DECLARE(%NFileOpt1) #! File option 1 [NO]
#DECLARE(%NFileOpt2) #! File option 2 [NC]
#DECLARE(%NFileOpt3) #! File option 3 [GT],[PR] Global Temp Table, Preserve Rows
#DECLARE(%NFileOpt4) #! File option 4 [IC]
#!
#DECLARE(%NFieldUser) #! Field user options [RASQL]
#DECLARE(%NFieldOpt1) #! Field option 1 [NO]
#DECLARE(%NFieldOpt2) #! Field option 2 [Override Clarion Data Type with SQL Data Type]
#DECLARE(%NFieldOpt3) #! Field option 3 [A],[G] Auto Inc or Global Auto Inc
#DECLARE(%NFieldOpt4) #! Field option 4 [#####] Global Auto Inc Partion Size
#!
#DECLARE(%NKeyUser) #! Key user options [RASQL]
#DECLARE(%NKeyOpt1) #! Key option 1 [NO]
#DECLARE(%NKeyOpt2) #! Key option 2 [C] Clustered] Added 20051230 Eddie Sizemore
#DECLARE(%NKeyOpt3) #! Key option 3
#DECLARE(%NKeyOpt4) #! Key option 4
#!
#DECLARE(%NRelationUser) #! Relation user options [RASQL]
#DECLARE(%NRelationOpt1) #! Relation option 1 [NO]
#DECLARE(%NRelationOpt2) #! Relation option 2 [] fkey name
#DECLARE(%NRelationOpt3) #! Relation option 3
#DECLARE(%NRelationOpt4) #! Relation option 4
#!
#DECLARE(%NFileName) #! File Name
#DECLARE(%NFileType) #! TYPE=???
#DECLARE(%NFileRowFormat) #! ROW_FORMAT=???
#!
#DECLARE(%NFieldPKey) #! Field is Primary Key?
#DECLARE(%NFieldLine) #! Field line
#DECLARE(%NFieldName) #! Field Name
#DECLARE(%NFieldTSql) #! Field SQL type
#DECLARE(%NFieldType) #! Field type
#DECLARE(%NFieldDef) #! Field default
#DECLARE(%NFieldAuto) #! Field AUTO_INCREMENT
#DECLARE(%NFieldNN) #! Field NOT NULL
#DECLARE(%NFieldSize ,LONG) #! Field decimal size
#DECLARE(%NFieldDec ,LONG) #! Field decimal places
#DECLARE(%NLeadZero ,LONG) #! Have a leading zero
#DECLARE(%NFNameAuto) #! Field Name Auto Increment
#!
#DECLARE(%NKeyName) #! Key name
#DECLARE(%NKeyFields) #! Key building line
#DECLARE(%NKeyField) #! Key field current
#DECLARE(%NKeyFieldCount) #! Number of key fields
#DECLARE(%PrimaryCount) #! Primary key exists
#DECLARE(%SecondaryCount) #! Secondary key exists
#DECLARE(%AutoIncrementCount) #! Auto-Increment key exists
#!
#DECLARE(%NFileList),UNIQUE #! ES 2003.01.03
#DECLARE(%NRelList),MULTI #! ES 2003.01.03
#DECLARE(%ESFileName,%NFileList) #! ES 2003.01.03
#DECLARE(%ESdFileName,%NFileList) #! ES 2003.01.03
#DECLARE(%ESIndexDef),MULTI #! ES 2003.01.03 - Index Defs
#DECLARE(%ESComments),MULTI #! ES 2003.01.03 - Comments
#DECLARE(%ESdTable),MULTI #! ES 2003.01.03 - Drop Table
#DECLARE(%ESdfk),MULTI #! ES 2003.01.03 - Drop FK
#DECLARE(%ESdindex),MULTI #! ES 2003.01.03 - Drop index
#DECLARE(%ESdTableName) #! ES 2003.01.03
#DECLARE(%ESdKeyName) #! ES 2003.01.03
#DECLARE(%NFieldCheck) #! ES 2003.01.03 - Column Constraints
#DECLARE(%NPrimaryKeyDef) #! ES 2003.01.03 - Primary Key Def
#DECLARE(%NKeyDir) #! ES 2003.01.03 - Key Sort Direction ASC or DESC
#DECLARE(%NForignScript),MULTI #! ES 2003.01.03 -
#DECLARE(%PossibleTimeStamp,LONG) #! ES 2003.01.03
#DECLARE(%PossibleTimeStampField) #! ES 2003.01.03
#DECLARE(%GroupOver) #! ES 2003.01.03
#DECLARE(%WriteLine) #! ES 2003.01.03
#DECLARE(%AddComma) #! ES 2003.01.03
#DECLARE(%ASCIIFileRecord) #! ES 2003.01.03
#DECLARE(%ESFieldNumeric) #! ES 2003.08.06
#DECLARE(%ESSetPKClustered) #! ES 2005.12.30
#DECLARE(%ESSetClustered) #! ES 2005.12.30
#!
#DECLARE(%NRelateItem) #! Working item number
#DECLARE(%NRelateCount) #! Total items to work
#DECLARE(%NRelateComma) #! Number of commas
#DECLARE(%NRelateFile) #! Related file
#DECLARE(%NRelateField1) #! Related origin field
#DECLARE(%NRelateField2) #! Related relate field
#DECLARE(%RelationField1Count) #! Count of origin file key items
#DECLARE(%RelationField2Count) #! Count of relate file key items
#DECLARE(%RelationField1) #! The origin file keys
#DECLARE(%RelationField2) #! The relate file keys
#DECLARE(%RelationUpdate) #! ON UPDATE ?
#DECLARE(%RelationDelete) #! ON DELETE ?
#!
#!#DECLARE(%nLoc1 ,LONG) #! Location 1
#!#DECLARE(%nLoc2 ,LONG) #! Location 2
#DECLARE(%TheCount ,LONG) #! Count posible relations
#DECLARE(%CStringLen) #! Length of types shortened by one
#DECLARE(%LastField) #! Last field processed
#DECLARE(%InnerGroup) #! Inner group level processed
#DECLARE(%FieldComma) #! Number of fields - 1
#!
#DECLARE(%ChoiceLine) #! Build ENUM field type line
#DECLARE(%ChoiceComma) #! Count ENUM values - 1
#!
#DECLARE(%DocVar) #! Documentation Variable
#DECLARE(%TableCount, 0) #! Count of tables
#DECLARE(%AutoCount, 0) #! Count of Auto-Increment Keys
#DECLARE(%PKeyCount, 0) #! Count of primary keys (From Keys)
#DECLARE(%PKeyOption, 0) #! Count of primary keys (From Options)
#DECLARE(%KeyOthers, 0) #! Count of secondary keys
#DECLARE(%KeyCount, 0) #! Count of all keys combined
#DECLARE(%FieldCount, 0) #! Count of fields
#DECLARE(%RelCount, 0) #! Relationship Counts
#DECLARE(%FieldTable),MULTI,UNIQUE #! List of unique fields
#DECLARE(%FieldUnique, 0) #! Count of unique fields
#!
#DECLARE(%TheDate) #! Display current date
#DECLARE(%TheTime) #! Display current time
#SET(%TheDate,FORMAT(TODAY(),@D010)) #! Set current date
#SET(%TheTime,FORMAT(CLOCK(),@T06)) #! Set current time
#!
#DECLARE (%DimCount ,LONG) #! Number of dimensions
#DECLARE (%FldArray ,STRING) #! Created field name from array
#DECLARE (%FD1S ,STRING) #! Number for dimension 1
#DECLARE (%FD2S ,STRING) #! Number for dimension 2
#DECLARE (%FD3S ,STRING) #! Number for dimension 3
#DECLARE (%FD4S ,STRING) #! Number for dimension 4
#DECLARE (%FD1I ,LONG) #! Looping in Dimension 1
#DECLARE (%FD2I ,LONG) #! Looping in Dimension 2
#DECLARE (%FD3I ,LONG) #! Looping in Dimension 3
#DECLARE (%FD4I ,LONG) #! Looping in Dimension 4
#DECLARE (%FD1L ,LONG) #! Set to %FieldDimension1
#DECLARE (%FD2L ,LONG) #! Set to %FieldDimension2
#DECLARE (%FD3L ,LONG) #! Set to %FieldDimension3
#DECLARE (%FD4L ,LONG) #! Set to %fieldDimension4
#!
#DECLARE(%LOOPCount)
#DECLARE(%TempFileName1)
#!
#IF (%KeepHistoryFiles)
#LOOP,FOR(%LoopCount,99,1),BY(-1)
#SET(%TempFileName1,%DictName & '.SY-'& FORMAT(%LOOPCount,@N02) &'.SQL')
#IF(FILEEXISTS(%TempFileName1))
#REPLACE(%DictName & '.SY-'& FORMAT(%LOOPCount + 1,@N02) &'.SQL',%TempFileName1) #!Replace old with new (if changed)
#ENDIF
#ENDLOOP
#!
#SET(%TempFileName1,%DictName & '.SY.SQL')
#IF(FILEEXISTS(%TempFileName1))
#REPLACE(%DictName & '.SY-01.SQL',%TempFileName1) #!Replace old with new (if changed)
#ENDIF
#ENDIF
#!
#!--------------------------------------------------------------!
#! List of table, key and rows names found in reserved list. !
#!--------------------------------------------------------------!
#DECLARE(%ReservedFieldList),MULTI,UNIQUE
#EQUATE (%FoundFileName ,'File Name: ')
#EQUATE (%FoundFileField ,'File Field Name: ')
#EQUATE (%FoundAIKeyName ,'AI Key Name: ')
#EQUATE (%FoundKeyName ,'Key Name: ')
#EQUATE (%FoundKeyField ,'Key Field Name: ')
#EQUATE (%FoundRelatedName ,'Related File Name: ')
#EQUATE (%FoundRelatedField ,'Related Field Name: ')
#!--------------------------------------------------------------------------!
#! RAS.2001.12.15 - Table of field-table to be able to create relations. !
#!--------------------------------------------------------------------------!
#DECLARE(%FieldTableList),MULTI,UNIQUE
#!---------------------------------------------------------------------
#DECLARE(%LFieldInKey),MULTI,UNIQUE #! Field list that are used in keys
#DECLARE(%IFieldInKey) #! Field item to search for in list
#DECLARE(%LFieldInKeyCount) #! How many fields are in keys?
#FREE(%LFieldInKey)
#FOR(%File)
#IF(ITEMS(%Key))
#FOR(%Key)
#FOR(%KeyField)
#ADD(%LFieldInKey,%KeyField)
#ENDFOR
#ENDFOR
#ENDIF
#ENDFOR
#SET(%LFieldInKeyCount,ITEMS(%LFieldInKey))
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#INSERT(%ClarionReservedWords)
#INSERT(%SqlReservedWords)
#FOR(%ClarionWordList)
#ADD(%SqlWordList,%ClarionWordList)
#ENDFOR
#IF(~%CheckReserved) #! ES.2002.12.03
#FREE(%SqlWordList) #! ES.2002.12.03
#ENDIF #! ES.2002.12.03
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#SET(%TableCount, 0) #! Count of tables
#SET(%AutoCount, 0) #! Count of Auto-Increment Keys
#SET(%PKeyCount, 0) #! Count of primary keys (From Keys)
#SET(%PKeyOption, 0) #! Count of primary keys (From Options)
#SET(%KeyOthers, 0) #! Count of secondary keys
#SET(%KeyCount, 0) #! Count of all keys combined
#SET(%FieldCount, 0) #! Count of fields
#SET(%RelCount, 0) #! Relationship Counts
#SET(%FieldUnique, 0) #! Count of unique fields
#!---------------------------------------------------------------------
#! ES 2003.01.03 Process tables by Alpha and filter files once
#!---------------------------------------------------------------------
#MESSAGE('Building Table List: ',1)
#SET(%TableCount,0)
#FOR(%File)
#!IF(UPPER(%FileType) = 'FILE' AND (UPPER(%FileDriver) = 'SQLANYWHERE' OR UPPER(%FileDriver) = 'ODBC')) #! ES .2002.12.03
#IF(UPPER(%FileDriver) = 'SQLANYWHERE' OR UPPER(%FileDriver) = 'ODBC') #! ES .2002.12.03
#IF(ITEMS(%Field)) #! RAS.2001.12.01
#IF(SUB(UPPER(EXTRACT(%FileUserOptions,'RASQL',1)),1,1)='N')
#CYCLE
#ELSE
#ADD(%NFileList,UPPER(%File))
#SET(%NFileName,%File)
#IF(%UsePrefix)
#SET(%NFileName,%FilePrefix & '_' & %File)
#ENDIF
#SET(%SqlWordItem, UPPER(%NFileName))
#FIND(%SqlWordList, %SqlWordItem)
#IF(%SqlWordList)
#ADD(%ReservedFieldList, %FoundFileName & %NFileName)
#SET(%NFileName, %NFileName & '_')
#ENDIF
#SET(%ESdFileName,%NFileName) #! ES 2003.01.03
#IF(%SQLPrefix) #! ES 2003.01.03
#IF(%UseQuotes) #! ES 2003.01.03
#SET(%NFileName,'"' & %SQLPrefix & '"."' & %NFileName & '"')
#ELSE #! ES 2003.01.03
#SET(%NFileName,%SQLPrefix &'.'& %NFileName)
#ENDIF #! ES 2003.01.03
#ELSE #! ES 2003.01.03
#IF(%UseQuotes) #! ES 2003.01.03
#SET(%NFileName,'"' & %NFileName & '"')
#ENDIF #! ES 2003.01.03
#ENDIF #! ES 2003.01.03
#SET(%ESFileName,%NFileName) #! ES 2003.01.03
#SET(%TableCount,%TableCount +1)
#MESSAGE('Table Structure: ' & %NFileList,2)
#MESSAGE('Table Count : ' & %TableCount,3)
#ENDIF
#ENDIF #! RAS.2001.12.01
#ENDIF #! ES .2002.12.03
#ENDFOR
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#IF(%SQLRelat)
#SET(%OutRelatName,%SQLDirectory & %SQLRelatName)
#CREATE(%OutRelatName)
#MESSAGE('Creating: ' & %SQLRelatName,1)
--
-- BOF: %OutRelatName
--
-- SQL script creator for SYBASE database [RELATIONS]
-- Created: %TheDate - %TheTime
--
PRINT '** Add Foregin Keys **';
#!
#SET(%RelCount, 0)
#FOR(%NFileList) #! ES 2003.01.03
#FIX(%File,%NFileList) #! ES 2003.01.03
#IF(%FileType='ALIAS') #! ES 2003.03.19
#CYCLE
#ENDIF
#SET(%NFileName,%ESFileName) #! ES 2003.01.03
#!
#SET(%TheCount, 0)
#IF(ITEMS(%Relation))
#FOR(%Relation)
#SET(%nLoc1,INSTRING('RASQL(',%RelationUserOptions,1,1))
#SET(%nLoc2,INSTRING(')',%RelationUserOptions,1,%nLoc1))
#SET(%nRelationUser,UPPER(SUB(%RelationUserOptions,%nLoc1,%nLoc2)))
#!SET(%NRelationUser,UPPER(EXTRACT(%RelationUserOptions,'RASQL')))
#SET(%NRelationOpt1,EXTRACT(%NRelationUser,'RASQL',1))
#SET(%NRelationOpt2,EXTRACT(%NRelationUser,'RASQL',2))
#SET(%NRelationOpt3,EXTRACT(%NRelationUser,'RASQL',3))
#SET(%NRelationOpt4,EXTRACT(%NRelationUser,'RASQL',4))
#!%NFileList, %Relation, %NRelationUser, %NRelationOpt1, %NRelationOpt2, %NRelationOpt3, %NRelationOpt4
#!-----------------------------------------------------------------!
#! The first option RASQL(NO) controls if a relation is processed. !
#!-----------------------------------------------------------------!
#IF(SUB(%NRelationOpt1,1,1)='N')
#CYCLE
#ENDIF
#!
#IF(%FileRelationType = 'MANY:1')
#SET(%Relationfield1, '')
#SET(%Relationfield2, '')
#SET(%NKeyField, SUB(%FileKey, INSTRING(':',%FileKey,1,1) + 1 , 50))
#IF(NOT %NKeyField)
#SET(%NKeyField, SUB(%RelationKey, INSTRING(':',%RelationKey,1,1) + 1 , 50))
#ENDIF
#IF(%UsePrefix)
#SET(%NKeyField, %FilePrefix & '_' & %NKeyField)
#ENDIF
#SET(%SqlWordItem, UPPER(%NKeyField))
#FIND(%SqlWordList, %SqlWordItem)
#IF(%SqlWordList)
#ADD(%ReservedFieldList, %FoundKeyField & %FilePrefix & ':' & %NKeyField)
#SET(%NKeyField, %NKeyField & '_')
#ENDIF
#SET(%ESdKeyName,%NKeyField) #! ES 2003.01.03
#IF(%UseQuotes) #! ES 2003.01.03
#SET(%NKeyField,'"' & %NKeyField & '"') #! ES 2003.01.03
#ENDIF #! ES 2003.01.03
#!
#IF(%RelationAlias) #! ES 2003.01.03
#SET(%NRelateFile, %RelationAlias) #! ES 2003.01.03
#ELSE #! ES 2003.01.03
#SET(%NRelateFile, %Relation)
#ENDIF #! ES 2003.01.03
#IF(%UsePrefix)
#SET(%NRelateFile, %RelationPrefix & '_' & %Relation)
#ENDIF
#SET(%SqlWordItem, UPPER(%NRelateFile))
#FIND(%SqlWordList, %SqlWordItem)
#IF(%SqlWordList)
#ADD(%ReservedFieldList, %FoundRelatedName & %NRelateFile)
#SET(%NRelateFile, %NRelateFile & '_')
#ENDIF
#IF(%SQLPrefix) #! ES 2003.05.28
#IF(%UseQuotes) #! ES 2003.05.28
#SET(%NRelateFile,'"' & %SQLPrefix & '"."' & %NRelateFile & '"')
#ELSE #! ES 2003.05.28
#SET(%NRelateFile,%SQLPrefix &'.'& %NRelateFile)
#ENDIF #! ES 2003.05.28
#ELSE #! ES 2003.05.28
#IF(%UseQuotes) #! ES 2003.05.28
#SET(%NRelateFile,'"' & %NRelateFile & '"')
#ENDIF #! ES 2003.05.28
#ENDIF #! ES 2003.05.28
#!
#SET(%RelationField1Count, ITEMS(%FileKeyField))
#SET(%RelationField2Count, ITEMS(%RelationKeyField))
#!
#SET(%NRelateCount, %RelationField1Count)
#SET(%NRelateComma, %NRelateCount - 1)
#SET(%NRelateItem, 0)
#FOR(%FileKeyField)
#IF(%NRelateItem > %NRelateCount)
#BREAK
#ENDIF
#SET(%NRelateItem, %NRelateItem + 1)
#SET(%NRelateField1, SUB(%FileKeyField,INSTRING(':',%FileKeyField,1,1)+1,50))
#SET(%NRelateField2, SUB(%FileKeyFieldLink,INSTRING(':',%FileKeyFieldLink,1,1)+1,50))
#!
#IF(%UsePrefix)
#SET(%NRelateField1, %FilePrefix & '_' & %NRelateField1)
#ENDIF
#SET(%SqlWordItem, UPPER(%NRelateField1))
#FIND(%SqlWordList, %SqlWordItem)
#IF(%SqlWordList)
#ADD(%ReservedFieldList, %FoundRelatedField & %FilePrefix & ':' & %NRelateField1)
#SET(%NRelateField1, %NRelateField1 & '_')
#ENDIF
#!
#IF(%UsePrefix)
#SET(%NRelateField2, %RelationPrefix & '_' & %NRelateField2)
#ENDIF
#SET(%SqlWordItem, UPPER(%NRelateField2))
#FIND(%SqlWordList, %SqlWordItem)
#IF(%SqlWordList)
#ADD(%ReservedFieldList, %FoundRelatedField & %RelationPrefix & ':' & %NRelateField2)
#SET(%NRelateField2, %NRelateField2 & '_')
#ENDIF
#!
#IF(%UseQuotes) #! ES 2003.01.03
#SET(%RelationField1, %RelationField1 & '"' & %NRelateField1 & '"') #! ES 2003.01.03
#SET(%RelationField2, %RelationField2 & '"' & %NRelateField2 & '"') #! ES 2003.01.03
#ELSE
#SET(%RelationField1, %RelationField1 & %NRelateField1)
#SET(%RelationField2, %RelationField2 & %NRelateField2)
#ENDIF #! ES 2003.01.03
#IF(%NRelateComma)
#SET(%NRelateComma, %NRelateComma - 1)
#SET(%RelationField1, %RelationField1 & ', ')
#SET(%RelationField2, %RelationField2 & ', ')
#ENDIF
#ENDFOR
#!-------------------------------------------!
#! RAS.2001.01.20 - Added this feature. !
#! Has syntax errors, so commented out. !
#!-------------------------------------------!
#! Added to the comments so programmer is at !
#! aware that other relationships may exist. !
#!-------------------------------------------!
#!SET(%RelationUpdate,%RelationConstraintUpdate) #! ON UPDATE ?
#!SET(%RelationDelete,%RelationConstraintDelete) #! ON DELETE ?
#CASE(%RelationConstraintUpdate) #! ES 2003.01.03
#OF ('CASCADE_SERVER') #! ES 2003.01.03
#SET(%RelationUpdate,'CASCADE') #! ES 2003.01.03
#OF ('CLEAR_SERVER') #! ES 2003.01.03
#SET(%RelationUpdate,'SET NULL') #! ES 2003.01.03
#OF ('RESTRICT_SERVER') #! ES 2003.01.03
#SET(%RelationUpdate,'RESTRICT') #! ES 2003.01.03
#ELSE #! ES 2003.01.03
#SET(%RelationUpdate,'') #! ES 2003.01.03
#ENDCASE #! ES 2003.01.03
#CASE(%RelationConstraintDelete) #! ES 2003.01.03
#OF ('CASCADE_SERVER') #! ES 2003.01.03
#SET(%RelationDelete,'CASCADE') #! ES 2003.01.03
#OF ('CLEAR_SERVER') #! ES 2003.01.03
#SET(%RelationDelete,'SET NULL') #! ES 2003.01.03
#OF ('RESTRICT_SERVER') #! ES 2003.01.03
#SET(%RelationDelete,'RESTRICT') #! ES 2003.01.03
#ELSE #! ES 2003.01.03
#SET(%RelationDelete,'') #! ES 2003.01.03
#ENDCASE #! ES 2003.01.03
#!-------------------------------------------!
#IF(%Relationfield1)
#MESSAGE('Relation of: ' & %File,2)
#SET(%RelCount, %RelCount + 1)
#!----------------------------------------------------------!
#! RAS.2001.07.22 - The alias name gets changed to the real !
#! name to generate the SQL statement for the relationship. !
#!----------------------------------------------------------!
#IF(%FileType = 'ALIAS')
#SET(%NFileName,%AliasFile)
#FIX(%File, %AliasFile)
#IF(%UsePrefix)
#SET(%NFileName,%FilePrefix & '_' & %File)
#ENDIF
#IF(%SQLPrefix) #! ES 2003.01.03
#IF(%UseQuotes) #! ES 2003.01.03
#SET(%NFileName,'"' & %SQLPrefix & '"."' & %NFileName & '"')
#ELSE #! ES 2003.01.03
#SET(%NFileName,%SQLPrefix &'.'& %NFileName)
#ENDIF #! ES 2003.01.03
#ELSE #! ES 2003.01.03
#IF(%UseQuotes) #! ES 2003.01.03
#SET(%NFileName,'"' & %NFileName & '"')
#ENDIF #! ES 2003.01.03
#ENDIF #! ES 2003.01.03
#ENDIF
#IF(%TheCount = 0)
PRINT '** Add FK to %File **';
#ENDIF
#SET(%TheCount,%TheCount+1)
#ADD(%NRelList,UPPER(%FileKey))
#IF(%SQLDrop)
#ADD(%ESdfk,'IF EXISTS(SELECT 1 FROM SYS.SYSFOREIGNKEY WHERE ROLE=''' & %ESdKeyName & ''') THEN')
#ADD(%ESdfk,' ALTER TABLE ' & %NFileName &' DELETE FOREIGN KEY ' & %NKeyField)
#!ADD(%ESdfk,' DELETE FOREIGN KEY ' & %NKeyField)
#ADD(%ESdfk,'END IF;')
#ADD(%ESdfk,'')
#ENDIF
ALTER TABLE %NFileName
#!ADD CONSTRAINT %NKeyField
#!FOREIGN KEY (%Relationfield1)
#IF(%NRelationOpt2) #! ES 2006.09.20
ADD FOREIGN KEY %NRelationOpt2 (%Relationfield1)
#ELSE #! ES 2006.09.20
ADD FOREIGN KEY %NKeyField (%Relationfield1)
#ENDIF #! ES 2006.09.20
REFERENCES %NRelateFile (%Relationfield2)
#IF(%RelationUpdate) #! ES 2003.01.03
ON UPDATE %RelationUpdate
#ENDIF
#IF(%RelationDelete) #! ES 2003.01.03
ON DELETE %RelationDelete
#ENDIF
;
#ENDIF
#ENDIF
#ENDFOR
#ENDIF
#ENDFOR
PRINT '** Add FK Script Complete **';
--
-- EOF: %OutRelatName
--
#CLOSE(%OutRelatName)
#ENDIF
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#IF(%SQLTable)
#SET(%OutTableName,%SQLDirectory & %SQLTableName)
#CREATE(%OutTableName)
#MESSAGE('The SYBASE Script Creator',0)
#MESSAGE('Creating: ' & %SQLTableName,1)
--
-- BOF: %OutTableName
--
-- SQL script creator for SYBASE database [TABLE]
-- Created: %TheDate - %TheTime
--
PRINT '** Create Tables **';
#!
#FOR(%NFileList) #! ES 2003.01.03
#FIX(%File,%NFileList) #! ES 2003.01.03
#IF(%FileType = 'ALIAS') #! ES 2003.01.03
#CYCLE #! ES 2003.01.03
#ENDIF
#SET(%nLoc1,INSTRING('RASQL(',%FileUserOptions,1,1))
#SET(%nLoc2,INSTRING(')',%FileUserOptions,1,%nLoc1))
#SET(%nFileUser,UPPER(SUB(%FileUserOptions,%nLoc1,%nLoc2)))
#!!SET(%NFileUser,UPPER(EXTRACT(%FileUserOptions,'RASQL')))
#SET(%NFileOpt1,EXTRACT(%NFileUser,'RASQL',1))
#SET(%NFileOpt2,EXTRACT(%NFileUser,'RASQL',2))
#SET(%NFileOpt3,EXTRACT(%NFileUser,'RASQL',3))
#SET(%NFileOpt4,EXTRACT(%NFileUser,'RASQL',4))
#MESSAGE('Table of: ' & %File,2)
#!
#!---------------------------------------------------------------------
#! Add Comments for table ES 2003.01.03
#!---------------------------------------------------------------------
#IF(%NFileOpt2 = 'NC') #!Override PKClustered Flag
#SET(%ESSetPKClustered,%False)
#ELSE
#SET(%ESSetPKClustered,%PKClustered)
#ENDIF
#IF(%FileLongDesc AND %NFileOpt4 <> 'IC')
#ADD(%ESComments,'COMMENT ON TABLE ' & %ESFileName & ' IS "' & %FileLongDesc &'";')
#ELSIF(%FileDescription)
#ADD(%ESComments,'COMMENT ON TABLE ' & %ESFileName & ' IS "' & %FileDescription &'";')
#ENDIF
#!
PRINT '** Create Table: %ESFileName **';
#IF(%SQLDrop)
#IF(%NFileOpt3='GT' OR %NFileOpt3='PR') #! ES 2003 05 31
#IF(%SQLPrefix) #! ES 2003.01.03
#ADD(%ESdTable,'IF EXISTS(SELECT 1 FROM SYS.SYSTABLE WHERE TABLE_NAME=''' & %ESdFileName & ''' AND TABLE_TYPE=''GBL TEMP'' AND CREATOR=USER_ID(''' & %SQLPrefix & ''')) THEN')
#ELSE
#ADD(%ESdTable,'IF EXISTS(SELECT 1 FROM SYS.SYSTABLE WHERE TABLE_NAME=''' & %ESdFileName & ''' AND TABLE_TYPE=''GBL TEMP'' AND CREATOR=USER_ID(''DBA'')) THEN')
#ENDIF
#ELSE
#IF(%SQLPrefix) #! ES 2003.01.03
#ADD(%ESdTable,'IF EXISTS(SELECT 1 FROM SYS.SYSTABLE WHERE TABLE_NAME=''' & %ESdFileName & ''' AND TABLE_TYPE=''BASE'' AND CREATOR=USER_ID(''' & %SQLPrefix & ''')) THEN')
#ELSE
#ADD(%ESdTable,'IF EXISTS(SELECT 1 FROM SYS.SYSTABLE WHERE TABLE_NAME=''' & %ESdFileName & ''' AND TABLE_TYPE=''BASE'' AND CREATOR=USER_ID(''DBA'')) THEN')
#ENDIF
#ENDIF
#ADD(%ESdTable,' DROP TABLE ' & %ESFileName)
#ADD(%ESdTable,'END IF;')
#ADD(%ESdTable,'')
#ENDIF
#!
#IF(%NFileOpt3='GT' OR %NFileOpt3='PR') #! ES 2003 05 31
CREATE GLOBAL TEMPORARY TABLE %ESFileName (
#ELSE
CREATE TABLE %ESFileName (
#ENDIF
#INSERT(%SYSqlIndex)
#INSERT(%EdSySqlField) #! Process fields
#IF(%NPrimaryKeyDef)
%NPrimaryKeyDef
#ENDIF
#IF(%NFileOpt3='PR')
) ON COMMIT PRESERVE ROWS ;
#ELSE
);
#ENDIF
#IF(%ESIndexDef)
#!PRINT '** Create Index for Table: %File **';
#FOR(%ESIndexDef)
%ESIndexDef
#ENDFOR
#ENDIF
#IF(%NFileOpt4='IC') #! ES 2003 05 31
%FileLongDesc
#ENDIF
#ENDFOR
#!
#IF(ITEMS(%ESComments))
--
-- Table & Column Comments
--
#FOR(%ESComments)
%ESComments
#ENDFOR
#ENDIF
#!
#IF(%AddTempTable) #! ES 2003.01.24
#IF(%SQLPrefix)
CREATE GLOBAL TEMPORARY TABLE "%SQLPrefix"."TempTable"
#ELSE
CREATE GLOBAL TEMPORARY TABLE "DBA"."TempTable"
#END
(
"Int1" INTEGER NULL,
"Int2" INTEGER NULL,
"Char1" CHAR(200) NULL,
"Char2" CHAR(200) NULL,
"Dec1" DECIMAL(30,6) NULL,
"Dec2" DECIMAL(30,6) NULL
) ON COMMIT PRESERVE ROWS
;
-------------------------------------------------
-- Create triggers
-------------------------------------------------
SETUSER "%SQLPrefix"
;
CREATE TRIGGER %SQLPrefix.tib_TempTable BEFORE INSERT ORDER 1 ON
%SQLPrefix.TempTable
FOR EACH ROW
BEGIN
DELETE FROM %SQLPrefix.TempTable
END
;
#ENDIF
#IF(%IncludeDctComments) #! ES 2003.09.16
%DictionaryDescription
#ENDIF
#!
PRINT '** Create Table Script Complete **';
--
-- EOF: %OutTableName
--
#CLOSE(%OutTableName)
#ENDIF
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#IF(%SQLGrant)
#SET(%OutGrantName,%SQLDirectory & %SQLGrantName)
#CREATE(%OutGrantName)
#MESSAGE('The SYBASE Script Creator',0)
#MESSAGE('Creating: ' & %SQLGrantName,1)
--
-- BOF: %OutGrantName
--
-- SQL script creator for SYBASE database [GRANT]
-- Created: %TheDate - %TheTime
--
PRINT '** Grant Rights **';
#FOR(%NFileList) #! ES 2003.01.03
#FIX(%File,%NFileList) #! ES 2003.01.03
#IF(%FileType = 'ALIAS') #! ES 2003.01.03
#CYCLE #! ES 2003.01.03
#ENDIF #! ES 2003.01.03
#MESSAGE('Table of: ' & %NFileList,2)
#!
GRANT SELECT, INSERT, DELETE, UPDATE ON %ESFileName TO %GrantUser;
#ENDFOR
PRINT '** Grant Script Complete **';
--
-- EOF: %OutGrantName
--
#CLOSE(%OutGrantName)
#ENDIF
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#IF(%SQLIndex)
#SET(%OutIndexName,%SQLDirectory & %SQLIndexName)
#CREATE(%OutIndexName)
#MESSAGE('The SYBASE Script Creator',0)
#MESSAGE('Creating: ' & %SQLIndexName,1)
--
-- BOF: %OutIndexName
--
-- SQL script creator for SYBASE database [KEYS]
-- Created: %TheDate - %TheTime
--
PRINT '** Create Indexes **';
#FOR(%NFileList) #! ES 2003.01.03
#FIX(%File,%NFileList) #! ES 2003.01.03
#IF(%FileType = 'ALIAS') #! ES 2003.01.03
#CYCLE #! ES 2003.01.03
#ENDIF #! ES 2003.01.03
#MESSAGE('Table: ' & %File,2)
#!PRINT '** Create Index for Table: %File **';
#SET(%PrimaryCount,0) #! Primary key exists
#SET(%SecondaryCount,0) #! Secondary key exists
#IF(ITEMS(%Key))
#FOR(%Key)
#IF(NOT ITEMS(%KeyField)) #! Key has fields? No!
#CYCLE #! Then go to the next
#ENDIF #! key to be processed
#!
#IF(NOT %KeyPrimary) #! ES 2003.01.03
#FIND(%NRelList,UPPER(%Key)) #! ES 2003.01.03
#IF(%NRelList) #! ES 2003.01.03
#CYCLE #! ES 2003.01.03 Do not create index for fks
#ENDIF #! ES 2003.01.03
#ENDIF #! ES 2003.01.03
#SET(%nLoc1,INSTRING('RASQL(',%KeyUserOptions,1,1))
#SET(%nLoc2,INSTRING(')',%KeyUserOptions,1,%nLoc1))
#SET(%nKeyUser,UPPER(SUB(%KeyUserOptions,%nLoc1,%nLoc2)))
#!SET(%NKeyUser,UPPER(EXTRACT(%KeyUserOptions,'RASQL')))
#SET(%NKeyOpt1,EXTRACT(%NKeyUser,'RASQL',1))
#SET(%NKeyOpt2,EXTRACT(%NKeyUser,'RASQL',2))
#SET(%NKeyOpt3,EXTRACT(%NKeyUser,'RASQL',3))
#SET(%NKeyOpt4,EXTRACT(%NKeyUser,'RASQL',4))
#!%NKeyUser, %NKeyOpt1, %NKeyOpt2, %NKeyOpt3, %NKeyOpt4
#!------------------------------------------------------------!
#! The first option RASQL(NO) controls if a key is processed. !
#!------------------------------------------------------------!
#IF(SUB(%NKeyOpt1,1,1)='N')
#CYCLE
#ENDIF
#IF(%NKeyOpt2 = 'C') #!Override PKClustered Flag
#SET(%ESSetClustered,%True)
#ELSE
#SET(%ESSetClustered,%False)
#ENDIF
#!
#SET(%NKeyName,%KeyID)
#IF(%UsePrefix)
#SET(%NKeyName,%FilePrefix & '_' & %KeyID)
#ENDIF
#SET(%SqlWordItem,UPPER(%NKeyName))
#FIND(%SqlWordList, %SqlWordItem)
#IF(%SqlWordList)
#ADD(%ReservedFieldList, %FoundKeyName & %FilePrefix & ':' & %NKeyName)
#SET(%NKeyName, %NKeyName & '_')
#ENDIF
#SET(%ESdKeyName,%NKeyName) #! ES 2003.01.03
#IF(%UseQuotes) #! ES 2003.01.03
#SET(%NKeyName, '"' & %NKeyName & '"') #! ES 2003.01.03
#ENDIF #! ES 2003.01.03
#!
#SET(%NKeyFields,'')
#SET(%NKeyFieldCount,0)
#FOR(%KeyField)
#SET(%NKeyField, SUB(%KeyField, INSTRING(':',%KeyField,1,1) + 1 , 50))
#!--------------------------------------------------------------------------!
#! RAS.2001.12.15 - Table of keyfield-table to be able to create relations. !
#!--------------------------------------------------------------------------!
#IF(%DoFieldFile)
#ADD(%FieldTableList, %NKeyField & ' ==> ' & %File)
#ENDIF
#!
#IF(%UsePrefix)
#SET(%NKeyField, %FilePrefix & '_' & %NKeyField)
#ENDIF
#SET(%SqlWordItem, UPPER(%NKeyField))
#!-- SqlWordItem = '%SqlWordItem'
#FIND(%SqlWordList, %SqlWordItem)
#!-- SqlWordList = '%SqlWordList'
#IF(%SqlWordList)
#ADD(%ReservedFieldList, %FoundKeyField & %FilePrefix & ':' & %NKeyField)
#SET(%NKeyField, %NKeyField & '_')
#ENDIF
#IF(%KeyPrimary) #! ES 2003.01.03
#SET(%NKeyDir,'') #! ES 2003.01.03
#ELSE #! ES 2003.01.03
#CASE(SUB(%KeyFieldSequence,1,1)) #! ES 2003.01.03
#OF('A') #! ES 2003.01.03
#SET(%NKeyDir,' ASC') #! ES 2003.01.03
#OF('D') #! ES 2003.01.03
#SET(%NKeyDir,' DESC') #! ES 2003.01.03
#ENDCASE #! ES 2003.01.03
#ENDIF #! ES 2003.01.03
#SET(%NKeyFieldCount,%NKeyFieldCount + 1 )
#IF(%NKeyFieldCount = 1)
#IF(%UseQuotes) #! ES 2003.01.03
#SET(%NKeyFields,'"' & %NKeyField & '"' & %NKeyDir) #! ES 2003.01.03
#ELSE #! ES 2003.01.03
#SET(%NKeyFields,%NKeyField & %NKeyDir) #! ES 2003.01.03
#ENDIF #! ES 2003.01.03
#ELSE #! ES 2003.01.03
#IF(%UseQuotes) #! ES 2003.01.03
#SET(%NKeyFields, %NKeyFields & ', "' & %NKeyField & '"' & %NKeyDir) #! ES 2003.01.03
#ELSE #! ES 2003.01.03
#SET(%NKeyFields, %NKeyFields &', '& %NKeyField & %NKeyDir) #! ES 2003.01.03
#ENDIF #! ES 2003.01.03
#ENDIF
#ENDFOR
#IF(%KeyPrimary)
#SET(%PrimaryCount, 1)
#SET(%PKeyCount, %PKeyCount + 1)
#SET(%KeyCount, %KeyCount + 1)
#IF(NOT %PKInTable)
#IF(%ESSetPKClustered)
#IF(%PKConstraint)
ALTER TABLE %ESFileName ADD CONSTRAINT %NKeyName PRIMARY KEY CLUSTERED (%NKeyFields);
ELSE
ALTER TABLE %ESFileName ADD PRIMARY KEY CLUSTERED (%NKeyFields);
#ENDIF
#ELSE