Guidance
指路人
g.yi.org
Upload / Forum Attachment / Reginald Rexx Programming Language Compiler User Forum Attachments and Pictures / 13236-change_db2_source.rex

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
/*****************************************************************

	Can be call to 
	-	initialize the ODBC menu options (I in option)
	-	change the current marked menu option. Option is C,
	  menu_position is the menu_number (where 1 is first ODBC 
	  database option, 2 is the second one etc etc). 
	  Menu_position can	ALSO be the name of a default chosen ODBC 
	  database
****************************************************************/
PROCEDURE EXPOSE guiwindow odbc_system. odbc_source. odbc_connection. db2.

PARSE ARG option, menu_position .

SELECT
	WHEN option = "I" THEN
		rc = init_db2_menus()
	WHEN option = "C" THEN
		rc = change_db2_menu()
	OTHERWISE
		NOP
END

RETURN 0			
/********************************************************************
 Change the menu option marked for the selected database
********************************************************************/ 
change_db2_menu:

IF db2.previous_database <> "" THEN
	/* We've had a database open - close it */
	rc = free_previous_database(db2.previous_database)

default_position = menu_position

IF DATATYPE(menu_position) = "CHAR" THEN
	DO
		/* Find the relevant line in ODBC_source. .... */
		/* ... but in case we DON'T find it */
		default_position = 1
		DO i = 1 TO odbc_system.0
			temp = STRIP(TRANSLATE(odbc_system.i," " ,"&")) 
			y = POS(" ", temp)
			IF y <> 0 THEN
				temp = LEFT(temp,y-1)||substr(temp,y+1)
			IF temp == menu_position THEN
				DO
					/* The requested default database has been found */
					default_position = i
					LEAVE
				END
		END
	END

menu_position =	default_position

/* Clear out any possible marked menu option */
DO i = 1 TO odbc_system.0
  guisetmenuopts("ODBC_source."i, '')
END 

/* Mark the selected menu option */
guisetmenuopts("ODBC_source."menu_position, 'MARK')
	
/* Get the text for the actual menu option they chose */
guigetmenuopts("ODBC_source."menu_position, , 'selected_database')  

/* Update the status bar to show which DB2 system is the default,
   removing any ampersands in the name */
selected_database = STRIP(TRANSLATE(selected_database," " ,"&")) 
y = POS(" ", selected_database)
IF y <> 0 THEN
	selected_database = LEFT(selected_database,y-1)||substr(selected_database,y+1)

status_bar = 'Default DB2 system is 'selected_database
db2.source = selected_database
guisetctlvalue('status_bar', 1)

db2.previous_database = selected_database

RETURN 0
/********************************************************************
 Create the menu with available database sources
********************************************************************/ 
init_db2_menus:

filename = "ODBC_defaults.txt"

DO
	STREAM(filename, 'C', 'OPEN READ')
	LOADTEXT('sourcecode.', filename,'BLT')
	STREAM(filename, 'C', 'CLOSE')
	CATCH SYNTAX
		err = STREAM(filename, "D")
		rc = wdwsay.rex(err, "|STOP")
		RETURN 1
END		

odbc_system.0 = 0
odbc_connection.0 = 0

user = USERID()
user = TRANSLATE(user)

/* Loop round the file we just read in and extract the available
   ODBC databases plus their connection strings */
DO i = 1 TO sourcecode.0
	SELECT
		WHEN "*" = LEFT(sourcecode.i,1) THEN
			NOP				/* Commented line - ignore */
		OTHERWISE
			DO
				odbc_system.0 = odbc_system.0 + 1
				odbc_connection.0 = odbc_connection.0 + 1
				PARSE VAR sourcecode.i db2 "§" connection_string
				connection_string = TRANSLATE(connection_string)
				IF POS("&USER", connection_string) <> 0 THEN
					connection_string = CHANGESTR("&USER", connection_string, user)
				y = POS("/*", connection_string)
				if y <> 0 then
					connection_string = left(connection_string,y - 1)	
				ODBC_system.[ODBC_system.0] = strip(db2)
				ODBC_connection.[ODBC_connection.0] = strip(connection_string)
			end
	end				
end

err = guiaddmenu('DB2 &Source, , ALT "S"', 'HEADING', 1)
do i = ODBC_system.0 to 1 by -1
	err = guiaddmenu(ODBC_system.i", ODBC_source."i, "ITEM", 1 1)
end

db2.previous_database = ""

return 0
/************************************************************************

************************************************************************/
free_previous_database:

arg selected_database 

temp = translate(selected_database, "_", " ")
db2_handlename = "DB2."temp"_handle"
if exists(db2_handlename) then
	do
		current_handle = VALUE(db2_handlename)
		rc = odbcfreedatabase("DROP", current_handle)
		drop db2_handlename
	end	
return 0
/*
select
	when selected_database = 'DB2T' & 1 = exists('DB2.db2t_handle') then
		do
			rc = odbcfreedatabase("DROP", DB2.db2t_handle)
			drop DB2.db2t_handle
		end	
	when selected_database = 'DBST' & 1 = exists('DB2.dbst_handle') then
		do
			rc = odbcfreedatabase("DROP", DB2.dbst_handle)
			drop DB2.dbst_handle
		end			
	when selected_database = 'MFE' & 1 = exists('DB2.mfe_handle') then
		do
			rc = odbcfreedatabase("DROP", DB2.mfe_handle)
			drop DB2.mfe_handle
		end
	when selected_database = 'SQLITE' & 1 = exists('DB2.sqlite_handle') then
		do
			rc = odbcfreedatabase("DROP", DB2.sqlite_handle)
			drop DB2.sqlite_handle
		end
	when selected_database = 'DB2 EXPRESS' & 1 = exists('DB2.db2_express_handle') then
		do
			rc = odbcfreedatabase("DROP", DB2.db2_express_handle)
			drop DB2.db2_express_handle
		end
	otherwise
		nop		
end

return 0
*/
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Fri 2024-6-14  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2010-03-08 22:56:18