home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
sybaserx.zip
/
SQLCMD.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1995-12-11
|
6KB
|
178 lines
/*******************************************************************/
/* */
/* SQLCMD.CMD */
/* */
/* This program calls the various REXX external functions */
/* provided in the SYBREXX.C function package. */
/* */
/* Each function is called once to illustrate how it is used. */
/* Some of the functions have multiple options and multiple */
/* types of output, but not all options are used here. */
/* */
/*******************************************************************/
'@echo off'
Arg SQLCMD
if SQLCMD == '' then do
Say 'Enter SQL command:'
Pull SQLCMD
end
/* Modify these variables to suite your environment */
UserID = 'sa'
Password = 'alicee'
Database = 'IVI'
Server = 'DUNX_NB'
/* RxSybLoadFuncs: This function will load all the rest, */
/* so we do not have to make many calls to RxFuncAdd. */
call RxFuncAdd 'SysSleep', 'RexxUtil', 'SysSleep'
call RxFuncAdd 'RxSybLoadFuncs', 'SYBREXX', 'RxSybLoadFuncs'
call RxSybLoadFuncs
/* Set return codes */
SUCCEED = 1
FAIL = 0
NO_MORE_ROWS = -2
MORE_ROWS = -1
SYBCHAR = 47
SYBDATETIME = 61
SYBTEXT = 35
TRUE = 1
FALSE = 0
/*** Demonstrate RxDbsethandlers ***/
Call RxDbsethandlers('')
/*** Demonstrate RxDbsetlogintime ***/
Call RxDbsetlogintime('5')
/*** Demonstrate RxDbsettime ***/
Call RxDbsettime('0')
pLoginRec = RxDblogin() /* Get a Login Structure */
Call RxDbsetluser pLoginRec, UserID /* Set the User ID in the Login Struct */
Call RxDbsetlpwd pLoginRec, Password /* Set the Password in the Login Struct */
Call RxDbsetlhost pLoginRec, 'SYBREXX' /* Set the Host in the Login Struct */
Call RxDbsetlapp pLoginRec, 'SYBRX.CMD'/* Set the Applic in the Login Struct */
Call RxDbsetlencrypt pLoginRec, TRUE /* Set password encryption */
dbproc = RxDbopen(pLoginRec, Server) /* Open a DBPROCESS */
if (dbproc == 0) then do /* Be sure to check we have a valid */
Say 'dbopen failed!' /* DBPROCESS before continuing! */
exit
end
RetCode = RxDbuse(dbproc, Database) /* Set the Database */
/* Set up a SQL command string */
RetCode = RxDbcmd(dbproc, SQLCMD)
if (RxDbsqlexec(dbproc) <> SUCCEED) then do /* Execute it */
Say 'dbsqlexec failed!' /* Note that we could have */
Call RxDbclose(dbproc) /* used RxDbsqlsend */
exit
end
/*****************************************************************************/
/* Would use this code if we had called RxDbsqlend() */
/* Using OS/2 I would prefer to make the call in a separate thread and just */
/* let the thread wait until the call returns */
/* It is a bit of a HACK polling to check if the call has returned yet and */
/* if it is done often from the main thread then some user interruption may */
/* be experienced (especially on low resource machines). */
/*****************************************************************************/
/* do while (RxDbsqlok(dbproc) <> SUCCEED) Check if results are ready */
/* Call SysSleep 1 would not be needed if we */
/* Call RxDbclose(dbproc) called RxDbsqlexec */
/* exit */
/* end */
/*****************************************************************************/
if (RxDbresults(dbproc) <> SUCCEED) then do /* Check results */
Say 'dbresults failed!'
Call RxDbclose(dbproc)
exit
end
if (RxDbrows(dbproc) <> SUCCEED) then do /* Check if rows are returned */
Say 'dbresults failed!'
Call RxDbclose(dbproc)
exit
end
/*** Write out the Titles ***/
NumCols = RxDbnumcols(dbproc)
Outputline = ''
OutputlineU = ''
do iCol = 1 to NumCols
ColType = RxDbcoltype(dbproc,iCol) /* get the column type */
if (ColType <> SYBCHAR & ColType <> SYBDATETIME & ColType <> SYBTEXT) then
ColLen.iCol = RxDbcollen(dbproc,iCol) * 2 /* get the column length */
else
ColLen.iCol = RxDbcollen(dbproc,iCol) /* get the column length */
ColName.iCol = RxDbcolname(dbproc, iCol) /* get the column name */
Outputline = Outputline || substr(ColName.iCol,1,Collen.iCol,' ') || ' '
OutputlineU = OutputlineU || substr('',1,Collen.iCol, '-') || ' '
end
Say Outputline
Say OutputlineU
do while (RxDbnextrow(dbproc) == MORE_ROWS)
/*** Get the Data ***/
/* NOTE: At this stage RxDbdata only allocates 256 bytes for the returned */
/* data - I still need to make it smarter so that it will allocate */
/* additional storage if required */
/* This will probably only impact TEXT and BINARY columns */
Outputline = ''
do iCol = 1 to NumCols
Outputline = Outputline || substr(RxDbdata(dbproc, iCol),1,Collen.iCol,' ') || ' '
end
Say Outputline
end
Call RxDbclose(dbproc) /* Close the DBPROCESS */
Call RxSybDropFuncs
exit
SysPause:
parse arg prompt
if prompt='' then
prompt='Press Enter key when ready . . .'
call SysSay prompt
Pull .
say
return
SysSay:
parse arg string
call charout 'STDOUT', string
return