-
Notifications
You must be signed in to change notification settings - Fork 1
/
D2_99_MYSQL.TPW
2078 lines (2067 loc) · 99.2 KB
/
D2_99_MYSQL.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: d2mySQL.tpw
#! Purpose: DCT to MySQL creation script
#! Author: Copyright © 1999-2999 by Roberto Artigas Jr
#! All rights reserved world wide.
#! Changes:
#! 2008.06.08 Vincent Tap
#! * Enhanced template to deal with multiple contrains on the same key having
#! the same name. Using InnoDB.
#! * Uncommented the ON UPDATE and ON DELETE so they would generate.
#! 2008.06.06 Roberto Artigas
#! * Added alter for UTF8 character set and collating sequence.
#! 2006.03.08 Roberto Artigas
#! * Added logic to deal with "SysID | READONLY" for backend auto_increments.
#! * Added option to prefix the keys with the file prefix separate.
#! * Made SQL RESERVED words adjustments optional. Default to previous behavior.
#! 2005.04.02 Roberto Artigas
#! * Added Logic to replace the EXTERNAL key name for the key name.
#! 2005.03.31 Roberto Artitas
#! * Hide "Create All Tables?" option. No longer used. Table list already hidden.
#! * Re-arranged Drop and Create options.
#! * Added "Create Database?" option.
#! * Added "Create tables?" option.
#! * Added "Create Secondary Indexes?" option.
#! * All these changes allow for the creation of scripts that have different
#! components depending on your needs. Like creation of secondary indexes by
#! themselves when you are converting existing tables with lots of records.
#! 2004.12.06 Roberto Artigas Jr
#! * Added options to the table for DATA DIRECTORY and INDEX DIRECTORY.
#! * Created DCT2SQL.APP (DCT2SQL.DLL) to get a directory when not entered.
#! * Changed table generation to deal with the new options.
#! ******************************************************************************
#! * The DATA DIRECTORY and INDEX DIRECTORY options do not work at this time. *
#! * The data/index files persist in being created at the MySQL data directory. *
#! ******************************************************************************
#! 2003.04.04 Roberto Artigas Jr
#! * Added logic to replace the EXTERNAL field name for the field name.
#! There are some utilities that add external names to the dictionaries.
#! And there are individuals that are overriding the field names and
#! using this script to create to convert clarion dictionaries using
#! other backends to MySQL (Reality is stranger than fiction).
#! 2002.12.23 Roberto Artigas Jr
#! * Wander Stabenow Weberling reported a syntax bug in the generation
#! of the UNSIGNED keyword after a field that has an size in parenthesis.
#! 2002.07.28 Roberto Artigas Jr
#! * Added keyword ISNULL to option 3 of the RASQL parameter string.
#! Keys and Refs are automatically made NOT NULL. In the case of
#! posible Refs that might not exist this NOT NULL needs an override.
#! 2002.07.12 Roberto Artigas Jr
#! * Option to override DATE's and TIME's and make them into longs.
#! This option can be used if you decide to define dates and times
#! in the MySQL side as INT. This will make it very easy to interface
#! with Clarion and very dificult for individuals to make out the
#! dates and times when just browsing the MySQL database with other
#! tools such as MySQLFront. As an alternative to having INT on the
#! MySQL side I made a choice to use DATE and TIME on the MySQL side
#! and CSTRING(11) @K####-##-##KB for DATEs and CSTRING(9) @K##:##:##KB
#! for TIME's. This makes everyone happy. Your choices are yours.
#! 2002.07.09 Roberto Artigas Jr
#! * Added field support for INT8 and UINT8 (INT8 = BIGINT = _int64).
#! * Logic to detect auto-increment fields by their options.
#! * Minor template code cleanup in several areas and documentation.
#! 2002.06.18 Roberto Artigas Jr
#! * Make sure template comment did not show inside script.
#! 2002.06.09 Roberto Artigas Jr
#! * Auto-increment logic modified to tell the difference between the
#! backend and front end handling the AUTO_INCREMENT attribute.
#! * Correction to INT types ZEROFILL attribute logic.
#! * Field options RAS(,,,BINARY) for fields now allowed (CHAR fields).
#! 2002.06.02 Roberto Artigas Jr
#! * Now shows script generated with NOTEPAD for viewing.
#! 2002.01.28 Roberto Artigas Jr
#! * Corrected UNSIGNED type generation. The UNSIGNED comes after.
#! 2001.12.31 Roberto Artigas Jr
#! * Corrected generation of %TrueValue and %FalseValue
#! 2001.12.15 Roberto Artigas Jr
#! * Added option of field-file listing to assist in create relations.
#! When you have lots of tables, fields, etc, this helps correctness.
#! * Minor cleanup of messages and other items.
#! 2001.12.01 Roberto Artigas Jr
#! * Ignore file definitions that are place holders (no fields).
#! * Make the addition of file prefix optional - Lee White.
#! * Report reserved words that where found - Lee White.
#! 2001.11.25 Roberto Artigas Jr
#! * Added True/False value definitions by user (one character).
#! This will allow choices for TRUE (Y,T,1) and FALSE (N,F,0),
#! which will allow boolean values to match existing systems.
#! This is one of those times that consistency (standards) pays off.
#! 2001.10.24 Roberto Artigas Jr
#! * Sugestion from Bruce Johnsom FilePrefix_* to eliminate duplicates.
#! * Added table type MRG_MYISAM to the list.
#! * Check option to turn off output of comments to file.
#! If output file gets too big it seems to GPF Clarion et al.
#! 2001.10.23 Roberto Artigas Jr
#! * Parse size of non-decimal numerics and flag for leading zero.
#! * If has leading zeros, set the integer size and ZEROFILL flag.
#! 2001.10.17 Roberto Artigas Jr
#! * Added InnoDB to table types allowed. ACID now here.
#! * NOTE: Case sensitivity for strings is activated by the keyword BINARY
#! on CHAR and VARCHAR in mySQL. For larger strings use BLOB types.
#! Binary flag is only available for MEMO and BLOB in Clarion.
#! No code to handle this behavior. Have to ponder this a bit.
#! 2001.10.02 Roberto Artigas Jr
#! * Minor corrections to keyword lists
#! * Fixed incorrect generation of primary key auto-increment.
#! 2001.09.15 Roberto Artigas Jr
#! * Output warning message if no auto-increment field is defined.
#! * Changed extension from *.sql -> *.mysql to show difference.
#! 2001.09.10 Roberto Artigas Jr
#! * Count the auto-increment keys. Normally is equal to tables.
#! * Indicate if auto-increment key is the primary key (should be).
#! * Output warning if no keys at all are defined for a file.
#! 2001.09.09 Roberto Artigas Jr
#! * Change database name generation to the dictionary name.
#! * Detect and setup auto-increment field automatically.
#! * Document "Field Choices" / "Field Values" for BOOLEAN and INLIST.
#! An excellent way to check the dictionaries multiple value fields.
#! 2001.09.07 Roberto Artigas Jr
#! * Minor cleanup and adjustment to documentation spacing.
#! 2001.07.27 Roberto Artigas Jr
#! * Adjusted documentation spaces
#! * Broke appart into smaller pieces
#!---------------------------------------------------------------------
#UTILITY(Dct2MySql, '2016.02.17: Dictionary to mySQL script')
#!---------------------------------------------------------------------
#SHEET,HSCROLL
#TAB('General')
#BOXED('')
#DISPLAY('The MySql Script Creator.')
#DISPLAY('Copyright 2001-2005 © by Roberto Artigas Jr.')
#DISPLAY('All Rights Reserved World Wide.')
#DISPLAY('')
#PROMPT('Output: ',@S80),%OutputFile,AT(50,,130),DEFAULT(SUB(%DictionaryFile,1,LEN(%DictionaryFile)-4) & '_mysql.sql')
#DISPLAY('')
#PROMPT('Drop existing database? ',CHECK),%DropDatabase,AT(10),DEFAULT(1)
#PROMPT('Drop existing tables? ',CHECK),%DropTable,AT(10),DEFAULT(1)
#DISPLAY('')
#PROMPT('Create database? ',CHECK),%CreateDatabase,AT(10),DEFAULT(1)
#PROMPT('Create tables? ',CHECK),%CreateTable,AT(10),DEFAULT(1)
#PROMPT('Create primary indexes? ',CHECK),%CreatePrimary,AT(10),DEFAULT(1)
#PROMPT('Create secondary indexes? ',CHECK),%CreateSecondary,AT(10),DEFAULT(1)
#PROMPT('Create relations? ',CHECK),%CreateRelation,AT(10),DEFAULT(1)
#DISPLAY('')
#DISPLAY('If you do not use PKEYA at the field level, check on the')
#DISPLAY('create primary indexes flag above these lines.')
#!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(0)
#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('Force INLIST validation to no default? ',CHECK),%ForceListNoDef,AT(10),DEFAULT(1)
#PROMPT('Fixed size for all STRINGS less than 256 bytes? ',CHECK),%FixedStr255,AT(10),DEFAULT(1)
#PROMPT('Prefix tables and fields with file prefix? ',CHECK),%UsePrefix,AT(10),DEFAULT(0)
#PROMPT('Prefix keys with file prefix? ',CHECK),%UsePrefixKeys,AT(10),DEFAULT(0)
#PROMPT('Do KEYFIELD-FILE list to create relations? ',CHECK),%DoFieldFile,AT(10),DEFAULT(0)
#PROMPT('Make DATE and TIME into a LONG? ',CHECK),%DoDtTmConvert,AT(10),DEFAULT(0)
#PROMPT('Create table using UTF8 character set? ',CHECK),%DoUTF8Alter,AT(10),DEFAULT(0)
#DISPLAY('')
#DISPLAY('')
#DISPLAY('')
#PROMPT('Adjust RESERVED words used in dictionary? ',CHECK),%AdjustReservedWords,AT(10),DEFAULT(1)
#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
#TAB('Files')
#BOXED('')
#DISPLAY('These options only work with MyISAM type tables.')
#DISPLAY('Set the checkbox on and then either enter the absolute')
#DISPLAY('path for the table or leave blank to be prompted.')
#DISPLAY('')
#PROMPT('Data Directory? ',CHECK),%DirData,AT(10),DEFAULT(0)
#ENABLE(%DirData)
#PROMPT('Data: ',@S240),%DirDataWhere,AT(40,,140),DEFAULT('')
#ENDENABLE
#DISPLAY('')
#PROMPT('Index Directory? ',CHECK),%DirIndex,AT(10),DEFAULT(0)
#ENABLE(%DirIndex)
#PROMPT('Index: ',@S240),%DirIndexWhere,AT(40,,140),DEFAULT('')
#ENDENABLE
#DISPLAY('')
#DISPLAY('')
#DISPLAY('')
#DISPLAY('')
#DISPLAY('')
#DISPLAY(' THIS OPTION IS NOT WORKING AT THIS TIME!')
#DISPLAY(' THIS OPTION IS NOT WORKING AT THIS TIME!')
#DISPLAY(' THIS OPTION IS NOT WORKING AT THIS TIME!')
#ENDBOXED
#ENDTAB
#!-----------------------------------------------------!
#! RAS.2004.12.06 - This option does not work anymore. !
#!-----------------------------------------------------!
#! #TAB('Select Tables')
#! #BOXED(''),HIDE
#! #PROMPT('Create all tables or selected tables? ',CHECK),%AllTables,AT(10),DEFAULT(1)
#! #BUTTON('Script only for tables...'),MULTI(%InclTables,%InclTable),AT(,,170,140),INLINE
#! #PROMPT('Table: ', FROM(%FILE)),%InclTable,REQ,DEFAULT('')
#! #ENDBUTTON
#! #ENDBOXED
#! #ENDTAB
#ENDSHEET
#!---------------------------------------------------------------------
#! RAS.2004.12.06 - Ask for the data and index directory locations
#!---------------------------------------------------------------------
#IF(%DirData)
#LOOP,WHILE(%DirDataWhere='')
#SET(%DirDataWhere,'Please select a DATA directory for this MySQL database')
#RUNDLL('DCT2SQL.DLL', 'GetDirectory', %DirDataWhere),WIN32
#ENDLOOP
#ENDIF
#IF(%DirIndex)
#LOOP,WHILE(%DirIndexWhere='')
#SET(%DirIndexWhere,'Please select a INDEX directory for this MySQL database')
#RUNDLL('DCT2SQL.DLL', 'GetDirectory', %DirIndexWhere),WIN32
#ENDLOOP
#ENDIF
#!---------------------------------------------------------------------
#DECLARE(%NFileUser) #! File user options [RASQL]
#DECLARE(%NFileOpt1) #! File option 1 [NO]
#DECLARE(%NFileOpt2) #! File option 2 [ISAM|MYISAM|HEAP|MERGE|DBD|GEMINI|INNODB|MRG_MYISAM]
#DECLARE(%NFileOpt3) #! File option 3 [DEFAULT|DYNAMIC|STATIC|COMPRESSED]
#DECLARE(%NFileOpt4) #! File option 4
#!
#DECLARE(%NFieldUser) #! Field user options [RASQL]
#DECLARE(%NFieldOpt1) #! Field option 1 [NO]
#DECLARE(%NFieldOpt2) #! Field option 2 [<Field Type>]
#DECLARE(%NFieldOpt3) #! Field option 3 [PKEYA+AUTO+NOTNULL+ISNULL]
#DECLARE(%NFieldOpt4) #! Field option 4 [<Field Attribute>]
#!
#DECLARE(%NKeyUser) #! Key user options [RASQL]
#DECLARE(%NKeyOpt1) #! Key option 1 [NO]
#DECLARE(%NKeyOpt2) #! Key option 2 [PKEYA|SKEYA]
#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
#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(%NFNameAutoDoc) #! Field Name Auto Increment Documentation
#DECLARE(%NFieldExternal) #! Field external ,NAME('...') RAS.2003.04.04
#!
#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(%NKeyExternal) #! Key external ,NAME('...') RAS.2005.04.02
#!
#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(%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(%NPrefix1) #! VT
#DECLARE(%NPrefix2) #! VT
#!
#!--------------------------------------------------------------!
#! 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
#!-------------------------------------------------------------------!
#! RAS.2001.09.09 - Change database name generation to the DCT name. !
#!-------------------------------------------------------------------!
#DECLARE(%DictName) #! Dictionary Name No Extension
#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)))
#!---------------------------------------------------------------------
#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
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#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
#!---------------------------------------------------------------------
#CREATE(%OutputFile)
#MESSAGE('The MySql Script Creator',0)
#MESSAGE('Creating: ' & %OutputFile,1)
#!---------------------------------------------------------------------
--
-- BOF: %OutputFile
--
-- DDL script creator for MySQL database
-- DDL CREATED ON: %TheDate - %TheTime
#IF(%DirData) #! RAS.2004.12.06
-- DATA DIRECTORY: %DirDataWhere
#ENDIF
#IF(%DirIndex) #! RAS.2004.12.06
-- INDEX DIRECTORY: %DirIndexWhere
#ENDIF
--
#IF(%AllTables)
#IF(%DropDatabase)
DROP DATABASE IF EXISTS %DictName ;
#ENDIF
#IF(%CreateDatabase) #! RAS.2005.03.31
CREATE DATABASE %DictName ;
#ENDIF #! RAS.2005.03.31
#ENDIF
USE %DictName ;
#!---------------------!
#! Dump the files here !
#!---------------------!
#FOR(%File)
#!----------------------------------------------------------------!
#! RAS.2001.12.01 - Ignore file place marker definitions. !
#! These are files that are defined but that contain no fields. !
#!----------------------------------------------------------------!
#IF(NOT ITEMS(%Field)) #! RAS.2001.12.01
#CYCLE #! RAS.2001.12.01
#ENDIF #! RAS.2001.12.01
#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))
#!%NFileUser, %NFileOpt1, %NFileOpt2, %NFileOpt3, %NFileOpt4
#!-------------------------------------------------------------!
#! The first option RASQL(NO) controls if a file is processed. !
#!-------------------------------------------------------------!
#IF(SUB(%NFileOpt1,1,1)='N')
#CYCLE
#ENDIF
#!
#CASE(%FileType)
#OF ('VIEW')
#OROF('ALIAS')
#CYCLE
#ENDCASE
#!
#CASE(%FileDriver)
#OF('ASCII')
#OROF('BASIC')
#OROF('DOS')
#CYCLE
#ENDCASE
#!
#IF(%AllTables = 0)
#FIND(%InclTable,%File)
#IF(%InclTable = '')
#CYCLE
#ENDIF
#ENDIF
#!
#MESSAGE('Table of: ' & %File,2) #! RAS.2001.12.15
#SET(%TableCount, %TableCount + 1)
#SET(%NFieldPKey,UPPER(%FilePrefix) & '_PK') #! PK Naming Convention
#!
#SET(%NFileName,%File) #! This is the name
#IF(%UsePrefix) #! RAS.2001.12.01
#SET(%NFileName,%FilePrefix & '_' & %File) #! RAS.2001.10.24
#ENDIF #! RAS.2001.12.01
#IF(%AdjustReservedWords) #! RAS.2006.03.08
#SET(%SqlWordItem, UPPER(%NFileName)) #! Set up search of
#FIND(%SqlWordList, %SqlWordItem) #! SQL reserved words
#IF(%SqlWordList) #! Found? Yes! We add
#ADD(%ReservedFieldList, %FoundFileName & %NFileName) #! RAS.2001.12.01
#SET(%NFileName, %NFileName & '_') #! trailing underscore
#ENDIF #! to get it through
#ENDIF #! RAS.2006.03.08
#IF(%DoComments)
--
-- File: %File(%FilePrefix) - %FileDescription
#ENDIF
#!------------------------------------------------------------------------!
#! RAS.2002.06.09 - Adjust logic to differentiate front end / back end. !
#! IF it IS a primary key, AND it is an integer, AND NOT auto-increment, !
#! AND there is one item in the key (only thing I can be sure about), !
#! THEN assume that it IS an auto-increment handled by the MYSQL backend. !
#!------------------------------------------------------------------------!
#! RAS.2001.09.09 - Process key to detect posible field containing the !
#! auto-increment attribute. Document here and add to line later. !
#!------------------------------------------------------------------------!
#SET(%NFNameAuto,'')
#SET(%AutoIncrementCount,0)
#IF(ITEMS(%Key))
#FOR(%Key)
#IF(%KeyAuto)
#SET(%AutoIncrementCount,%AutoIncrementCount + 1) #! RAS.2001.09.15
#SET(%AutoCount, %AutoCount + 1) #! RAS.2001.09.10
#!
#! #SET(%NFNameAuto, SUB(%KeyAuto, INSTRING(':',%KeyAuto,1,1) + 1 , 50))
#! #IF(%UsePrefixKeys) #! RAS.2006.03.08
#! #SET(%NFNameAuto, %FilePrefix & '_' & %NFNameAuto) #! RAS.2001.10.24
#! #ENDIF #! RAS.2001.12.01
#! #IF(%AdjustReservedWords) #! RAS.2006.03.08
#! #SET(%SqlWordItem, UPPER(%NFNameAuto)) #! Set up search of
#! #FIND(%SqlWordList, %SqlWordItem) #! SQL reserved words
#! #IF(%SqlWordList) #! Found? Yes! We add
#! #ADD(%ReservedFieldList, %FoundAIKeyName & %FilePrefix & ':' & %NFNameAuto)
#! #SET(%NFNameAuto, %NFNameAuto & '_') #! trailing underscore
#! #ENDIF #! to get it through
#! #ENDIF #! RAS.2006.03.08
#!
#IF(%DoComments)
#!------------------------------------------------!
#!------------------------------------------------!
#! RAS.2002.07.09 - Documentation has to happen. !
#! And the change in logic and commented out code !
#! killed part of the documention. Now corrected. !
#!------------------------------------------------!
#SET(%NFNameAutoDoc, SUB(%KeyAuto, INSTRING(':',%KeyAuto,1,1) + 1 , 50))
#IF(%UsePrefix)
#SET(%NFNameAutoDoc, %FilePrefix & '_' & %NFNameAutoDoc)
#ENDIF
#IF(%AdjustReservedWords) #! RAS.2006.03.08
#SET(%SqlWordItem, UPPER(%NFNameAutoDoc))
#FIND(%SqlWordList, %SqlWordItem)
#IF(%SqlWordList)
#ADD(%ReservedFieldList, %FoundAIKeyName & %FilePrefix & ':' & %NFNameAutoDoc)
#SET(%NFNameAutoDoc, %NFNameAutoDoc & '_')
#ENDIF
#ENDIF #! RAS.2006.03.08
#IF(%KeyPrimary)
-- Auto: %NFNameAutoDoc (PRIMARY KEY)
-- Auto: Defined in the data dictionary for clarion to handle
#ELSE
-- Auto: %NFNameAutoDoc (NOT A PRIMARY KEY)
-- Auto: Defined in the data dictionary for clarion to handle
#ENDIF
#!------------------------------------------------!
#!------------------------------------------------!
#ENDIF
#!-----------------------------------------------------------------------------!
#! RAS.2002.06.09 - The key is not an auto-increment in the data dictionary. !
#! If the key is primary and the item count is a 1, and the item is a long, !
#! Then assume that this is an auto-increment for the back end. !
#!-----------------------------------------------------------------------------!
#ELSE
#IF(%KeyPrimary)
#IF(ITEMS(%KeyField) > 1)
#CYCLE
#ENDIF
#FOR(%KeyField)
#FIX(%Field,%KeyField)
#CASE(%FieldType)
#OF('LONG')
#SET(%NFNameAuto, SUB(%KeyField, INSTRING(':',%KeyField,1,1) + 1 , 50))
#ENDCASE
#ENDFOR
#IF(%NFNameAuto)
#SET(%AutoIncrementCount,%AutoIncrementCount + 1)
#SET(%AutoCount, %AutoCount + 1)
#IF(%UsePrefix)
#SET(%NFNameAuto, %FilePrefix & '_' & %NFNameAuto)
#ENDIF
#IF(%AdjustReservedWords) #! RAS.2006.03.08
#SET(%SqlWordItem, UPPER(%NFNameAuto))
#FIND(%SqlWordList, %SqlWordItem)
#IF(%SqlWordList)
#ADD(%ReservedFieldList, %FoundAIKeyName & %FilePrefix & ':' & %NFNameAuto)
#SET(%NFNameAuto, %NFNameAuto & '_')
#ENDIF
#ENDIF #! RAS.2006.03.08
#IF(%DoComments)
-- Auto: %NFNameAuto (PRIMARY KEY)
-- Auto: Defined in the backend SQL engine and not handled by clarion
#ENDIF
#ELSE
#!----------------------------------------------------------------------!
#! RAS.2002.07.09 - Check to see if the field is defined auto-increment !
#! by the options in the field. This corrects the warning message that !
#! shows up when you set up primary keys by field options on special !
#! types of fields (ex: INT8). This also documents when necessary. !
#!----------------------------------------------------------------------!
#FOR(%KeyField)
#FIX(%Field,%KeyField)
#SET(%nLoc1,INSTRING('RASQL(',%FieldUserOptions,1,1))
#SET(%nLoc2,INSTRING(')',%FieldUserOptions,1,%nLoc1))
#SET(%nFieldUser,UPPER(SUB(%FieldUserOptions,%nLoc1,%nLoc2)))
#!SET(%NFieldUser,UPPER(EXTRACT(%FieldUserOptions,'RASQL')))
#SET(%NFieldOpt1,EXTRACT(%NFieldUser,'RASQL',1))
#SET(%NFieldOpt2,EXTRACT(%NFieldUser,'RASQL',2))
#SET(%NFieldOpt3,EXTRACT(%NFieldUser,'RASQL',3))
#SET(%NFieldOpt4,EXTRACT(%NFieldUser,'RASQL',4))
#IF(%NFieldOpt3)
#IF(INSTRING('PKEYA',%NFieldOpt3,1,1))
#!
#SET(%AutoIncrementCount,%AutoIncrementCount + 1)
#SET(%AutoCount, %AutoCount + 1)
#!
#IF(%DoComments)
#SET(%NFNameAutoDoc, SUB(%KeyField, INSTRING(':',%KeyField,1,1) + 1 , 50))
#IF(%UsePrefixKeys) #! RAS.2006.03.08
#SET(%NFNameAutoDoc, %FilePrefix & '_' & %NFNameAutoDoc)
#ENDIF
#IF(%AdjustReservedWords) #! RAS.2006.03.08
#SET(%SqlWordItem, UPPER(%NFNameAutoDoc))
#FIND(%SqlWordList, %SqlWordItem)
#IF(%SqlWordList)
#ADD(%ReservedFieldList, %FoundAIKeyName & %FilePrefix & ':' & %NFNameAutoDoc)
#SET(%NFNameAutoDoc, %NFNameAutoDoc & '_')
#ENDIF
#ENDIF #! RAS.2006.03.08
-- Auto: %NFNameAutoDoc (PRIMARY KEY - FIELD OPTION)
-- Auto: Defined in the backend SQL engine and not handled by clarion
#ENDIF
#ENDIF
#ENDIF
#ENDFOR
#!----------------------------------------------------------------------!
#ENDIF
#ENDIF
#ENDIF
#ENDFOR
#!
#IF(%AutoIncrementCount = 0)
-- WARNING: %File(%FilePrefix) has no AUTO-INCREMENT KEY defined.
#ENDIF
#ENDIF
#!
#IF(%DoComments)
--
#ENDIF
#FOR(%Field)
#SET(%nLoc1,INSTRING('RASQL(',%FieldUserOptions,1,1))
#SET(%nLoc2,INSTRING(')',%FieldUserOptions,1,%nLoc1))
#SET(%nFieldUser,UPPER(SUB(%FieldUserOptions,%nLoc1,%nLoc2)))
#!SET(%NFieldUser,UPPER(EXTRACT(%FieldUserOptions,'RASQL')))
#SET(%NFieldOpt1,EXTRACT(%NFieldUser,'RASQL',1))
#SET(%NFieldOpt2,EXTRACT(%NFieldUser,'RASQL',2))
#SET(%NFieldOpt3,EXTRACT(%NFieldUser,'RASQL',3))
#SET(%NFieldOpt4,EXTRACT(%NFieldUser,'RASQL',4))
#IF(SUB(%NFieldOpt1,1,1)='N')
#CYCLE
#ENDIF
#CASE(%FieldType)
#OF ('GROUP')
#OROF('END')
#CYCLE
#ENDCASE
#IF(%DoComments)
#SET(%DocVar, SUB(%Field, INSTRING(':',%Field,1,1) + 1 , 50))
-- %[34]DocVar %[11]FieldType %FieldDescription
#ENDIF
#!----------------------------------------------------------------------------------!
#! RAS.2001.09.09 - Show values if an INLIST or BOOLEAN type of validation. !
#! If the designer decides to change the type of variable he/she is going to store !
#! these values in the database, it will be usefull to have these values documented !
#! somewhere. This is as good a place as any. !
#!----------------------------------------------------------------------------------!
#IF(%DoComments)
#IF(%FieldValidation)
#CASE(%FieldValidation)
#OF ('NONZERO')
#OF ('INRANGE')
#OF ('BOOLEAN')
-- TRUE: %FieldTrueValue
-- FALSE: %FieldFalseValue
#OF ('INLIST')
#IF(ITEMS(%FieldChoices))
#FOR(%FieldChoices)
-- Field Choices: %FieldChoices
#ENDFOR
#ENDIF
#IF(ITEMS(%FieldValues))
#FOR(%FieldValues)
-- Field Values: %FieldValues
#ENDFOR
#ENDIF
#OF ('INFILE')
#ENDCASE
#ENDIF
#ENDIF
#ENDFOR
#IF(%DoComments)
--
#ENDIF
#!
#IF(%DropTable)
DROP TABLE IF EXISTS %NFileName ;
#ENDIF
#IF(%CreateTable) #! RAS.2005.03.31 - Create Table?
CREATE TABLE %NFileName (
#INSERT(%MySqlField) #! Process fields
)
#!COMMENT = '%FileDescription' #! Works and commented out
#!------------------------------------------------!
#! Deal with the different type of internal files !
#! available for the MySQL database. !
#!------------------------------------------------!
#SET(%NFileType,'') #! TYPE=???
#IF(%NFileOpt2)
#CASE(%NFileOpt2)
#OF ('ISAM')
#OROF('MYISAM')
#OROF('HEAP')
#OROF('MERGE')
#OROF('DBD')
#OROF('GEMINI') #! RAS.2001.07.22
#OROF('INNODB') #! RAS.2001.10.17
#OROF('MRG_MYISAM') #! RAS.2001.10.24
#SET(%NFileType, 'TYPE = ' & %NFileOpt2)
#ENDCASE
#ENDIF
#!---------------------------------------------!
#! Deal with the different type of row_formats !
#! available for the MySQL database. !
#!---------------------------------------------!
#SET(%NFileRowFormat,'') #! ROW_FORMAT=???
#IF(%NFileOpt3)
#CASE(%NFileOpt3)
#OF ('DEFAULT')
#OROF('DYNAMIC')
#OROF('STATIC')
#OROF('COMPRESSED')
#SET(%NFileRowFormat, 'ROW_FORMAT = ' & %NFileOpt3)
#ENDCASE
#ENDIF
#!----------------------------------------!
#! Dump all the extra table option lines. !
#!----------------------------------------!
#IF(%NFileType) #! TYPE=???
%NFileType
#ENDIF
#IF(%NFileRowFormat) #! ROW_FORMAT=???
%NFileRowFormat
#ENDIF
#IF(%DirData) #! RAS.2004.12.06
DATA DIRECTORY = '%DirDataWhere'
#ENDIF
#IF(%DirIndex) #! RAS.2004.12.06
INDEX DIRECTORY = '%DirIndexWhere'
#ENDIF
;
#ENDIF #! RAS.2005.03.31 - Create Table?
#!-----------------------------!
#! RA.2008.06.06 - UTF8 option !
#!-----------------------------!
#IF(%DoUTF8Alter)
ALTER TABLE %NFileName CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci
;
#ENDIF
#!--------------------!
#! Dump the keys here !
#!--------------------!
#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
#!
#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
#!
#SET(%NKeyName,%KeyID)
#IF(%UsePrefixKeys) #! RAS.2006.03.08
#SET(%NKeyName,%FilePrefix & '_' & %KeyID) #! RAS.2001.10.24
#ENDIF #! RAS.2001.12.01
#!---------------------------------------------------!
#! RAS.2005.04.02 - Process external key names here. !
#!---------------------------------------------------!
#SET(%NKeyExternal,EXTRACT(%KeyStatement,'NAME',1))
#!-- NKeyExternal = %NKeyExternal
#IF(%NKeyExternal<>'')
#SET(%NKeyExternal,SUB(%NKeyExternal, 2, LEN(%NKeyExternal) - 2))
#SET(%NKeyName, %NKeyExternal) #! Key Name from External
#ENDIF
#!
#IF(%AdjustReservedWords) #! RAS.2006.03.08
#SET(%SqlWordItem, UPPER(%NKeyName)) #! Set up search of
#FIND(%SqlWordList, %SqlWordItem) #! SQL reserved words
#IF(%SqlWordList) #! Found? Yes! We add
#ADD(%ReservedFieldList, %FoundKeyName & %FilePrefix & ':' & %NKeyName)
#SET(%NKeyName, %NKeyName & '_') #! trailing underscore
#ENDIF #! to get it through
#ENDIF #! RAS.2006.03.08
#!
#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) #! RAS.2001.12.15
#ADD(%FieldTableList, %NKeyField & ' ==> ' & %File) #! RAS.2001.12.15
#ENDIF #! RAS.2001.12.15
#!
#IF(%UsePrefix) #! RAS.2001.12.01
#SET(%NKeyField, %FilePrefix & '_' & %NKeyField)
#ENDIF #! RAS.2001.12.01
#IF(%AdjustReservedWords) #! RAS.2006.03.08
#SET(%SqlWordItem, UPPER(%NKeyField)) #! Set up search of
#!-- SqlWordItem = '%SqlWordItem'
#FIND(%SqlWordList, %SqlWordItem) #! SQL reserved words
#!-- SqlWordList = '%SqlWordList'
#IF(%SqlWordList) #! Found? Yes! We add
#ADD(%ReservedFieldList, %FoundKeyField & %FilePrefix & ':' & %NKeyField)
#SET(%NKeyField, %NKeyField & '_') #! trailing underscore
#ENDIF #! to get it through
#ENDIF #! RAS.2006.03.08
#SET(%NKeyFieldCount,%NKeyFieldCount + 1 )
#IF(%NKeyFieldCount = 1)
#SET(%NKeyFields,%NKeyField)
#ELSE
#SET(%NKeyFields, %NKeyFields & ', ' & %NKeyField)
#ENDIF
#!------------------------------------------------------!
#! The dictionary has ASCENDING and DESCENDING defined. !
#! Tried adding the keywords bellow and it parsed okay. !
#! It does nothing (not part of SQL) and was taken out. !
#!------------------------------------------------------!
#!#IF(SUB(%KeyFieldSequence,1,1)='A')
#! #SET(%NKeyFields,%NKeyFields & ' ASC')
#!#ELSE
#! #SET(%NKeyFields,%NKeyFields & ' DESC')
#!#ENDIF
#ENDFOR
#!
#IF(%KeyPrimary)
#!----------------------------------------------------------!
#! This option being OFF allows you to create PRIMARY KEY's !
#! that are AUTO_INCREMENTED at the field level. !
#!----------------------------------------------------------!
#IF(%CreatePrimary)
#SET(%PrimaryCount, 1)
#SET(%PKeyCount, %PKeyCount + 1)
#SET(%KeyCount, %KeyCount + 1)
#!--------------------------------------------------------------------!
#! RAS.2001.10.02 - If a PRIMARY KEY AUTO_INCREMENT is defined do not !
#! create a PRIMARY KEY here since mySQL will complain in a bad way. !
#! You know that one will be defined at the field level if NFNameAuto !
#! contains the name of a field. !
#!--------------------------------------------------------------------!
#IF(%NFNameAuto='')
#IF(%DoComments)
--
-- Key: %KeyID(%FilePrefix) - %KeyDescription
#CASE(%NKeyOpt2)
#OF ('PKEYA')
-- Dsc: Primary key for definition of constraints
#OF ('SKEYA')
-- Dsc: Secondary key for lookup of primary key value
#ENDCASE
--
#FOR(%KeyField)
#SET(%DocVar, SUB(%KeyField, INSTRING(':',%KeyField,1,1) + 1 , 50))
-- %[34]DocVar %KeyFieldSequence
#ENDFOR
--
#ENDIF
ALTER TABLE %NFileName ADD
CONSTRAINT %NKeyName
PRIMARY KEY (%NKeyFields)
;
#ENDIF
#ENDIF
#ELSIF(NOT %KeyPrimary)
#SET(%KeyOthers, %KeyOthers + 1)
#SET(%KeyCount, %KeyCount + 1)
#IF(%KeyDuplicate)
#IF(%DoComments)
--
-- Key: %KeyID(%FilePrefix) - %KeyDescription
#CASE(%NKeyOpt2)
#OF ('PKEYA')
-- Dsc: Primary key for definition of constraints
#OF ('SKEYA')
-- Dsc: Secondary key for lookup of primary key value
#ENDCASE
--
#FOR(%KeyField)
#SET(%DocVar, SUB(%KeyField, INSTRING(':',%KeyField,1,1) + 1 , 50))
-- %[34]DocVar %KeyFieldSequence
#ENDFOR
--
#ENDIF
#CASE(%KeyIndex)
#OF ('KEY')
#IF(%CreateSecondary) #! RAS.2005.03.31 - Create secondary index?
ALTER TABLE %NFileName ADD
KEY %NKeyName
(%NKeyFields)
;
#ENDIF #! RAS.2005.03.31 - Create secondary index?
#OF ('INDEX')
#OROF('DYNAMIC')
#IF(%CreateSecondary) #! RAS.2005.03.31 - Create secondary index?
ALTER TABLE %NFileName ADD
INDEX %NKeyName
(%NKeyFields)
;
#ENDIF #! RAS.2005.03.31 - Create secondary index?
#ENDCASE
#ELSE
#IF(%DoComments)
--
-- Key: %KeyID(%FilePrefix) - %KeyDescription
#CASE(%NKeyOpt2)
#OF ('PKEYA')
-- Dsc: Primary key for definition of constraints
#OF ('SKEYA')
-- Dsc: Secondary key for lookup of primary key value
#ENDCASE
--
#FOR(%KeyField)
#SET(%DocVar, SUB(%KeyField, INSTRING(':',%KeyField,1,1) + 1 , 50))
-- %[34]DocVar %KeyFieldSequence
#ENDFOR
--
#ENDIF
#CASE(%KeyIndex)
#OF ('KEY')
#IF(%CreateSecondary) #! RAS.2005.03.31 - Create secondary index?
ALTER TABLE %NFileName ADD
UNIQUE %NKeyName
(%NKeyFields)
;
#ENDIF #! RAS.2005.03.31 - Create secondary index?
#OF ('INDEX')
#OROF('DYNAMIC')
#IF(%CreateSecondary) #! RAS.2005.03.31 - Create secondary index?
ALTER TABLE %NFileName ADD
UNIQUE INDEX %NKeyName
(%NKeyFields)
;
#ENDIF #! RAS.2005.03.31 - Create secondary index?
#ENDCASE
#ENDIF
#ENDIF
#ENDFOR
#IF(%CreatePrimary)
#IF(NOT %PrimaryCount)
--
-- WARNING: %File(%FilePrefix) has no PRIMARY KEY defined.
--
#ENDIF
#ENDIF
#ELSE
--
-- WARNING: %File(%FilePrefix) has no KEYS defined.
--
#ENDIF
#ENDFOR
#!-------------------------!
#! Dump the relations here !