ValidateTableFromFile and ValidateTableFromFileW
- Last Updated: August 19, 2019
- 4 minute read
- DataDirect Connectors
- ODBC
- Aha! 8.0
- Amazon Redshift 8.0
- Apache Cassandra 8.0
- Apache Hive 8.0
- Apache Spark SQL 8.0
- Autonomous Rest Connector 8.0
- Cloudera Impala 7.1
- dBase 7.1
- + 24
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 user's guide for your driver for more detailed information.
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 data types - Each column data type is checked to ensure no loss of data
occurs. If a data type mismatch is detected, the driver adds an entry to the
MessageList in the following format:
Risk of data conversion loss: Destinationcolumn_numberis of typex, and sourcecolumn_numberis of typey. - Check column sizes - Each column is checked for appropriate size. If column sizes
are too small in destination tables, the driver adds an entry to the MessageList in
the following format:
Possible Data Truncation: Destinationcolumn_numberis of sizexwhile sourcecolumn_numberis of sizey. - 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 forcolumn_numberrisks data corruption if transposed without correct character conversion from sourcecolumn_number. - Check Config Col Info - The destination metadata and the column metadata in the
configuration file are checked for consistency of items such as length for character
and binary data types, the character encoding code page for character types,
precision and scale for numeric types, and nullablity for all types. If any
inconsistency is found, the driver adds an entry to the MessageList in the following
format:
Destination column metadata forcolumn_numberhas column info mismatches from sourcecolumn_number. - Check Column Names and Mapping - The columns defined in the configuration file are
compared to the destination table columns based on the order of the columns. If the
number of columns in the configuration file and/or import file does not match the
number of columns in the table, the driver adds an entry to the MessageList in the
following format:
The number of destination columnsnumberdoes not match the number of source columnsnumber.
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.
- Check data types - Each column data type is checked to ensure no loss of data
occurs. If a data type mismatch is detected, the driver adds an entry to the
MessageList in the following format:
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);
}