DataDirect Bulk Load : Export, Validate, and Load Functions : ValidateTableFromFile and ValidateTableFromFileW

ValidateTableFromFile and ValidateTableFromFileW
Syntax
SQLReturn
ValidateTableFromFile  (HDBC       hdbc,
                        SQLCHAR*   TableName,
                        SQLCHAR*   ConfigFile,
                        SQLCHAR*   MessageList,
                        SQLULEN    MessageListSize,
                        SQLULEN*   NumMessages)
ValidateTableFromFileW (HDBC       hdbc,
                        SQLCHAR*   TableName,
                        SQLCHAR*   ConfigFile,
                        SQLCHAR*   MessageList,
                        SQLULEN    MessageListSize,
                        SQLULEN*   NumMessages)
The standard ODBC return codes are returned: SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_INVALID_HANDLE, and SQL_ERROR.
Purpose
ValidateTableFromFile (ANSI application) and ValidateTablefromFileW (Unicode application) verify the metadata in the configuration file against the data structure of the target database table. Refer to "Verification of the Bulk Load Configuration File" in the DataDirect Connect Series for ODBC User’s Guide for more detailed information.
The Salesforce driver does not support ValidateTableFromFile and ValidateTableFromFileW.
Parameters
hdbc
is the driver’s connection handle, which is not the handle returned by SQLAllocHandle or SQLAllocConnect. To obtain the driver's connection handle, the application must then use the standard ODBC function SQLGetInfo (ODBC Conn Handle, SQL_DRIVER_HDBC).
TableName
is a null-terminated character string that specifies the name of the target database table into which the data is to be loaded.
ConfigFile
is a null-terminated character string that specifies the path (relative or absolute) and file name of the bulk configuration file.
MessageList
specifies a pointer to a buffer used to record any of the errors and warnings. MessageList must not be null.
MessageListSize
specifies the maximum number of characters that can be written to the buffer to which MessageList points. If the buffer to which MessageList points is not big enough to hold all of the messages generated by the validation process, the validation is aborted and SQL_ERROR is returned.
NumMessages
contains the number of messages that were added to the buffer. This method reports the following criteria:
Check codepages - Each column is checked for appropriate code page alignment between the source and destination. If a mismatch occurs, the driver adds an entry to the MessageList in the following format: Destination column code page for column_number risks data corruption if transposed without correct character conversion from source column_number.
The function returns an array of null-terminated strings in the buffer to which MessageList points with an entry for each of these checks. If the driver determines that the information in the bulk load configuration file matches the metadata of the destination table, a return code of SQL_SUCCESS is returned and the MessageList remains empty.
If the driver determines that there are minor differences in the information in the bulk load configuration file and the destination table, then SQL_SUCCESS_WITH_INFO is returned and the MessageList is populated with information on the cause of the potential problems.
If the driver determines that the information in the bulk load information file cannot successfully be loaded into the destination table, then a return code of SQL_ERROR is returned and the MessageList is populated with information on the problems and mismatches between the source and destination.
Example
HDBC      hdbc;
HENV      henv;
void      *driverHandle;
HMODULE   hmod;
PValidateTableFromFile validateTableFromFile;

char      tableName[128];
char      configFile[512];
char      messageList[10240];
SQLLEN    numMessages;

/* Get the driver's connection handle from the DM. This handle must be used when calling directly into the driver. */

rc = SQLGetInfo (hdbc, SQL_DRIVER_HDBC, &driverHandle, 0, NULL);
if (rc != SQL_SUCCESS) {
    ODBC_error (henv, hdbc, SQL_NULL_HSTMT);
    EnvClose (henv, hdbc);
    exit (255);
}

/* Get the DM's shared library or DLL handle to the driver. */

rc = SQLGetInfo (hdbc, SQL_DRIVER_HLIB, &hmod, 0, NULL);
if (rc != SQL_SUCCESS) {
    ODBC_error (henv, hdbc, SQL_NULL_HSTMT);
    EnvClose (henv, hdbc);
    exit (255);
}

validateTableFromFile = (PValidateTableFromFile)
  resolveName (hmod, "ValidateTableFromFile");
if (!validateTableFromFile) {
  printf ("Cannot find ValidateTableFromFile!\n");
  exit (255);
}

messageList[0] = 0;
numMessages = 0;

rc = (*validateTableFromFile) (
      driverHandle,
      (const SQLCHAR *) tableName,
      (const SQLCHAR *) configFile,
      (SQLCHAR *) messageList,
      sizeof (messageList),
      &numMessages);
printf ("%d message%s%s\n", numMessages,
       (numMessages == 0) ? "s" :
       ((numMessages == 1) ? " : " : "s : "),
       (numMessages > 0) ? messageList : "");
if (rc == SQL_SUCCESS) {
       printf ("Validate succeeded.\n");
}
else {
    driverError (driverHandle, hmod);
}

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