Guidance
指路人
g.yi.org
Guidance Forums / Reginald Rexx / ODBC question for Mike

Register 
新用户注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. ODBC question for Mike
#12197
Posted by: jfauden 2008-01-04 13:04:35 Last edited by: Jeff Glatt 2009-03-04 14:38:06 (Total edited 1 time)
Is if there is a way to return a row immediately without having to issue an OdbcFetch. Also, I have found that when I issue an OdbcExecute which has no match for the criteria, I get a null returned, and the first column of the last row in the table is returned on a subsequent OdbcFetch. While I have your attention, is there anyway to query sqlcode or sqlstate?
Jimmy Auden
Message2. ODBC
#12203
Posted by: Michael S 2008-01-04 16:29:26 Last edited by: Jeff Glatt 2008-01-05 00:45:15 (Total edited 1 time)
Doesn't sound logical to me. That would be the equivalent (?) in the mainframe world of doing a declare
and open cursor without doing the first fetch. Until you've done the fetch, you have no data.
As to the no match etc, here's an example of the code I have

/* Set the SQL_TXN_ISOLATION option to the value 1 (uncommitted reads) */
/* rc = sqlsetconnectoptionint(mfe.!database, 108, 1)  */
result = odbcsetconnectopt("TXN|UNCOMMIT")

DO
	odbcexecute(data., "columns")
	CATCH ERROR
		err = CONDITION('D')
		rc = show_db2_error.rex(err)
		RETURN -1
END

table_row = 0
rc = 0
insert_limit = 10
/* If there are more than 500 rows, show progress every 200 records */
IF db2.!count > 500 THEN
	progress_limit = 200
ELSE	
	progress_limit = 25
	
db2_data.0 = 0
riidfr = ''

DO
	DO UNTIL odbcfetch("data.", columns) = "DONE" | table_row > max_records | rc \= 0
		/* 	Did we have another row ? We also need to test for the second
				condition in case they only want (say) 50 rows, but the table
				has more than 50. That would mean that we fetch row 51, update
				db2_data.0 etc, and when we then leave this loop, we think 
				there's STILL data to insert 	*/
         /* Fetch and process data .....*/
END

and the show_db2_error.rex contains

/*
 Show a DB2 error in a window. Argument passed is the ODBC error
 string. This code revereses the error string, then takes everthing 
 BEFORE the first ']', reverses this and issues wdwsay message
*/
PROCEDURE EXPOSE db2.

/* Might want to issue different messages depending on DB2 source */
PARSE ARG result

/* Get the name of the script that called us */
temp = UNAME(-2)
temp = FILESPEC('N',temp)
PARSE VAR temp title '.' .

temp = WORDS(result)
cause = WORD(result, temp)

SELECT 
	WHEN cause = 'CANCEL' THEN
		/* They obviously pressed Cancel (for whatever reason) */
		RETURN 1
	WHEN POS('SQL30082N',result) <> 0 THEN 
		/* This seems to be correct */
		temp = "Cannot connect to "db2.source" - incorrect password ?"
	WHEN (POS('SQL30081N',result) <> 0) & (POS('10061',result) <> 0) THEN 
		/* This worked for me */
		temp = "Cannot connect to "db2.source" - try rebooting your machine"
	WHEN POS('IM002',result) <> 0 THEN
		DO
			/* The following line is an example of what Fredrik received when trying to
				 connect to DB2T when he had no ODBC DB2 driver */
			temp = "Your PC has not been configured for ODBC connection to "db2.source" - investigate"
		END
	OTHERWISE
		DO
			err = REVERSE(result)
			y = POS(']',err)
			SELECT 
				WHEN y = 0 THEN
					y = REVERSE(y)
				OTHERWISE
					err = SUBSTR(err,1,y-1)
			END		
			temp = REVERSE(err) 
		END
END
		
temp = "DB2 Error:" || "0D0A"x || temp
rc = wdwsay.rex(temp, 'STOP', title)
RETURN 1
Does this answer your question ? (As to SQLCODE etc, as you can see from show_db2_error.rex, their
"equivalents" are not available - to my knowledge - as such. The argument to show_db2_error.rex - result -
is the equivalent of calling DSNTIAR on the mainframe, ie, a long error message)
Message3.
#12206
Posted by: jfauden 2008-01-04 23:47:11
Mike,

The documentation that I have doesn't include many examples. Where can I find the online help in RPC?

I have looked at REXX/SQL, and the syntax is very similar to other  ODBC drivers that I have used. I had no problems using it with the REGINA REXX implementation. However, I prefer Reginald for it's GUI interface. Is there any way to load the REXX/SQL library in Reginald?

I need to download DB2 data from the mainframe and feed it into a Report Writer application.

Thanks for all your help!
Jimmy Auden
Message4.
#12208
Posted by: Jeff Glatt 2008-01-05 00:43:36
RPC has a help window listing all of the available help books. There should be a book titled "Database support". Those are the online docs for RexxOdbc.

There is also my "Example scripts" web page. There should be a full ODBC example there (originally written by Mike, and rewritten to use RexxOdbc).

REXX/SQL isn't written to support Reginald.

RexxOdbc is a thin wrapper around Microsoft's odbc32 library. OdbcExecute is mostly a wrapper around SQLExecDirect (but also may call SQLNumResultCols to set your columns variable, and SQLDescribeCol to return column info). OdbcFetch is a wrapper around SQLFetch (and SQLGetData if you want the data returned). OdbcColAttribute is a wrapper around SQLColAttributes. Etc. So any docs about Microsoft's SQL stuff should be helpful.
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Wed 2021-4-14  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0