---
title: "CCI API reference: statements and results"
description: "CCI reference for running SQL: cci_prepare, cci_execute, parameter binding, batches, fetching rows, result metadata and query plans."
url: "https://www.coradb.ai/manual/api/cciapi_query.html"
markdown_url: "https://www.coradb.ai/manual/markdown/api/cciapi_query.md"
product: "CoraDB"
version: "1.0"
keywords: "cci_prepare, cci_execute, cci_bind_param, cci_fetch, cci_get_data, cci_get_result_info, cci_execute_batch, cci_schema_info, coradb cci"
---

# CCI API reference: statements and results

Part of the [CCI API reference](https://www.coradb.ai/manual/api/cciapi.html); see the [CCI overview](https://www.coradb.ai/manual/api/cci.html) for how to build and use CCI programs.

## cci_bind_param

``` c
int cci_bind_param (int req_handle, int index, T_CCI_A_TYPE a_type, void *value, T_CCI_U_TYPE u_type, char flag)
```

The **cci_bind_param** function binds data in the *bind* variable of prepared statement. This function converts *value* of the given *a_type* to an actual binding type and stores it. Subsequently, whenever [cci_execute](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute) is called, the stored data is sent to the server. If **cci_bind_param** () is called multiple times for the same *index*, the latest configured value is valid.

> - **CCI_ER_BIND_INDEX**
> - **CCI_ER_CON_HANDLE**
> - **CCI_ER_NO_MORE_MEMORY**
> - **CCI_ER_REQ_HANDLE**
> - **CCI_ER_TYPE_CONVERSION**
> - **CCI_ER_USED_CONNECTION**

To bind **NULL** to the database, choose one of below settings.

- Set the value of *value* to a **NULL** pointer
- Set the value of *u_type* to `CCI_U_TYPE_NULL`

The following shows a part of code to bind NULL.

``` c
res = cci_bind_param (req, 2 /* binding index*/, CCI_A_TYPE_STR, NULL, CCI_U_TYPE_STRING, CCI_BIND_PTR);
```

or

``` c
res = cci_bind_param (req, 2 /* binding index*/, CCI_A_TYPE_STR, data, CCI_U_TYPE_NULL, CCI_BIND_PTR);
```

can be used.

If **CCI_BIND_PTR** is configured for *flag*, the pointer of *value* variable is copied (shallow copy), but no value is copied. If it is not configured for *flag*, the value of *value* variable is copied (deep copy) by allocating memory. If multiple columns are bound by using the same memory buffer, **CCI_BIND_PTR** must not be configured for the *flag*.

**T_CCI_A_TYPE** is a C language type that is used in CCI applications for data binding, and consists of primitive types such as int and float, and user-defined types defined by CCI such as **T_CCI_BIT** and **T_CCI_DATE**. The identifier for each type is defined as shown in the table below.

| a_type                | value type                             |
|-----------------------|----------------------------------------|
| **CCI_A_TYPE_STR**    | char \*                                |
| **CCI_A_TYPE_INT**    | int \*                                 |
| **CCI_A_TYPE_FLOAT**  | float \*                               |
| **CCI_A_TYPE_DOUBLE** | double \*                              |
| **CCI_A_TYPE_BIT**    | **T_CCI_BIT** \*                       |
| **CCI_A_TYPE_SET**    | **T_CCI_SET**                          |
| **CCI_A_TYPE_DATE**   | **T_CCI_DATE** \*                      |
| **CCI_A_TYPE_BIGINT** | int64_t \* (For Windows: \_\_int64 \*) |
| **CCI_A_TYPE_BLOB**   | **T_CCI_BLOB**                         |
| **CCI_A_TYPE_CLOB**   | **T_CCI_CLOB**                         |

**T_CCI_U_TYPE** is a column type of database and data bound though the *value* argument is converted into this type. The **cci_bind_param** () function uses two kinds of types to send information which is used to convert U-type data from A-type data; the U-type data can be interpreted by database language and the A-type data can be interpreted by C language.

There are various A-type data that are allowed by U-type data. For example, **CCI_U_TYPE_INT** can receive **CCI_A_TYPE_STR** as A-type data including **CCI_A_TYPE_INT**. For information on type conversion, see [Implicit type conversion](https://www.coradb.ai/manual/sql/datatype.html#implicit-type-conversion).

Both **T_CCI_A_TYPE** and **T_CCI_U_TYPE** enum(s) are defined in the **cas_cci.h** file. The definition of each identifier is described in the table below.

| u_type                   | Corresponding a_type (default) |
|--------------------------|--------------------------------|
| **CCI_U_TYPE_CHAR**      | **CCI_A_TYPE_STR**             |
| **CCI_U_TYPE_STRING**    | **CCI_A_TYPE_STR**             |
| **CCI_U_TYPE_BIT**       | **CCI_A_TYPE_BIT**             |
| **CCI_U_TYPE_VARBIT**    | **CCI_A_TYPE_BIT**             |
| **CCI_U_TYPE_NUMERIC**   | **CCI_A_TYPE_STR**             |
| **CCI_U_TYPE_INT**       | **CCI_A_TYPE_INT**             |
| **CCI_U_TYPE_SHORT**     | **CCI_A_TYPE_INT**             |
| **CCI_U_TYPE_FLOAT**     | **CCI_A_TYPE_FLOAT**           |
| **CCI_U_TYPE_DOUBLE**    | **CCI_A_TYPE_DOUBLE**          |
| **CCI_U_TYPE_DATE**      | **CCI_A_TYPE_DATE**            |
| **CCI_U_TYPE_TIME**      | **CCI_A_TYPE_DATE**            |
| **CCI_U_TYPE_TIMESTAMP** | **CCI_A_TYPE_DATE**            |
| **CCI_U_TYPE_OBJECT**    | **CCI_A_TYPE_STR**             |
| **CCI_U_TYPE_BIGINT**    | **CCI_A_TYPE_BIGINT**          |
| **CCI_U_TYPE_DATETIME**  | **CCI_A_TYPE_DATE**            |
| **CCI_U_TYPE_BLOB**      | **CCI_A_TYPE_BLOB**            |
| **CCI_U_TYPE_CLOB**      | **CCI_A_TYPE_CLOB**            |
| **CCI_U_TYPE_ENUM**      | **CCI_A_TYPE_STR**             |

When the string including the date is used as an input parameter of **DATE**, **DATETIME**, or **TIMESTAMP**, "YYYY/MM/DD" or "YYYY-MM-DD" is allowed for the date string type. Therefore, "2012/01/31" or "2012-01-31" is valid, but "01/31/2012" is invalid. The following is an example of having the string that includes the date as an input parameter of the date type.

``` c
// "CREATE TABLE tbl(aa date, bb datetime)";

char *values[][3] =
{
    {"1994/11/30", "1994/11/30 20:08:08"},
    {"2008-10-31", "2008-10-31 20:08:08"}
};

req = cci_prepare(conn, "insert into tbl (aa, bb) values ( ?, ?)", CCI_PREPARE_INCLUDE_OID, &error);

for(i=0; i< 2; i++)
{
    res = cci_bind_param(req, 1, CCI_A_TYPE_STR, values[i][0], CCI_U_TYPE_DATE, (char)NULL);
    res = cci_bind_param(req, 2, CCI_A_TYPE_STR, values[i][1], CCI_U_TYPE_DATETIME, (char)NULL);
    cci_execute(req, CCI_EXEC_QUERY_ALL, 0, err_buf);
}
```

**Parameters**

- `req_handle`: (IN) Request handle of a prepared statement
- `index`: (IN) Location of binding; it starts with 1.
- `a_type`: (IN) Data type of *value*
- `value`: (IN) Data value to bind
- `u_type`: (IN) Data type to be applied to the database
- `flag`: (IN) bind_flag(:c`CCI_BIND_PTR`).

**Returns:** Error code (0: success)

## cci_bind_param_array

``` c
int cci_bind_param_array(int req_handle, int index, T_CCI_A_TYPE a_type, void *value, int *null_ind, T_CCI_U_TYPE u_type)
```

The **cci_bind_param_array** function binds a parameter array for a prepared [cci_execute_array](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute_array) is called, data is sent to the server by the stored *value* pointer. If **cci_bind_param_array** () is called multiple times for the same *index*, the last configured value is valid. If **NULL** is bound to the data, a non-zero value is configured in *null_ind*. If *value* is a **NULL** pointer, or *u_type* is **CCI_U_TYPE_NULL**, all data are bound to **NULL** and the data buffer used by *value* cannot be reused. For the data type of *value* for *a_type*, see the [cci_bind_param](https://www.coradb.ai/manual/api/cciapi_query.html#cci_bind_param) function description.

> - **CCI_ER_BIND_INDEX**
> - **CCI_ER_BIND_ARRAY_SIZE**
> - **CCI_ER_CON_HANDLE**
> - **CCI_ER_NO_MORE_MEMORY**
> - **CCI_ER_REQ_HANDLE**
> - **CCI_ER_TYPE_CONVERSION**
> - **CCI_ER_USED_CONNECTION**

**Parameters**

- `req_handle`: (IN) Request handle of the prepared statement
- `index`: (IN) Binding location
- `a_type`: (IN) Data type of *value*
- `value`: (IN) Data value to be bound
- `null_ind`: (IN) **NULL** indicator array (0 : not **NULL**, 1 : **NULL**)
- `u_type`: (IN) Data type to be applied to the database.

**Returns:** Error code (0: success)

## cci_bind_param_array_size

``` c
int cci_bind_param_array_size(int req_handle, int array_size)
```

The **cci_bind_param_array_size** function determines the size of the array to be used in [cci_bind_param_array](https://www.coradb.ai/manual/api/cciapi_query.html#cci_bind_param_array). **cci_bind_param_array_size** () must be called first before [cci_bind_param_array](https://www.coradb.ai/manual/api/cciapi_query.html#cci_bind_param_array) is used.

> - **CCI_ER_CON_HANDLE**
> - **CCI_ER_REQ_HANDLE**
> - **CCI_ER_USED_CONNECTION**

**Parameters**

- `req_handle`: Request handle of a prepared statement
- `array_size`: (IN) binding array size

**Returns:** Error code (0: success)

## cci_bind_param_ex

``` c
int cci_bind_param_ex (int req_handle, int index, T_CCI_A_TYPE a_type, void *value, int length, T_CCI_U_TYPE u_type, char flag)
```

The **cci_bind_param_ex** function works as the same with [cci_bind_param](https://www.coradb.ai/manual/api/cciapi_query.html#cci_bind_param). However, it has an additional argument, *length*, which specifies the byte length of a string if bound data is a string.

The *length* argument can be used for binding a string which includes '\0' as below.

``` c
cci_bind_param_ex(statement, 1, CCI_A_TYPE_STR, "aaa\0bbb", 7, CCI_U_TYPE_STRING, 0); 
```

**Parameters**

- `req_handle`: (IN) Request handle of the prepared statement
- `index`: (IN) Binding location, starting from 1
- `a_type`: (IN) Data type of *value*
- `value`: (IN) Data value to be bound
- `length`: (IN) Byte length of a string to be bound
- `u_type`: (IN) Data type to be applied to the database.
- `flag`: (IN) bind_flag(:c`CCI_BIND_PTR`).

**Returns:** Error code(0: success)

## cci_close_query_result

``` c
int cci_close_query_result(int req_handle, T_CCI_ERROR *err_buf)
```

The **cci_close_query_result** function closes the resultset returned by [cci_execute](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute), [cci_execute_array](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute_array) or [cci_execute_batch](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute_batch). If you run [cci_prepare](https://www.coradb.ai/manual/api/cciapi_query.html#cci_prepare) repeatedly without closing the request handle(req_handle), it is recommended to call this function before calling [cci_close_req_handle](https://www.coradb.ai/manual/api/cciapi_query.html#cci_close_req_handle).

> - **CCI_ER_CON_HANDLE**
> - **CCI_ER_COMMUNICATION**
> - **CCI_ER_DBMS**
> - **CCI_ER_NO_MORE_MEMORY**
> - **CCI_ER_REQ_HANDLE**
> - **CCI_ER_RESULT_SET_CLOSED**
> - **CCI_ER_USED_CONNECTION**

**Parameters**

- `req_handle`: (IN) Request handle
- `err_buf`: (OUT) Error buffer

**Returns:** Error code (0: success)

## cci_close_req_handle

``` c
int cci_close_req_handle(int req_handle)
```

The **cci_close_req_handle** function closes the request handle obtained by [cci_prepare](https://www.coradb.ai/manual/api/cciapi_query.html#cci_prepare).

> - **CCI_ER_CON_HANDLE**
> - **CCI_ER_REQ_HANDLE**
> - **CCI_ER_COMMUNICATION**
> - **CCI_ER_DBMS**
> - **CCI_ER_NO_MORE_MEMORY**
> - **CCI_ER_USED_CONNECTION**

**Parameters**

- `req_handle`: (IN) Request handle

**Returns:** Error code (0: success)

## cci_cursor

``` c
int cci_cursor(int req_handle, int offset, T_CCI_CURSOR_POS origin, T_CCI_ERROR *err_buf)
```

The **cci_cursor** function moves the cursor specified in the request handle to access the specific record in the query result executed by [cci_execute](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute). The position of cursor is moved by the values specified in the *origin* and *offset* values. If the position to be moved is not valid, **CCI_ER_NO_MORE_DATA** is returned.

> - **CCI_ER_REQ_HANDLE**
> - **CCI_ER_NO_MORE_DATA**
> - **CCI_ER_COMMUNICATION**

**Example**

``` c
//the cursor moves to the first record
cci_cursor(req, 1, CCI_CURSOR_FIRST, &err_buf);

//the cursor moves to the next record
cci_cursor(req, 1, CCI_CURSOR_CURRENT, &err_buf);

//the cursor moves to the last record
cci_cursor(req, 1, CCI_CURSOR_LAST, &err_buf);

//the cursor moves to the previous record
cci_cursor(req, -1, CCI_CURSOR_CURRENT, &err_buf);
```

**Parameters**

- `req_handle`: (IN) Request handle
- `offset`: (IN) Offset to be moved
- `origin`: (IN) Variable to represent a position. The type is **T_CCI_CURSOR_POS**. **T_CCI_CURSOR_POS** enum consists of **CCI_CURSOR_FIRST**, **CCI_CURSOR_CURRENT** and **CCI_CURSOR_LAST**.
- `err_buf`: (OUT) Database error buffer

**Returns:** Error code (0: success)

## cci_cursor_update

``` c
int cci_cursor_update(int req_handle, int cursor_pos, int index, T_CCI_A_TYPE a_type, void *value, T_CCI_ERROR *err_buf)
```

The **cci_cursor_update** function updates *cursor_pos* from the value of the *index* -th column to *value*. If the database is updated to **NULL**, *value* becomes **NULL**. For update conditions, see [cci_prepare](https://www.coradb.ai/manual/api/cciapi_query.html#cci_prepare). The data types of *value* for *a_type* are shown in the table below.

> - **CCI_ER_REQ_HANDLE**
> - **CCI_ER_TYPE_CONVERSION**
> - **CCI_ER_ATYPE**

Data types of *value* for *a_type* are as below.

| a_type                | value type                             |
|-----------------------|----------------------------------------|
| **CCI_A_TYPE_STR**    | char \*                                |
| **CCI_A_TYPE_INT**    | int \*                                 |
| **CCI_A_TYPE_FLOAT**  | float \*                               |
| **CCI_A_TYPE_DOUBLE** | double \*                              |
| **CCI_A_TYPE_BIT**    | **T_CCI_BIT** \*                       |
| **CCI_A_TYPE_SET**    | **T_CCI_SET**                          |
| **CCI_A_TYPE_DATE**   | **T_CCI_DATE** \*                      |
| **CCI_A_TYPE_BIGINT** | int64_t \* (For Windows: \_\_int64 \*) |
| **CCI_A_TYPE_BLOB**   | **T_CCI_BLOB**                         |
| **CCI_A_TYPE_CLOB**   | **T_CCI_CLOB**                         |

**Parameters**

- `req_handle`: (IN) Request handle
- `cursor_pos`: (IN) Cursor position
- `index`: (IN) Column index
- `a_type`: (IN) *value* Type
- `value`: (IN) A new value
- `err_buf`: (OUT) Database error buffer

**Returns:** Error code (0: success)

## cci_escape_string

``` c
long cci_escape_string(int conn_handle, char *to, const char *from, unsigned long length, T_CCI_ERROR *err_buf)
```

Converts the input string to a string that can be used in the CoraDB query. The following parameters are specified in this function: connection handle or **no_backslash_escapes** setting value, output string pointer, input string pointer, the length of the input string, and the address of the **T_CCI_ERROR** struct variable.

> - **CCI_ER_CON_HANDLE**
> - **CCI_ER_COMMUNICATION**

When the system parameter **no_backslash_escapes** is yes (default) or when the **CCI_NO_BACKSLASH_ESCAPES_TRUE** value is sent to the connection handle location, the string is converted to the following characters.

- ' (single quote) =\> ' + ' (escaped single quote)

When the system parameter **no_backslash_escapes** is no or when the **CCI_NO_BACKSLASH_ESCAPES_FALSE** value is sent to the connection handle location, the string is converted to the following characters:

- \n (new line character, ASCII 10) =\> \\ + n (backslash + Alphabet n)
- \r (carriage return, ASCII 13) =\> \\ + r (backslash + Alphabet r)
- \0 (ASCII 0) =\> \\ + 0 (backslash + 0(ASCII 48)
- \\ (backslash) =\> \\ + \\

You can assign the space where the result string will be saved by using the *length* parameter. It will take as much as the byte length of the maximum input string \* 2 + 1.

**Parameters**

- `conn_handle`: (IN) connection handle or **no_backslash_escapes** setting value. When a connection handle is given, the **no_backslash_escapes** parameter value is read to determine how to convert. Instead of the connection handle, **CCI_NO_BACKSLASH_ESCAPES_TRUE** or **CCI_NO_BACKSLASH_ESCAPES_FALSE** value can be sent to determine how to convert.
- `to`: (OUT) Result string
- `from`: (IN) Input string
- `length`: (IN) Maximum byte length of the input string
- `err_buf`: (OUT) Database error buffer

**Returns:** Success: Byte length of the changed string, Failure: Error Code

## cci_execute

``` c
int cci_execute(int req_handle, char flag, int max_col_size, T_CCI_ERROR *err_buf)
```

The **cci_execute** function executes the SQL statement (prepared statement) that has executed [cci_prepare](https://www.coradb.ai/manual/api/cciapi_query.html#cci_prepare). A request handle, *flag*, the maximum length of a column to be fetched, and the address of a **T_CCI_ERROR** construct variable in which error information being stored are specified as arguments.

> - **SELECT** : Returns the number of results
> - **INSERT**, **UPDATE** : Returns the number of rows reflected
> - Others queries : 0
> - Failure : Error code
>   - **CCI_ER_REQ_HANDLE**
>   - **CCI_ER_BIND**
>   - **CCI_ER_DBMS**
>   - **CCI_ER_COMMUNICATION**
>   - **CCI_ER_QUERY_TIMEOUT**
>   - **CCI_ER_LOGIN_TIMEOUT**

Through a *flag*, the way of query execution can be set as all queries or the first one.

> **Note:**
> CoraDB does not support the *flag* **CCI_EXEC_ASYNC** (asynchronous results).


If the *flag* is set to **CCI_EXEC_QUERY_ALL**, all prepared queries(separated by semicolon) are executed. If not, only the first query is executed.

If the *flag* is set to **CCI_EXEC_QUERY_ALL**, the following rules are applied.

- The return value is the result of the first query.
- If an error occurs in any query, the execution is processed as a failure.
- For a query composed of in a query composed of q1; q2; q3, even if an error occurs in q2 after q1 succeeds the execution, the result of q1 remains valid. That is, the previous successful query executions are not rolled back when an error occurs.
- If a query is executed successfully, the result of the second query can be obtained using [cci_next_result](https://www.coradb.ai/manual/api/cciapi_query.html#cci_next_result).

*max_col_size* is a value that is used to determine the maximum length of a column to be sent to a client when the columns of the prepared statement are **CHAR**, **VARCHAR**, **BIT** or **VARBIT**. If this value is 0, full length is fetched.

**Parameters**

- `req_handle`: (IN) Request handle of the prepared statement
- `flag`: (IN) exec flag ( **CCI_EXEC_QUERY_ALL** )
- `max_col_size`: (IN) The maximum length of a column to be fetched when it is a string data type in bytes. If this value is 0, full length is fetched.
- `err_buf`: (OUT) Database error buffer

**Returns:**

## cci_execute_array

``` c
int cci_execute_array(int req_handle, T_CCI_QUERY_RESULT **query_result, T_CCI_ERROR *err_buf)
```

If more than one value is bound to the prepared statement, this gets the values of the variables to be bound and executes the query by binding each value to the variable.

> - **CCI_ER_REQ_HANDLE**
> - **CCI_ER_BIND**
> - **CCI_ER_DBMS**
> - **CCI_ER_COMMUNICATION**
> - **CCI_ER_QUERY_TIMEOUT**
> - **CCI_ER_LOGIN_TIMEOUT**

To bind the data, call the [cci_bind_param_array_size](https://www.coradb.ai/manual/api/cciapi_query.html#cci_bind_param_array_size) function to specify the size of the array, bind each value to the variable by using the [cci_bind_param_array](https://www.coradb.ai/manual/api/cciapi_query.html#cci_bind_param_array) function, and execute the query by calling the [cci_execute_array](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute_array) function. The query result will be stored on the array of **T_CCI_QUERY_RESULT** structure.

[cci_execute_array](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute_array) function returns the results of queries to the *query_result* variable. You can use below macros to get the result of each query. In the macro, note that the validation check for each parameter entered is not performed.

After using the query_result variable, you must delete the query_result by using the [cci_query_result_free](https://www.coradb.ai/manual/api/cciapi_query.html#cci_query_result_free) function.

| Macro | Return type | Description |
|---|---|---|
| `CCI_QUERY_RESULT_RESULT` | int | Number of affected rows, or an error indicator (-1: CAS error, -2: DBMS error) |
| `CCI_QUERY_RESULT_ERR_NO` | int | Error number of the statement |
| `CCI_QUERY_RESULT_ERR_MSG` | char * | Error message of the statement |
| `CCI_QUERY_RESULT_STMT_TYPE` | int (**T_CCI_CORADB_STMT**) | Statement type |

If autocommit mode is on, each query in the array is committed after executing.

> **Note:**
> - In autocommit mode off, if the general error occurs during executing one of the queries in the array on the cci_execute_array function which does a batch processing of the queries, the query with an error is ignored and the next query is executed continuously. But if the deadlock occurs, the error occurs as rolling back the transaction.


``` c
char *query =
    "update orders set shipping_cost = ? where id = ?";
int cost[2];
char *order_id[2];
int null_ind[2];
T_CCI_QUERY_RESULT *result;
int n_executed;
...

req = cci_prepare (con, query, 0, &cci_error);
if (req < 0)
{
    printf ("prepare error: %d, %s\n", cci_error.err_code, cci_error.err_msg);
    goto handle_error;
}

cost[0] = 12;
order_id[0] = "1";

cost[1] = 15;
order_id[1] = "2";

null_ind[0] = null_ind[1] = 0;
error = cci_bind_param_array_size (req, 2);
if (error < 0)
{
    printf ("bind_param_array_size error: %d\n", error);
    goto handle_error;
}

error =
    cci_bind_param_array (req, 1, CCI_A_TYPE_INT, cost, null_ind, CCI_U_TYPE_INT);
if (error < 0)
{
    printf ("bind_param_array error: %d\n", error);
    goto handle_error;
}
error =
    cci_bind_param_array (req, 2, CCI_A_TYPE_STR, order_id, null_ind, CCI_U_TYPE_INT);
if (error < 0)
{
    printf ("bind_param_array error: %d\n", error);
    goto handle_error;
}

n_executed = cci_execute_array (req, &result, &cci_error);
if (n_executed < 0)
{
    printf ("execute error: %d, %s\n", cci_error.err_code, cci_error.err_msg);
    goto handle_error;
}
for (i = 1; i <= n_executed; i++)
{
    printf ("query %d\n", i);
    printf ("result count = %d\n", CCI_QUERY_RESULT_RESULT (result, i));
    printf ("error message = %s\n", CCI_QUERY_RESULT_ERR_MSG (result, i));
    printf ("statement type = %d\n",
            CCI_QUERY_RESULT_STMT_TYPE (result, i));
}
error = cci_query_result_free (result, n_executed);
if (error < 0)
{
    printf ("query_result_free: %d\n", error);
    goto handle_error;
}
error = cci_end_tran(con, CCI_TRAN_COMMIT, &cci_error);
if (error < 0)
{
    printf ("end_tran: %d, %s\n", cci_error.err_code, cci_error.err_msg);
    goto handle_error;
}
```

**Parameters**

- `req_handle`: (IN) Request handle of the prepared statement
- `query_result`: (OUT) Query results
- `err_buf`: (OUT) Database error buffer

**Returns:** Success: The number of executed queries, Failure: Negative number

## cci_execute_batch

``` c
int cci_execute_batch(int conn_handle, int num_sql_stmt, char **sql_stmt, T_CCI_QUERY_RESULT **query_result, T_CCI_ERROR *err_buf)
```

In CCI, multiple jobs can be processed simultaneously when using DML queries such as **INSERT** / **UPDATE** / **DELETE**. `CCI_QUERY_RESULT_RESULT` and [cci_execute_batch](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute_batch) functions can be used to execute such batch jobs. Note that prepared statements cannot be used in the [cci_execute_batch](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute_batch) function. The query result will be stored on the array of **T_CCI_QUERY_RESULT** structure.

> - **CCI_ER_CON_HANDLE**
> - **CCI_ER_DBMS**
> - **CCI_ER_COMMUNICATION**
> - **CCI_ER_NO_MORE_MEMORY**
> - **CCI_ER_CONNECT**
> - **CCI_ER_QUERY_TIMEOUT**
> - **CCI_ER_LOGIN_TIMEOUT**

Executes *sql_stmt* as many times as *num_sql_stmt* specified as a parameter and returns the number of queries executed with the query_result variable. You can use `CCI_QUERY_RESULT_RESULT`, c`CCI_QUERY_RESULT_ERR_NO`, `CCI_QUERY_RESULT_ERR_MSG` and `CCI_QUERY_RESULT_STMT_TYPE` macros to get the result of each query. Regarding the summary of these macros, see the [cci_execute_array](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute_array) function.

Note that the validity check is not performed for each parameter entered in the macro.

After using the *query_result* variable, you must delete the query result by using the [cci_query_result_free](https://www.coradb.ai/manual/api/cciapi_query.html#cci_query_result_free) function.

If autocommit mode is on, each query in the array is committed after executing.

> **Note:**
> - If autocommit mode is off, after the general error occurs during executing one of the queries in the array on the cci_execute_batch function which does a batch processing of the queries, the query with an error is ignored and the next query is executed. But if the deadlock occurs, the error occurs as rolling back the transaction.


``` c
...
char **queries;
T_CCI_QUERY_RESULT *result;
int n_queries, n_executed;
...
count = 3;
queries = (char **) malloc (count * sizeof (char *));
queries[0] =
    "insert into order_items (order_id, product_id, quantity, discount_pct) values (1, 1618, 2, 0)";
queries[1] =
    "insert into order_items (order_id, product_id, quantity, discount_pct) values (1, 1619, 1, 10)";
queries[2] =
    "select product_id, quantity from order_items where order_id = 1 order by product_id";

//calling cci_execute_batch()
n_executed = cci_execute_batch (con, count, queries, &result, &cci_error);
if (n_executed < 0)
{
    printf ("execute_batch: %d, %s\n", cci_error.err_code, cci_error.err_msg);
    goto handle_error;
}
printf ("%d statements were executed.\n", n_executed);

for (i = 1; i <= n_executed; i++)
{
    printf ("query %d\n", i);
    printf ("result count = %d\n", CCI_QUERY_RESULT_RESULT (result, i));
    printf ("error message = %s\n", CCI_QUERY_RESULT_ERR_MSG (result, i));
    printf ("statement type = %d\n",
            CCI_QUERY_RESULT_STMT_TYPE (result, i));
}

error = cci_query_result_free (result, n_executed);
if (error < 0)                                                                                                                            
{                                                                                                                                       
    printf ("query_result_free: %d\n", error);   
    goto handle_error;
}
...
```

**Parameters**

- `conn_handle`: (IN) Connection handle
- `num_sql_stmt`: (IN) The number of *sql_stmt*
- `sql_stmt`: (IN) SQL statement array
- `query_result`: (OUT) The results of *sql_stmt*
- `err_buf`: (OUT) Database error buffer

**Returns:** Success: The number of executed queries, Failure: Negative number

## cci_execute_result

``` c
int cci_execute_result(int req_handle, T_CCI_QUERY_RESULT **query_result, T_CCI_ERROR *err_buf)
```

The **cci_execute_result** function stores the execution results (e.g. statement type, result count) performed by [cci_execute](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute) to the array of **T_CCI_QUERY_RESULT** structure. You can use `CCI_QUERY_RESULT_RESULT`, `CCI_QUERY_RESULT_ERR_NO`, `CCI_QUERY_RESULT_ERR_MSG`, `CCI_QUERY_RESULT_STMT_TYPE` macros to get the results of each query. Regarding the summary of these macros, see the [cci_execute_array](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute_array) function.

Note that the validity check is not performed for each parameter entered in the macro.

The memory of used query results must be released by the [cci_query_result_free](https://www.coradb.ai/manual/api/cciapi_query.html#cci_query_result_free) function.

> - **CCI_ER_REQ_HANDLE**
> - **CCI_ER_COMMUNICATION**

``` c
...
T_CCI_QUERY_RESULT *qr;
...

cci_execute( ... );
res = cci_execute_result(req_h, &qr, &err_buf);
if (res < 0) 
{
    /* error */
}
else 
{
    for (i=1 ; i <= res ; i++) 
    {
        result_count = CCI_QUERY_RESULT_RESULT(qr, i);
        stmt_type = CCI_QUERY_RESULT_STMT_TYPE(qr, i);
    }
    cci_query_result_free(qr, res);
}
...
```

**Parameters**

- `req_handle`: (IN) Request handle of the prepared statement
- `query_result`: (OUT) Query results
- `err_buf`: (OUT) Database error buffer

**Returns:** Success: The number of queries, Failure: Negative number

## cci_fetch

``` c
int cci_fetch(int req_handle, T_CCI_ERROR *err_buf)
```

The **cci_fetch** function fetches the query result executed by [cci_execute](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute) from the server-side CAS and stores it to the client buffer. The [cci_get_data](https://www.coradb.ai/manual/api/cciapi_query.html#cci_get_data) function can be used to identify the data of a specific column from the fetched query result.

> - **CCI_ER_REQ_HANDLE**
> - **CAS_ER_HOLDABLE_NOT_ALLOWED**
> - **CCI_ER_NO_MORE_DATA**
> - **CCI_ER_RESULT_SET_CLOSED**
> - **CCI_ER_DELETED_TUPLE**
> - **CCI_ER_COMMUNICATION**
> - **CCI_ER_NO_MORE_MEMORY**

**Parameters**

- `req_handle`: (IN) Request handle
- `err_buf`: (OUT) Database error buffer

**Returns:** Error code (0: success)

## cci_fetch_buffer_clear

``` c
int cci_fetch_buffer_clear(int req_handle)
```

The **cci_fetch_buffer_clear** function clears the records temporarily stored in the client buffer.

> - **CCI_ER_REQ_HANDLE**

**Parameters**

- `req_handle`: Request handle

**Returns:** Error code (0: success)

## cci_fetch_sensitive

``` c
int cci_fetch_sensitive(int req_handle, T_CCI_ERROR *err_buf)
```

The **cci_fetch_sensitive** function sends changed values for sensitive column when the **SELECT** query result is delivered. If the results by *req_handle* are not sensitive, they are same as the ones by [cci_fetch](https://www.coradb.ai/manual/api/cciapi_query.html#cci_fetch). The return value of **CCI_ER_DELETED_TUPLE** means that the given row has been deleted.

> - **CCI_ER_REQ_HANDLE**
> - **CCI_ER_NO_MORE_DATA**
> - **CCI_ER_COMMUNICATION**
> - **CCI_ER_DBMS**
> - **CCI_ER_DELETED_TUPLE**

sensitive column means the item that can provide updated value in the **SELECT** list when you re-request the results. For example, if a column is directly used as an item of the **SELECT** list without aggregation operation, this column can be called a sensitive column.

When you fetch the result again, the sensitive result receive the data from the server, not from the client buffer.

**Parameters**

- `req_handle`: (IN) Request handle
- `err_buf`: (OUT) Database error buffer

**Returns:** Error code (0: success)

## cci_fetch_size

``` c
int cci_fetch_size(int req_handle, int fetch_size)
```

This function is deprecated. Even if it's called, there will be ignored.

## cci_get_bind_num

``` c
int cci_get_bind_num(int req_handle)
```

The **cci_get_bind_num** function gets the number of input bindings. If the SQL statement used during preparation is composed of multiple queries, it represents the number of input bindings used in all queries.

> - **CCI_ER_REQ_HANDLE**

**Parameters**

- `req_handle`: (IN) Request handle for the prepared statement

**Returns:** The number of input bindings

## cci_get_class_num_objs

``` c
int cci_get_class_num_objs(int conn_handle, char *class_name, int flag, int *num_objs, int *num_pages, T_CCI_ERROR *err_buf)
```

The **cci_get_class_num_objs** function gets the number of objects of the *class_name* class and the number of pages being used. If the flag is configured to 1, an approximate value is fetched; if it is configured to 0, an exact value is fetched.

> - **CCI_ER_REQ_HANDLE**
> - **CCI_ER_COMMUNICATION**
> - **CCI_ER_CONNECT**

**Parameters**

- `conn_handle`: (IN) Connection handle
- `class_name`: (IN) Class name
- `flag`: (IN) 0 or 1
- `num_objs`: (OUT) The number of objects
- `num_pages`: (OUT) The number of pages
- `err_buf`: (OUT) Database error buffer

**Returns:** Error code (0: success)

## cci_get_data

``` c
int cci_get_data(int req_handle, int col_no, int type, void *value, int *indicator)
```

The **cci_get_data** function gets the *col_no* -th value from the currently fetched result.

> - If *type* is **CCI_A_TYPE_STR** : -1 is returned in case of **NULL**; the length of string stored in *value* is returned, otherwise.
> - If *type* is not **CCI_A_TYPE_STR** : -1 is returned in case of **NULL**, 0 is returned, otherwise.
>
> > - **CCI_ER_REQ_HANDLE**
> > - **CCI_ER_TYPE_CONVERSION**
> > - **CCI_ER_COLUMN_INDEX**
> > - **CCI_ER_ATYPE**

The *type* of the *value* variable is determined based on the given *type* argument, and the value or the pointer is copied to the *value* variable accordingly. For a value to be copied, the memory for the address to be transferred to the *value* variable must have been previously assigned. Note that if a pointer is copied, a pointer in the application client library is returned, so the value becomes invalid next time the [cci_get_data](https://www.coradb.ai/manual/api/cciapi_query.html#cci_get_data) function is called.

In addition, the pointer returned by the pointer copy must not be freed. However, if the type is **CCI_A_TYPE_SET**, the memory must be freed by using the [cci_set_free](https://www.coradb.ai/manual/api/cciapi_types.html#cci_set_free) function after using the set because the set is returned after the **T_CCI_SET** type memory is allocated. The following table shows the summary of *type* arguments and data types of their corresponding *value* values.

| type              | value type                             | Meaning                                   |
|-------------------|----------------------------------------|-------------------------------------------|
| CCI_A_TYPE_STR    | char \*\*                              | Pointer copy                              |
| CCI_A_TYPE_INT    | int \*                                 | Value copy                                |
| CCI_A_TYPE_FLOAT  | float \*                               | Value copy                                |
| CCI_A_TYPE_DOUBLE | double \*                              | Value copy                                |
| CCI_A_TYPE_BIT    | **T_CCI_BIT** \*                       | Value copy (pointer copy for each member) |
| CCI_A_TYPE_SET    | **T_CCI_SET** \*                       | Memory allocation and value copy          |
| CCI_A_TYPE_DATE   | **T_CCI_DATE** \*                      | Value copy                                |
| CCI_A_TYPE_BIGINT | int64_t \* (For Windows: \_\_int64 \*) | Value copy                                |
| CCI_A_TYPE_BLOB   | **T_CCI_BLOB** \*                      | Memory allocation and value copy          |
| CCI_A_TYPE_CLOB   | **T_CCI_CLOB** \*                      | Memory allocation and value copy          |

**Remark**

- For **LOB** type, if the [cci_get_data](https://www.coradb.ai/manual/api/cciapi_query.html#cci_get_data) function is called, meta data with the **LOB** type column (locator) is displayed. To call data of the **LOB** type column, the [cci_blob_read](https://www.coradb.ai/manual/api/cciapi_types.html#cci_blob_read) function should be called.

The below example shows a part of a code to print out the fetched result with [cci_get_data](https://www.coradb.ai/manual/api/cciapi_query.html#cci_get_data).

``` c
...

if ((res=cci_get_data(req, i, CCI_A_TYPE_INT, &buffer, &ind))<0) {
    printf( "%s(%d): cci_get_data fail\n", __FILE__, __LINE__);
    goto handle_error;
}
if (ind != -1)
        printf("%d \t|", buffer);
else
        printf("NULL \t|");
...
```

**Parameters**

- `req_handle`: (IN) Request handle
- `col_no`: (IN) One-based column index. It starts with 1.
- `type`: (IN) Data type (defined in the **T_CCI_A_TYPE**) of *value* variable
- `value`: (OUT) Variable address for data to be stored. If *type* is one of (CCI_A_TYPE_STR, CCI_A_TYPE_SET, CCI_A_TYPE_BLOB or CCI_A_TYPE_CLOB) and the value of a column is NULL, the *value* will be NULL, too.
- `indicator`: (OUT) **NULL** indicator. (-1 : **NULL**)

**Returns:** Error code (0: success)

## cci_get_last_insert_id

``` c
int cci_get_last_insert_id(int conn_handle, void *value, T_CCI_ERROR *err_buf)
```

Gets the primary key of the INSERT statement which executed at the last time.

> - **CCI_ER_CON_HANDLE**
> - **CCI_ER_USED_CONNECTION**
> - **CCI_ER_INVALID_ARGS**

``` c
#include <stdio.h>
#include "cas_cci.h"

int main ()
{
    int con = 0;
    int req = 0;

    int error;
    T_CCI_ERROR cci_error;

    char *query = "insert into t1 values(NULL);";
    char *value = NULL;

    con = cci_connect ("localhost", 33000, "e-commerce", "dba", "");

    if (con < 0)
    {
        printf ("con error\n");
        return;
    }

    req = cci_prepare (con, query, 0, &cci_error);
    if (req < 0)
    {
        printf ("cci_prepare error: %d\n", req);
        printf ("cci_error: %d, %s\n", cci_error.err_code, cci_error.err_msg);
        return;
    }
    error = cci_execute (req, 0, 0, &cci_error);
    if (error < 0)
    {
        printf ("cci_execute error: %d\n", error);
        return;
    }

    error = cci_get_last_insert_id (con, &value, &cci_error);
    if (error < 0)
    {
        printf ("cci_get_last_insert_id error: %d\n", error);
        return;
    }

    printf ("## last insert id: %s\n", value);

    error = cci_close_req_handle (req);
    error = cci_disconnect (con, &cci_error);
    return 0;
}
```

**Parameters**

- `conn_handle`: (IN) Request handle
- `value`: (OUT) The pointer of the result buffer pointer(char \*\*). It stores the last primary key of INSERT statement executed on the last time. The memory which this pointer indicates doesn't need to be released, because it is the fixed buffer inside the connection handle.
- `err_buf`: (OUT) Error buffer

**Returns:** Error code (0: success)

## cci_get_param_info

``` c
int cci_get_param_info(int req_handle, T_CCI_PARAM_INFO **param, T_CCI_ERROR *err_buf)
```

The **cci_get_param_info** function returns information about the parameters (`?`) of a prepared statement, typically a **CALL** of a stored procedure: for each parameter its mode, type, scale and precision. The array returned in *param* is allocated by CCI; free it with [cci_param_info_free](https://www.coradb.ai/manual/api/cciapi_query.html#cci_param_info_free). The return value is the number of parameters.

Read the array with the macros below, where *index* starts at 1:

| Macro | Value |
|---|---|
| `CCI_GET_PARAM_INFO_MODE(param, index)` | **T_CCI_PARAM_MODE**: `CCI_PARAM_MODE_IN`, `CCI_PARAM_MODE_OUT`, `CCI_PARAM_MODE_INOUT` or `CCI_PARAM_MODE_UNKNOWN` |
| `CCI_GET_PARAM_INFO_TYPE(param, index)` | Data type (**T_CCI_U_EXT_TYPE**) |
| `CCI_GET_PARAM_INFO_SCALE(param, index)` | scale |
| `CCI_GET_PARAM_INFO_PRECISION(param, index)` | precision |

> - **CCI_ER_REQ_HANDLE**
> - **CCI_ER_COMMUNICATION**
> - **CCI_ER_DBMS**

**Example**

``` c
T_CCI_PARAM_INFO *param = NULL;
int n, i;

n = cci_get_param_info (req, &param, &err);
for (i = 1; i <= n; i++)
  {
    printf ("param %d: mode %d, type %d\n", i,
            CCI_GET_PARAM_INFO_MODE (param, i), CCI_GET_PARAM_INFO_TYPE (param, i));
  }
cci_param_info_free (param);
```

**Parameters**

- `req_handle`: (IN) Request handle of a prepared statement
- `param`: (OUT) Array of parameter information
- `err_buf`: (OUT) Database error buffer

**Returns:** Number of parameters, or an error code

## cci_get_query_plan

``` c
int cci_get_query_plan(int req_handle, char **out_buf_p)
```

Saves the query plan to the result buffer; the query plan about the request handle which the cci_prepare function returned. You can call this function whether to call the cci_execute function or not.

After calling the cci_get_query_plan function, if the use of a result buffer ends, you should call the [cci_query_info_free](https://www.coradb.ai/manual/api/cciapi_query.html#cci_query_info_free) function to release the result buffer created by cci_get_query_plan function.

``` text
char *out_buf;
...
req = cci_prepare (con, query, 0, &cci_error);
...
ret = cci_get_query_plan(req, &out_buf); 
...
printf("plan = %s", out_buf);
cci_query_info_free(out_buf);

*    **CCI_ER_REQ_HANDLE**
*    **CCI_ER_CON_HANDLE**
*    **CCI_ER_USED_CONNECTION**
```

**See also:** [cci_query_info_free](https://www.coradb.ai/manual/api/cciapi_query.html#cci_query_info_free)

**Parameters**

- `req_handle`: (IN) Request handle
- `out_buf_p`: (OUT) The pointer of a result buffer pointer

**Returns:** Error code

## cci_last_insert_id

``` c
int cci_last_insert_id(int conn_handle, void *value, T_CCI_ERROR *err_buf)
```

Deprecated; use [cci_get_last_insert_id](https://www.coradb.ai/manual/api/cciapi_query.html#cci_get_last_insert_id). The **cci_last_insert_id** function returns the same value, but as a string allocated with **malloc** that the caller must free; this can cause problems with custom allocators ([cci_set_allocators](https://www.coradb.ai/manual/api/cciapi.html#cci_set_allocators)) and across Windows DLL boundaries.

**Parameters**

- `conn_handle`: (IN) Connection handle
- `value`: (OUT) Pointer to a `char *` that receives the allocated string
- `err_buf`: (OUT) Database error buffer

**Returns:** Error code (0: success)

## cci_param_info_free

``` c
int cci_param_info_free(T_CCI_PARAM_INFO *param)
```

The **cci_param_info_free** function frees the array returned by [cci_get_param_info](https://www.coradb.ai/manual/api/cciapi_query.html#cci_get_param_info).

**Parameters**

- `param`: (IN) Parameter information array

**Returns:** 0

## cci_query_info_free

``` c
int cci_query_info_free(char *out_buf)
```

Releases the result buffer memory allocated from the [cci_get_query_plan](https://www.coradb.ai/manual/api/cciapi_query.html#cci_get_query_plan) function.

> - **CCI_ER_NO_MORE_MEMORY**

**See also:** [cci_get_query_plan](https://www.coradb.ai/manual/api/cciapi_query.html#cci_get_query_plan)

**Parameters**

- `req_handle`: (IN) Request handle
- `out_buf`: (OUT) Result buffer pointer

**Returns:** Error code

## cci_get_result_info

``` c
T_CCI_COL_INFO* cci_get_result_info(int req_handle, T_CCI_CORADB_STMT *stmt_type, int *num)
```

If the prepared statement is **SELECT**, the **T_CCI_COL_INFO** struct that stores the column information about the execution result can be obtained by using this function. If it is not **SELECT**, **NULL** is returned and the *num* value becomes 0.

You can access the **T_CCI_COL_INFO** struct directly to get the column information from the struct, but you can also use a macro to get the information, which is defined as follows. The address of the **T_CCI_COL_INFO** struct and the column index are specified as parameters for each macro. The macro can be called only for the **SELECT** query. Note that the validity check is not performed for each parameter entered in each macro. If the return type of the macro is char\*, do not free the memory pointer.

| Macro                                                                             | Return type | Meaning |
|-----------------------------------------------------------------------------------|-------------|---------|
| `CCI_GET_RESULT_INFO_TYPE` \| **T_CCI_U_TYPE** \| Column type \|                  |             |         |
| `CCI_GET_RESULT_INFO_SCALE` \| short \| Column scale \|                           |             |         |
| `CCI_GET_RESULT_INFO_PRECISION` \| int \| Column precision \|                     |             |         |
| `CCI_GET_RESULT_INFO_NAME` \| char \* \| Column name \|                           |             |         |
| `CCI_GET_RESULT_INFO_ATTR_NAME` \| char \* \| Column attribute name \|            |             |         |
| `CCI_GET_RESULT_INFO_CLASS_NAME` \| char \* \| Column class name \|               |             |         |
| `CCI_GET_RESULT_INFO_IS_NON_NULL` \| char (0 or 1) \| Whether a column is NULL \| |             |         |

``` c
col_info = cci_get_result_info (req, &stmt_type, &col_count);
if (col_info == NULL)
{
  printf ("get_result_info error\n");
  goto handle_error;
}

for (i = 1; i <= col_count; i++)
{
  printf ("%-12s = %d\n", "type", CCI_GET_RESULT_INFO_TYPE (col_info, i));
  printf ("%-12s = %d\n", "scale",
          CCI_GET_RESULT_INFO_SCALE (col_info, i));
  printf ("%-12s = %d\n", "precision",
          CCI_GET_RESULT_INFO_PRECISION (col_info, i));
  printf ("%-12s = %s\n", "name", CCI_GET_RESULT_INFO_NAME (col_info, i));
  printf ("%-12s = %s\n", "attr_name",
          CCI_GET_RESULT_INFO_ATTR_NAME (col_info, i));
  printf ("%-12s = %s\n", "class_name",
          CCI_GET_RESULT_INFO_CLASS_NAME (col_info, i));
  printf ("%-12s = %s\n", "is_non_null",
          CCI_GET_RESULT_INFO_IS_NON_NULL (col_info,i) ? "true" : "false");
}
```

**Parameters**

- `req_handle`: (IN) Request handle for the prepared statement
- `stmt_type`: (OUT) Command type
- `num`: (OUT) he number of columns in the **SELECT** statement (if *stmt_type* is **CORADB_STMT_SELECT**)

**Returns:** Success: Result info pointer, Failure: **NULL**

## CCI_GET_RESULT_INFO_ATTR_NAME

``` c
#define CCI_GET_RESULT_INFO_ATTR_NAME(T_CCI_COL_INFO* res_info, int index)
```

The **CCI_GET_RESULT_INFO_ATTR_NAME** macro gets the actual attribute name of the *index*-th column of a prepared **SELECT** list. If there is no name for the attribute (constant, function, etc), " " (empty string) is returned. It does not check whether the specified argument, *res_info*, is **NULL** and whether *index* is valid. You cannot delete the returned memory pointer with **free**().

**Parameters**

- `res_info`: (IN) A pointer to the column information fetched by [cci_get_result_info](https://www.coradb.ai/manual/api/cciapi_query.html#cci_get_result_info)
- `index`: (IN) Column index

**Returns:** Attribute name (char \*)

## CCI_GET_RESULT_INFO_CLASS_NAME

``` c
#define CCI_GET_RESULT_INFO_CLASS_NAME(T_CCI_COL_INFO* res_info, int index)
```

The **CCI_GET_RESULT_INFO_CLASS_NAME** macro gets the *index*-th column's class name of a prepared **SELECT** list. It does not check whether the specified argument, *res_info*, is **NULL** and whether *index* is valid. You cannot delete the returned memory pointer with **free** (). The return value can be **NULL**.

**Parameters**

- `res_info`: (IN) Column info pointer by [cci_get_result_info](https://www.coradb.ai/manual/api/cciapi_query.html#cci_get_result_info)
- `index`: (IN) Column index

**Returns:** Class name (char \*)

## CCI_GET_RESULT_INFO_IS_NON_NULL

``` c
#define CCI_GET_RESULT_INFO_IS_NON_NULL(T_CCI_COL_INFO* res_info, int index)
```

The **CCI_GET_RESULT_INFO_IS_NON_NULL** macro gets a value indicating whether the *index*-th column of a prepared **SELECT** list is nullable. It does not check whether the specified argument, *res_info*, is **NULL** and whether *index* is valid.

When a column of a **SELECT** list is not a column but an expression, CoraDB cannot judge it's NON_NULL or not; therefore, CCI_GET_RESULT_INFO_IS_NON_NULL macro always returns 0.

**Parameters**

- `res_info`: (IN) Column info pointer by [cci_get_result_info](https://www.coradb.ai/manual/api/cciapi_query.html#cci_get_result_info)
- `index`: (IN) Column index

**Returns:** 0: nullable, 1: non **NULL**

## CCI_GET_RESULT_INFO_NAME

``` c
#define CCI_GET_RESULT_INFO_NAME(T_CCI_COL_INFO* res_info, int index)
```

The **CCI_GET_RESULT_INFO_NAME** macro gets the *index*-th column's name of a prepared **SELECT** list. It does not check whether the specified argument, *res_info*, is **NULL** and whether *index* is valid. You cannot delete the returned memory pointer with **free** ().

**Parameters**

- `res_info`: (IN) Column info pointer to [cci_get_result_info](https://www.coradb.ai/manual/api/cciapi_query.html#cci_get_result_info)
- `index`: (IN) Column index

**Returns:** Column name (char \*)

## CCI_GET_RESULT_INFO_PRECISION

``` c
#define CCI_GET_RESULT_INFO_PRECISION(T_CCI_COL_INFO* res_info, int index)
```

The **CCI_GET_RESULT_INFO_PRECISION** macro gets the *index*-th column's precision of a prepared **SELECT** list. It does not check whether the specified argument, *res_info*, is **NULL** and whether *index* is valid.

**Parameters**

- `res_info`: (IN) Column info pointer by [cci_get_result_info](https://www.coradb.ai/manual/api/cciapi_query.html#cci_get_result_info)
- `index`: (IN) Column index

**Returns:** precision (int)

## CCI_GET_RESULT_INFO_SCALE

``` c
#define CCI_GET_RESULT_INFO_SCALE(T_CCI_COL_INFO* res_info, int index)
```

The **CCI_GET_RESULT_INFO_SCALE** macro gets the *index*-th column's scale of a prepared **SELECT** list. It does not check whether the specified argument, *res_info*, is **NULL** and whether *index* is valid.

**Parameters**

- `res_info`: (IN) Column info pointer by [cci_get_result_info](https://www.coradb.ai/manual/api/cciapi_query.html#cci_get_result_info)
- `index`: (IN) Column index

**Returns:** scale (int)

## CCI_GET_RESULT_INFO_TYPE

``` c
#define CCI_GET_RESULT_INFO_TYPE(T_CCI_COL_INFO* res_info, int index)
```

The **CCI_GET_RESULT_INFO_TYPE** macro gets the *index*-th column's type of a prepared **SELECT** list. It does not check whether the specified argument, *res_info*, is **NULL** and whether *index* is valid.

If you want to check which column is a SET type or not, use `CCI_IS_SET_TYPE`.

**Parameters**

- `res_info`: (IN) pointer to the column information fetched by [cci_get_result_info](https://www.coradb.ai/manual/api/cciapi_query.html#cci_get_result_info)
- `index`: (IN) Column index

**Returns:** Column type (**T_CCI_U_TYPE**)

## cci_is_updatable

``` c
int cci_is_updatable(int req_handle)
```

The **cci_is_updatable** function checks the SQL statement executing [cci_prepare](https://www.coradb.ai/manual/api/cciapi_query.html#cci_prepare) can make updatable result set (which means CCI_PREPARE_UPDATABLE is configured in *flag* when executing [cci_prepare](https://www.coradb.ai/manual/api/cciapi_query.html#cci_prepare)).

> - 1 : updatable
> - 0 : not updatable
> - **CCI_ER_REQ_HANDLE**

**Parameters**

- `req_handle`: (IN) Request handle for the prepared statement

**Returns:**

## cci_next_result

``` c
int cci_next_result(int req_handle, T_CCI_ERROR *err_buf)
```

The **cci_next_result** function gets results of next query if **CCI_EXEC_QUERY_ALL** *flag* is set upon [cci_execute](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute). The information about the query fetched by next_result can be obtained with [cci_get_result_info](https://www.coradb.ai/manual/api/cciapi_query.html#cci_get_result_info). If next_result is executed successfully, the database is updated with the information of the current query.

You can execute multiple queries in the written order when **CCI_EXEC_QUERY_ALL** *flag* is set on [cci_execute](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute). At this time, CoraDB brings the first query's result after calling [cci_execute](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute); CoraDB brings the second and the other queries' results after calling **cci_next_result** function. At this time, the column information about the query result can be brought by calling [cci_get_result_info](https://www.coradb.ai/manual/api/cciapi_query.html#cci_get_result_info) function whenever [cci_execute](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute) function or **cci_next_result** function is called.

In other words, when you run Q1, Q2, and Q3 at once with calling [cci_prepare](https://www.coradb.ai/manual/api/cciapi_query.html#cci_prepare) function, the result of Q1 is brought by calling [cci_execute](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute); the result of Q2 or Q3 is brought by calling **cci_next_result**. The result of Q1, Q2 or Q3 is brought by calling [cci_get_result_info](https://www.coradb.ai/manual/api/cciapi_query.html#cci_get_result_info) function for each time.

``` c
sql = "SELECT * FROM orders WHERE id = 1; SELECT * FROM order_items WHERE order_id = 1; SELECT * FROM countries";
req = cci_prepare (con, sql, 0, &error);
...
ret = cci_execute (req, CCI_EXEC_QUERY_ALL, 0, &error);
res_col_info = cci_get_result_info (req, &cmd_type, &col_count);
...
ret = cci_next_result (req, &error);
res_col_info = cci_get_result_info (req, &cmd_type, &col_count);
...
ret = cci_next_result (req, &error);
res_col_info = cci_get_result_info (req, &cmd_type, &col_count);

*     **SELECT** : The number of results
*     **INSERT**, **UPDATE** : The number of records reflected
*     Others : 0
*     Failure : Error code

    *   **CCI_ER_REQ_HANDLE**
    *   **CCI_ER_DBMS**
    *   **CCI_ER_COMMUNICATION**
```

The error code **CAS_ER_NO_MORE_RESULT_SET** means that no more result set exists.

**Parameters**

- `req_handle`: (IN) Request handle of a prepared statement
- `err_buf`: (OUT) Database error buffer

**Returns:**

## cci_prepare

``` c
int cci_prepare(int conn_handle, char *sql_stmt, char flag,T_CCI_ERROR *err_buf)
```

The [cci_prepare](https://www.coradb.ai/manual/api/cciapi_query.html#cci_prepare) function prepares SQL execution by acquiring request handle for SQL statements. If a SQL statement consists of multiple queries, the preparation is performed only for the first query. With the parameter of this function, an address to **T_CCI_ERROR** where connection handle, SQL statement, *flag*, and error information are stored.

> - **CCI_ER_CON_HANDLE**
> - **CCI_ER_DBMS**
> - **CCI_ER_COMMUNICATION**
> - **CCI_ER_STR_PARAM**
> - **CCI_ER_NO_MORE_MEMORY**
> - **CCI_ER_CONNECT**
> - **CCI_ER_QUERY_TIMEOUT**
> - **CCI_ER_LOGIN_TIMEOUT**

**CCI_PREPARE_UPDATABLE**, **CCI_PREPARE_INCLUDE_OID**, **CCI_PREPARE_CALL** or **CCI_PREPARE_HOLDABLE** can be configured in *flag*. If **CCI_PREPARE_UPDATABLE** is configured, updatable resultset is created and **CCI_PREPARE_INCLUDE_OID** is automatically configured. **CCI_PREPARE_UPDATABLE** and **CCI_PREPARE_HOLDABLE** cannot be used simultaneously in *flag*. If you want to call the Java Stored Procedure, specify **CCI_PREPARE_CALL** flag into the **cci_prepare** function. You can see an related example on [cci_register_out_param](https://www.coradb.ai/manual/api/cciapi_query.html#cci_register_out_param).

The default value of whether to keep result set after commit is cursor holdability. Thus, if you want to configure **CCI_PREPARE_UPDATABLE** in *flag* of [cci_prepare](https://www.coradb.ai/manual/api/cciapi_query.html#cci_prepare), you should call [cci_set_holdability](https://www.coradb.ai/manual/api/cciapi_transaction.html#cci_set_holdability) first before calling [cci_prepare](https://www.coradb.ai/manual/api/cciapi_query.html#cci_prepare) so that cursor cannot be maintained.

However, not all updatable resultsets are created even though **CCI_PREPARE_UPDATABLE** is configured. So you need to check if the results are updatable by using [cci_is_updatable](https://www.coradb.ai/manual/api/cciapi_query.html#cci_is_updatable) after preparation. You can use [cci_oid_put](https://www.coradb.ai/manual/api/cciapi_types.html#cci_oid_put) or [cci_oid_put2](https://www.coradb.ai/manual/api/cciapi_types.html#cci_oid_put2) to update result sets.

The conditions of updatable queries are as follows:

- Must be **SELECT**.
- OID can be included in the query result.
- The column to be updated must be the one that belongs to the table specified in the **FROM** clause.

If **CCI_PREPARE_HOLDABLE** is set, a cursor is held as long as result set is closed or connection is disconnected after the statement is committed (see [Cursor holdability](https://www.coradb.ai/manual/sql/transaction.html#cursor-holdability)).

**Parameters**

- `conn_handle`: (IN) Connection handle
- `sql_stmt`: (IN) SQL statement
- `flag`: (IN) prepare flag (CCI_PREPARE_UPDATABLE, CCI_PREPARE_INCLUDE_OID, CCI_PREPARE_CALL or CCI_PREPARE_HOLDABLE)
- `err_buf`: (OUT) Database error buffer

**Returns:** Success: Request handle ID (int), Failure: Error code

## cci_prepare_and_execute

``` c
int cci_prepare_and_execute(int conn_handle, char *sql_stmt, int max_col_size, int *exec_retval, T_CCI_ERROR *err_buf)
```

The **cci_prepare_and_execute** function executes the SQL statement immediately and returns a request handle for the SQL statement. A request handle, SQL statement, the maximum length of a column to be fetched, error code, and the address of a **T_CCI_ERROR** construct variable in which error information being stored are specified as arguments. *max_col_size* is a value to configure the maximum length of a column to be sent to a client when the column of a SQL statement is **CHAR**, **VARCHAR**, **BIT**, or **VARBIT**. If this value is 0, full length is fetched.

> - **CCI_ER_CON_HANDLE**
> - **CCI_ER_DBMS**
> - **CCI_ER_COMMUNICATION**
> - **CCI_ER_STR_PARAM**
> - **CCI_ER_NO_MORE_MEMORY**
> - **CCI_ER_CONNECT**
> - **CCI_ER_QUERY_TIMEOUT**

**Parameters**

- `conn_handle`: (IN) Connection handle
- `sql_stmt`: (IN) SQL statement
- `max_col_size`: (IN) The maximum length of a column to be fetched when it is a string data type in bytes. If this value is 0, full length is fetched.
- `exec_retval`: (OUT) Success: Affected rows, Failure: Error code
- `err_buf`: (OUT) Database error buffer

**Returns:** Success: Request handle ID (int), Failure: Error code

## cci_query_result_free

``` c
int cci_query_result_free(T_CCI_QUERY_RESULT* query_result, int num_query)
```

The **cci_query_result_free** function releases query results created by [cci_execute_batch](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute_batch), [cci_execute_array](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute_array) or [cci_execute_result](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute_result) function from memory.

``` c
T_CCI_QUERY_RESULT *qr;
char **sql_stmt;

...

res = cci_execute_array(conn, &qr, &err_buf);

...

cci_query_result_free(qr, res);
```

**Parameters**

- `query_result`: (IN) Query results to release from memory
- `num_query`: (IN) The number of arrays in *query_result*

**Returns:** 0: success

## CCI_QUERY_RESULT_ERR_NO

``` c
#define CCI_QUERY_RESULT_ERR_NO(T_CCI_QUERY_RESULT* query_result, int index)
```

Since query results performed by [cci_execute_batch](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute_batch), [cci_execute_array](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute_array), or [cci_execute_result](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute_result) function are stored as an array of **T_CCI_QUERY_RESULT** structure, you need to check the query result for each item of the array.

**CCI_QUERY_RESULT_ERR_NO** fetches the error number for the array item specified as *index*, if it is not an error, it returns 0.

**Parameters**

- `query_result`: (IN) Query result to retrieve
- `index`: (IN) Index of the result array(base :1). It represents a specific location of the result array.

**Returns:** Error number

## CCI_QUERY_RESULT_ERR_MSG

``` c
#define CCI_QUERY_RESULT_ERR_MSG(T_CCI_QUERY_RESULT* query_result, int index)
```

The **CCI_QUERY_RESULT_ERR_MSG** macro gets error messages about query results executed by [cci_execute_batch](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute_batch), [cci_execute_array](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute_array) or [cci_execute_result](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute_result) function. If there is no error message, this macro returns ""(empty string). It does not check whether the specified argument, *query_result*, is **NULL**, and whether *index* is valid.

**Parameters**

- `query_result`: (IN) Query results of to be executed
- `index`: (IN) Column index (base: 1)

**Returns:** Error message

## CCI_QUERY_RESULT_RESULT

``` c
#define CCI_QUERY_RESULT_RESULT(T_CCI_QUERY_RESULT* query_result, int index)
```

The **CCI_QUERY_RESULT_RESULT** macro gets the result count executed by [cci_execute_batch](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute_batch), [cci_execute_array](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute_array) or [cci_execute_result](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute_result) function. It does not check whether the specified argument, *query_result*, is **NULL** and whether *index* is valid.

**Parameters**

- `query_result`: (IN) Query results to be retrieved
- `index`: (IN) Column index (base: 1)

**Returns:** result count

## CCI_QUERY_RESULT_STMT_TYPE

``` c
#define CCI_QUERY_RESULT_STMT_TYPE(T_CCI_QUERY_RESULT* query_result, int index)
```

Since query results performed by [cci_execute_batch](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute_batch), [cci_execute_array](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute_array) or [cci_execute_result](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute_result) function are stored as an array of T_CCI_QUERY_RESULT type, you need to check the query result for each item of the array.

The **CCI_QUERY_RESULT_STMT_TYPE** macro gets the statement type for the array items specified as *index*.

It does not check whether the specified argument, *query_result*, is **NULL** and whether *index* is valid.

**Parameters**

- `query_result`: (IN) Query results to be retrieved
- `index`: (IN) Column index (base: 1)

**Returns:** statement type (**T_CCI_CORADB_STMT**)

## cci_register_out_param

``` c
int cci_register_out_param(int req_handle, int index)
```

The **cci_register_out_param** function is used to bind the parameters as outbind in Java Stored Procedure. The index value begins from 1. To call this function, **CCI_PREPARE_CALL** flag of **cci_prepare** function should be specified.

> - **CCI_ER_BIND_INDEX**
> - **CCI_ER_REQ_HANDLE**
> - **CCI_ER_CON_HANDLE**
> - **CCI_ER_USED_CONNECTION**

The following shows to print out "Hello, CoraDB" string with Java Stored Procedure.

To use Java Stored Procedure, firstly specify **java_stored_procedure** parameter in coradb.conf as **yes**, then start the database.

``` bash
$ vi coradb.conf
java_stored_procedure=yes

$ coradb service start
$ coradb server start e-commerce
```

Implement and compile the class to be used as Java Stored Procedure.

``` java
public class SpCoraDB{
    public static void outTest(String[] o) {
        o[0] = "Hello, CoraDB";
    }
}

%javac SpCoraDB.java
```

Load the compiled Java class into CoraDB.

``` bash
$ loadjava e-commerce SpCoraDB.class
```

Register the loaded Java class.

``` sql
CREATE PROCEDURE test_out(x OUT STRING)
AS LANGUAGE JAVA
NAME 'SpCoraDB.outTest(java.lang.String[])';
```

In the CCI program, prepare the **CALL** with the **CCI_PREPARE_CALL** flag, register the **OUT** parameter with **cci_register_out_param**, execute, and fetch the value.

``` c
// On Linux, compile with "gcc -g -o jsp jsp.c -I$CORADB/include/ -L$CORADB/lib/ -lcascci -lpthread"

#include <stdio.h>
#include <unistd.h>
#include <cas_cci.h>
char *cci_client_name = "test";

int
main (int argc, char *argv[])
{
    int con = 0, req = 0, res, ind, i, col_count;
    T_CCI_ERROR error;
    T_CCI_COL_INFO *res_col_info;
    T_CCI_CORADB_STMT cmd_type;
    char *buffer, db_ver[16];

    if ((con = cci_connect ("localhost", 33000, "e-commerce", "dba", "")) < 0)
    {
        printf ("%s(%d): cci_connect fail\n", __FILE__, __LINE__);
        return -1;
    }

    if ((req = cci_prepare (con, "call test_out(?)", CCI_PREPARE_CALL, &error)) < 0)
    {
        printf ("%s(%d): cci_prepare fail(%d)\n", __FILE__, __LINE__,
            error.err_code);
        goto handle_error;
    }
    if ((res = cci_register_out_param (req, 1)) < 0)
    {
        printf ("%s(%d): cci_register_out_param fail(%d)\n", __FILE__, __LINE__,
            error.err_code);
        goto handle_error;
    }
    if ((res = cci_execute (req, 0, 0, &error)) < 0)
    {
      printf ("%s(%d): cci_execute fail(%d)\n", __FILE__, __LINE__,
            error.err_code);
      goto handle_error;
    }
    res = cci_cursor (req, 1, CCI_CURSOR_CURRENT, &error);
    if (res == CCI_ER_NO_MORE_DATA)
    {
        printf ("%s(%d): cci_cursor fail(%d)\n", __FILE__, __LINE__,
            error.err_code);
        goto handle_error;
    }

    if ((res = cci_fetch (req, &error) < 0))
    {
        printf ("%s(%d): cci_fetch(%d, %s)\n", __FILE__, __LINE__,
            error.err_code, error.err_msg);
      goto handle_error;
    }
    if ((res = cci_get_data (req, 1, CCI_A_TYPE_STR, &buffer, &ind)) < 0)
    {
        printf ("%s(%d): cci_get_data fail\n", __FILE__, __LINE__);
        goto handle_error;
    }
    // ind: string length, buffer: a string which came from the out binding parameter of test_out(?) Java SP.
    if (ind != -1) 
        printf ("%d, (%s)\n", ind, buffer);
    else // if ind== -1, then data is NULL
        printf ("NULL\n");

    if ((res = cci_close_query_result (req, &error)) < 0)
    {
        printf ("%s(%d): cci_close_query_result fail(%d)\n", __FILE__, __LINE__, error.err_code);
        goto handle_error;
    }

    if ((res = cci_close_req_handle (req)) < 0)
    {
        printf ("%s(%d): cci_close_req_handle fail\n", __FILE__, __LINE__);
        goto handle_error;
    }

    if ((res = cci_disconnect (con, &error)) < 0)
    {
        printf ("%s(%d): cci_disconnect fail(%d)\n", __FILE__, __LINE__,
            error.err_code);
        goto handle_error;
    }
    printf ("Program ended!\n");
    return 0;

handle_error:
    if (req > 0)
        cci_close_req_handle (req);
    if (con > 0)
        cci_disconnect (con, &error);
    printf ("Program failed!\n");
    return -1;
}
```

**See also:** [cci_prepare](https://www.coradb.ai/manual/api/cciapi_query.html#cci_prepare)

**Parameters**

- `req_handle`: (IN) Request handle

**Returns:** Error code

## cci_register_out_param_ex

``` c
int cci_register_out_param_ex(int req_handle, int index, T_CCI_U_TYPE u_type)
```

The **cci_register_out_param_ex** function registers the *index*-th parameter of a **CALL** as an **OUT** parameter, like [cci_register_out_param](https://www.coradb.ai/manual/api/cciapi_query.html#cci_register_out_param), and also gives its data type *u_type*, so that the value is returned in that type.

> - **CCI_ER_REQ_HANDLE**
> - **CCI_ER_BIND_INDEX**

**Parameters**

- `req_handle`: (IN) Request handle
- `index`: (IN) Parameter position, from 1
- `u_type`: (IN) Data type of the parameter (**T_CCI_U_TYPE**)

**Returns:** Error code (0: success)

## cci_row_count

``` c
int cci_row_count(int conn_handle, int *row_count, T_CCI_ERROR * err_buf)
```

The **cci_row_count** function gets the number of rows affected by the last executed query.

> - **CCI_ER_COMMUNICATION**
> - **CCI_ER_LOGIN_TIMEOUT**
> - **CCI_ER_NO_MORE_MEMORY**
> - **CCI_ER_DBMS**

**Parameters**

- `conn_handle`: (IN) Connection handle
- `row_count`: (OUT) The number of rows affected by the last executed query
- `err_buf`: (OUT) Error buffer

**Returns:** Error code

## cci_schema_info

``` c
int cci_schema_info(int conn_handle, T_CCI_SCHEMA_TYPE type, char *class_name, char *attr_name, char flag, T_CCI_ERROR *err_buf)
```

The **cci_schema_info** function gets schema information. If it is performed successfully, the results are managed by the request handle and can be fetched by fetch and getdata. If you want to retrieve a *class_name* and *attr_name* by using pattern matching of the **LIKE** statement, you should configure *flag*.

> - **CCI_ER_CON_HANDLE**
> - **CCI_ER_DBMS**
> - **CCI_ER_COMMUNICATION**
> - **CCI_ER_NO_MORE_MEMORY**
> - **CCI_ER_CONNECT**

Two types of *flag* s, **CCI_CLASS_NAME_PATTERN_MATCH**, and **CCI_ATTR_NAME_PATTERN_MATCH**, are used for pattern matching; you can configure these two *flag* s by using the OR operator ( \| ). To use pattern matching, search by using the **LIKE** statement. For example, to search the information on a column whose *class_name* is "athlete" and *attr_name* is "code," you can enter as follows (in the example, "%code" is entered in the value of *attr_name*).

``` text
cci_schema_info(conn, CCI_SCH_ATTRIBUTE, "orders", "ship%", CCI_ATTR_NAME_PATTERN_MATCH, &error);
```

The table below shows record type for each *type*.

**Record for each type**

**CCI_SCH_CLASS** — tables; **CCI_SCH_VCLASS** — views:

| Column order | Column name | Column type |
|---|---|---|
| 1 | NAME | char * |
| 2 | TYPE | short (0: system class, 1: view, 2: table, 3: vertex table, 4: edge table) |
| 3 | REMARKS | char * |

**CCI_SCH_QUERY_SPEC** — the query of a view:

| Column order | Column name | Column type |
|---|---|---|
| 1 | QUERY_SPEC | char * |

**CCI_SCH_ATTRIBUTE** — columns; **CCI_SCH_CLASS_ATTRIBUTE** — class attributes, with the same columns:

| Column order | Column name | Column type |
|---|---|---|
| 1 | NAME | char * |
| 2 | DOMAIN | short |
| 3 | SCALE | short |
| 4 | PRECISION | int |
| 5 | INDEXED | short (1: indexed) |
| 6 | NON_NULL | short (1: NOT NULL) |
| 7 | SHARED | short (1: shared) |
| 8 | UNIQUE | short (1: unique) |
| 9 | DEFAULT | char * |
| 10 | ATTR_ORDER | int (from 1) |
| 11 | CLASS_NAME | char * |
| 12 | SOURCE_CLASS | char * |
| 13 | IS_KEY | short (1: key) |
| 14 | REMARKS | char * |

**CCI_SCH_CLASS_METHOD** — methods:

| Column order | Column name | Column type |
|---|---|---|
| 1 | NAME | char * |
| 2 | RET_DOMAIN | short |
| 3 | ARG_DOMAIN | char * |

**CCI_SCH_METHOD_FILE** — method files:

| Column order | Column name | Column type |
|---|---|---|
| 1 | METHOD_FILE | char * |

**CCI_SCH_SUPERCLASS**, **CCI_SCH_SUBCLASS** — superclasses and subclasses:

| Column order | Column name | Column type |
|---|---|---|
| 1 | CLASS_NAME | char * |
| 2 | TYPE | short |

**CCI_SCH_CONSTRAINT** — indexes and constraints:

| Column order | Column name | Column type |
|---|---|---|
| 1 | TYPE | short (0: unique, 1: index, 2: reverse unique, 3: reverse index) |
| 2 | NAME | char * |
| 3 | ATTR_NAME | char * |
| 4 | NUM_PAGES | int |
| 5 | NUM_KEYS | int |
| 6 | PRIMARY_KEY | short (1: primary key) |
| 7 | KEY_ORDER | short (from 1) |
| 8 | ASC_DESC | char * |

**CCI_SCH_TRIGGER** — triggers:

| Column order | Column name | Column type |
|---|---|---|
| 1 | NAME | char * |
| 2 | STATUS | char * |
| 3 | EVENT | char * |
| 4 | TARGET_CLASS | char * |
| 5 | TARGET_ATTR | char * |
| 6 | ACTION_TIME | char * |
| 7 | ACTION | char * |
| 8 | PRIORITY | float |
| 9 | CONDITION_TIME | char * |
| 10 | CONDITION | char * |
| 11 | REMARKS | char * |

**CCI_SCH_CLASS_PRIVILEGE** — privileges on tables; **CCI_SCH_ATTR_PRIVILEGE** — privileges on columns (first column ATTR_NAME):

| Column order | Column name | Column type |
|---|---|---|
| 1 | CLASS_NAME | char * |
| 2 | PRIVILEGE | char * |
| 3 | GRANTABLE | char * |

**CCI_SCH_DIRECT_SUPER_CLASS** — direct superclasses:

| Column order | Column name | Column type |
|---|---|---|
| 1 | CLASS_NAME | char * |
| 2 | SUPER_CLASS_NAME | char * |

**CCI_SCH_PRIMARY_KEY** — primary key columns:

| Column order | Column name | Column type |
|---|---|---|
| 1 | CLASS_NAME | char * |
| 2 | ATTR_NAME | char * |
| 3 | KEY_SEQ | int (from 1) |
| 4 | KEY_NAME | char * |

**CCI_SCH_IMPORTED_KEYS** — the primary keys referenced by the foreign keys of the table given in *class_name* (*attr_name* is **NULL**), sorted by PKTABLE_NAME and KEY_SEQ; **CCI_SCH_EXPORTED_KEYS** — the foreign keys that reference the primary key of the table given in *class_name*, sorted by FKTABLE_NAME and KEY_SEQ; **CCI_SCH_CROSS_REFERENCE** — the foreign keys of the table given in *attr_name* that reference the primary key of the table given in *class_name*, sorted by FKTABLE_NAME and KEY_SEQ. All three return:

| Column order | Column name | Column type |
|---|---|---|
| 1 | PKTABLE_NAME | char * |
| 2 | PKCOLUMN_NAME | char * |
| 3 | FKTABLE_NAME | char * |
| 4 | FKCOLUMN_NAME | char * |
| 5 | KEY_SEQ | short |
| 6 | UPDATE_ACTION | short (0: cascade, 1: restrict, 2: no action, 3: set null) |
| 7 | DELETE_ACTION | short (0: cascade, 1: restrict, 2: no action, 3: set null) |
| 8 | FK_NAME | char * |
| 9 | PK_NAME | char * |

In the **cci_schema_info** function, the *type* argument supports the pattern matching of the **LIKE** statement for the *class_name* and *attr_name*.

**type, class_name(table name), and attr_name(column name) that supports pattern matching**

| type                                | class_name     | attr_name      |
|-------------------------------------|----------------|----------------|
| CCI_SCH_CLASS (VCLASS)              | string or NULL | always NULL    |
| CCI_SCH_ATTRIBUTE (CLASS ATTRIBUTE) | string or NULL | string or NULL |
| CCI_SCH_CLASS_PRIVILEGE             | string or NULL | always NULL    |
| CCI_SCH_ATTR_PRIVILEGE              | always NULL    | string or NULL |
| CCI_SCH_PRIMARY_KEY                 | string or NULL | always NULL    |
| CCI_SCH_TRIGGER                     | string or NULL | always NULL    |

- The type with "NULL" in class_name doesn't support the pattern matching about the table name.
- The type with "NULL" in attr_name doesn't support the pattern matching about the column name.
- If the pattern *flag* is not configured, exact matching will be used for the given table and column names; in this case, no result will be returned if the value is **NULL**.
- If *flag* is configured and the value is **NULL**, the result will be the same as when "%" is given in the **LIKE** statement. In other words, the result about all tables or all columns will be returned.

``` c
// gcc -o schema_info schema_info.c -m64 -I${CORADB}/include -lnsl ${CORADB}/lib/libcascci.so -lpthread

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "cas_cci.h"

int
main ()
{
  int conn = 0, req = 0, col_count = 0, res = 0, i, ind;
  char *data, query_result_buffer[1024];
  T_CCI_ERROR cci_error;
  T_CCI_COL_INFO *col_info;
  T_CCI_CORADB_STMT cmd_type;

  conn = cci_connect ("localhost", 33000, "e-commerce", "dba", "");
  // get all columns' information of table "orders"
  // req = cci_schema_info(conn, CCI_SCH_ATTRIBUTE, "orders", "id", 0, &cci_error);
  req =
    cci_schema_info (conn, CCI_SCH_ATTRIBUTE, "orders", NULL,
                     CCI_ATTR_NAME_PATTERN_MATCH, &cci_error);

  if (req < 0)
  {
      fprintf (stdout, "(%s, %d) ERROR : %s [%d] \n\n", __FILE__, __LINE__,
               cci_error.err_msg, cci_error.err_code);
      goto _END;
  }
  col_info = cci_get_result_info (req, &cmd_type, &col_count);
  if (!col_info && col_count == 0)
  {
      fprintf (stdout, "(%s, %d) ERROR : cci_get_result_info\n\n", __FILE__,
               __LINE__);
      goto _END;
  }
  res = cci_cursor (req, 1, CCI_CURSOR_FIRST, &cci_error);
  if (res == CCI_ER_NO_MORE_DATA)
  {
      goto _END;
  }
  if (res < 0)
  {
      fprintf (stdout, "(%s, %d) ERROR : %s [%d] \n\n", __FILE__, __LINE__,
               cci_error.err_msg, cci_error.err_code);
      goto _END;
  }

  while (1)
  {
      res = cci_fetch (req, &cci_error);
      if (res < 0)
      {
          fprintf (stdout, "(%s, %d) ERROR : %s [%d] \n\n", __FILE__,
                   __LINE__, cci_error.err_msg, cci_error.err_code);
          goto _END;
      }

      for (i = 1; i <= col_count; i++)
      {
          if ((res = cci_get_data (req, i, CCI_A_TYPE_STR, &data, &ind)) < 0)
          {
              goto _END;
          }
          if (ind != -1)
          {
              strcat (query_result_buffer, data);
              strcat (query_result_buffer, "|");
          }
          else
          {
              strcat (query_result_buffer, "NULL|");
          }
      }
      strcat (query_result_buffer, "\n");

      res = cci_cursor (req, 1, CCI_CURSOR_CURRENT, &cci_error);
      if (res == CCI_ER_NO_MORE_DATA)
      {
          goto _END;
      }
      if (res < 0)
        {
          fprintf (stdout, "(%s, %d) ERROR : %s [%d] \n\n", __FILE__,
                   __LINE__, cci_error.err_msg, cci_error.err_code);
          goto _END;
        }
  }

_END:
  if (req > 0)
    cci_close_req_handle (req);
  if (conn > 0)
    res = cci_disconnect (conn, &cci_error);
  if (res < 0)
    fprintf (stdout, "(%s, %d) ERROR : %s [%d] \n\n", __FILE__, __LINE__,
             cci_error.err_msg, cci_error.err_code);

  fprintf (stdout, "Result : %s\n", query_result_buffer);

  return 0;
}
```

**Parameters**

- `conn_handle`: (IN) Connection handle
- `type`: (IN) Schema type
- `class_name`: (IN) Class name or NULL
- `attr_name`: (IN) Attribute name or NULL
- `flag`: (IN) Pattern matching flag (**CCI_CLASS_NAME_PATTERN_MATCH** or **CCI_ATTR_NAME_PATTERN_MATCH**)
- `err_buf`: (OUT) Database error buffer

**Returns:** Success: Request handle, Failure: Error code

## cci_set_max_row

``` c
int cci_set_max_row(int req_handle, int max)
```

The **cci_set_max_row** function configures the maximum number of records for the results of the **SELECT** statement executed by [cci_execute](https://www.coradb.ai/manual/api/cciapi_query.html#cci_execute). If the *max* value is 0, it is the same as not setting the value.

``` c
req = cci_prepare( ... );
cci_set_max_row(req, 1);
cci_execute( ... );
```

**Parameters**

- `req_handle`: (IN) Connection handle
- `max`: (IN) The maximum number of rows

**Returns:** Error code
