Re: How do you choose database at RUNTIME in r4gl?
Posted in 1994
mike, add the following function to your programs and call it from the main function: database standard main * * * if not(change_db()) then error "Cannot change to database.." exit program end if * * * end main function change_db() define i integer define dbname char(18) for i = 1 to num_args() if(downshift(arg_val(i))='-d') then let dbname=arg_val(i+1) end if end for whenever error continue close database database dname if(status!=0) then return false else return true end if end function to run the program: fglgo *.4gi -d stores > > SCENERIO: > We have two systems, production and development. > ISTAR is installed on both systems so we can perform remote queries. > > We have scores of 4gl reports that share a common 4gl GLOBAL header file. > When we wish to access data that is on production, we change the statement > database lotsadata > to > database lotsadata@production > > and recompile the program. When we run the program on development, we will > get production data. > > This causes problems because we have several programmers working in > Interactive 4gl (OnLine 4.11 for AIX 3.2.5) and we step on each other. > It is difficult to know where a compiled program will pull its data from > by looking at the P code, and the "database xxxx@yyyyy" statement causes > contention between programmers needing data from development and those > needing to access production. > > Is there a way that we can specify the database name at run time, instead > of compile time? Maybe make r4gl look at the contents of a UNIX > environmental variable, DBNAME? > > I have done some playing around and haven't found a nice solution. > If you put the "database" statement in the MAIN block, you can change > databases in the program, but I don't want to do this to 200 programs. I > would rather find a way to put the database selection in the shared > GLOBAL header... > > Any tips would be greatly appreciated. > > > > Thanks, > Mike Lester > Programmer/Analyst > USAA Investment Management Co. > > > > -- regards, +----------------------------------------------------------------------------+ | . . | Bob Baskett | | ... ... | Software Engineer | | ..... ..... | Business Systems Integration Group | | .. ... .. | Semiconductor Products Sector | | . . . | Mesa, AZ | | | President, Informix Users Group Of Arizona | | Motorola, Inc. | | +----------------------------------------------------------------------------+ | Sun 690MP 4.1.3, Online 5.01, 4.10.UD1 Tools, Fourgen v4.10.UC1 | +----------------------------------------------------------------------------+