Programs that can benefit from persistent binding

Not all Embedded SQL programs benefit from persistent binding. To find out whether persistent binding can benefit your program, answer the following questions:

  1. Does your program contain at least one Embedded SQL statement that executes more than once?

  2. If so, does that statement repeatedly use the same host variables to exchange values with Adaptive Server?

If you answered “yes” to both questions, your program can probably benefit from persistent binding. If you answered “no” to either question, persistent binding would not improve your program’s performance—unless you modify your program so that you can answer “yes” to both questions.

To maximize the benefit from persistent binding, your program should execute a single Embedded SQL statement repeatedly instead of executing two or more identical statements. For example, the following insert statement executes repeatedly:

for (i = 1; i <= 3; i++)
 {
  exec sql insert into titles (title_id, title)
  values (:bk_id, :bk_title);
 }

Although the insert statement in this example executes three times, its variables are bound only once. Because binding is not repeated, this example should run faster than a series of identical insert statements that execute only once.