home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sqlcla.zip / MKSQL.CMD < prev    next >
OS/2 REXX Batch file  |  1993-07-14  |  3KB  |  131 lines

  1. /* (C) Copyright Stephen B. Behman, 1993 -- All rights reserved. */
  2. /* $Header: h:/ubin/RCS/mksql.cmd 2.0 93/07/14 10:08:09 Steve Exp $ */
  3. /* I will clean this up -- some day! For now, it works. */
  4.  
  5. '@echo off'
  6. upper='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  7. lower='abcdefghijklmnopqrstuvwxyz'
  8. parse upper arg a b c d
  9. if c='' | d<>'' then do
  10.   say 'Builds stuff for an ".SPP" file.'
  11.   say ''
  12.   say 'Arguments are: Database Table Pointer_Symbol'
  13.   exit
  14. end
  15. do j=1 to queued()
  16.   pull g
  17. end
  18. c=translate( c, lower, upper )
  19. n=translate( b, lower, upper )
  20. 'call describe ' a b '| rxqueue '
  21. j=0
  22. s=  '         SELECT'
  23. do i=1 to queued()
  24. pull a
  25. if substr(a, 1, 8)='--------' then
  26.   do
  27.    found=1
  28.    iterate
  29.   end
  30. if found='FOUND' then iterate
  31. if word( a,2 )='RECORD(S)' then  leave
  32. if word( a,1 )='' then iterate
  33. j=j+1
  34. aa=a
  35. a= translate(a, lower, upper )
  36. select
  37.   when    word(a,2 )= 'timestmp' then do
  38.       descb.j='char '
  39.       desce.j=word( a,1 )
  40.       desc.j='[27]'
  41.       end
  42.   when word( a, 2 )='date' then do
  43.       descb.j='char '
  44.       desce.j=word( a,1 )
  45.       desc.j='[12]'
  46.       end
  47.  
  48.   when word( a, 2 )='char' then do
  49.       descb.j='char '
  50.       desce.j=word( a,1 )
  51.       if word( a,3 )=1 then  desc.j=''
  52.       else
  53.     do
  54.       desc.j='['||word( a,3 )||']'
  55.     end
  56.       end
  57.  
  58.   when word( a, 2 )='time' then do
  59.       descb.j='char '
  60.       desce.j=word( a,1 )
  61.       desc.j='[10]'
  62.       end
  63.  
  64.   when word( a, 2 )='longvar' then do
  65.       descb.j='char '
  66.       desce.j=word( a,1 )
  67.       desc.j='[32700]'
  68.       end
  69.  
  70.   when    word(a,2 )= 'varchar' | word(a,2)='char' then do
  71.       descb.j='char '
  72.       desce.j=word( a,1 )
  73.       desc.j='[' || word(a,3)+1 || ']'
  74.       end
  75.   when    word(a,2 )= 'decimal' then do
  76.       descb.j='double '
  77.       desce.j=word(a,1)
  78.       desc.j=''
  79.       end
  80.  
  81.   when    word(a,2 )= 'float' then do
  82.       descb.j='double '
  83.       desce.j=word(a,1)
  84.       desc.j=''
  85.       end
  86.  
  87.   when    word(a,2 )= 'integer' then do
  88.       descb.j='long '
  89.       desce.j=word(a,1)
  90.       desc.j=''
  91.       end
  92.   when    word(a,2 )= 'smallint' then  do
  93.       descb.j='short '
  94.       desce.j=word(a,1)
  95.       desc.j=''
  96.       end
  97.   otherwise say 'error in table '
  98.   end
  99. assign.j=n ||'_'|| word( a, 1 ) ||'='|| c || '.' || word( a, 1 )||';'
  100. assign.j= c || '.' || word( a, 1 )||';'
  101.  
  102. fetch.j=  word( a,1 )
  103. sel.j=word( aa,1 )
  104. if word( a,5 )='y' then ni.j=fetch.j || '_ni'
  105. end
  106.  
  107. g=translate( substr( n, 1, 1 ), upper,lower )||substr( n,2 )
  108. say 'class' g
  109. say '  {'
  110. say '  public:'
  111. do i=1 to j
  112.   out='  ' descb.i||desce.i
  113. /*  if desc.i<>1 then out=out||'['||desc.i|| '];'
  114.   else ; */ out=out||desc.i';'
  115.   say out
  116.   end
  117. do i=1 to j
  118.   if substr( ni.i,1,2 )<>'NI' then say '   short ' ni.i || ';'
  119.   end
  120. say '  };'
  121. say '//static' g c || ';'
  122.  
  123. do i=1 to j
  124. if substr(ni.i,1,2)<>'NI' then
  125. out= '//CV(' sel.i ',' strip(descb.i) ':' || c || '.'||desce.i || desc.i  ':'||c||'.'||ni.i  ')'
  126. else
  127. out= '//CV(' sel.i ',' strip(descb.i) ':' || c || '.'||desce.i || desc.i  ')'
  128. if i=j then say out
  129. else; say out||','
  130. end
  131.