Collection Contents Index Error checking in ODBC Working with result sets pdf/chap4.pdf

Programming Interfaces Guide
   CHAPTER 4. ODBC Programming     

Using prepared statements in ODBC


Prepared statements provide performance advantages for statements that are used repeatedly. ODBC provides a full set of functions for using prepared statements.

For Info     For an introduction to prepared statements, see Preparing statements.

  To execute a prepared statement:
  1. You prepare the statement using SQLPrepare. The following code fragment illustrates how to prepare an INSERT statement:

    SQLRETURN   retcode;
    SQLHSTMT    hstmt;
    
    retcode = SQLPrepare(hstmt,
                "INSERT 
                 INTO department 
                 (dept_id, dept_name, dept_head_id ) 
                 VALUES (?, ?, ?,)", 
              SQL_NTS);

    In this example:

  2. You set statement parameter values using SQLBindParameter. For example, the following function call sets the value of the dept_id variable:

    SQLBindParameter(hstmt, 
                     1, 
                     SQL_PARAM_INPUT, 
                     SQL_C_SSHORT,
                     SQL_INTEGER, 
                     0, 
                     0, 
                     &sDeptID, 
                     0, 
                     &cbDeptID);

In this example:

For Info     For more information, see the ODBC SDK documentation.


Collection Contents Index Error checking in ODBC Working with result sets pdf/chap4.pdf