> For the complete documentation index, see [llms.txt](https://mariadb.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mariadb.com/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_attr_get.md).

# mysql\_stmt\_attr\_get

## Syntax

```c
my_bool mysql_stmt_attr_get(MYSQL_STMT * stmt,
                            enum enum_stmt_attr_type,
                            void * attr);
```

## Parameters

| Parameter             | Description                                                                                                                                                            |
| --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `stmt`                | A statement handle, which was previously allocated by [mysql\_stmt\_init()](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_init.md). |
| `enum_stmt_attr_type` | Attribute. See [Attribute Types](#attribute-types).                                                                                                                    |
| `attr`                | Pointer to a variable, which will contain the attribute value.                                                                                                         |

## Description

Gets the current value of a statement attribute. Returns zero on success, non zero on failure.

## Attribute Types

The `enum_stmt_attr_type` parameter has the following possible values:

* `STMT_ATTR_UPDATE_MAX_LENGTH`: Indicates if [mysql\_stmt\_store\_result()](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_store_result.md) will update the max\_length value of MYSQL\_FIELD structures.

  ```c
  my_bool is_update;
  rc= mysql_stmt_attr_get(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &is_update);
  ```
* `STMT_ATTR_CURSOR_TYPE`: Cursor type. Possible values are `CURSOR_TYPE_READ_ONLY` or default value `CURSOR_TYPE_NO_CURSOR`.

  ```c
  unsigned long cursor_type;
  rc= mysql_stmt_attr_get(stmt, STMT_ATTR_CURSOR_TYPE, &cursor_type);
  ```
* `STMT_ATTR_PREFETCH_ROWS`: Number of rows which will be prefetched. The default value is 1.

  ```c
  unsigned long prefetch_rows;
  rc= mysql_stmt_attr_get(stmt, STMT_ATTR_PREFETCH_ROWS, &prefetch_rows);
  ```
* `STMT_ATTR_PREBIND_PARAMS`: Number of parameters used for [mariadb\_stmt\_execute\_direct()](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mariadb_stmt_execute_direct.md)

  ```c
  unsigned int param_count;
  rc= mysql_stmt_attr_get(stmt, STMT_ATTR_PREBIND_PARAMS, ¶m_count);
  ```
* `STMT_ATTR_STATE`: Status of the prepared statement. The returned value is of type `enum mysql_stmt_state`. Possible values are defined in `enum mysql_stmt_state`. Introduced in MariaDB Connector/C 3.1.0

  ```c
  enum mysql_stmt_state stmt_state; 
  rc= mysql_stmt_attr_get(stmt, STMT_ATTR_STATE, &stmt_state); 
  ```
* `STMT_ATTR_SQL_STATEMENT`: The SQL statement from the last executed [mysql\_stmt\_prepare()](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_prepare.md) call. The returned value is of type `MARIADB_CONST_STRING`. Added in MariaDB Connector/C 3.4.4

  ```c
  MARIADB_CONST_STRING sql_statement; 
  rc= mysql_stmt_attr_get(stmt, STMT_ATTR_SQL_STATEMENT, &sql_statement);
  ```

{% hint style="info" %}
Setting the number of prefetched rows will work only for read only cursors.
{% endhint %}

## See Also

* [mysql\_stmt\_attr\_set()](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_attr_set.md)

{% @marketo/form formId="4316" %}
