he database server begins processing an SQL request

status = 1

While the database server executes an SQL request, when the time-out interval has elapsed

status = 2

When the database server completes the processing of an SQL request

status = 0

When you call the callback function with a status value of 2, the callback function can determine whether the database server can continue processing with one of following actions:

The callback function, and any of its subroutines, can contain only the following ESQL/C control functions: sqldone(), sqlbreak(), and sqlbreakcallback(). For more information about the callback function, see page 12-38.

If you call sqlbreakcallback() with a time-out value of zero (0), the callback function executes immediately. The callback function executes over and over again unless it contains a call to sqlbreakcallback() to redefine the callback function with one of the following actions:

Important: Small time-out values might adversely affect the performance of your application.
For more information about the time-out interval, see page 12-37.

You must establish a database server connection before you call the sqlbreakcallback() function. The callback function remains in effect for the duration of the connection or until the sqlbreakcallback() function redefines the callback function.

Return Codes

0

The call to sqlbreakcallback() was successful.

<0

The call to sqlbreakcallback() was not successful.

sqldetach()

The sqldetach() function detaches a process from the database server. You generally call this function when an application forks a new process to begin a new stream of execution.

Syntax

Usage

If an application spawns one or more processes after it initiates a connection to a database server, all the child processes inherit that database server connection from the parent process (the application process that spawned the child). However, the database server still assumes that this connection has only one process. If one database server connection tries to serve both the parent and child processes at the same time, problems can result. For example, if both processes send messages to do something, the database server has no way of knowing which messages belong to which process. The database server might not receive messages in an order that makes sense and might thereby generate an error (such as error -408).

In this situation, call the sqldetach() function from the child process. The sqldetach() function detaches the child process from the connection that the parent process establishes (which the child inherits). This action drops all database server connections in the child process. The child process can then establish its own connection to a database server.

Use the sqldetach() function with the fork() system call. When you spawn a child process from an application process with a database server connection, sequence the function calls as follows:

1. Call fork() from the parent process to create a copy of the parent process (the child process). Now both parent and child share the same connection to the database server.

    2. Call sqldetach() from the child process to detach the child process from the database server. This call closes the connection in the child process.

Tip: You cannot use sqldetach() after a vfork() call because vfork() does not execute a true process fork until the exec() function is called. Do not use sqldetach() after the parent process uses an exec(); when exec() starts the child process, the child process does not inherit the connection that the parent process established.
A call to the sqldetach() function does not affect the database server sessions of the parent process. Therefore, after sqldetach() executes in the child process, the parent process retains any open cursors, transactions, or databases, and the child process has neither database server sessions nor database server connections.

When you call the sqlexit() function from the parent process, the function drops the connection in the parent process but does not affect the connections in the child process. Similarly, when you call sqlexit() from the child process, the function drops only the child connections; it does not affect the parent connections. The sqlexit() function rolls back any open transactions before it closes the connection.

If you execute the DISCONNECT statement from a child process, you disconnect the process from database server connections and terminate the database server sessions that correspond to those connections. The DISCONNECT fails if any transactions are open.

If the child process application has only one implicit connection before it calls sqldetach(), execution of the next SQL statement or of the sqlstart() library function reestablishes an implicit connection to the default database server. If the application has made one or more explicit connections, you must issue a CONNECT statement before you execute any other SQL statements.

The sqldetach demonstration program illustrates how to use the sqldetach() function.

Return Codes

0

The call to sqldetach() was successful.

<0

The call to sqldetach() was not successful.

Example

The sqldetach.ec file in the demo directory contains this sample program.

Example Output

sqldone()

The sqldone() function determines whether the database server is currently processing an SQL request.

Syntax

Usage

Use sqldone() to test the status of the database server in the following situations:

When the sqldone() function determines that the database server is not currently processing an SQL request, you can assume that the database server does not begin any other processing until your application issues its next request.

You might want to create a defined constant for the -439 value to make your code more readable. For example, the following code fragment creates the SERVER_BUSY constant and then uses it to test the sqldone() return status:

Return Codes

0

The database server is not currently processing an SQL request: it is idle.

-439

The database server is currently processing an SQL request.

sqlexit()

The sqlexit() function terminates all database server connections and frees resources. You can use sqlexit() to reduce database overhead in programs that refer to a database only briefly and after long intervals, or that access a database only during initialization.

Syntax

Usage

Only call the sqlexit() function when no databases are open. If an open database uses transactions, sqlexit() rolls back any open transactions before it closes the database. The behavior of this function is similar to that of the DISCONNECT ALL statement. However, the DISCONNECT ALL statement fails if any current transactions exist. Use the CLOSE DATABASE statement to close open databases before you call sqlexit().

If the application has only one implicit connection before it calls sqlexit(), execution of the next SQL statement or of the sqlstart() library function re-establishes an implicit connection to the default database server. If the application makes one or more explicit connections, you must issue a CONNECT statement before you execute any other SQL statements.

Return Codes

0

The call to sqlexit() was successful.

<0

The call to sqlexit() was not successful.

sqlsignal()

The sqlsignal() function enables, disables, or reenables signal handling of the signals that the ESQL/C library handles.

Syntax

Usage

The sqlsignal() function currently provides handling only for the SIGCHLD signal. In some instances, defunct child processes remain after the application ends. If the application does not clean up these processes, they can cause needless use of process IDs and increase the risk that you run out of processes. This behavior is only apparent when the application uses pipes for client-server communication (that is, the nettype field of the sqlhosts file is ipcpip). You do not need to call sqlsignal() for other communication mechanisms (for example, a nettype of tlipcp).

The mode argument of sqlsignal() determines the task that sqlsignal() performs, as follows:

When you initialize SIGCHLD signal handling with sqlsignal(), you allow the ESQL/C library to process SIGCHLD cleanup. Otherwise, your application must perform the cleanup for these processes if defunct child processes are a problem.

sqlstart()

The sqlstart() function starts an implicit default connection. An implicit default connection can support one connection to the default database server (that the INFORMIXSERVER environment variable specifies).

Tip: Restrict use of sqlstart() to pre-Version 6.0 applications that only use one connection. ESQL/C continues to support this function for backward compatibility with these applications. For applications of Version 6.0 and later, use the CONNECT statement to establish explicit connections to a default database server.

Syntax

Usage

ESQL/C provides the sqlstart() function for pre-Version 6.0 applications that can only support single connections. In this context, possible uses of sqlstart() are as follows:

If you have a pre-Version 6.0 application that needs an implicit default connection for any other reason, use the DATABASE statement instead of sqlstart(). For applications of Version 6.0 and later, use the CONNECT statement to establish database server connections.

When you call the sqlstart() function, make sure that the application has not yet established any connections, implicit or explicit. When the application has established an explicit connection, sqlstart() returns error -1811. If an implicit connection has been established, sqlstart() returns error -1802.

You can call this function several times before you establish an explicit connection, as long as each implicit connection is disconnected before the next call to sqlstart(). For information on disconnecting, see "Terminating a Connection". For more information on explicit and implicit connections, see "Establishing a Connection".

Return Codes

0

The call to sqlstart() was successful.

<0

The call to sqlstart() was not successful.




Informix-ESQL/C Programmer's Manual, version 9.1
Copyright © 1998, Informix Software, Inc. All rights reserved.