informix
INFORMIX-ESQL/C Programmer's Manual
Programming with INFORMIX-ESQL/C

Setting and Retrieving Environment Variables in Windows Environments

You might change the settings of environment variables or create new variables to increase the flexibility of an application. Instead of assuming a particular environment configuration, you can define the environment at runtime. This option can benefit your application in the following ways:

The following ESQL/C library functions are available for setting and retrieving environment variables. The library functions are located in Appendix B, ESQL/C Function Library.

Function Name Description Reference
ifx_putenv() Modifies or removes an existing environment variable or creates a new variable B-245
ifx_getenv() Retrieves the value of an environment variable B-108

Important: The ifx_putenv() function sets the value of an environment variable in the InetLogin structure, and the ifx_getenv() function retrieves the value of an environment variable from InetLogin. Informix recommends that you use these functions to set and retrieve InetLogin field values.

For more information about InetLogin fields, see Fields of the InetLogin Structure.

These functions affect only the environment that is local to the current process. The ifx_putenv() function cannot modify the command-level environment. The functions operate only on data structures accessible to the ESQL/C runtime library and not on the environment segment that the operating system creates for the process. When the current process terminates, the environment reverts to the level of the calling process (in most cases, the operating-system level).

The process cannot directly pass on the modified environment to any new processes that _spawn(), _exec(), or system() creates. These new processes do not receive any new variables that ifx_putenv() added. You can, however, pass on an environment variable to a new process in the following way:

  1. The current process creates an environment variable with the ESQL/C ifx_putenv() function.
  2. The current process uses the C putenv() function to put the environment variable into the operating-system environment segment.
  3. The current process starts a new process.
  4. The new process uses the C getenv() function to retrieve the environment variable from the operating-system environment segment.
  5. The new process uses the ESQL/C ifx_getenv() function to retrieve the variable into the runtime environment segment.

For environment variable entries, observe the following guidelines:

InetLogin Structure

Important: Informix supports the InetLogin structure for backward compatibility only. For new development, Informix recommends that you use the ifx_getenv() and ifx_putenv() functions instead.

An ESQL/C client application in a Windows environment can use the InetLogin structure to set dynamically the configuration information that the application needs.

This section provides the following information about InetLogin:

Fields of the InetLogin Structure

The InetLogin structure is a global C structure that the login.h header file declares. To use this structure in your ESQL/C program, you must include login.h in your source file (.ec). For more information on login.h, see Figure 1-19 on page 1-40.

Tip: Because login.h does not contain ESQL/C statements, you can include the file with the C #include or the ESQL/C include directive.

Figure 1-20 defines the fields in the InetLogin structure.

Figure 1-20
Fields of the InetLogin Structure

InetLogin Field Data Type Purpose
InfxServer char[19] Specifies the value for the INFORMIXSERVER environment variable (the default database server)
DbPath char[129] Specifies the value for the DBPATH environment variable
DbDate char[6] Specifies the value for the DBDATE environment variable Provides backward compatibility for client applications that are based on earlier versions of Informix products
DbMoney char[19] Specifies the value for the DBMONEY environment variable Provides backward compatibility for client applications that are based on earlier versions of Informix products
DbTime char[81] Specifies the value for the DBTIME environment variable Provides backward compatibility for client applications that are based on earlier versions of Informix products
DbTemp char[81] Specifies the value for the DBTEMP environment variable
DbLang char[19] Specifies the value for the DBLANG environment variable
DbAnsiWarn char[1] Specifies the value for the DBANSIWARN environment variable
InformixDir char[255] Specifies the value for the INFORMIXDIR environment variable
Client_Loc char * Specifies the value for the CLIENT_LOCALE environment variable
DB_Loc char * Specifies the value for the DB_LOCALE environment variable
DbNls char[3] Specifies the value for the DBNLS environment variable Provides backward compatibility for client applications that are based on earlier versions of Informix NLS products
CollChar char[3] Specifies the value for the COLLCHAR environment variable Provides backward compatibility for client applications that are based on earlier versions of Informix NLS products
Lang char[81] Specifies the value for the LANG environment variable for the database locale Provides backward compatibility for client applications that are based on earlier versions of Informix NLS products
Lc_Collate char[81] Specifies the value for the LC_COLLATE environment variable for the database locale Provides backward compatibility for client applications that are based on earlier versions of Informix NLS products
Lc_CType char[81] Specifies the value of the LC_CTYPE environment variable for the database locale Provides backward compatibility for client applications that are based on earlier versions of Informix NLS products
Lc_Monetary char[81] Specifies the value of the LC_MONETARY environment variable for the database locale Provides backward compatibility for client applications that are based on earlier versions of Informix NLS products
Lc_Numeric char[81] Specifies the value of the LC_NUMERIC environment variable for the database locale Provides backward compatibility for client applications that are based on earlier versions of Informix NLS products
Lc_Time char[81] Specifies the value for the LC_TIME environment variable for the database locale Provides backward compatibility for client applications that are based on earlier versions of Informix NLS products
ConRetry char[4] Specifies the value of the environment variable INFORMIXCONRETRY
ConTime char[4] Specifies the value of the environment variable INFORMIXCONTIME
DelimIdent char[4] Specifies the value of the DELIMIDENT environment variable
Host char[19] Specifies the value for the HOST network parameter
User char[19] Specifies the value for the USER network parameter
Pass char[19] Specifies the value for the PASSWORD network parameter
AskPassAtConnect char[2] Indicates whether sqlauth() should request a password at connection time; should contain the value for yes or no. AskPassAtConnect is set if the first character is Y or y.
Service char[19] Specifies the value for the SERVICE network parameter
Protocol char[19] Specifies the value for the PROTOCOL network parameter
Options char[20] Reserved for future use
InformixSqlHosts char[255] Specifies the value for the INFORMIXSQLHOSTS environment variable
FetBuffSize char[6] Specifies the value for the FET_BUF_SIZE environment variable
CC8BitLevel char[2] Specifies the value for the CC8BITLEVEL environment variable
EsqlMF char[2] Specifies the value for the ESQLMF environment variable
GlDate char[129] Specifies the value for the GL_DATE environment variable
GlDateTime char[129] Specifies the value for the GL_DATETIME environment variable
DbAlsBc char[2] Specifies the value for the DBALSBC environment variable Provides backward compatibility for client applications that are based on earlier versions of Informix products
DbApiCode char[24] Specifies the value for the DBAPICODE environment variable Provides backward compatibility for client applications that are based on earlier versions of Informix products
DbAsciiBc char[2] Specifies the value for the DBASCIIBC environment variable Provides backward compatibility for client applications that are based on earlier versions of Informix products
DbCentury char[2] Specifies the value for the DBCENTURY environment variable
DbCodeset char[24] Specifies the value for the DBCODESET environment variable Provides backward compatibility for client applications that are based on 4.x and 4.x versions of Informix Asian Language Support (ALS) products
DbConnect char[2] Specifies the value for the DBCONNECT environment variable Provides backward compatibility for client applications that are based on earlier versions of Informix products
DbCsConv char[9] Specifies the value for the DBCSCONV environment variable Provides backward compatibility for client applications that are based on earlier versions of Informix products
DbCsOverride char[2] Specifies the value for the DBCSOVERRIDE environment variable Provides backward compatibility for client applications that are based on earlier versions of Informix Asian Language Support (ALS) products
DbCsWidth char[12] Specifies the value for the DBCSWIDTH environment variable Provides backward compatibility for client applications that are based on earlier versions of Informix products
DbFltMsk char[4] Specifies the value for the DBFLTMASK environment variable
DbMoneyScale char[6] Specifies the value for the DBMONEYSCALE environment variable Provides backward compatibility for client applications that are based on earlier versions of Informix products
DbSS2 char[5] Specifies the value for the DBSS2 environment variable Provides backward compatibility for client applications that are based on earlier versions of Informix products
DbSS3 char[5] Specifies the value for the DBSS3 environment variable Provides backward compatibility for client applications that are based on earlier versions of Informix products
OptoFC char[2] Not used
OptMSG char[2] Not used

All fields in the InetLogin structure, except DbAnsiWarn, Client_Loc, and DB_Loc, are of data type char and are null-terminated strings. The Client_Loc and DB_Loc fields are character pointers whose data space your ESQL/C program must allocate.

InetLogin Field Values

Your application must set InetLogin values before it executes the SQL statement or ESQL/C library function that needs the configuration information. Informix recommends that you use the ifx_putenv() and ifx_getenv() functions to set and retrieve InetLogin field values through environment variables, but you can set the values of the InetLogin fields directly.

Figure 1-21 shows a dialog box that a client application might use to obtain network parameters from an end user. This application takes the account information that the user enters and sets the appropriate network values in the InetLogin structure.

Figure 1-21
User Dialog Box for Login Parameters

Figure 1-22 shows a code fragment that sets login values in the InetLogin structure. The application can obtain these values from the end user through a dialog box (such as the one in Figure 1-21).

Figure 1-22
Code to Prompt the User for InetLogin Values


In Figure 1-22, if the user enters host information, the fragment sets the InetLogin.Host and InetLogin.User fields for the mainsrvr database server to the user-specified names of the host name and user name, respectively. If the user does not enter host information, ESQL/C uses the HOST and USER Registry values from the subkey for the mainsrvr database server.

Tip: For another example of how to set the InetLogin fields, see the ILOGIN demo program in the %INFORMIXDIR%\demo\ilogin directory.

Precedence of Configuration Values

When a client application in a Windows environment requires configuration information, ESQL/C obtains it from the following locations:

  1. The InetLogin structure
  2. If the application uses the InetLogin structure, ESQL/C first checks for configuration information in this structure. (To set the value of an environment variable for the application process, the ifx_putenv() function changes the value of an InetLogin field.)

  3. The INFORMIX subkey of the Registry
  4. If the application has not set the desired configuration information in InetLogin, ESQL/C checks for this information in its copy of the Registry information. For more information on how to set the Registry, see the Informix Client Products Installation Guide for Microsoft Windows Environments.

You do not need to define all the values in the InetLogin structure. The application uses the configuration information in the Registry for any values it cannot find in InetLogin. If you do not set the corresponding Registry value, the application uses its default value.

Important: The first time that the application requires configuration information, ESQL/C reads this information from the Registry and stores it in memory. For subsequent references to Registry information, ESQL/C accesses this in-memory copy and does not reread the Registry.

This hierarchy of configuration information is valuable if, for example, you want the application user to provide a user name and password at runtime, or if an application has some configuration information that differs from the general values in the Registry. For example, suppose the application sets the ConRetry field of InetLogin to 2 but does not set the ConTime field, as the following code fragment shows:

When ESQL/C establishes the connection to the accnts database, it tries to establish the connection twice (instead of the default value of once) but it still uses a connection time of 15 seconds (the default value from the in-memory copy of the Registry information). If Setnet32 has modified the connection values, ESQL/C uses the modified Registry values instead of the default values.

Tip: Use the Setnet32 utility to define configuration information in the Registry. For more information about Setnet32, refer to the "Informix Client Products Installation Guide for Microsoft Windows Environments."


INFORMIX-ESQL/C Programmer's Manual, Version 9.21
Copyright © 1999, Informix Software, Inc. All rights reserved