Set and retrieve 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 run time.
- The application becomes less dependent on a predefined environment.
- Users can enter their user name and password within an application.
- Users can run two applications with different network parameters on the same client computer.
- The same application can run on client computers with different configurations.
- ifx_putenv()
- Modifies or removes an existing environment variable or creates a variable.
- ifx_getenv()
- Retrieves the value of an environment variable.
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 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 current process creates an environment variable with the ifx_putenv() function.
- The current process uses the C putenv() function to put the environment variable into the operating-system environment segment.
- The current process starts a new process.
- The new process uses the C getenv() function to retrieve the environment variable from the operating-system environment segment.
- The new process uses the ifx_getenv() function to retrieve the variable into the runtime environment segment.
Environment variable guidelines
- If you plan to set any HCL OneDB™ environment variables with ifx_putenv(), have the application set all of them before it calls any other library routine, including ifx_getenv(), or any SQL statement. The first call to any other library routine or SQL statement requires initialization of the GLS locales. This initialization loads and freezes the values of CLIENT_LOCALE, DB_LOCALE, and the DATE, TIME, and DATETIME formatting values.
- If Setnet32 sets the HCL
OneDB environment
variable to a non-null value in the Registry, the ifx_putenv() function
cannot change the value of the variable to a null string.
If you specify a null string for an environment variable in an ifx_putenv() function call, clears any value set for the environment variable from the runtime environment segment. Then the Registry value for the environment variable is available to the application.
- Do not change an environment variable with setenv in the
command line or with the C putenv() function because
a change to the operating-system environment segment has no effect
on the ESQL client-interface DLL after application execution begins.
Instead, use ifx_putenv() to change an environment variable in the runtime environment segment.
- To modify the return value of ifx_getenv() without affecting the environment table, use _strdup() or strcpy() to make a copy of the string.