Sybase Technical Library - Product Manuals Home
[Search Forms] [Previous Section with Hits] [Next Section with Hits] [Clear Search] Expand Search

Chapter 10 Using Bulk

Copy Transfer [Table of Contents] Chapter 12 Accessing

Catalog Information with CSPs

Access Service User's Guide DirectConnect Anywhere

[-] Chapter 11 Using Destination-Template Transfer

Chapter 11

Using Destination-Template Transfer

This chapter describes the destination-template transfer process. it covers the following topics:

General description

The destination-template transfer statement allows you to perform operations that do more than transfer data. You can feed a result set into a template and force the template to perform operations such as the following:

During a destination-template transfer, the access service inserts the data values it retrieves with the sourceselectstatement from the source database into the destination-template SQL clause. This clause contains one question mark for each column in the result set of the sourceselectstatement.

Each value from the result set is substituted for the corresponding question mark in the template on a row-by-row basis. The access service executes the resulting statement against the target database.

Syntax

The syntax for a destination-template transfer statement is as follows:

transfer [with report]
{to | from} 'secondaryname

userid password';
sourceselectstatement;
destinationtemplatestatement

where:

To increase processing efficiency, you can batch destination-templates together for processing. Use the TransferBatch configuration property or a set statement to specify how many templates to batch.

Datatype qualifiers

Qualifiers tell the access service how to format data that is inserted for a placeholder. If you do not supply a qualifier, the access service applies default transformations.

Qualification is required for date and time values. You can use the ?T, ?t, ?D, and ?d qualifiers for dates, or you can create a custom qualifier using special qualifiers. For information about special qualifiers, see "Special Date and Time qualifiers" .

The following table defines valid datatype qualifiers.

Destination-template transfer datatype qualifiers

Placeholder/ Qualifier

Definition

?C

Character string enclosed in quotes

?N

Numeric data, no quotes

?D

Standard format Adaptive Server datetime data enclosed in quotes

?T

Standard format SQL_TIMESTAMP data enclosed in quotes, 'YYYY-MM-DD-hh.mm.ss.nnnnnn'

?d

'mm/dd/yyyy'

?t

'hh:mm:ss'

?X

Standard format Adaptive Server hexadecimal data (for example, 0xffee) used for transferring binary data

?x

Standard format hexadecimal data (for example, X'FFEE') used for transferring binary data

?y

'yy/mm/dd'

?G

G'<...>' used for transferring graphic datatypes or formatting a graphic constant from binary character data

?g

GX'<...>' used for transferring graphic datatypes or formatting a graphic constant from binary character data (returns data in hexadecimal format)

The following three tables show the effects of qualifiers on datatypes.

For each table, special circumstances are detailed in the text following.

The first table shows the effects of the ?C, ?N, ?D, and ?T qualifiers.

Effects of qualifiers on datatypes (1)

Open Server datatype

Default

Effects (by qualifier)

?C

?N

?D

?T

CS_CHAR CS_VARCHAR CS_TEXT

?C

Quote

No quote

Convert to Open Server datetime string, quote

Convert to ISO TIMESTAMP, quote

CS_BIT, CS_INT1 CS_INT2 CS_ INT4 CS_REAL CS_FLOAT

?N

Convert to char, quote

Convert to char, no quote

n/a

n/a

CS_MONEY CS_MONEY4 CS_DECIMAL

?N

Convert to char, quote

Convert to char, no quote

n/a

n/a

CS_DATETIME CS_DATETIME4

?D

'MON DD YYYY hh:mm'[AM or PM]

n/a

'MON DD YYYY hh:mm:ss:nnn'

'YYYY-MM-DD-hh.mm.ss. nnnnnn'

For CS_CHAR, CS_VARCHAR, AND CS_TEXT used with the ?D qualifier:

For CS_CHAR, CS_VARCHAR, AND CS_TEXT used with the ?T qualifier:

The following table shows the effects of the ?y, ?d, ?t, and ?x qualifiers.

Effects of qualifiers on datatypes (2)

Open Server datatype

Default

Effects (by qualifier)

?y

?d

?t

?x

CS_CHAR CS_VARCHAR CS_TEXT

?C

Quote

Quote

Quote

Convert to hex; leading 'X, trailing '

CS_BIT, CS_INT1 CS_INT2 CS_INT4 CS_REAL CS_FLOAT CS_MONEY CS_MONEY4 CS_DECIMAL

?N

n/a

n/a

n/a

n/a

CS_DATETIME CS_DATETIME4

?D

'yy/mm/dd'

'yy/mm/dd'

'hh:mm:ss'

n/a

CS_BINARY CS_VARBINARY CS_IMAGE

?X or ?x

n/a

n/a

n/a

Convert to hex; leading 'X, trailing '

For CS_CHAR, CS_VARCHAR, AND CS_TEXT used with the ?y qualifier:

For CS_CHAR, CS_VARCHAR, AND CS_TEXT used with the ?d qualifier:

For CS_CHAR, CS_VARCHAR, AND CS_TEXT used with the ?t qualifier:

For all datatypes used with the ?x qualifier:

The following table shows the effects of the ?X and ?O qualifiers.

Effects of qualifiers on datatypes (3)

Open Server datatype

Default

Effects (by qualifier)

?X

?O

CS_CHAR CS_VARCHAR CS_TEXT

Convert to hex; leading 0x, no quote

n/a

CS_BIT, CS_ INT1 CS_INT2 CS_INT4 CS_REAL CS_FLOAT CS_MONEY CS_MONEY4 CS_DECIMAL

?N

n/a

n/a

CS_DATETIME CS_DATETIME4

?D

n/a

n/a

CS_BINARY CS_VARBINARY CS_IMAGE

?X or ?x

Convert to hex; leading 0x, no quote

n/a

For CS_BINARY, CS_VARBINARY, AND CS_IMAGE datatypes used with the ?X qualifier:

Special Date and Time qualifiers

You can combine special date and time qualifiers and construct the date or time format that the target database requires, using the following rules:

The following table shows qualifier definitions.

Special date and time qualifiers

Qualifier

Definition

yy

Last two digits of year

yyyy

All four digits of year

mm

Month or minute (recognized by context)

mon

Three-character month abbreviation: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec

dd

Day

hh

Hour

ss

Seconds

nnn

Milliseconds

nnnnnn or uuuuuu

Microseconds

am or pm

Indicates that you want an am or pm designator included. The actual designator is inserted appropriate to the value.

Destination-Template processing

The following sections describe destination-template processing using transfer from and transfer to statements.

transfer from statements

The following steps describe how a service library processes a destination-template transfer from statement from Adaptive Server to ODBC.

transfer to statements

The following steps describe how a service library processes a destination-template transfer to statement to a target from ODBC.

Datatype conversion for transfer to statements

Datatype conversion takes place in two steps. The following table shows how incoming target ODBC datatypes are initially converted to Open Server datatypes.

Datatype conversion for transfer to statements

ODBC Datatype

Open Server Datatype

CHAR

CS_CHAR

VARCHAR

CS_CHAR

LONGVARCHAR

CS_TEXT

SMALLINT

CS_SMALLINT

INT

CS_INT

DECIMAL

CS_DECIMAL

DOUBLE

CS_FLOAT

REAL

CS_REAL

FLOAT

CS_FLOAT

DATE

CS_CHAR

TIME

CS_CHAR

TIMESTAMP

CS_CHAR

BINARY

CS_BINARY

VARBINARY

CS_VARBINARY

LONGVARBINARY

CS_IMAGE

TINYINT

CS_TINYINT

BIT

CS_BIT

BIGINT

CS_FLOAT

NUMERIC

CS_NUMERIC

These datatypes are converted into the datatypes specified by the destinationtemplatestatement datatype qualifiers.

Destination-Template Transfer errors

Value errors occur during transfer processing when the value being inserted is out of range for the column's datatype. The access service handles these errors using the following properties:

If the SendWarningMessages property is set to yes, the access service sends a message to the client application when it encounters value errors. In addition, these properties can be used to fill in default values when datatype conversion fails during both types of transfer.

Obtaining error information

You can obtain destination-template transfer error information in the following ways:

During processing, the access service sets the StopCondition property to none. It uses the value in the TransferErrorCount property to determine the number of error rows it will allow before it stops processing.

You can set this value with the following statement:

set  TransferErrorCount nnn

The default setting is 0, which causes the access service to ignore errors.

Creating a Transfer RPC

The client application can create a stored procedure within Adaptive Server that invokes the DirectConnect Server library transfer function. The service library receives the transfer command as an RPC event with the following arguments:

Transfer RPC example

The following example outlines how a stored procedure shows a bulk copy transfer statement to be received as an RPC.

create procedure  replauth as
begin
execute servername. . .transfer
"to 'servername2 userid password';",
 "with  replace into authors;",
 "select * from  authors;"
end

where:

Executing a Transfer RPC

A client may log in to the Adaptive Server on which this procedure is defined and invoke it as follows:

execute replauth

When Adaptive Server executes replauth, it passes an RPC to the access service. The access service returns any result rows or messages to the client application, not to Adaptive Server.


Chapter 10 Using Bulk

Copy Transfer [Table of Contents] Chapter 12 Accessing

Catalog Information with CSPs