setting database at runtime with 4gl
Posted in 1995
If you wanted to use the declarative database statement and get the benefits at compile time, but switch to another database at runtime then a case statement will do the trick. Databases can be switched at run-time by using a case statement and passing the name of the database as either a command line argumen using arg_val, as an environment variable using fgl_getenv or some other method you might think of. Since you cannot prepare a database statement the possibilities have to be hardcoded. function set_db(dbname) # make this a function so you can add clients # and not have to edit all your code define dbname char(20) case when dbname="d1" close database database d1 when dbname="d2" close database database d2 when dbname="d3" close database database d3 end case end function This case structure will open a database if the name is in the list, or work with the DEFAULT database if there is none matched. The default database would be the one that you put in your declarative statement. One thing though, if you move your compiled code to another system then the database that is in your declarative statement has to exist on that system. It probably needs to be just there, without tables, maybe. Anyway, by this method your clients can all have separate but similar databases, and you only need one bit of code.