home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
dclgen2.zip
/
DCLGEN2.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1993-09-06
|
11KB
|
378 lines
/*---------------------------------------------------------*/
/* DCLGEN2 - DCLGEN for Data Base Manager */
/*---------------------------------------------------------*/
/* By Alberto Forlai - 75840141 at ITHXA01/ITHVM03 */
/* Add. Mktg. */
/* Viale F. Testi 250 */
/* Milano (Italy) */
/*---------------------------------------------------------*/
arg data_base tabella linguaggio
call test_args /* test sull'input letto */
i = 0
rc = 0
cblfloat = 0 /* indicatore di errore per FLOAT in COBOL */
file_pre = 'DBTM' /* prefisso nome file di output */
file_num = 1 /* numero file di output */
file_log = 'DCLGEN2.LOG' /* file di log */
signal on error
say 'Starting DBM'
if Rxfuncquery('SQLDBS') <> 0 then rcy=Rxfuncadd('SQLDBS' ,'SQLAR','SQLDBS' )
if Rxfuncquery('SQLEXEC') <> 0 then rcy=Rxfuncadd('SQLEXEC','SQLAR','SQLEXEC')
call sqldbs 'START DATABASE MANAGER'
select
when sqlca.sqlcode = -1026 then nop /* database gia' attivo */
when sqlca.sqlcode = 0 then nop /* attivazione riuscita */
otherwise signal error
end
call sqldbs 'START USING DATABASE' data_base 'IN SHARED MODE'
select
when sqlca.sqlcode = -1098 then nop /* gia' collegato */
when sqlca.sqlcode = 0 then nop /* collegamento riuscito */
otherwise signal error
end
say 'DBM Started'
tabella = "'" || strip(tabella) || "'"
sqlstmt = "SELECT NAME , COLTYPE , LENGTH , SCALE "
sqlstmt = sqlstmt "FROM SYSIBM.SYSCOLUMNS "
sqlstmt = sqlstmt "WHERE TBNAME =" tabella
call sqlexec 'PREPARE s1 FROM :sqlstmt' ; if sqlca.sqlcode <> 0 then signal error
call sqlexec 'DECLARE c1 CURSOR FOR s1' ; if sqlca.sqlcode <> 0 then signal error
call sqlexec 'OPEN c1' ; if sqlca.sqlcode <> 0 then signal error
call sqlexec 'FETCH c1 INTO :name , :type , :clen , :scle'
if sqlca.sqlcode <> 0 & sqlca.sqlcode <> 100 then signal error
do while sqlca.sqlcode = 0
i = i + 1
tbname.i = strip(name)
tbtype.i = strip(type)
tbleng.i = strip(clen)
tbscle.i = strip(scle)
call sqlexec 'FETCH c1 INTO :name , :type , :clen , :scle'
if sqlca.sqlcode <> 0 & sqlca.sqlcode <> 100 then signal error
end
if i = 0 then signal error
call sqlexec 'CLOSE c1'
call sqldbs 'STOP USING DATABASE'
tabella = strip(tabella,,"'")
numcol = i
if linguaggio = 'COBOL' then do
record.1 = ' *' || copies('*',59)
record.2 = ' * DATABASE : ' || left(data_base,9)
record.2 = record.2 || ' * TABLE : ' || left(tabella,18) || ' *'
record.3 = ' *' || copies('*',59)
end
if linguaggio = 'C' then do
say ''
say ' You can rappresent a VARCHAR columns as :'
say ''
say ' 0 ) structure ( length + NOT NULL terminating string )'
say ' 1 ) NULL terminatig string'
say ''
say ' Type 0 or 1 , press ENTER to exit'
pull usertype
if usertype = '' then exit
do while usertype <> '0' & usertype <> '1'
say ' Please type 0 or 1 , press ENTER to exit'
pull usertype
if usertype = '' then exit
end
record.1 = '/*' || copies('=',60) || '*/'
record.2 = '/* DATABASE : ' || left(data_base,9)
record.2 = record.2 || ' * TABLE : ' || left(tabella,18) || '*/'
record.3 = '/*' || copies('=',60) || '*/'
end
record.0 = 3
j = record.0
do i = 1 to numcol
if linguaggio = 'C' then tbname.i = lowercase(tbname.i);
select
when tbtype.i = 'SMALLINT' then call sqlsmallint
when tbtype.i = 'INTEGER' then call sqlinteger
when tbtype.i = 'FLOAT' then call sqlfloat
when tbtype.i = 'DECIMAL' then call sqldecimal
when tbtype.i = 'CHAR' then call sqlchar
when tbtype.i = 'VARCHAR' then call sqlvarchar
when tbtype.i = 'LONGVAR' then call sqllvarchar
when tbtype.i = 'DATE' then call sqldate
when tbtype.i = 'TIME' then call sqltime
when tbtype.i = 'TIMESTMP' then call sqltimestamp
otherwise do
say 'Type :' tbtype.i ' not valid'
signal error
end
end
end
j = j + 1
if linguaggio = 'COBOL' then do
record.j = ' *' || copies('-',59)
end
if linguaggio = 'C' then do
record.j = '/*' || copies('-',59) || '*/'
end
record.0 = j
call RxFuncAdd 'SysLoadFuncs' , 'RexxUtil' , 'SysLoadFuncs'
call SysLoadFuncs
call find_file_number
call write_record
say 'DCLGEN2 ended with no errors'
exit
sqlsmallint:
j = j + 1
if linguaggio = 'COBOL' then do
record.j = ' 01' left(tbname.i,20) 'PIC S9(4) COMP-5.'
end
if linguaggio = 'C' then do
record.j = ' short int' strip(tbname.i) ';'
end
record.0 = j
return
sqlinteger:
j = j + 1
if linguaggio = 'COBOL' then do
record.j = ' 01' left(tbname.i,20) 'PIC S9(9) COMP-5.'
end
if linguaggio = 'C' then do
record.j = ' long int' strip(tbname.i) ';'
end
record.0 = j
return
sqlfloat:
j = j + 1
if linguaggio = 'COBOL' then do
cblfloat = 1 /* FLOAT non supportato dal COBOL */
signal error
end
if linguaggio = 'C' then do
record.j = ' double ' strip(tbname.i) ';'
end
return
sqldecimal:
j = j + 1
if linguaggio = 'COBOL' then do
record.j = ' 01' left(tbname.i,20)
record.j = record.j 'PIC S9(' || tbleng.i || ')'
record.j = record.j 'V9(' || tbscle.i || ') COMP-3.'
end
if linguaggio = 'C' then do
record.j = ' double ' strip(tbname.i) ';'
say 'WARNING : SQL type DECIMAL transated as DOUBLE'
end
record.0 = j
return
sqlchar:
j = j + 1
if linguaggio = 'COBOL' then do
record.j = ' 01' left(tbname.i,20) 'PIC X(' || tbleng.i || ').'
end
if linguaggio = 'C' then do
if tbleng.i = 1 then do
record.j = ' char ' strip(tbname.i) || ';'
end
else do
record.j = ' char ' strip(tbname.i) || '[' || tbleng.i || '];'
end
end
record.0 = j
return
sqlvarchar:
if linguaggio = 'COBOL' then do
j = j + 1
record.j = ' 01' strip(tbname.i) || '.'
j = j + 1
record.j = ' 49 L' || left(tbname.i,20) 'PIC S9(4) COMP-5.'
j = j + 1
record.j = ' 49 D' || left(tbname.i,20) 'PIC X(' || tbleng.i || ').'
end
if linguaggio = 'C' then do
if usertype = 1 then do
j = j + 1
record.j = ' char ' strip(tbname.i) || '[' || tbleng.i || '];'
end
else do
j = j + 1
record.j = ' struct ' strip(tbname.i) || '{'
j = j + 1
record.j = ' short int L' || strip(tbname.i) || ';'
j = j + 1
record.j = ' char D' || strip(tbname.i) || '[' || tbleng.i || '];'
j = j + 1
record.j = ' };'
end
end
record.0 = j
return
sqllvarchar:
if linguaggio = 'COBOL' then do
j = j + 1
record.j = ' 01' strip(tbname.i) || '.'
j = j + 1
record.j = ' 49 L' || left(tbname.i,20) 'PIC S9(4) COMP-5.'
j = j + 1
record.j = ' 49 D' || left(tbname.i,20) 'PIC X(' || tbleng.i || ').'
end
if linguaggio = 'C' then do
j = j + 1
record.j = ' struct ' strip(tbname.i) || '{'
j = j + 1
record.j = ' short int L' || strip(tbname.i) || ';'
j = j + 1
record.j = ' char D' || strip(tbname.i) || '[' || tbleng.i || '];'
j = j + 1
record.j = ' };'
end
record.0 = j
return
sqldate:
j = j + 1
if linguaggio = 'COBOL' then do
record.j = ' 01' left(tbname.i,20) 'PIC X(10).'
end
if linguaggio = 'C' then do
record.j = ' char ' strip(tbname.i) || '[10];'
end
record.0 = j
return
sqltime:
j = j + 1
if linguaggio = 'COBOL' then do
record.j = ' 01' left(tbname.i,20) 'PIC X(8).'
end
if linguaggio = 'C' then do
record.j = ' char ' strip(tbname.i) || '[8];'
end
record.0 = j
return
sqltimestamp:
j = j + 1
if linguaggio = 'COBOL' then do
record.j = ' 01' left(tbname.i,20) 'PIC X(26).'
end
if linguaggio = 'C' then do
record.j = ' char ' strip(tbname.i) || '[26];'
end
record.0 = j
return
find_file_number:
call SysFileTree 'DBTM*.' || ext , 'list' , 'FO'
if list.0 = 0 then do
call gen_file_out
return
end
do k = 1 to list.0
call SysFileSearch record.2 , list.k , 'dummy.'
if dummy.0 = 1 then do
posb = lastpos('\',list.k)
file_out = substr(list.k,posb + 1)
call write_log
return
end
end
maxnum = 0
do k = 1 to list.0
posb = lastpos('\',list.k)
num = substr(list.k , posb + 5 , 3)
if num > maxnum then maxnum = num
end
file_num = maxnum + 1
call gen_file_out
return
gen_file_out:
file_out = file_pre || right(file_num,3,'0') || '.' || ext
call write_log
return
write_log:
log_line = date('E') time() left(file_out,12)
log_line = log_line '- Table :' left(tabella,18) || ', DBase :' data_base
call lineout file_log , log_line
call lineout file_log
return
write_record:
signal on error
rc = SysFileDelete(file_out)
call beep 2500, 70
if rc = 2 then say '------> Start writing :' file_out
if rc = 0 then say '------> Start RE-writing :' file_out
do i = 1 to record.0
call lineout file_out , record.i
end
call lineout file_out
return
test_args:
if data_base = '' | data_base = '?' then call help
do while tabella = ''
say 'TABLE NAME missing, reenter this field'
say ' or press ENTER to exit'
pull tabella
if tabella = '' then exit
end
if linguaggio = '' then do
linguaggio = 'COBOL'
say 'WARNING : language missing, COBOL assumed'
end
do while linguaggio <> 'COBOL' & linguaggio <> 'C'
say 'LANGUAGE :' strip(linguaggio) 'is not valid'
say ' reenter this field as COBOL or C'
say ' press ENTER to exit'
pull linguaggio
if linguaggio = '' then exit
end
if linguaggio = 'COBOL' then ext = 'CBL'
else ext = 'H'
return
lowercase:
arg low
lc = 'abcdefghijklmnopqrstuvwxyz'
uc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
low = translate(low , lc , uc )
return low
error:
call beep 80,500
if sqlca.sqlcode <> 0 then do
say copies('-',79)
say 'SQLCODE =' sqlca.sqlcode
say sqlmsg
say copies('-',79)
end
if rc <> 0 then do
say 'an ERROR was found in this line :'
say sourceline(sigl)
say 'RC =' rc
end
if cblfloat = 1 then do
say 'FLOAT column type not supported by COBOL'
end
call sqlexec 'CLOSE c1'
call sqldbs 'STOP USING DATABASE'
say 'DCLGEN2 ended with errors'
exit
help:
say ' '
say ' Syntax : '
say ' '
say ' dclgen2 <data_base> <table_name> (language) '
say ' '
say ' language can be : COBOL (default) or C '
exit