Re: 4GL - Database Names
Posted in 1996
That doesn't look really different from what I suggested. However you are assuming that the original poster has a non procedural database statement before the main program clause (This is something I don't particularly like). If indeed this is the case, IMO it would be wiser to drop it rather than closing the currently opened database. OTOH if he hasn't, your code leads to RT error -349. BTW database accepts string variables, so no need to prepare it. HTH, Marco (not flaming anyone even though he usually sounds rude) Greco. ____________________________________________________________________________ rem radioterapia, which I immeritately manage, seldom agrees with what I say marco greco (Catania, Italy) Work: marcog@ctonline.it rem radioterapia 39 95 447828 fax 446558 (was mar.greco@agora.stm.it) Achea 39 95 503117 --- On Tue, 01 Oct 1996 19:44:35 GMT Perry Dillard <bpd@criinc.com> wrote: Forget the other posts and use the following ideaa. If you have an initialization routine that is called first thing in all your programs you can put the following code there. Otherwise you will need to add an initialization call as the first statement in main for all programs. This is generally a good technique and can also help you provide restart capability to your programs. ie. let users switch databases on the fly, which is actually a little trickier than it sounds. Anyway, here is the code: function init() define sqlStr char(80), nArgs smallint, idx smallint let sqlStr = null let nArgs = num_args() for idx = 1 to nArgs if arg_val(idx) = "-d" then let sqlStr = "database ", arg_val(idx+1) end if end for if sqlStr is not null then close database prepare openStmt from sqlStr execute openStmt # Check for errors and exit the program if there are any if sqlca.sqlcode != 0 then display "Error opening the database!" exit program(1) end if end if end function That should be it. Of course you'll have to recompile but this is a nice little technique to add to your programs. And the best part is that if you put it in a library, you can add it to programs as needed. You can always make a one time pass and add it to all programs as well. [Snip] -----------------End of Original Message-----------------