Example 64-bit ODBC application

Applications that deal with large amounts of data are good candidates for 64-bit addressing.

The following example shows a 64-bit application that inserts a row into a table by binding two application variables to INTEGER and CHAR(10) parameter markers and then uses SQLFetch() to retrieve the row data from bound columns of the result set. The DSNTEJ8E sample in the SDSNSAMP library shows the JCL for compiling, binding, and executing a 64-bit ODBC application.

/* Declare local variables. When compiled in LP64 mode, variables are
   allocated in stack storage above the 2G line */
SQLINTEGER 		H1INT;
SQLCHAR 			H1CHAR[10];
SQLINTEGER 		H2INT;
SQLCHAR 			H2CHAR[10];

SQLLEN 			LEN_H1INT;
SQLLEN 			LEN_H1CHAR;
SQLLEN 			LEN_H2INT;
SQLLEN 			LEN_H2CHAR;

strcpy( (char *)sqlstmt, "INSERT INTO MYTABLE (INT4, CHAR10) VALUES( ?, ? )" );
rc = SQLPrepare( hstmt, sqlstmt, SQL_NTS );
if( rc != SQL_SUCCESS ) goto dberror;
/* Bind to DB2 INTEGER with data located above the 2G line*/
rc = SQLBindParameter( (SQLHSTMT) hstmt,
                       (SQLUSMALLINT) 1,
                       (SQLSMALLINT) SQL_PARAM_INPUT,
                       (SQLSMALLINT) SQL_C_LONG,
                       (SQLSMALLINT) SQL_INTEGER,
                       (SQLULEN) 0,
                       (SQLSMALLINT) 0,
                       (SQLPOINTER) &H1INT,
                       (SQLLEN) sizeof(H1INT),
                       (SQLLEN *) &LEN_H1INT );
if( rc != SQL_SUCCESS ) goto dberror;
/* Bind to DB2 CHAR(10) with data located above the 2G line*/
rc = SQLBindParameter( (SQLHSTMT) hstmt,
                       (SQLUSMALLINT) 2,
                       (SQLSMALLINT) SQL_PARAM_INPUT,
                       (SQLSMALLINT) SQL_C_CHAR,
                       (SQLSMALLINT) SQL_CHAR,
                       (SQLULEN) 10,
                       (SQLSMALLINT) 0,
                       (SQLPOINTER) H1CHAR,
                       (SQLLEN) sizeof(H1CHAR),
                       (SQLLEN *) &LEN_H1CHAR );
if( rc != SQL_SUCCESS ) goto dberror;
rc = SQLExecute( hstmt );
if( rc != SQL_SUCCESS ) goto dberror;
.
.
.
strcpy( (char *)sqlstmt, "SELECT INT4, CHAR10 FROM MYTABLE" );
rc = SQLPrepare( hstmt,sqlstmt,SQL_NTS );
if( rc != SQL_SUCCESS ) goto dberror;
rc = SQLExecute( hStmt );
if( rc != SQL_SUCCESS ) goto dberror;
/* Bind DB2 INTEGER column */
rc = SQLBindCol( (SQLHSTMT) hstmt,
                 (SQLUSMALLINT) 1,
                 (SQLSMALLINT) SQL_C_LONG,
                 (SQLPOINTER) &H2INT,
                 (SQLLEN) sizeof(H2INT),
                 (SQLLEN *) &LEN_H2INT );
if( rc != SQL_SUCCESS ) goto dberror;
/* Bind DB2 CHAR(10) column */
rc = SQLBindCol( (SQLHSTMT) hstmt,
                 (SQLUSMALLINT) 2,
                 (SQLSMALLINT) SQL_C_CHAR,
                 (SQLPOINTER) H2CHAR,
                 (SQLLEN) sizeof(H2CHAR),
                 (SQLLEN *) &LEN_H2CHAR );
if( rc != SQL_SUCCESS ) goto dberror;
/* Fetch data into storage above the 2G line */
rc = SQLFetch( hstmt );
.
.
.
dberror:
  rc = SQL_ERROR;
  return(rc);