mysql_stmt_attr_set

You are viewing an old version of this article. View the current version here.

Syntax

my_bool mysql_stmt_attr_set(MYSQL_STMT * stmt,
                            enum enum_stmt_attr_type,
                            const void * attr);
  • stmt - a statement handle, which was previously allocated by mysql_stmt_init().
  • enum_stmt_attr_type - the attribute that you want to set. See below.
  • attr - the value to assign to the attribute

Description

Used to modify the behavior of a prepared statement. This function may be called multiple times to set several attributes. Returns zero on success, non-zero on failure.

Attribute types

The enum_stmt_attr_type attribute can have one of the following values:

  • STMT_ATTR_UPDATE_MAX_LENGTH If set to 1, mysql_stmt_store_result() will update the max_length value of MYSQL_FIELD structures.

    my_bool update= 1;
    rc= mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &update);
    
  • STMT_ATTR_CURSOR_TYPE: cursor type when mysql_stmt_execute() is invoked. Possible values are CURSOR_TYPE_READ_ONLY or default value CURSOR_TYPE_NO_CURSOR.

    unsigned long cursor_type= CURSOR_TYPE_READ_ONLY;
    rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, &cursor_type);
    
  • STMT_ATTR_PREFETCH_ROWS: number of rows which will be prefetched. The default value is 1.

    unsigned long rows=4;
    rc= mysql_stmt_attr_set(stmt, STMT_ATTR_PREFETCH_ROWS, &rows);
    
  • STMT_ATTR_PREBIND_PARAMS: number of parameter markers when using mariadb_stmt_execute_direct(). If the statement handle is reused it will be resetted automatically to the state after mysql_stmt_init(). This option was added in Connector/C 3.0

    unsigned int params= 5;
    rc= mysql_stmt_attr_set(stmt, STMT_ATTR_PREBIND_PARAMS, &params);
    
  • STMT_ATTR_ARRAY_SIZE: number of array elements. This option was added in Connector/C 3.0 and requires MariaDB 10.2 or later

    unsigned int array_size= 5;
    rc= mysql_stmt_attr_set(stmt, STMT_ATTR_ARRAY_SIZE, &array_size);
    
  • STMT_ATTR_ROW_SIZE: specifies size of a structure for row wise binding. This length must include space for all of the bound parameters and any padding of the structure or buffer to ensure that when the address of a bound parameter is incremented with the specified length, the result will point to the beginning of the same parameter in the next set of parameters. When using the sizeof operator in ANSI C, this behavior is guaranteed. If the value is zero column-wise binding will be used (default). This option was added in Connector/C 3.0 and requires MariaDB 10.2 or later

    unsigned int row_size= sizeof(struct st_customer);
    rc= mysql_stmt_attr_set(stmt, STMT_ATTR_ROW_SIZE, &array_size);
    

See also

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.