ODBC Users` Manual

Add to My manuals
280 Pages

advertisement

ODBC Users` Manual | Manualzz

SQLSetStmtAttr

SQLSetStmtAttr

SQLSetStmtAttr() sets the attribute related to the statement handle.

SQLSetStmtAttrW() as a Unicode string supports same execution as SQLSetStmtAttr().

Syntax

SQLRETURN SQLSetStmtAttr (

SQLHSTMT stmt,

SQLINTEGER Attribute,

SQLPOINTER param,

SQLINTEGER StringLength );

Arguments

Data Type

SQLHENV

Argument stmt

In/Out

Input

Description

Statement handle

151 ODBC Functions

SQLSetStmtAttr

Data Type

SQLINTEGER

SQLPOINTER

Argument

Attribute

In/Out

Input param Input

Description

Attribute to set, Supported attribute value:

SQL_ATTR_CONCURRENCY,

SQL_ATTR_CURSOR_SCROLLABLE,

SQL_ATTR_CURSOR_SENSITIVITY,

SQL_ATTR_CURSOR_TYPE,

SQL_ATTR_PARAM_BIND_TYPE,

SQL_ATTR_PARAM_STATUS_PTR,

SQL_ATTR_PARAMS_PROCESSED_PTR,

SQL_ATTR_PARAMS_ROW_COUNTS_PTR,

SQL_ATTR_PARAMS_SET_ROW_COUNTS,

SQL_ATTR_PARAMSET_SIZE,

SQL_ATTR_ROW_ARRAY_SIZE,

SQL_ATTR_ROW_BIND_TYPE,

SQL_ATTR_ROW_STATUS_PTR,

SQL_ATTR_ROWS_FETCHED_PTR

ALTIBASE_STMT_ATTR_ATOMIC_ARRAY

Attribute value which is not currently being supported:

SQL_ATTR_APP_PARAM_DESC,

SQL_ATTR_APP_ROW_DESC,

SQL_ATTR_ASYNC_ENABLE,

SQL_ATTR_ENABLE_AUTO_IPD,

SQL_ATTR_FETCH_BOOKMARK_PTR,

SQL_ATTR_IMP_PARAM_DESC,

SQL_ATTR_IMP_ROW_DESC,

SQL_ATTR_KEYSET_SIZE,

SQL_ATTR_MAX_LENGTH,

SQL_ATTR_METADATA_ID,

SQL_ATTR_NOSCAN,

SQL_ATTR_PARAM_BIND_OFFSET_PTR,

SQL_ATTR_PARAM_OPERATION_PTR,

SQL_ATTR_QUERY_TIMEOUT,

SQL_ATTR_RETRIEVE_DATA,

SQL_ATTR_ROW_BIND_OFFSET_PTR,

SQL_ATTR_ROW_NUMBER,

SQL_ATTR_ROW_OPERATION_PTR,

SQL_ATTR_SIMULATE_CURSOR,

SQL_ATTR_USE_BOOKMARKS

Pointer of the value related to the Attribute

Depending on the pointer, Attribute, the param will be a 32-bit integer, the pointer of the Null-terminator, the character string’s pointer, the binary pointer, or the value defined in the ODBC.

If Attribute is the unique value of the ODBC, param is the integer number with a sign.

ODBC Users’ Manual 152

Data Type

SQLINTEGER

SQLSetStmtAttr

Argument In/Out

StringLength Input

Description

If Attribute has been defined in the ODBC and param indicates the character string or binary buffer, this argument must be the byte length of *param.

If Attribute has been defined in the ODBC and param is an integer, this argument is ignored.

Return Values

SQL_SUCCESS

SQL_SUCCESS_WITH_INFO

SQL_INVALID_HANDLE

SQL_ERROR

Description

The command option for stmt is valid until the option is changed by calling of SQLSetStmtAttr () or till stmt is removed by calling of SQLFreeHandle (). Handle release method: Calling SQL_CLOSE,

SQL_UNBIND, or SQL_RESET_PARAMS with SQLFreeStmt () does not reset the statement attribute.

To use a column-wise binding, set SQL_ATTR_PARAM_BIND_TYPE in Arguments Attribute of an application function SQLSetStmtAttr() and set SQL_PARAM_BIND_BY_COLUMN in param.

ARRAY_SIZE changes only PARAM_SIZE at every execution moment. PARAM_STATUS_PTR is the vaule to return if each column will be executed, and specifies SQLSMALLINT array. If succeeds,

SQL_SUCCESS, SQL_SUCCESS_WITH_INFO will be returned, and if fails, then SQL_PARAM_UNUSED will be returned respectively.

For Macro values: SQL_PARAM_SUCCESS is 0SQL_PARAM_ERROR is 5,

SQL_PARAM_SUCCESS_WITH_INFO is 6SQL_PARAM_UNUSED is 7.

SQLSetStmtAttr(stmt, SQL_ATTR_PARAM_BIND_TYPE,

SQL_PARAM_BIND_BY_COLUMN);SQLSetStmtAttr(stmt, SQL_ATTR_PARAMSET_SIZE,

ARRAY_SIZE, 0);SQLSetStmtAttr(stmt, SQL_ATTR_PARAM_STATUS_PTR, ParamStatusArray, 0);

Designates the pointer of the variables to store the number of columns processed by

PARAMS_PROCESSED_PTR. The pointer type of SQLINTEGER. Then, execute SQLBindParameter () like before.

SQLSetStmtAttr(stmt, SQL_ATTR_PARAMS_PROCESSED_PTR, &ParamsProcessed,

0);then, Executing SQLBindParameter().

When using the row-wise binding, define the size of the structure in PARAM_Bind_Type, unlike in the column-wise binding.

SQLSetStmtAttr(stmt, SQL_ATTR_PARAM_BIND_TYPE, sizeof(struct…));SQLSetStmtAttr(stmt, SQL_ATTR_PARAMSET_SIZE, ARRAY_SIZE, 0);SQLSetStmtAttr(stmt,

153 ODBC Functions

SQLSetStmtAttr

SQL_ATTR_PARAM_STATUS_PTR, ParamStatusArray, 0);SQLSetStmtAttr(stmt,

SQL_ATTR_PARAMS_PROCESSED_PTR, &ParamsProcessed, 0); then, Execute SQLBindParameter().

Statement Attributes

Attribute

SQL_ATTR_CONCURRENCY

SQL_ATTR_CURSOR_SCROLLABLE

SQL_ATTR_CURSOR_SENSITIVITY

SQL_ATTR_CURSOR_TYPE

SQL_ATTR_PARAM_BIND_TYPE

SQL_ATTR_PARAM_STATUS_PTR

ODBC Users’ Manual

Contents

SQLUINTEGER value specifying the temporary processing of the cursor:

SQL_CONCUR_READ_ONLY: The cursor supports readonly. Updating is not allowed.

32-bit integer to designate whether the open cursor can be scrolled for this statement handle. (Supports only SQL_FETCH_NEXT.)

Not used

SQLUINTEGER indicating the cursor type.

SQL_CURSOR_FORWARD_ONLY: The cursor only proceeds forward.

SQL_CURSOR_STATIC: The data located in the result set are static.

Setting value which is necessary for array binding

To retrieve the data by the column-wise binding,

SQL_PARAM_BIND_BY_COLUMN (default) is set in this field.

To retrieve the data by the row-wise binding, the length of the structure or the length of the buffer to which the dynamic parameter will be bound will be set. This length must include the bound parameter space.

(Necessary for array binding)

This field is requested only when PARAMSET_SIZE is higher than 1.

Status values are as follows:

SQL_PARAM_SUCCESS: An SQL statement has been successfully executed. The macro value is 0.

SQL_PARAM_SUCCESS_WITH_INFO: An SQL statement has been successfully executed.: however, the warning data can be viewed from the diagnosis data structure.

The macro value is 5.

SQL_PARAM_ERROR: Error occurs during the execution of parameters. additional error information can be viewed on the diagnosis data structure. The macro value is 6.

SQL_PARAM_UNUSED: This parameter set is not used partly because an error has occurred preventing the previous parameter from further proceeding. The macro value is 7.

154

SQLSetStmtAttr

Attribute Contents

SQL_ATTR_PARAMS_PROCESSED_PTR (Necessary for array binding)

Indicates the buffer that return the number of parameters including the errors.

In case of the NULL pointer, no data will be returned.

If SQL_SUCCESS or SQL_SUCCESS_WITH_INFO is not returned upon calling of SQLExecDirect () or SQLExecute (), the contents of the buffer will not be defined.

SQL_ATTR_PARAMS_ROW_COUNTS_

PTR

(Necessary for array binding)

Sets the buffer that returns the following values as the result of SQLExecute to array binding.

SQL_SUCCESS: When an SQL statement was successfully executed for all array elements

SQL_ERROR When even one array element fails to execute SQL statement

SQL_NO_DATA: When no array element was changed

(inputted or deleted)

SQL_ATTR_PARAMS_SET_ROW_COU

NTS

SQL_ATTR_PARAMSET_SIZE

SQL_ATTR_ROW_ARRAY_SIZE

SQL_ATTR_ROW_BIND_TYPE

(Necessary for array binding)

SQL_ROW_COUNTS_ON: Returns the number of records changed by each array element. In other words, if there are changed records, the number of records will be returned. If there is no record changed, 0 will be returned. In case an error occurs, SQL_USHRT_MAX

(65534) will be returned.

SQL_ROW_COUNTS_OFF: Existing behaviors of attribute

SQL_ATTR_PARAM_STATUS_PTR will be maintained.

(Necessary for array binding)

SQLUINTEGER value that indicates the number of values for each parameter.

(Necessary setting value at the time of the array fetch in the SELECT statement)

SQLUINTEGER that indicates the number of rows returned by calling each SQLFetch ().

(Necessary setting value at the time of the array fetch in the SELECT statement)

SQLUINTEGER that sets the direction of the binding to be used upon calling of SQLFetch (). The column-wise binding is searched by setting

SQL_BIND_BY_COLUMN. The row-wise binding searches the data by setting the length of the structure or the length of the buffer to which the results columns will be bound.

In case the length is specified, the space for the columns to be bound must be included.

155 ODBC Functions

SQLSetStmtAttr

Attribute

SQL_ATTR_ROW_STATUS_PTR

SQL_ATTR_ROWS_FETCHED_PTR

ALTIBASE_STMT_ATTR_ATOMIC_ARR

AY

Contents

(Necessary setting value at the time of the array fetch in the SELECT statement)

The size of the array is same as the number of rows of the row set.

In this attribute, the NULL pointer can be set. In this case, the ODBC does not return the column status value.

(Necessary setting value at the time of the array fetch in the SELECT statement)

SQLUINTEGER* value indicating the buffer that returns the number of fetched rows after SQLFetch () is called

This is Altibase only attribute indicating to execute

Atomic Array Insert. Array Insert can execute the entire statements respectively, whereas Atomic Array Insert can execute several statements at one execution and this results in them executed as a single statement in other words. You may specify

ALTIBASE_STMT_ATTR_ATOMIC_ARRAY in Attribute and SQL_TRUE/SQL_FALSE in the param argument.

If you choose SQL_TRUE, you can execute Atomic Array

Insert.

However, you must specify Array Size in order that

Atomic Array Insert has better performance than the existing Array Insert does.(SQL_ATTR_PARAMSET_SIZE)

And you can save result values with using the following attributes.

SQL_ATTR_PARAM_STATUS_PRT : Real result values are saved only in the first row and the rest is successfully processed.

SQL_ATTR_PARAMS_PROCESSED_PTR : Real result values are saved only in the first row and the rest of them are ignored.

Diagnosis

SQLSTATE

HY000 General error

Description Comments

Example

See: $ALTIBASE_HOME/sample/SQLCLI/demo_ex4.cpp

SQLSetStmtAttr(stmt, SQL_ATTR_PARAM_BIND_TYPE, (void*)sizeof(demo_ex4_data),

0);

ODBC Users’ Manual 156

SQLSetStmtAttr

SQLSetStmtAttr(stmt, SQL_ATTR_PARAMSET_SIZE, (void*)10, 0);

SQLSetStmtAttr(stmt, SQL_ATTR_PARAMS_PROCESSED_PTR,(void*) &processed_ptr,

0);

SQLSetStmtAttr(stmt, SQL_ATTR_PARAM_STATUS_PTR, (void*)status, 0);

You may use Automic Array Insert.

SQLSetStmtAttr(stmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER) array_size, 0); //

Specify Array Size.

SQLSetStmtAttr(stmt, ALTIBASE_STMT_ATTR_ATOMIC_ARRAY, (SQLPOINTER) SQL_TRUE,

0); // Specify Atomic attribute.

157 ODBC Functions

advertisement

advertisement

Table of contents