-
Notifications
You must be signed in to change notification settings - Fork 1
/
D2_99_JKRFB.tpw
3620 lines (3485 loc) · 127 KB
/
D2_99_JKRFB.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
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!---------------------------------------------------------------------
#!
#! This template was adapted from a SQL template by G W Bomford
#! Roberto Artigas Jr's template for Reserved words is used with his requirements
#! Since I modified it I have used my initials in the declared data so as not to discredit
#! G W Bomford OR Roberto Artigas Jr for my mistakes
#!
#! The person who modified this for Firebird - Jimmy Rogers - may be contacted by email at [email protected]
#! An article on Clarion Mag explains the template in more detail. 'Migrating your Topseed Application to Firebird'
#!
#! No warranty of any kind is expressed, or implied, the template is used at your own risk.
#!
#! INSTRUCTIONS
#!
#! 1. a conversion set
#! step 1 template - old way was to create from a topspeed dictionary and place into an incude file. this should be generic.
#! step 4 template - create a separate conversion file for each table pair and converts from topseed tables to firebird odbc tables.
#!
#! 2 step 2 template - create the firebird scripts from the topspeed dictionary, using the external name for columns with one
#! a. I created many different scripts for firebird. triggers, generators, all keys from the dictionary sp's and all
#! had both drop and create in same script. allowing pick your own.
#!
#! 3 step 3 template - modify the txd of your dictionary to get it ready for odbc.
#! a. this was done mainly because i had existing apps to convert and did not want to import the script created firebird
#! tables into a dictionary and break my app.
#! b. this adds reserved word columns to the external name, changing from a rule(same as scrip would do) for that column only
#! c. changes driver to odbc
#! d. add external names to keys with the table ext
#! e. changed memo to the firebird string to match what the script created for firebird.
#! f. adds owner variable
#! g. adds table name to full path. this is for firebird and can be modified for all odbc requirments.
#!
#! all i can think of for now.
#!
#! jimmy rogers
#!
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#UTILITY (JKR_FirebirdTemplateStep1, 'Step 1 - Generate topspeed table structures into an include file'), WIZARD
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#SHEET
#TAB('Page 1 0f 1 To Save Topspeed Table Structures'),FINISH(1)
#DISPLAY('This Utility will write out all the topspeed table structures into an include file.')
#DISPLAY('These structures are used for the converson of your tps to ODBC tables.')
#DISPLAY('The name of the include file is TpsToOdbc.Inc.')
#DISPLAY('We write out the converson files after the dictionary has been changed to ODBC.')
#DISPLAY()
#DISPLAY('Its best to do this on your topspeed dictionary that you will not change and')
#DISPLAY('is in a different location than the conversion in Step 4.')
#DISPLAY()
#DISPLAY('A sub-directory off the App directory named... ''\convert'' is required for the convert files.')
#DISPLAY('The TpsToOdbc.Inc needs to be in the \Convert folder for Step 4.')
#DISPLAY('Remember after you run this it will be saved to the directory where your are now.')
#DISPLAY()
#DISPLAY('The DLL and Lib file will need to be in your convert folder when compiling the conversion files')
#DISPLAY('if you use the Data Dll conversion method.')
#DISPLAY()
#DISPLAY('Step 2 writes the script files.')
#DISPLAY('Step 3 changes a txd to ODBC etc.. for import into a new dictionary.')
#DISPLAY('Step 4 writes the conversion files.')
#DISPLAY()
#DISPLAY('REQUIREMENTS')
#DISPLAY('A. CHANGES TO DICTIONARY')
#DISPLAY(' 1. YOU CANNOT MAKE CHANGES TO THE COLUMN NAMES. ONLY THE EXTERNAL NAME.')
#DISPLAY(' 2. YOU CANNOT ADD COLUMN NAMES UNTIL AFTER THE CONVERSION.')
#DISPLAY(' 3. WE NEED AN EXACT MATCH FOR THE CONVERSION.')
#DISPLAY()
#DISPLAY('B. DICTIONARY TO USE FOR THIS TEMPLATE')
#DISPLAY(' 1. MAKE SURE YOU USE YOUR DATADLL APP OR YOUR SINGLE EXE APP.')
#DISPLAY()
#DISPLAY('C. SOMETIMES ITS GOOD TO SHOUT')
#DISPLAY()
#ENDTAB
#ENDSHEET
#!
#!
#DECLARE(%ASCIIFileRecord)
#DECLARE(%InstancePrefix)
#DECLARE(%InstanceQueue),MULTI
#DECLARE(%OutputFile)
#DECLARE (%CurrentPath)
#DECLARE (%JKRCounter)
#DECLARE (%FileStructure)
#!
#MESSAGE('Creating Topseed Convertion Files',1)
#! Set to current path
#! Set the current path to '\Scripts\'
#LOOP
#SET (%JKRCounter, INSTRING('\',%DictionaryFile,1,%JKRCounter+1))
#IF (%JKRCounter)
#SET (%CurrentPath,SUB(%DictionaryFile,1,%JKRCounter))
#ELSE
#BREAK
#ENDIF
#ENDLOOP
#SET (%OutputFile, %CurrentPath & 'TpsToOdbc.Inc')
#CREATE(%OutputFile)
File structures for the topspeed files that will imported into the ODBC conversion files
#FOR (%File), WHERE (%FileDriver = 'TOPSPEED' AND %FileType = 'FILE' AND NOT INSTRING('LOCALFILE',UPPER(%FileUserOptions),1,1 ) )
[[%File]]
#IF(%FileOwner)
FileOwner=1
#IF(Sub(%FileOwner,1,1) = '''')
FileOwnerIsAVariable=0
#else
FileOwnerIsAVariable=1
#Endif
#ELSE
FileOwner=0
#Endif
#IF(%FileName)
FileName=1
#IF(Sub(%FileName,1,1) = '''')
FileNameIsAVariable=0
#else
FileNameIsAVariable=1
#Endif
#ELSE
FileName=0
#Endif
#!
#SET(%FileStructure,' FILE,DRIVER(''TOPSPEED''),PRE(' & %FilePrefix & ')' )
#!
#IF(%FileOwner)
#IF(Sub(%FileOwner,1,1) = '''')
#! found ' on FileOwner ist char of %FileOwner
#SET(%FileStructure,%FileStructure & ',OWNER(' & %FileOwner & ')' )
#else
#! found ! on FileOwner ist char of %FileOwner
#SET(%FileStructure,%FileStructure & ',OWNER(FileOwnerPassword)' )
#Endif
#Endif
#!
#IF(%FileName)
#IF(Sub(%FileName,1,1) = '''')
#! found ' on FileName ist char of %FileName
#SET(%FileStructure,%FileStructure & ',NAME(' & %FileName & ')' )
#else
#! found ! on FileName ist char of %FileName
#SET(%FileStructure,%FileStructure & ',NAME(FullPathName)' )
#Endif
#ELSE
#SET(%FileStructure,%FileStructure & ',NAME(FullPathName)' )
#Endif
#!
%[20]File %FileStructure
#FOR (%Key) #! %KeyIndex Contains KEY, INDEX, or DYNAMIC
%KeyStruct
#ENDFOR
#FOR (%Field), WHERE(%FieldType = 'MEMO')
%FieldStruct
#ENDFOR
#FOR (%Field), WHERE(%FieldType = 'BLOB')
%FieldStruct
#ENDFOR
%FileStructRec,PRE()
#FOR (%Field), WHERE(%FieldType <> 'MEMO' AND %FieldType <> 'BLOB')
%FieldStruct
#ENDFOR
%FileStructRecEnd
%FileStructEnd
#ENDFOR
#CLOSE(%OutputFile)
#!
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#UTILITY (JKR_FirebirdTemplateStep2, 'Step 2 - Scripts - Generate Firebird SQL Scripts from Topeed or ODBC tables'), WIZARD
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#! This template was adapted from a SQL template by G W Bomford
#!-----------------------------------------------
#SHEET
#TAB('Page 1 0f 5'),FINISH(0)
#BOXED('Generating Firebird SQL Scripts')
#DISPLAY()
#DISPLAY('MAKE BACKUP COPIES OF YOUR DICTIONARY.')
#DISPLAY()
#DISPLAY('*** The ''\SCRIPTS\'' Sub-Directory MUST exist! ***')
#DISPLAY()
#DISPLAY('See next Tab for steps to follow.')
#DISPLAY()
#DISPLAY('Select the Topspeed or ODBC tables to generate SQL scripts or leave blank to generate for all tables.')
#DISPLAY()
#DISPLAY('IF YOU CREATE AND OPTION CALLED LocalFile FOR A TABLE NO SCRIPT IS CREATED.')
#DISPLAY('The USEROPTIONS are checked for LOCALFILE and this table is skipped if found.')
#DISPLAY()
#DISPLAY(' Leave Blank to Select ALL Topspeed or ODBC Tables')
#PROMPT('Select Tables for SQL Script',FILE),%JKRSelectedFiles,SELECTION('Tables - Leave Blank to Select ALL TPS or ODBC Tables'),INLINE,AT(10)
#DISPLAY()
#ENDBOXED
#ENDTAB
#TAB('Page 2 0f 5'),FINISH(0)
#BOXED('Conditions when creating Firebird scripts')
#DISPLAY()
#DISPLAY('Name of the SQL file that is created for errors - SqlErrors.Txt:')
#DISPLAY()
#PROMPT('Check for conditions below and if found cancel writing script files?',CHECK),%JKRCheckForValidFieldNames,DEFAULT(1),AT(10)
#DISPLAY()
#DISPLAY('Conditions Checked')
#DISPLAY('1. Reserved words are not allowed - use EXTERNAL NAME to correct.')
#DISPLAY('2. EXTERNAL NAMES are checked for UPPERCASE.')
#DISPLAY('3. Field Names > 27 Characters. Maximum in Firebird for object names is 31.')
#DISPLAY('4. No primary key in a table in the dictionary is not allowed. It will cause errors at runtime.')
#DISPLAY('** Template ASSUMES a string Boolean value has no '' on say the Y N or a T F and adds them.')
#DISPLAY(' This is NOT allowed ''Y'' but this is Y. The Initial Value entered value must have '' around it.')
#DISPLAY()
#DISPLAY('The dictionary changes are described in Step 3.')
#DISPLAY('Step 3 makes changes in a txd file for import into a new dictionary.')
#DISPLAY('Always use the check box that prints a report of any found problems.')
#DISPLAY('Keep using this until you have no more problems in the dictionary.')
#DISPLAY()
#DISPLAY('Remember that if you want your scripts to allow an existing application to work for testing')
#DISPLAY('then you want the column and file names to match with the dictionary.')
#DISPLAY('Use the external name attribute on your columns or let this template do it for you.')
#ENDBOXED
#ENDTAB
#TAB('Page 3 of 5'),FINISH(0)
#BOXED('Conversion Settings')
#DISPLAY()
#DISPLAY('Be consistant with the next 2 column Date and Time types.')
#DISPLAY('If you do not change them to a Date and Time type in the Firebird Script')
#DISPLAY('then do not change them in Step 3 that changes the TXD.')
#DISPLAY()
#PROMPT ('Change All LONGs With @D To DATE field type',check),%JKRChangeDateNames,DEFAULT(0),AT(10)
#PROMPT ('Change All LONGs With @T To TIME field type',check),%JKRChangeTimeNames,DEFAULT(0),AT(10)
#DISPLAY()
#DISPLAY('Be consistant with the next column type change.')
#DISPLAY('If you do not change them to a BLOB type in the Firebird Script')
#DISPLAY('then do not change them in Step 3 that changes the TXD.')
#DISPLAY()
#PROMPT ('Make STRING CSTRING PSTRING above this size a BLOB for text',check),%JKRChangeStringTypesToBlob,DEFAULT(0),AT(10)
#ENABLE(%JKRChangeStringTypesToBlob = 1),CLEAR
#DISPLAY('Example: 2000 makes any of these strings that are 2000 or more in size into BLOBS')
#DISPLAY('Enter a number or uncheck the box')
#PROMPT ('',@N5),%JKRChangeStringTypesToBlobSize,DEFAULT(0),AT(10)
#ENDENABLE
#DISPLAY()
#ENDBOXED
#ENDTAB
#TAB('Page 4 of 5'),FINISH(0)
#BOXED('Initial Values And Validity Checks')
#DISPLAY()
#DISPLAY('Initial Values And Validity Checks in the dictionary can cause problems when creating scripts')
#DISPLAY('This could cause problems in your inported scripts if your column Initial Values do not work in Firebird')
#DISPLAY('Validity Checks in the dictionary can cause problems when converting your data and also')
#DISPLAY('when your program does not assign the value the same.')
#DISPLAY('If Cannot Be Zero Or Blank is set it is always written into the scripts ')
#DISPLAY()
#DISPLAY('Use the Report for Initial Values and Validity Checks to see what you have before')
#DISPLAY('creating scripts.')
#DISPLAY()
#PROMPT ('Do not use Initial Value from dictionary column to create a default for the script column',check),%JKRNoDefaults,DEFAULT(1),AT(10)
#ENABLE(%JKRNoDefaults = 0),CLEAR
#DISPLAY()
#PROMPT ('Do not use Validity Checks from dictionary column to create a check constraint for the script column',check),%JKRFieldValidation,DEFAULT(1),AT(10)
#DISPLAY()
#DISPLAY('Initial Value=Default')
#DISPLAY('Example: Today()=''NOW'' ')
#DISPLAY('Example: Cus:No=CUSNO')
#DISPLAY('Next example has an empty default so one is not created and = is required')
#DISPLAY('Example: MONTH(TODAY())=')
#DISPLAY('Enter the dictionary value = and the Firebird value')
#DISPLAY('The scripts will get the right side value if the left side value is found.')
#DISPLAY('The scripts will get all other entered Initial Values.')
#PROMPT ('Initial Values',@S40),%JKRInitialValueList,MULTI('Change this initial value to this'),INLINE
#ENDENABLE
#DISPLAY()
#ENDBOXED
#ENDTAB
#TAB('Page 5 of 5'),FINISH(1)
#BOXED('Firebird Conversion Notes')
#DISPLAY()
#DISPLAY('SCRIPTS ARE ONLY GENERATED FOR TOPSPEED AND ODBC TABLES!')
#DISPLAY()
#DISPLAY('The following rules are used for creating Firebird scripts.')
#DISPLAY('BLOB -> BLOB SUB_TYPE 0 SEGMENT SIZE 80')
#DISPLAY('BYTE -> SMALLINT')
#DISPLAY('CSTRING/PSTRING -> VARCHAR')
#DISPLAY('DECIMAL/FLOAT -> DECIMAL')
#DISPLAY('LONG/ULONG -> INTEGER')
#DISPLAY('MEMO -> BLOB SUB_TYPE TEXT SEGMENT SIZE 80')
#DISPLAY('SHORT/USHORT/BYTE -> SMALLINT')
#DISPLAY('SREAL/BFLOAT4 -> FLOAT')
#DISPLAY('REAL/BFLOAT8 -> DOUBLE PRECISION')
#DISPLAY('STRING -> CHAR')
#DISPLAY()
#DISPLAY('STRING/CSTRING/PSTRING size over the template setting')
#DISPLAY('-> BLOB SUB_TYPE TEXT SEGMENT SIZE 80')
#DISPLAY()
#DISPLAY('STRING/CSTRING/PSTRING over 32765')
#DISPLAY('-> BLOB SUB_TYPE TEXT SEGMENT SIZE 80')
#DISPLAY()
#DISPLAY('''Not Null'' applied to columns marked as NON ZERO and BOOLEAN')
#DISPLAY()
#ENDBOXED
#ENDTAB
#ENDSHEET
#!
#DECLARE (%JKRKeyDescription)
#DECLARE (%FileExternalFlag)
#DECLARE (%FileThreadedFlag)
#DECLARE (%SortedFiles), UNIQUE
#DECLARE (%Groups), MULTI
#DECLARE (%JKRFileName)
#DECLARE (%JKRRelation)
#DECLARE (%JKRKeyName)
#DECLARE (%JKRFieldName)
#DECLARE (%JKRFieldType)
#DECLARE (%JKRShortDataType)
#DECLARE (%JKRHasPrimary)
#DECLARE (%JKRKeyField)
#DECLARE (%JKRCounter)
#DECLARE(%JKRCounterLoc,LONG)
#DECLARE (%JKRUniqueKeys)
#DECLARE (%RelationErrorMessage)
#DECLARE (%ValueConstruct)
#DECLARE (%JKRFileKeyField)
#DECLARE (%JKRFileFieldLink)
#DECLARE (%CurrentPath)
#DECLARE (%OutPutFile)
#DECLARE (%TotalChars)
#!
#DECLARE (%JKRPassedExternalName)
#DECLARE (%JKRFoundReseredWord)
#DECLARE (%JKRChangedReseredWord)
#DECLARE(%JKRAddSpaceCounter)
#DECLARE(%JKRIndexDeclaration)
#!
#DECLARE(%IndexForAllKeyColumns),UNIQUE #! unique so we cannot add one already there
#!
#DECLARE(%JKRLeftSideOfStringLocation)
#DECLARE(%JKRRightSideOfStringLocation)
#DECLARE(%JKRLeftSideOfString)
#DECLARE(%JKRRightSideOfString)
#DECLARE(%JKRFoundLeftSideMatch,LONG)
#!
#MESSAGE('Creating Firebird Scripts',1)
#! Set the current path to '\Scripts\'
#LOOP
#SET (%JKRCounter, INSTRING('\',%DictionaryFile,1,%JKRCounter+1))
#IF (%JKRCounter)
#SET (%CurrentPath,SUB(%DictionaryFile,1,%JKRCounter) & 'Scripts\')
#ELSE
#BREAK
#ENDIF
#ENDLOOP
#!
#SET (%OutputFile, %CurrentPath & 'SqlErrors.Txt')
#!
#IF (%JKRSelectedFiles)
#FOR (%JKRSelectedFiles)
#FIX (%FILE,%JKRSelectedFiles)
#ADD (%SortedFiles, %File)
#ENDFOR
#ELSE
#FOR (%File), WHERE ((%FileDriver = 'TOPSPEED' OR %FileDriver = 'ODBC') AND %FileType = 'FILE' AND NOT INSTRING('LOCALFILE',UPPER(%FileUserOptions),1,1 ) )
#ADD (%SortedFiles, %File)
#ENDFOR
#ENDIF
#!
#CREATE (%OutputFile)
/* JKRSQL.Tpl SQL Script Generated %@D17@(TODAY()) at %@T7@(CLOCK())
Created from definitions in %DictionaryFile
*/
#!
#! added
#!---------------------------------------------------------------------
#INSERT(%ClarionReservedWords)
#INSERT(%SqlReservedWords)
#FOR(%ClarionWordList)
#ADD(%SqlWordList,%ClarionWordList)
#ENDFOR
#!
#! -----------------------------------------------------------------------------------------------
#!
#! Check for Errors in Files and Fields
#IF (%JKRCheckForValidFieldNames = 1)
#INSERT (%JKRCheckNames)
#IF (%JKRCounter > 0)
#CLOSE (%OutputFile)
#ABORT
#ENDIF
#ENDIF
#CLOSE (%OutputFile)
#!
#! If no errors in files and fields we can continue
#!
#SET (%OutputFile, %CurrentPath & 'SqlTablesAndTriggers.Txt')
#!
#CREATE (%OutputFile)
/* JKRSQL.Tpl SQL Script Generated %@D17@(TODAY()) at %@T7@(CLOCK())
Created from definitions in %DictionaryFile
*/
#IF (%JKRCounter = 0)
#FOR (%SortedFiles)
#FIX (%File, %SortedFiles)
#INSERT (%JKRSQLFileDetail,1)
#! #INSERT (%JKRKeyDefinitions)
#INSERT(%JKRGetPrimaryKeyColumn)
#IF (%JKRHasPrimary = 1)
#INSERT (%JKRTriggers,%File, %JKRKeyField)
#ENDIF
#ENDFOR
#!
#CLOSE (%OutputFile)
#!
#! -----------------------------------------------------------------------------------------------
#!
#!
#SET (%OutputFile, %CurrentPath & 'SqlAll.Txt')
#!
#CREATE (%OutputFile)
/* JKRSQL.Tpl SQL Script Generated %@D17@(TODAY()) at %@T7@(CLOCK())
Created from definitions in %DictionaryFile
This includes all these together
1. TableWithoutDrop
2. CreateSingleIndex
3. Index
4. ForeignKeys
5. AutoNoTriggers
6. SPReturnNextAutoNo
*/
#FOR (%SortedFiles)
#FIX (%File, %SortedFiles)
#INSERT (%JKRSQLFileDetail,0)
#! #INSERT (%JKRKeyDefinitions)
#INSERT(%JKRGetPrimaryKeyColumn)
#IF (%JKRHasPrimary = 1)
#INSERT (%JKRTriggers,%File, %JKRKeyField)
#ENDIF
#ENDFOR
#!
#! Create single indexes for all tables
#!
#FOR (%SortedFiles)
#FIX (%File, %SortedFiles)
#INSERT(%JKRMakeSingleIndexFromKeyDefinitions)
#ENDFOR
#!
#! Indexes for all tables
#!
#FOR (%SortedFiles)
#FIX (%File, %SortedFiles)
#INSERT (%JKRKeyDefinitions)
#ENDFOR
#!
#! ForeignKeys for all tables
#!
#FOR (%SortedFiles)
#FIX (%File, %SortedFiles)
#FOR (%Relation)
#INSERT (%JKRForeignKeys)
#ENDFOR
#ENDFOR
#!
#! Auto No Triggers for all tables
#!
#FOR (%SortedFiles)
#FIX (%File, %SortedFiles)
#INSERT(%JKRGetPrimaryKeyColumn)
#IF (%JKRHasPrimary = 1)
#INSERT (%JKRTriggers,%File, %JKRKeyField)
#ENDIF
#ENDFOR
#!
#! Stored procedures that return the next auto no inc on a tables primary key
#!
#FOR (%SortedFiles)
#FIX (%File, %SortedFiles)
#INSERT(%JKRGetPrimaryKeyColumn)
#IF (%JKRHasPrimary = 1)
#INSERT (%JKRGenPrimaryKeySP,%File, %JKRKeyField)
#ENDIF
#ENDFOR
#!
#CLOSE (%OutputFile)
#!
#! -----------------------------------------------------------------------------------------------
#!
#SET (%OutputFile, %CurrentPath & 'TablesWithDrop.SQL')
#CREATE (%OutputFile)
/* JKRSQL.Tpl SQL Script Generated %@D17@(TODAY()) at %@T7@(CLOCK())
Created from definitions in %DictionaryFile
Tables with drop table
*/
#FOR (%SortedFiles)
#FIX (%File, %SortedFiles)
#INSERT (%JKRSQLFileDetail,1)
#ENDFOR
#CLOSE (%OutputFile)
#!
#! -----------------------------------------------------------------------------------------------
#!
#SET (%OutputFile, %CurrentPath & 'TablesWithoutDrop.SQL')
#CREATE (%OutputFile)
/* JKRSQL.Tpl SQL Script Generated %@D17@(TODAY()) at %@T7@(CLOCK())
Created from definitions in %DictionaryFile
Tables without drop table
*/
#FOR (%SortedFiles)
#FIX (%File, %SortedFiles)
#INSERT (%JKRSQLFileDetail,0)
#ENDFOR
#CLOSE (%OutputFile)
#!
#! -----------------------------------------------------------------------------------------------
#!
#SET (%OutputFile, %CurrentPath & 'Indexs.SQL')
#CREATE (%OutputFile)
/* JKRSQL.Tpl SQL Script Generated %@D17@(TODAY()) at %@T7@(CLOCK())
Created from definitions in %DictionaryFile
Indexes for all tables
*/
#!
#FOR (%SortedFiles)
#FIX (%File, %SortedFiles)
#INSERT (%JKRKeyDefinitions)
#ENDFOR
#CLOSE (%OutputFile)
#!
#!
#SET (%OutputFile, %CurrentPath & 'DropIndexs.SQL')
#CREATE (%OutputFile)
/* JKRSQL.Tpl SQL Script Generated %@D17@(TODAY()) at %@T7@(CLOCK())
Created from definitions in %DictionaryFile
Drop Indexes for all tables
*/
#!
#FOR (%SortedFiles)
#FIX (%File, %SortedFiles)
#INSERT (%JKRDropKeyDefinitions)
#ENDFOR
#CLOSE (%OutputFile)
#!
#! -----------------------------------------------------------------------------------------------
#!
#SET (%OutputFile, %CurrentPath & 'ForeignKeys.SQL')
#CREATE (%OutputFile)
/* JKRSQL.Tpl SQL Script Generated %@D17@(TODAY()) at %@T7@(CLOCK())
Created from definitions in %DictionaryFile
Foreign keys
*/
#!
#FOR (%SortedFiles)
#FIX (%File, %SortedFiles)
#FOR (%Relation)
#INSERT (%JKRForeignKeys)
#ENDFOR
#ENDFOR
#CLOSE (%OutputFile)
#!
#! -----------------------------------------------------------------------------------------------
#!
#SET (%OutputFile, %CurrentPath & 'AutoNoTriggers.SQL')
#CREATE (%OutputFile)
/* JKRSQL.Tpl SQL Script Generated %@D17@(TODAY()) at %@T7@(CLOCK())
Created from definitions in %DictionaryFile
Auto No Triggers
*/
#!
#FOR (%SortedFiles)
#FIX (%File, %SortedFiles)
#INSERT(%JKRGetPrimaryKeyColumn)
#IF (%JKRHasPrimary = 1)
#INSERT (%JKRTriggers,%File, %JKRKeyField)
#ENDIF
#ENDFOR
#CLOSE (%OutputFile)
#!
#!
#! -----------------------------------------------------------------------------------------------
#!
#SET (%OutputFile, %CurrentPath & 'AutoNoTriggersWithNullCheck.SQL')
#CREATE (%OutputFile)
/* JKRSQL.Tpl SQL Script Generated %@D17@(TODAY()) at %@T7@(CLOCK())
Created from definitions in %DictionaryFile
Auto No Triggers with null check on the primary column before incrementing
*/
#!
#FOR (%SortedFiles)
#FIX (%File, %SortedFiles)
#INSERT(%JKRGetPrimaryKeyColumn)
#IF (%JKRHasPrimary = 1)
#INSERT (%JKRNullTriggers,%File, %JKRKeyField)
#ENDIF
#ENDFOR
#CLOSE (%OutputFile)
#!
#!
#!
#! -----------------------------------------------------------------------------------------------
#!
#SET (%OutputFile, %CurrentPath & 'SPReturnsNextAutoNo.SQL')
#CREATE (%OutputFile)
/* JKRSQL.Tpl SQL Script Generated %@D17@(TODAY()) at %@T7@(CLOCK())
Created from definitions in %DictionaryFile
Stored procedures that return the next auto no inc on a tables primary key
*/
#!
#FOR (%SortedFiles)
#FIX (%File, %SortedFiles)
#INSERT(%JKRGetPrimaryKeyColumn)
#IF (%JKRHasPrimary = 1)
#INSERT (%JKRGenPrimaryKeySP,%File, %JKRKeyField)
#ENDIF
#ENDFOR
#CLOSE (%OutputFile)
#!
#! -----------------------------------------------------------------------------------------------
#!
#SET (%OutputFile, %CurrentPath & 'Constraints.SQL')
#CREATE (%OutputFile)
/* JKRSQL.Tpl SQL Script Generated %@D17@(TODAY()) at %@T7@(CLOCK())
Created from definitions in %DictionaryFile
Constraints
*/
#!
#FOR (%SortedFiles)
#FIX (%File, %SortedFiles)
#FOR (%Relation)
#INSERT (%JKRConstraints)
#ENDFOR
#ENDFOR
#CLOSE (%OutputFile)
#!
#! -----------------------------------------------------------------------------------------------
#!
#SET (%OutputFile, %CurrentPath & 'NotNullColumns.TXT')
#CREATE (%OutputFile)
/* JKRSQL.Tpl SQL Script Generated %@D17@(TODAY()) at %@T7@(CLOCK())
Created from definitions in %DictionaryFile
All columns declared with NOT NULL condition
Important for conversion purposes
*/
#!
#FOR (%SortedFiles)
#FIX (%File, %SortedFiles)
#FOR (%File)
#INSERT (%JKRNotNullColumns)
#ENDFOR
#ENDFOR
#CLOSE (%OutputFile)
#!
#! -----------------------------------------------------------------------------------------------
#!
#SET (%OutputFile, %CurrentPath & 'DropTables.SQL')
#CREATE (%OutputFile)
/* JKRSQL.Tpl SQL Script Generated %@D17@(TODAY()) at %@T7@(CLOCK())
Created from definitions in %DictionaryFile
Drop table for all tables
*/
#!
#FOR (%SortedFiles)
#FIX (%File, %SortedFiles)
#SET (%JKRFileName, UPPER(%File))
DROP TABLE %JKRFileName;
#ENDFOR
#CLOSE (%OutputFile)
#!
#! -----------------------------------------------------------------------------------------------
#!
#SET (%OutputFile, %CurrentPath & 'CreateSingleIndex.SQL')
#CREATE (%OutputFile)
/* JKRSQL.Tpl SQL Script Generated %@D17@(TODAY()) at %@T7@(CLOCK())
Created from definitions in %DictionaryFile
Create single indexes for all tables
*/
#FOR (%SortedFiles)
#FIX (%File, %SortedFiles)
#INSERT(%JKRMakeSingleIndexFromKeyDefinitions)
#ENDFOR
#CLOSE (%OutputFile)
#!
#! -----------------------------------------------------------------------------------------------
#!
#SET (%OutputFile, %CurrentPath & 'DropSingleIndex.SQL')
#CREATE (%OutputFile)
/* JKRSQL.Tpl SQL Script Generated %@D17@(TODAY()) at %@T7@(CLOCK())
Created from definitions in %DictionaryFile
Drop single indexes for all tables
*/
#FOR (%SortedFiles)
#FIX (%File, %SortedFiles)
#INSERT(%JKRMakeDropSingleIndexFromKeyDefinitions)
#ENDFOR
#CLOSE (%OutputFile)
#ENDIF
#!
#!
#!-----------------------------------------------
#GROUP (%JKRSQLFileDetail,%JKRAddDropTable)
#!-----------------------------------------------
#! Print Dictionary
#!-----------------------------------------------
#!
#IF (%FileDescription)
/* %[23]SortedFiles %FileDescription */
#IF (%FileLongDesc)
#!/* %FileLongDesc */
#ENDIF
#ELSE
/* %SortedFiles*/
#IF (%FileLongDesc)
#!/* %FileLongDesc */
#ENDIF
#ENDIF
#SET (%JKRFileName, UPPER(%File))
#IF(%JKRAddDropTable = 1)
/* Drop the existing table & data if it already exists */
DROP TABLE %JKRFileName;
#ENDIF
CREATE TABLE %JKRFileName
(
#SET (%JKRCounter,0)
#! #FOR (%Field)
#INSERT (%JKRConvertFieldToSQL)
#! #ENDFOR
#INSERT (%JKRPrimaryKey)
);
#!
#!-----------------------------------------------
#GROUP (%JKRConvertFieldToSQL)
#!-----------------------------------------------
#! Convert TPS data type to Firebird
#!-----------------------------------------------
#!
#! #CLEAR( %JKRFieldType)
#!
#! #FOR (%Field)
#! %[30]%FieldID %FieldType
#! #ENDFOR
#FOR (%Field)
#! #SET (%JKRCounter, %JKRCounter + 1)
#! #IF (%JKRCounter > 1) #! Insert previous field
#! %[30]JKRFieldName %JKRFieldType,
#! #ENDIF
#! Use external name if specified - might be needed if SQL reserved words have been used
#IF (%FieldName)
#SET (%JKRFieldName, UPPER(SUB(%FieldName,2,LEN(%FieldName)-2)))
#ELSE
#SET (%JKRFieldName, UPPER(%FieldID))
#ENDIF
#!
#! See what type we have
#!
#! TargetDatabase = 'Firebird'
#CASE (%FieldType)
#OF ('PICTURE') #OROF ('LIKE') #OROF ('TYPE')
#SET (%JKRFieldType,'PICTURE - TYPE - LIKE - ARE NOT ALLOWED')
#OF ('BLOB')
#SET (%JKRFieldType,'BLOB SUB_TYPE 0 SEGMENT SIZE 80')
#OF ('BYTE')
#SET (%JKRFieldType,'SMALLINT')
#OF ('CSTRING') #OROF ('PSTRING')
#IF (%FieldMemoSize > 32765)
#SET (%JKRFieldType,'BLOB SUB_TYPE TEXT SEGMENT SIZE 80')
#ELSE
#IF(%JKRChangeStringTypesToBlob = 1)
#IF (%FieldMemoSize > %JKRChangeStringTypesToBlobSize-1)
#SET (%JKRFieldType,'BLOB SUB_TYPE TEXT SEGMENT SIZE 80')
#ELSE
#SET (%JKRFieldType,'VARCHAR' & '(' & %FieldMemoSize & ')')
#ENDIF
#ELSE
#SET (%JKRFieldType,'VARCHAR' & '(' & %FieldMemoSize & ')')
#ENDIF
#ENDIF
#OF ('DATE')
#SET (%JKRFieldType,'DATE')
#OF ('TIME')
#SET (%JKRFieldType,'TIME')
#OF ('LONG')
#! Convert longs fields to DATE and longs to Time if checked - else make interger
#IF (INSTRING('D',UPPER(%FieldPicture),1,1))
#IF(%JKRChangeDateNames = 1)
#SET (%JKRFieldType,'DATE')
#ELSE
#SET (%JKRFieldType,'INTEGER')
#ENDIF
#ELSIF (INSTRING('T',UPPER(%FieldPicture),1,1))
#IF(%JKRChangeTimeNames = 1)
#SET (%JKRFieldType,'TIME')
#ELSE
#SET (%JKRFieldType,'INTEGER')
#ENDIF
#ELSE
#SET (%JKRFieldType,'INTEGER')
#ENDIF
#OF ('ULONG')
#SET (%JKRFieldType,'INTEGER')
#OF ('SHORT') #OROF ('USHORT')
#SET (%JKRFieldType,'SMALLINT')
#OF ('STRING')
#IF (%FieldMemoSize > 32765)
#SET (%JKRFieldType,'BLOB SUB_TYPE TEXT SEGMENT SIZE 80')
#ELSE
#IF(%JKRChangeStringTypesToBlob = 1)
#IF (%FieldMemoSize > %JKRChangeStringTypesToBlobSize-1)
#SET (%JKRFieldType,'BLOB SUB_TYPE TEXT SEGMENT SIZE 80')
#ELSE
#SET (%JKRFieldType,'CHAR' & '(' & %FieldMemoSize & ')')
#ENDIF
#ELSE
#SET (%JKRFieldType,'CHAR' & '(' & %FieldMemoSize & ')')
#ENDIF
#ENDIF
#OF ('MEMO')
#IF(%FieldMemoImage = 1)
#SET (%JKRFieldType,'BLOB SUB_TYPE 0 SEGMENT SIZE 80')
#ELSE
#SET (%JKRFieldType,'BLOB SUB_TYPE TEXT SEGMENT SIZE 80')
#ENDIF
#OF ('DECIMAL')
#OROF('PDECIMAL')
#SET(%JKRFieldType, 'DECIMAL(' & %FieldMemoSize & ',' & %FieldPlaces & ')')
#OF ('SREAL')
#OROF('BFLOAT4')
#SET(%JKRFieldType, 'FLOAT')
#OF ('REAL')
#OROF('BFLOAT8')
#SET(%JKRFieldType, 'DOUBLE PRECISION')
#OF ('GROUP')
#OROF('END')
#CYCLE
#ENDCASE
#!
#IF(%JKRNoDefaults = 0)
#IF(%FieldInitial)
#SET(%JKRFoundLeftSideMatch,0)
#IF(ITEMS(%JKRInitialValueList))
#FOR(%JKRInitialValueList)
#IF(INSTRING('=',%JKRInitialValueList,1,1))
#SET(%JKRLeftSideOfStringLocation,(INSTRING('=',%JKRInitialValueList,1,1)))
#SET(%JKRLeftSideOfString,SUB(%JKRInitialValueList,1,%JKRLeftSideOfStringLocation-1))
#SET(%JKRRightSideOfString,SUB(%JKRInitialValueList,%JKRLeftSideOfStringLocation+1,LEN(%JKRInitialValueList)))
#IF(UPPER(CLIP(RIGHT(%JKRLeftSideOfString))) = UPPER(CLIP(RIGHT(%FieldInitial))) )
#SET(%JKRFoundLeftSideMatch,1)
#IF(CLIP(RIGHT(%JKRRightSideOfString))='')
#! EMPTY JKRRightSideOfString %JKRRightSideOfString
#CYCLE
#ELSE
#! NO EMPTY JKRRightSideOfString %JKRRightSideOfString
#SET (%JKRFieldType, %JKRFieldType & ' DEFAULT ' & CLIP(RIGHT(%JKRRightSideOfString)))
#CYCLE
#ENDIF
#ENDIF
#ELSE
#CYCLE
#ENDIF
#ENDFOR
#ENDIF
#!
#IF(%JKRFoundLeftSideMatch = 0)
#IF (INSTRING('D',UPPER(%FieldPicture),1,1))
#! do nothing for dates or times
#ELSIF (INSTRING('T',UPPER(%FieldPicture),1,1))
#! do nothing for dates or times
#ELSE
#! #SET (%JKRFieldType, %JKRFieldType & ' DEFAULT ')
#SET (%JKRFieldType, %JKRFieldType & ' DEFAULT ' & %FieldInitial)
#ENDIF
#ENDIF
#ENDIF
#ENDIF
#!
#! If Cannot Be Zero Or Blank is set it is always written into the scripts
#!
#CASE(%FieldValidation)
#OF ( 'NONZERO')
#SET (%JKRFieldType, %JKRFieldType & ' NOT NULL')
#ENDCASE
#IF(%JKRFieldValidation = 0)
#CASE(%FieldValidation)
#OF ( 'BOOLEAN')
#IF(%FieldTrueValue AND %FieldFalseValue)
#CASE (%FieldType)
#OF ('CSTRING') #OROF ('PSTRING') #OROF ('STRING')
#SET (%JKRFieldType, %JKRFieldType & ' NOT NULL CHECK(' & %JKRFieldName & ' = ' & '''' & %FieldTrueValue & '''' & ' OR ' & %JKRFieldName & ' = ' & '''' & %FieldFalseValue & '''' & ')' )
#ELSE
#SET (%JKRFieldType, %JKRFieldType & ' NOT NULL CHECK(' & %JKRFieldName & ' = ' & %FieldTrueValue & ' OR ' & %JKRFieldName & ' = ' & %FieldFalseValue & ')' )
#ENDCASE
#ENDIF
#OF ( 'INLIST')
#IF (ITEMS(%FieldValues))
#SET (%JKRFieldType, %JKRFieldType & ' NOT NULL CHECK(' & %JKRFieldName & ' IN (')
#SET (%JKRCounterLoc, 0)
#FOR(%FieldValues)
#IF (%JKRCounterLoc = 0)
#SET (%JKRFieldType, %JKRFieldType & '''' & %FieldValues & '''' )
#SET (%JKRCounterLoc, 1)
#ELSE
#SET (%JKRFieldType, %JKRFieldType & ',' & '''' & %FieldValues & '''' )
#ENDIF
#ENDFOR
#SET (%JKRFieldType, %JKRFieldType & '))')
#ENDIF
#OF ( 'INRANGE')
#IF (%FieldRangeLow AND %FieldRangeHigh)
#SET (%JKRFieldType, %JKRFieldType & ' NOT NULL CHECK(' & %JKRFieldName & ' BETWEEN ' & %FieldRangeLow & ' AND ' & %FieldRangeHigh &')' )
#ELSIF (%FieldRangeLow AND NOT %FieldRangeHigh)
#SET (%JKRFieldType, %JKRFieldType & ' NOT NULL CHECK(' & %JKRFieldName & ' >= ' & %FieldRangeLow &')' )
#ELSIF (NOT %FieldRangeLow AND %FieldRangeHigh)
#SET (%JKRFieldType, %JKRFieldType & ' NOT NULL CHECK(' & %JKRFieldName & ' <= ' & %FieldRangeHigh &')' )
#ENDIF
#ENDCASE
#ENDIF
%[30]JKRFieldName %JKRFieldType,
#ENDFOR
#!
#!
#!-----------------------------------------------
#GROUP (%JKRPrimaryKey)
#!-----------------------------------------------
#! Define Primary Key for file and Unique Keys
#!
#!-----------------------------------------------
#!
#SET (%JKRFileName, UPPER(%File))
#!
#! See if file has a Primary key field
#SET (%JKRHasPrimary,0)
#FOR (%Key)
#IF (%KeyPrimary)
#SET (%JKRHasPrimary,1)
#BREAK
#ENDIF
#ENDFOR
#IF (%JKRHasPrimary = 1)
#IF (%JKRCounter > 0) #! Insert previous field and if only one in file set the if to 0
%[30]JKRFieldName %JKRFieldType,
#ENDIF
#FOR (%Key)
#IF (%KeyPrimary = 1)
#SET (%JKRCounter,0)
#FOR (%KeyField)
#SET (%JKRCounter,%JKRCounter + 1)
#FIX (%Field, %KeyField)
#! Use external name if specified - might be needed if SQL reserved words have been used for field names
#IF (%FieldName)
#SET (%JKRKeyField, UPPER(SUB(%FieldName,2,LEN(%FieldName)-2)))
#ELSE
#SET (%JKRKeyField, UPPER(%FieldID))
#ENDIF
#IF (%JKRCounter > 1)
#SET (%JKRFieldName, %JKRFieldName & ', ' & %JKRKeyField)
#ELSE
#SET (%JKRFieldName, %JKRKeyField)
#ENDIF
#ENDFOR
CONSTRAINT PK_%JKRFileName PRIMARY KEY (%JKRFieldName)
#ENDIF
#ENDFOR
#ELSE #! No Comma!
%[30]JKRFieldName %JKRFieldType
#ENDIF
#!
#!
#!-----------------------------------------------
#GROUP (%JKRKeyDefinitions)
#!-----------------------------------------------
#! Define Other Keys for all Files
#!
#!-----------------------------------------------
#! %JKRFileName
#! #IF (%FileName)
#! #SET (%JKRFileName, UPPER(SUB(%FileName,2,LEN(%FileName)-2)))