ConnectDatasource:

token_oracle = 0

/* **************************************** *
 *                                          *
 * Connect to an ORACLE  database           *
 *                                          *
 * Invocation of procedure from PROLOG:     *
 *                                          *
 * ora_rc = ConnectDatasource()             *
 * Note: The CONNECTSTRING must be changed  *
 * or can be deleted from the snippet, but  *
 * then it must be supplied before the pro- *
 * cedure is called.                        *
 *                                          *
 * **************************************** */


DBI.InterfaceType    = 'ORACLE'
DBI.ConnectString    = 'DSN=connectstring'
rc = CALLDB('CONNECT', 'DBI', 'DQ3')

IF rc = 0 THEN token_oracle = DQ3.Token

IF rc <> 0 THEN DO
   SAY 'CONNECT Oracle rc('rc') ErrorMessage('DQ3.ErrorMessage')'
   Return rc','DQ3.ErrorMessage
END  

RETURN 0


DisconnectDatasource:

/* **************************************** *
 *                                          *
 * Disconnect from an ORACLE database       *
 * Invocation of procedure from EPILOG:     *
 *                                          *
 * ora_rc = DisconnectDatasource()          * 
 *                                          *
 * **************************************** */

say 'Disconnect ********'

IF token_oracle > 0 THEN DO
	DBI.Token = token_oracle
	rc = CALLDB('DISCONNECT', 'DBI', 'DBO')
	
	
	IF rc <> 0 THEN DO
	  SAY 'DISCONNECT Oracle rc('rc') ErrorMessage('DBO.ErrorMessage')'
	  RETURN '12, ODBC Disconnect Error'
	END
	  
END

RETURN 0


ExecuteDatasource:

/* **************************************** *
 *                                          *
 * Execute the SQL statements               *
 * against an ORACLE  database              *
 *                                          *
 * The procedure can be called with         *
 * ora_rc = ExecuteDatasource()             *
 *                                          *
 * Before the procdeure is called           *
 * you may provide the SQL statement in     *
 * DBI.SQL_Command                          *
 *                                          * 
 * The code in the snippet must be changed  *
 * to replace "localvariable" with the name *
 * of the variable that should contain the  *
 * result.                                  *  
 * **************************************** */

DBI.Token       = token_oracle
DBI.MaxRecords = 10
DBI.SQL_Command = 'select * from peter.kategorie where nr = ' katval
rc = CALLDB('EXECUTE', 'DBI', 'DQ3')
 
IF rc <> 0 THEN DO
   SAY 'EXECUTE Oracle rc('rc')  ErrorMessage('DQ3.ErrorMessage')'
   Return rc','DQ3.ErrorMessage
END 

/* **************************************** *
 *                                          *
 * Retrieve the records from the            *
 * resultset                                *
 *                                          *
 * **************************************** */


IF rc = 0 THEN DO

	DBI.Token      = token_oracle
	DBI.RequestId  = 0
	rc = CALLDB('FETCH', 'DBI', 'SQL')
	SAY 'FETCH rc('rc')'
    IF RC = 0 THEN localvariable = SQL.V.Value.3
	IF rc = 16  then localvariable = 'Invalid CAT: ' katval
	
END	

RETURN 0