Hitachi

Hitachi Advanced Database Application Development Guide


16.10.4 SQLPrimaryKeys, SQLPrimaryKeysW

Organization of this subsection

(1) Function

This ODBC function returns the column names that make up the primary key for a table. The driver returns the information as a result set for the specified SQL statement.

This function does not support returning primary keys from multiple tables in a single call.

(2) Format

(3) Arguments

StatementHandle

Specifies a statement handle.

Specify a value that was output by *OutputHandlePtr of SQLAllocHandle before this function is executed.

CatalogName

Specifies that the specified information is to be used as a catalog name.

The specified information is ignored, but the specification itself is required. Therefore, when you use this function, specify a null character string ("") or NULL.

NameLength1

Specifies the length of *CatalogName# or SQL_NTS.

The specified information is ignored, but the specification itself is required. Therefore, when you use this function, specify 0.

SchemaName

Specifies a schema name. If NULL is specified, all schema names are processed.

NameLength2

Specifies the length of *SchemaName# or SQL_NTS.

If 0 is specified, SchemaName is not used for filtering.

TableName

Specifies a table name. If NULL is specified, all table names are processed.

NameLength3

Specifies the length of *TableName# or SQL_NTS.

If 0 is specified, the function assumes that NULL is specified for TableName.

#

The length must be in bytes for SQLPrimaryKeys and in characters for SQLPrimaryKeysW.

(4) Return value

This ODBC function returns SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, or SQL_INVALID_HANDLE.

A result set is created when SQLPrimaryKeys or SQLPrimaryKeysW is executed. The following table shows the format of the result set that is returned.

Table 16‒14: Format of the result set that is returned

Column No.

Type

Column name

Description

1

Varchar

TABLE_CAT

The null value is always returned.

2

Varchar

TABLE_SCHEM

Schema name

3

Varchar

TABLE_NAME

Table name

4

Varchar

COLUMN_NAME

Column name

5

Smallint

KEY_SEQ

Column's order number within the primary key

6

Varchar

PK_NAME

Primary key name

(5) SQLSTATE

This ODBC function returns one of the following SQLSTATE values:

SQLSTATE

Description

Remarks

Returned

01000

General warning

--

N

08S01

Communication link failure

N

24000

Invalid cursor status

The function was executed while a cursor was open.

Y

40001

Serialization failure

--

N

40003

Statement completion unknown

N

HY000

General error

N

HY001

Memory allocation error

Y

HY008

Operation cancelled

N

HY009

Invalid use of null pointer

TableName is a null pointer.

Y

HY010

Function sequence error

--

Y

HY013

Memory management error

N

HY090

Invalid string or buffer length

One of the arguments that stores a name length exceeded the maximum length for the corresponding name.

Y

HY117

Connection suspended

--

N

HYC00

Optional feature not implemented

N

HYT00

Timeout expired

N

HYT01

Connection timeout expired

N

IM001

Driver does not support this function

N

IM017

Invalid asynchronous polling

N

IM018

Incomplete asynchronous execution

N

Legend:

Y: This SQLSTATE might be returned by the HADB ODBC driver.

N: This SQLSTATE is not returned by the HADB ODBC driver.

--: None

(6) Notes

The primary key information that can be acquired depends on the privileges of the HADB user who executes this function. For details about the privileges and the primary key information that can be acquired, see the topic Scope of information in dictionary tables and system tables that can be referenced by HADB users in the HADB Setup and Operation Guide.