home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
rxhll.zip
/
DATABASE.REX
< prev
next >
Wrap
OS/2 REXX Batch file
|
1994-01-26
|
5KB
|
214 lines
/* #include <database.rex> */
/**
*** ╔═══════════════════════════════════════════════════════════════════════╗
*** ║ OS/2 Database Manager & DB2/2 Support routines ║
*** ╚═══════════════════════════════════════════════════════════════════════╝
**/
LoadDBMFunctions: procedure
/**
*** Load the Database Manager REXX DLL
**/
if RxFuncQuery('SQLEXEC') <> 0 then
do
RCode = RxFuncAdd('SQLEXEC','SQLAR','SQLEXEC')
if RCode <> 0 then
call Error 1001,0,RCode
end
if RxFuncQuery('SQLDBS') <> 0 then
do
RCode = RxFuncAdd('SQLDBS', 'SQLAR', 'SQLDBS')
if RCode <> 0 then
call Error 1001,0,RCode
end
return
StartDatabase: procedure
/**
*** This will start the Database Manager and open the database with
*** the name that was passed
**/
arg Database
call sqldbs 'start database manager'
if Database <> '' then
call sqldbs 'start using database' Database
return result
StopDatabase: procedure
/**
*** This will stop the use of the current database.
**/
call sqldbs 'stop using database'
return result
SqlDynamic: procedure expose MsgQ.
/**
*** This will upadate a record in the database
**/
parse arg SqlCommand
call SqlExec "EXECUTE IMMEDIATE :SqlCommand"
if result <> 0 then
call Error 1002,0,result
else
select
when SQLCA.SQLCODE = 0 then nop /* Ok */
when SQLCA.SQLCODE = 100 then nop /* Not found. */
otherwise
call Error 1003,0,SQLCA.SQLCODE,SQLCA.SQLMSG
end /* select */
return SQLCA.SQLCODE
SqlCommit: procedure expose MsgQ.
/**
*** This will commit the changes to the database
**/
SqlCommit = 'COMMIT'
call SqlExec "EXECUTE IMMEDIATE :SqlCommit"
return SQLCA.SQLCODE
SqlGetData: procedure expose sqlda.
/**
*** This will get the information from the sqlda structure while looking
*** for NULL values.
**/
arg j
if sqlda.j.sqlind < 0 then
Data = ""
else
Data = strip(sqlda.j.sqldata)
return Data
Sql:
/**
*** This will issue the SqlExec API call and check the return codes and
*** results. It will terminate on error.
**/
arg SqlCommand
call SqlExec SqlCommand
if result <> 0 then
call Error 1002,0,result
else
select
when SQLCA.SQLCODE = 0 then nop /* Ok */
when SQLCA.SQLCODE = 100 then nop /* Not found. */
otherwise
call Error 1003,0,SQLCA.SQLCODE,SQLCA.SQLMSG
end /* select */
return SQLCA.SQLCODE
DbMakeValue: procedure
/**
*** This will cleanup of the information from the windows to make sure
*** they are valid for the database.
**/
parse arg field, type
if field = '' then
return "NULL"
type = translate(type)
select
when left(type, 1) = 'C' then
return "'"DbDoubleApostrophe(field)"'"
when left(type, 1) = 'N' then
return field
otherwise
return field
end /* select */
return
DbDate: procedure
/**
*** This will return today's date in Database Manager date format
**/
today = date('Sorted')
parse var today yyyy 5 mm 7 dd
today = mm'-'dd'-'yyyy
return today
DbDoubleApostrophe: procedure
/**
*** This will convert a single apostrophe in a string to double
*** apostrophe's so that it is correctly used in the SQL calls
**/
parse arg Field
Start = 1
Found = pos("'", Field, Start)
do while Found > 0
Field = insert("'", Field, Found)
Start = Found + 2
Found = pos("'", Field, Start)
end
return Field
DbValidNum: procedure
/**
*** This will verify that the number passed is a valid number or null
**/
arg number
if number = '' then return 1
if datatype(number,'N') = 0 then return 0
return 1
DbValidDate: procedure
/**
*** This will return a boolean based on whether this is a valid date
*** for a database record
**/
parse arg CheckDate .
parse var CheckDate mm '-' dd '-' yyyy
if CheckDate = mm then
parse var CheckDate mm '/' dd '/' yyyy
/* A NULL is a valid date in this case */
if mm = '' then
return 1
if datatype(mm ,'N') = 0 then return 0
if datatype(dd ,'N') = 0 then return 0
if datatype(yyyy,'N') = 0 then return 0
if (mm < 1) | (mm > 12) then
return 0
if (dd < 1) | (dd > 31) then
return 0
if (yyyy < 1990) | (yyyy > 1999) then
return 0
return 1