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

Chapter 11 Using Destination-Template Transfer [Table of Contents] Chapter 13 Retrieving

information with System Procedures

Access Service User's Guide DirectConnect Anywhere

[-] Chapter 12 Accessing Catalog Information with CSPs

Chapter 12

Accessing Catalog Information with CSPs

This chapter describes how to use catalog stored procedures (CSPs). It covers the following topics:

General description

CSPs are specially recognized commands that return catalog information. Client applications use CSPs instead of SQL to access information contained in the system catalog of the target database. The service library implements CSPs by executing stored procedures against the target catalog.

When you invoke a CSP, the access service executes a stored procedure that returns a result set that attempts to match the results an Adaptive Server would return under the same circumstances. Because the ODBC catalog is significantly different from the Adaptive Server catalog, an exact match is impossible. To make the results match, the access service performs additional computations as the rows are returned.

Because some information is static, sp_datatype_info uses memory tables to improve the speed of operation.

Syntax

The following syntactical rules apply to CSPs:

The positional forms (1, 2, and 3) cannot be mixed with the named form (4).

The service library does not support the TABLE_QUALIFIER or PROCEDURE_QUALIFIER parameters. For all CSPs, leave the parameter empty or set it to NULL.

The argument syntax for most of the CSPs referenced in this chapter is contained in the Sybase Adaptive Server Reference Manual, v 2.

RPC events

You can execute CSPs using a language command or an RPC event.

When the access service processes a CSP as an RPC event, it retrieves the name and parameters from the client application using standard RPC processing techniques. However, the argument cannot be named using the following syntax:

@name=parm  form

Treatment of special characters

The access service supports only the "%" wildcard character, which can be used in parameters that allow wildcard-character search patterns. The character represents any string of zero or more characters.

The access service treats all underscore characters as literals.

ODBC information

The ODBC definition of the CSPS is the model for behavior. If the access service cannot support a particular procedure, it returns the expected column form descriptors, with no data rows.

The format and content of results returned by most CSPs are described in the Microsoft ODBC 2.0 Programmer's Reference and SDK Guide.

ODBC conformance levels

The three conformance levels for ODBC drivers are core, level one, and level two. CSPs that support the functionality in levels one and two are as follows:

Level One

Level Two

Compatibility

To maintain compatibility with Adaptive Server and previous versions of the MDI Database Gateway, all CSPs accomplish the same tasks as their counterparts in the other systems. Areas in which DirectConnect Anywhere differs are as follows:

When a CSP requirements conflict arises, the following precedence rules are used:

sp_column_privileges

Description

Returns column privilege information for one or more columns in a table or view.

Syntax

sp_column_privileges table_name [, table_owner[, table_qualifier [, column_name]]]

Parameters

table_name

is the name of the table. Wildcard-character search patterns are not supported.

table_owner

is the name of the table owner. Wildcard-character search patterns are not supported.

table_qualifier

is ignored. Leave blank or set to NULL.

column_name

is the name of the column for which you want privilege information. Use wildcard-character search patterns to request information about more than one column. Leave blank or set to NULL to request information about all columns in the table or tables.

Usage

sp_columns

Description

Returns information about the type of data that can be stored in one or more columns.

Syntax

sp_columns table_name [, table_owner]
 [, table_qualifier] [, column_name]

Parameters

table_name

is the table name or view. Use the wildcard character to request information about more than one table.

table_owner

is the owner of the table or view. Use the wildcard character to request information about tables owned by more than one user.

table_qualifier

is ignored. Leave blank or set to NULL.

column_name

is the name of the column for which you want information. Use the wildcard character to request information about more than one column.

Usage

Results

This procedure returns one row containing a description of each column in a table.

Table 12-1 also describes the identifiers returned in the TYPE_NAME and DATA_TYPE columns in the result set for sp_special_columns.

ODBC Datatypes

ODBC Datatype (TYPE_NAME)

Target Datatype Length

DATA-TYPE

ODBC Type

Sybase Type

BINARY

254

(-2)

SQL_BINARY

CS_BINARY

VARBINARY

254

(-3)

SQL_VARBINARY

CS_VARBINARY

LONGVARBINARY

2^31

(-4)

SQL_LONGVARBINARY

CS_LONGBINARY

CHAR()

254

(1)

SQL_CHAR

CS_CHAR

VARCHAR

254

(12)

SQL_VARCHAR

CS_VARCHAR

LONGVARCHAR

2^31

(-1)

SQL_LONGVARCHAR

CS_LONGCHAR

SMALLINT

2

(5)

SQL_SMALLINT

CS_SMALLINT

INTEGER

4

(4)

SQL_INTEGER

CS_INT

DOUBLE

8

(8)

SQL_DOUBLE

CS_FLOAT

FLOAT()

8

(6)

SQL_FLOAT

CS_FLOAT

REAL

4

(7)

SQL_REL

CS_REAL

DECIMAL()

17

(3)

SQL_DECIMAL

CS_DECIMAL

NUMERIC

17

(2)

SQL_NUMERIC

CS_NUMERIC

DATE

4

(9)

SQL_DATE

CS_DATE

TIME

(10)

SQL_TIME

CS_TIME

TIMESTAMP

10

(11)

SQL_TIMESTAMP

CS_DATETIME

TINYINT

1

(-6)

SQL_TINYINT

CS_TINYINT

BIGINT

19

(-5)

SQL_BIGINT

CS_FLOAT

BIT

1

(-7)

SQL_BIT

CS_BIT

This procedure allows transmission of column datatypes using a target-specific type ID. The REMOTE_DATA_TYPE column contains a 32-bit composite datatype defined by the access service.

The following table describes the datatype value.

REMOTE_DATA_TYPE return value

Bits

Value Returned

Bits 0-7

ODBC datatype (can be extended for types not defined in ODBC)

Bit 8

1 if nullable, 0 if not nullable

Bit 9

1 if case-sensitive, 0 if not case-sensitive

Bits 10, 11

10 (binary); ability to be updated unknown

Bits 12, 13

Reserved; always returns 00 (binary). The access service bulk copy feature uses this.

Bits 14, 15

01 (binary); NEWODBCDATATYPE (used for all except REAL) 10 (binary); NEWUSERTYPE (used for REAL)

Numeric types: Bits 17-23 Bits 24-31

Precision Scale

Non-numeric types: Bits 16-31

Length

sp_databases

Description

Returns a list of databases on a target DBMS.

Syntax

sp_databases

Parameters

This procedure does not allow parameters.

Usage

Not defined

sp_datatype_info

Description

Returns information about a particular datatype or all supported datatypes.

Syntax

sp_datatype_info [data_type]

Parameters

data_type

is the ODBC code number for the specified datatype for which sp_datatype_info returns information. See Table 12-1 for a description of these codes.

Usage

Results

sp_datatype_info returns a list of datatypes with information about each. Results are ordered by the following columns:

The lengths for varchar columns shown in the result set tables are maximums; the actual lengths depend on the target database.

The following table shows the result set.

Result set for sp_datatype_info

Column

Datatype

Description

TYPE_NAME

varchar(128)

NOT NULL

Name of the Transact SQL datatype or the target database datatype that corresponds to the ODBC datatype in the DATA_TYPE column.

DATA_TYPE

smallint

NOT NULL

ODBC datatype to which all columns of this type are mapped.

PRECISION

int

Maximum precision allowed for this datatype. (NULL is returned for datatypes where precision is not applicable.

LITERAL_PREFIX

varchar(128)

Character(s) used to prefix a literal; NULL is returned for datatypes where a literal prefix is not applicable.

LITERAL_SUFFIX

varchar(128)

Character(s) used to mark the end of a literal; NULL is returned for datatypes where a literal suffix is not applicable.

CREATE_PARAMS

varchar(128)

Description of the creation parameters required for this datatype (for example: precision and scale); NULL is returned if the datatype does not have creation parameters.

NULLABLE

smallint

NOT NULL

Indicates whether the datatype accepts NULL values:

  • 0 means the column does not accept NULL values.

  • 1 means the column accepts NULL values.

CASE_SENSITIVE

smallint

NOT NULL

Indicates whether the datatype distinguishes between uppercase and lowercase characters:

  • 0 means the datatype is not a character type or is not case sensitive.

  • 1 means the datatype is a character type and is case sensitive.

SEARCHABLE

smallint

NOT NULL

Indicates how this datatype is used in where clauses:

  • 0 means the datatype cannot be used in a where clause.

  • 1 means the datatype can be used in a where clause.

UNSIGNED_ATTRIBUTE

smallint

Indicates whether this attribute is unsigned:

  • 0 means the datatype is signed.

  • 1 means the datatype is unsigned.

  • NULL means the datatype is not numeric.

MONEY

smallint

NOT NULL

Indicates whether this is a money datatype:

  • 0 means it is not a money datatype.

  • 1 means it is a money datatype.

AUTO_INCREMENT

smallint

Indicates whether this datatype automatically increments:

  • 0 means columns of this datatype do not automatically increment.

  • 1 means columns of this datatype automatically increment.

  • NULL means the column is not numeric and does not have a sign.

LOCAL_TYPE_NAME

varchar(128)

The database name or the Transact SQL name for the datatype.

MINIMUM_SCALE

smallint

Minimum scale for the datatype; NULL if scale is not applicable.

MAXIMUM_SCALE

smallint

Maximum scale for the datatype; NULL if scale is not applicable.

sp_fkeys

Description

Returns primary and foreign key information for the specified table or tables. Foreign keys must be declared through the ANSI integrity constraint mechanism.

Syntax

sp_fkeys pktable_name [, pktable_owner]
 [, pktable_qualifier] [, fktable_name] 
 [, fktable_owner] [, fktable_qualifier]

Parameters

pktable_name

is the name of the table containing the primary key. Wildcard-character search patterns are not supported. You must specify this parameter, the fktable_name parameter, or both.

pktable_owner

is the owner of the table containing the primary key. Wildcard-character search patterns are not supported.

pktable_qualifier

is ignored. Leave blank or set to NULL.

fktable_name

is the name of the table containing the foreign key. Wildcard-character search patterns are not supported. You must specify this parameter, the pktable_name parameter, or both.

fktable_owner

is the owner of the table containing the foreign key. Wildcard-character search patterns are not supported.

fktable_qualifier

is ignored. Leave blank or set to NULL.

Usage

This procedure corresponds to the ODBC function SQLForeignKeys.

sp_pkeys

Description

Returns primary key information for a single table. Primary keys must be declared through the ANSI integrity constraint mechanism.

Syntax

sp_pkeys table_name [, table_owner]
 [, table_qualifier]

Parameters

table_name

is the name of the table. Wildcard-character search patterns are not supported.

table_owner

is the owner of the table. Wildcard-character search patterns are not supported.

table_qualifier

is ignored. Leave blank or set to NULL.

Usage

This procedure corresponds to the ODBC function SQLPrimaryKeys.

sp_server_info

Description

Returns target server metadata containing a list of attribute names and matching values for the target.

Syntax

sp_server_info [attribute_id]

Parameters

attribute_id

is the integer ID of the attribute.

Usage

This procedure generates an extensible result set. It can be expanded, depending upon the needs of the specific access service library.

sp_special_columns

Description

Retrieves the following information about columns within a specified table or view:

Syntax

sp_special_columns table_name [, table_owner]
 [, table_qualifier] [, col_type]

Parameters

table_name

is the name of the table. Wildcard-character search patterns are not supported.

table_owner

is the owner of the table. Wildcard-character search patterns are not supported.

table_qualifier

is ignored. Leave blank or set to NULL.

col_type

is a value that requests information about columns of a specific type as follows:

"R" returns information about columns with values that uniquely identify any row in the table.

"V" returns information about columns with values that are automatically generated by a target each time a row is inserted or updated.

Usage

sp_sproc_columns

Description

Returns information about stored procedure input and return parameters.

Syntax

DirectConnect supports SQL-Server version 10 and 11 syntax.

sp_sproc_columns sp_name [, sp_owner]
 [, sp_qualifier] [, column_name]
or
sp_sproc_columns procedure_name [, procedure_owner]
 [, procedure_qualifier] [, column_name]

Parameters

sp_name or procedure_name

is the name of the stored procedure. Wildcard-character search patterns are not supported.

sp_owner or procedure_owner

is the owner of the stored procedure. Wildcard-character search patterns are not supported.

sp_qualifier or procedure_qualifier

is ignored. Leave blank or set to NULL.

column_name

is the name of the parameter about which you want information. If you do not supply a parameter name, this procedure returns information about all input parameters.

Usage

This procedure corresponds to the ODBC function SQLProcedureColumns.

In DirectConnect Anywhere, sp_sproc_columns returns extra, unsolicited columns.

sp_statistics

Description

Returns a list of indexes in a single table.

Syntax

sp_statistics table_name [, table_owner]
 [, table_qualifier] [, index_name] [, is_unique]

Parameters

table_name

is name of the table. Wildcard-character search patterns are not supported.

table_owner

is the owner of the table.

table_qualifier

is ignored. Leave blank or set to NULL.

is_unique

is one of the following values:

"Y" if unique indexes are to be returned

"N" if unique indexes are not to be returned

index_name

is the name of the index. Wildcard-character search patterns are not supported.

Usage

With all platforms in DirectConnect Anywhere, the index_name parameter is ignored, regardless of the value. This applies even if you set the value to a nonexistent name or to NULL.

This procedure corresponds to the ODBC function SQLStatistics.

sp_stored_procedures

Description

Returns a list of available procedures.

Syntax

sp_stored_procedures [sp_name] [, sp_owner]
 [, sp_qualifier]

Parameters

sp_name

is the stored procedure name. Use the wildcard character to request information about more than one stored procedure.

sp_owner

is the owner of the stored procedure. Use the wildcard character to request information about procedures owned by more than one user.

sp_qualifier

is the name of the database. Acceptable values are the current database or NULL.

Usage

This procedure corresponds to the ODBC function SQLProcedures.

sp_table_privileges

Description

Returns privilege information for all columns in a table or view.

Syntax

sp_table_privileges table_name [, table_owner[, table_qualifier]]

Parameters

table_name

is the name of the table. Wildcard-character search patterns are not supported.

table_owner

is the name of the table owner. Wildcard-character search patterns are not supported.

table_qualifier

is ignored. Leave blank or set to NULL.

Usage

This procedure corresponds to the ODBC function SQLTablePrivileges.

sp_tables

Description

Returns a list of objects that can appear in a from clause.

Syntax

sp_tables [table_name] [, table_owner]
 [, table_qualifier] [, table_type]

Parameters

table_name

is the name of the table. Use the wildcard character to request information about more than one table.

table_owner

is the owner of the table. Use the wildcard character to request information about tables owned by more than one user.

table_qualifier

is the name of the database. Acceptable values are the current database or NULL.

table_type

is a list of values, separated by commas, that gives information about all tables of the types specified, including the following:

"'TABLE', 'SYSTEM TABLE', 'VIEW', 'SYNONYM'"

Usage


Chapter 11 Using Destination-Template Transfer [Table of Contents] Chapter 13 Retrieving

information with System Procedures