Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need to use an unix environment variable in my DATABASE statement

Status
Not open for further replies.

cschmidt08822

Programmer
Jun 11, 2008
2
US
Can I use an environment variable, such as DBASE1, as my database name in a 4gl program? I can get the environment variable with fgl_getenv (let dbase = fgl_getenv("DBASE")), but cannot seem to use it. I tried to prepare it in a variable like db_stmt = "DATABASE ",dbase CLIPPED, but cannot execute it because it is not a cursor. Any ideas?

I would also need to do this for .per forms that are used by the 4gl program (at least I think I would have to)
 
Most Informix 4GL programs and screen forms have the database name hard coded as the first executable statement. (Yes, Informix 4GL is old technology and it's brain dead). However, you can close the database and reopen it early in your MAIN function:

Code:
DATABASE standard

MAIN

  DEFINE db_stmt CHAR(80)

  WHENEVER ERROR CONTINUE
  LET db_stmt = fgl_getenv("DBASE")
  CLOSE DATABASE
  DATABASE db_stmt
  IF sqlca.sqlcode <>  0
  THEN
      DISPLAY "can not open database: ", db_stmt

  END IF

END MAIN

In the above code, the program executes by getting the new database name, closing standard db, and opening the new database. Now, the program can go about it's business with the new database.

In production, the standard database only has to exist and be readable. It could be completely empty.

When I made a living as a 4GL programmer selling apps to other customers, my shop would develop in the standard database, and then name our customer's database something else using exactly this technique. Of course, the customer's database had to be a copy of standard or the programs would fail.

On the customer's unix box, we always had a null copy of standard.

Screen forms were a different matter. You really can not change the database name. At the time, this wasn't a hard ship because we knew what the customer's database name.

What you can do is define the database as formonly:

database formonly

Of course, this would limit the form's functionality. This forces you to define the variables with the form such as this:

attributes
f01 = formonly.jet_filter type char;

I can probably scare up an example of a screen form using database formonly.

Let me know if you have any questions.
 
I tried the DATABASE db_name syntax before and it failed, but now it works. I think it was because I did not close the initial database. As for forms, yeah, I knew the formonly way, but that means altering allot of code. I was hoping for an easier solution. If the closed database and the new database are the same (I am using one for production and the other for testing) then the forms should be ok if I leave them alone.

Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top