DataDirect Bulk Load : Utility 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.
Description
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:
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;
}

© 2013 Progress Software Corporation and/or its subsidiaries or affiliates.