Neoview ODBC Drivers Manual (R2.5)

NOTE: If you reuse the same job ID over time, all work done under that ID is assumed to be
related to the same job. Such reuse over a long period of time can result in undefined statistical
aggregation, because some aged work statistics might have been archived and removed from
the active statistics repository.
Example
In the following example, an application allocates environment and connection handles. It then
connects to the RUSH data source with the user ID Neo and password Neo, sets the job_id
connection attribute SQL_ATTR_SESSIONAME, and processes data. When it has finished
processing data, it disconnects from the data source and frees the handles.
#include hpsqlext.h
SQLHENV henv;
SQLHDBC hdbc;
SQLHSTMT hstmt;
SQLRETURN retcode;
/*Allocate environment handle */
retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
/* Set the ODBC version environment attribute */
retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
/* Allocate connection handle */
retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
/* Set job id to 2468. */
SQLSetConnectAttr(hdbc, (void*)SQL_ATTR_SESSIONNAME,
(SQLCHAR*) "2468", SQL_NTS);
/* Connect to data source */
retcode = SQLConnect(hdbc, (SQLCHAR*) "RUSH", SQL_NTS,
(SQLCHAR*) "Neo", SQL_NTS,
(SQLCHAR*) "Neo", SQL_NTS);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
/* Allocate statement handle */
retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
/* Process data */
...;
...;
...;
SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
}
SQLDisconnect(hdbc);
}
SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
}
}
SQLFreeHandle(SQL_HANDLE_ENV, henv);
Specifying an Application Name
SQL_ATTR_APPLNAME
Neoview ODBC provides the ability to specify an Application Name that persists for the duration
of a connection. By default, the application name is obtained from the application window title
or the name of the executable file, but you can override this value by specifying a connection
attribute.
Neoview Platform Specific Extensions and Attributes 41