skip to main content
Using the ODBC Client : Using DataDirect Bulk Load : DataDirect Bulk Load Functions : Utility Functions
 

Utility Functions

The example code in this section shows utility functions to which the DataDirect functions for bulk exporting, verification, and bulk loading refer, as well as the DataDirect functions GetBulkDiagRec and GetBulkDiagRecW.

GetBulkDiagRec and GetBulkDiagRecW

Syntax 

SQLReturn
GetBulkDiagRec (SQLSMALLINT HandleType,
SQLHANDLE Handle,
SQLSMALLINT RecNumber,
SQLCHAR* Sqlstate,
SQLINTEGER* NativeError,
SQLCHAR* MessageText,
SQLSMALLINT BufferLength,
SQLSMALLINT* TextLength);
GetBulkDiagRecW (SQLSMALLINT HandleType,
SQLHANDLE Handle,
SQLSMALLINT RecNumber,
SQLWCHAR* Sqlstate,
SQLINTEGER* NativeError,
SQLWCHAR* MessageText,
SQLSMALLINT BufferLength,
SQLSMALLINT* TextLength);
The standard ODBC return codes are returned: SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_INVALID_HANDLE, SQL_NO_DATA, and SQL_ERROR.

Purpose 

GetBulkDiagRec (ANSI application) and GetBulkDiagRecW (Unicode application) return errors and warnings generated by bulk operations. The argument definition, return values, and function behavior is the same as for the standard ODBC SQLGetDiagRec and SQLGetDiagRecW functions with the following exceptions:
The GetBulkDiagRec and GetBulkDiagRecW functions can be called after a bulk load, export or validate function is invoked to retrieve any error messages generated by the bulk operation. Calling these functions after any function except a bulk function is not recommended.
The values returned in the Sqlstate and MessageText buffers by the GetBulkDiagRecW function are encoded as UTF-16 on Windows platforms. On UNIX and Linux platforms, the values returned for Sqlstate and MessageText are UTF-16 if the value of the SQL_ATTR_APP_UNICODE_TYPE is SQL_DD_CP_UTF16 and UTF-8 if the value of SQL_ATTR_APP_UNICODE_TYPE is SQL_DD_CP_UTF8.
The handle passed as the Handle argument must be a driver connection handle obtained by calling SQLGetInfo (<ODBC Conn Handle>, SQL_DRIVER_HDBC).
SQL_HANDLE_DBC is the only value accepted for HandleType. Any other value causes an error to be returned.

Example 

#include "qesqlext.h"
 
#ifndef NULL
#define NULL 0
#endif
 
#if (! defined (_WIN32)) && (! defined (_WIN64))
typedef void * HMODULE;
#endif
 
/* Get the address of a routine in a shared library or DLL. */
void * resolveName (
HMODULE hmod,
const char *name)
{
#if defined (_WIN32) || defined (_WIN64)
 
return GetProcAddress (hmod, name);
#elif defined (hpux)
void *routine = shl_findsym (hmod, name);
 
shl_findsym (hmod, name, TYPE_PROCEDURE, &routine);
 
return routine;
#else
return dlsym (hmod, name);
#endif
}
 
/* Get errors directly from the driver's connection handle. */
void driverError (void *driverHandle, HMODULE hmod)
{
UCHAR sqlstate[16];
UCHAR errmsg[SQL_MAX_MESSAGE_LENGTH * 2];
SDWORD nativeerr;
SWORD actualmsglen;
RETCODE rc;
SQLSMALLINT i;
PGetBulkDiagRec getBulkDiagRec;
 
getBulkDiagRec = (PGetBulkDiagRec)
resolveName (hmod, "GetBulkDiagRec");
 
if (! getBulkDiagRec) {
printf ("Cannot find GetBulkDiagRec!\n");
return;
}
 
 
i = 1;
loop: rc = (*getBulkDiagRec) (SQL_HANDLE_DBC,
driverHandle, i++,
sqlstate, &nativeerr, errmsg,
SQL_MAX_MESSAGE_LENGTH - 1, &actualmsglen);
 
if (rc == SQL_ERROR) {
printf ("GetBulkDiagRec failed!\n");
return;
}
 
if (rc == SQL_NO_DATA_FOUND) return;
 
printf ("SQLSTATE = %s\n", sqlstate);
printf ("NATIVE ERROR = %d\n", nativeerr);
errmsg[actualmsglen] = '\0';
printf ("MSG = %s\n\n", errmsg);
goto loop;
}