![]() | ![]() |
Home |
|
|
Access Service User's Guide DirectConnect Anywhere |
|
| Chapter 10 Using Bulk Copy Transfer |
Chapter 10
This chapter describes the bulk copy transfer process. It covers the following topics:
Bulk copy transfer initiates a direct transfer of data between two databases from the client application. You use the bulk copy transfer statement to copy large amounts of data between similar tables.
When you use a bulk copy transfer statement, the following restrictions apply:
The transfer statement must be the only statement in a request.
The table into which you want to transfer data (the target) must already exist. The transfer statement does not create new tables in the transfer target.
The structure of the target table must match the structure of the source table.
Bulk copy transfer processing occurs in the following sequence:
The client application initiates a transfer request.
The access service receives the transfer request and executes the sourceselectstatement against the source database to retrieve the schema of the result set, including column datatypes, length, precision, and scale.
The access service queries the target table for a description of the target table columns and compares this information to the structure of the result set for these criteria:
The target table must have at least as many columns as the result set.
The datatype of each result set column must be convertible to the type of its target column.
If either of these tests fails, the access service stops processing the transfer and issues an error message.
If the transfer statement includes the with replace or truncate clause, the access service deletes data in the target table, provided the user ID of the person executing the request is authorized to do so. If the user ID is not authorized, the transfer fails.
The access service maps the columns from the result set to the columns in the target table in the order in which they appear. The access service attempts to insert NULL values (if allowable) in all columns in the target table that do not have corresponding columns in the result set.
The access service prepares an insert or equivalent bulk load statement for execution against the target table.
If conversion errors occur as rows are inserted (for example, a value is out of range), the invalid rows are handled according to the values set in the following properties:
CharConvertError
NumConvertError
DatetimeConvertError
DefaultDate
DefaultTime
DefaultNum
The transfer continues processing. If the SendWarningMessages property is set to yes, the access service sends a warning message to the client application.
The required syntax for a bulk copy transfer statement is as follows:
transfer [with report]
{to | from} 'secondaryname userid password';with {insert | replace | truncate} into tablename;sourceselectstatement
where:
transfer must begin all transfer statements.
with report is an optional phrase specified in the first line of the transfer statement. It instructs the access service to return processing information to the client application.
This information is returned as a result set consisting of a VARCHAR column and a single row. The row contains the number of rows transferred, rejected, and modified during processing.
{to | from} indicates the direction of the transfer:
to specifies that the data is transferred from the primary database to the secondary database.
from specifies that the data is transferred from the secondary database to the primary database.
'secondaryname userid password' is a three-part character string that provides the information needed to connect to the secondary database:
secondaryname is the name used to identify the secondary database.
userid and password must be valid on the secondary database.If the password is NULL, you can substitute an asterisk for password and it will be corrected to a NULL when sent to the secondary connection. Exactly three tokens are sent to the secondary connection.
All of the elements of the character string must be enclosed in single or double quotes in the order shown.
with {insert | replace | truncate} into specifies whether the data is appended onto the target table (insert) or the existing data is deleted and replaced (replace or truncate).
When transferring data to Adaptive Server, the truncate option causes transfer to issue a truncate, rather than a delete against the target table. For other target databases, delete and truncate are equivalent.
tablename specifies the table into which data is inserted or replaced. The table must already exist because the transfer statement does not create a new one in the target database.
sourceselectstatement specifies a SQL statement that is executed against the source database to produce the result set used in the transfer.
This statement can be as complex as the source database will accept, including stored procedures. SQL transformation is not performed on the sourceselectstatement. It must be in the source database SQL dialect.
Use transfer from when you want to transfer data from a secondary database to the primary database. The primary database, ODBC, is the target. The secondary database is specified in the transfer statement.
The access service performs datatype conversions for bulk copy transfer from statements. These conversions are defined within the access service and are not affected by the settings of the datatype conversions configuration properties.
The following table shows the acceptable Open Server datatypes that the access service can convert into corresponding ODBC datatypes. To fit the items in the table, the CS_ prefix is removed from the datatypes, ODBC datatypes are shown in lowercase letters, and similar ODBC datatypes are combined.
Open Server Datatype | ODBC Datatypes | ||||
CHAR VARCHAR LONGVARCHAR | TINYINT SMALLINT, INT BIGINT, DECIMAL NUMERIC, REAL FLOAT, DOUBLE | DATE TIME TIMESTAMP | BINARY VARBINARY LONGVARBINARY | BIT | |
CHAR | X | X | X | X | X |
TEXT | X | X | X | X | X |
BINARY | X | X | |||
VARBINARY | X | X | |||
IMAGE | X | X | |||
BIT | X | X | X | X | |
TINYINT | X | X | X | ||
SMALLINT | X | X | |||
INTEGER | X | X | |||
MONEY | X | X | |||
MONEY4 | X | X | |||
REAL | X | X | |||
FLOAT | X | X | |||
DATETIME | X | X | |||
DATETIME4 | X | X |
Use the transfer to statement when you want to move data to a secondary database from the primary database.
The access service performs datatype conversions for bulk copy transfer to statements. These conversions are defined within the access service and are not affected by the settings of the datatype conversions configuration properties.
Datatype conversion takes place in two steps. The following table shows how incoming target ODBC datatypes are initially converted to Open Server datatypes.
ODBC Datatype | Open Server Datatype |
SQL_CHAR | CS_CHAR |
SQL_VARCHAR | CS_VARCHAR |
SQL_LONGVARCHAR | CS_LONGCHAR |
SQL_DECIMAL | CS_DECIMAL |
SQL_NUMERIC | CS_NUMERIC |
SQL_SMALLINT | CS_SMALLINT |
SQL_INTEGER | CS_INT |
SQL_REAL | CS_REAL |
SQL_FLOAT | CS_FLOAT |
SQL_DOUBLE | CS_FLOAT |
SQL_BIT | CS_BIT |
SQL_TINYINT | CS_TINYINT |
SQL_BIGINT | CS_FLOAT |
SQL_BINARY | CS_BINARY |
SQL_VARBINARY | CS_VARBINARY |
SQL_LONGVARBINARY | CS_LONGBINARY |
SQL_DATE | CS_CHAR |
SQL_TIME | CS_CHAR |
SQL_TIMESTAMP | CS_CHAR |
Table 10-3 shows how the converted datatypes from the previous table are converted into actual datatypes of the target columns. If a column match is incompatible, the transfer ends with an error.
To fit the items in the table, the CS_ prefix is removed from the datatypes, datatypes are shown in lowercase letters, and similar Open Server datatypes are combined.
Access Service Open Server Datatype | Target Open Server Column Datatypes | ||||||
binary image | tinyint | smallint, int, float, real, money, money4, decimal | char | bit | datetime datetime4 | text | |
binary | X | X | X | ||||
char | X | X | X | X | X | X | X |
float | X | X | X | X | X | ||
decimal | X | X | X | ||||
image | X | X | X | ||||
smallint | X | X | X | X | |||
int | X | X | X | X | |||
text | X | X | X | X | X | X | X |
The following guidelines apply to bulk copy values.
Character datatypes (CHAR, VARCHAR, TEXT) can be converted to any other datatype. Conversely, every datatype can be converted to character data. You must ensure that the character string is convertible to the target datatype.
For example, the character string "450" can be converted to a numeric datatype such as INTEGER or DECIMAL, but the character string "Hello" causes a value error going to a numeric datatype.
Numeric datatypes can be converted to other numeric datatypes or to character datatypes, but they cannot be converted to binary or date datatypes.
Additional guidelines are as follows:
All numeric conversions use rounding.
Any loss of digits to the left of the decimal results in an error. For example, an integer of value 123 cannot be converted to a decimal (4,2) value without losing a digit to the left of the decimal point.
Any loss of digits to the right of the decimal point is not considered an error. For example, a float of value 123.456 is converted to an integer of value 123 without error.
When you transfer data from a decimal column to a float column, the precision of the result is not better than the precision of the target column.
For example, if you transfer data from a decimal(15,0) column to a float column, then back to a decimal(15,0) column, the results in the target decimal(15,0) column do not match the results of the source decimal(15,0) column, due to the float column precision.
Date datatypes can be converted to other date datatypes or to character strings. However, they cannot be converted to numeric or binary datatypes.
Binary datatypes can be converted to other binary datatypes or to character strings. However, these datatypes cannot be converted to numeric or other date datatypes.
Value errors occur during transfer processing when the value being inserted is out of range for the column datatype. The access service handles these errors using the following properties:
CharConvertError
NumConvertError
DateTimeConvertError
DefaultDate
DefaultTime
If the SendWarningMessages property is set to yes, the access service sends a message to the client application when it encounters value errors.
The following rules apply for values during the bulk copy transfer process:
NULL Values
If a source column contains NULL values but the destination does not allow them, the row is rejected.
Numeric Data
All numeric conversions use rounding.
Any loss of digits to the left of the decimal results in an error. For example, an integer of value 123 could not be converted to a decimal(4,2) value without losing a digit to the left of the decimal point.
Any loss of digits to the right of the decimal point is not considered an error. For example, a float of value 123.456 would be converted to an integer value of 123 without error.
Binary Data
Binary data is transferred to a binary column without byte translation. A byte value in the source will have the same value in the destination.
The following table shows data values that can cause errors during transfer.
Open Server Input Datatypes | Open Server or ODBC Output Datatypes | Error Condition |
char, varchar, text | OS char, varchar, text, binary, varbinary, or image. ODBC CHAR, VARCHAR, LONGVARCHAR | Source data is longer than the destination column. |
char, varchar, text | OS decimal ODBC DECIMAL | Source is not a valid decimal string (must contain an optional leading sign and decimal digits). Number of digits to the left of the decimal point is greater than the destination column precision minus scale. Any digits to the right of the decimal will be lost without error. |
char, varchar, text | OS integer ODBC INT | Source is not a valid decimal string (must contain an optional leading sign, decimal digits, decimal point, and fractional decimal digits). String of digits to the left of the decimal point is greater than 2147483647 (positive values) or less than -2147483648 (negative values). Any digits to the right of the decimal will be lost without error. |
char, varchar, text | OS smallint ODBC SMALLINT | Source is not a valid decimal string (must contain an optional leading sign, decimal digits, decimal point, and fractional decimal digits). String of digits to the left of the decimal point is greater than 32767 (positive values) or less than -32768 (negative values). |
char, varchar, text | OS tinyint ODBC TINYINT | Source is not a valid positive integer string (must contain an optional leading "+" and decimal digits). String of digits does not form an integer value between 0 and 255. |
char, varchar, text | OS bit ODBC BIT | Source data length is greater than 1 or source value !="0" or "1." |
char, varchar, text | OS float ODBC FLOAT | Source is not a valid floating point format string (must contain optional leading sign, decimal digits, optional decimal point, fractional decimal digits, and optional E[+|-] nnn exponent). Destination is ODBC and the value is out of range for an ODBC FLOAT. |
char, varchar, text | OS real ODBC REAL | Source is not a valid floating point format string (must contain optional leading sign, decimal digits, optional decimal point, fractional decimal digits, and optional E[+|-] nnn exponent). Destination is ODBC and the value is out of range for an ODBC FLOAT. Destination is Adaptive Server and the value is greater than 3.402823466E38 or less than -3.402823466E38. |
char, varchar, text | OS date ODBC DATE | Source is not an ISO format date (YYY-MM-DD) or a valid Adaptive Server date/time string with a year later than 1753. |
char, varchar, text | OS time ODBC TIME | Source is not an ISO format time (HH.MM.SS) or an HH:MM:SS format time. |
char, varchar, text | ODBC TIMESTAMP | Source is not an ISO format date (YYYY-MM-DD-HH.MM.SS) or a YYYY-MM-DD-HH.MM.SS.NNNNNN date with YYYY greater than 0001, or a valid Adaptive Server date/time string with a year later than 1753. |
char, varchar, text | OS datetime | Source is not an ISO format date, time, or timestamp with a year later than 1752 or a valid Adaptive Server date/time string with a year later than 1752. |
char, varchar, text | OS datetime4 | Source is not an ISO format date, time, or timestamp with a year later than 1899 and the year, month, and day earlier than Jun 7, 2079, or a valid Adaptive Server date/time string with a year later than 1899 and the year, month, and day earlier than Jun 7, 2079. |
char, varchar, text | OS money | Source is not a valid decimal string (must contain an optional leading sign, decimal digits, optional decimal point, and fractional decimal digits). Value is greater than 922337203685477.5807 or less than -922337203685477.5808. |
char, varchar, text | OS money4 | Source is not a valid decimal string (must contain an optional leading sign, decimal digits, optional decimal point, and fractional decimal digits). Value is greater than 214748.3647 or less than -214748.3648. |
binary, varbinary, image | OS char, varchar, text, binary, varbinary, image ODBC CHAR, VARCHAR, LONGVARCHAR | Source data is longer than the destination column. |
byte, int, smallint | OS char, varchar, text ODBC CHAR, VARCHAR | Destination column is too small to hold the digits required to express the value (for example, the source value is 103 and the destination column is char(2)). |
byte, int, smallint | OS bit | Source value !=0 or 1. |
smallint, int, float, real, money, money4, decimal | OS decimal ODBC DECIMAL | Destination column precision minus scale is too small to hold the value (for example, a source data value of 98 requires destination column precision minus scale of 2). |
money, money4, decimal, numeric | OS decimal ODBC DECIMAL | If precision=scale=maximum, precision for the datatype does not transfer properly when the data value is 0. A workaround is to alter the table so that one of these conditions is avoided. |
smallint | OS tinyint ODBC TINYINT | Source value is greater than 255 or less than 0. |
int | OS smallint ODBC SMALLINT | Source is greater than 32767 or less than -32768. |
int | OS money4 | Source is greater than 214748 or less than -214748. |
int | OS tinyint ODBC TINYINT | Source is greater than 255 or less than 0. |
bit | OS decimal ODBC DECIMAL | Destination column precision minus scale is less than 1. |
float, real | OS char, varchar, text ODBC CHAR, VARCHAR | Destination column is too small to hold the digits required to express the value (for example, source is 1030303E+30 and destination column is char(12)). |
float, real, money | OS int ODBC INT | Source value greater than 2147483647.0 or less than -2147483648.0. |
float, real, money, money4, decimal | OS smallint ODBC SMALLINT | Source is greater than 32767.0 or less than -32768.0. |
float, real, money, money4, decimal | OS tinyint ODBC TINYINT | Source is greater than 255.0 or less than 0.0. |
float, real | OS money | Source value is greater than 922337203685477.0 or less than -922337203685477.0. Since float accuracy is 15 digits, a value of this magnitude is accurate only to the nearest dollar. Since real accuracy is seven digits, a value of this magnitude is accurate only to the nearest hundred million dollars. |
float, real, money, decimal | OS money4 | Source is greater than 214748.3647 or less than -214748.3648. |
float, real, money, money4, decimal | OS bit ODBC BIT | Source value !=0.0 or 1.1. |
money, money4, decimal | OS char, varchar, text ODBC CHAR, VARCHAR, TEXT | Destination column is too small to hold digits required to express value (for example, source is 100000000.001 and destination column is char(12)). |
datetime, datetime4 | OS char, varchar, text ODBC CHAR, VARCHAR, LONGVARCHAR | Destination column length is less than 19. |
datetime | OS datetime4 | Date portion of source value is earlier than Jan 1 1900 or later than Jun 6 2079. |
You can obtain bulk copy transfer error information in the following ways:
If you include with report in the transfer statement, you receive a result set containing one VARCHAR column and one row indicating the number of rows transferred, rejected, and modified during processing.
You can execute @@RejectedRowCount or @@DefaultedRowCount immediately after a successful transfer. These global variables return the number of rejected or defaulted rows.
If you set SendWarningMessages to yes, the access service returns data conversion errors to the client application.
|
|