Binding an application

 

Before you can run your application program, a relationship between the program and any referred-to tables and views must be established. This process is called binding.

The result of binding is an access plan. The access plan is a control structure that describes the actions necessary to satisfy each SQL request. An access plan contains information about the program and about the data the program intends to use. For distributed relational database work, the access plan is stored in the SQL package and managed by the system along with the SQL package.

SQL automatically attempts to bind and create access plans when the result of a successful compilation is a program or service program object. If the compilation is not successful or the result of a compilation is a module object, access plans are not created. If, at run time, the database manager detects that an access plan is not valid or that changes have occurred to the database that might improve performance (for example, the addition of indexes), a new access plan is automatically created. If the application server (AS) is not a System i™ product, then a bind must be done again using the Create Structured Query Language Package (CRTSQLPKG) command. Binding performs these tasks:

If the characteristics of a table or view your program accesses have changed, the access plan might no longer be valid. When you attempt to use an access plan that is not valid, the system automatically attempts to rebuild the access plan. If the access plan cannot be rebuilt, a negative SQLCODE is returned. In this case, you might have to change the program's SQL statements and reissue the CRTSQLxxx command to correct the situation.

For example, if a program contains an SQL statement that refers to COLUMNA in TABLEA and the user deletes and recreates TABLEA so that COLUMNA no longer exists, when you call the program, the automatic rebind is unsuccessful because COLUMNA no longer exists. You must change the program source and reissue the CRTSQLxxx command.

 

Parent topic:

Preparing distributed relational database programs

 

Related concepts


Working with SQL packages

 

Related reference


SQL package creation
Create Structured Query Language Package (CRTSQLPKG) command