mysql_stmt_attr_set(3)

πŸ“¦
version 13.0.2 Β· 4 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, debian trixie, fedora 43, fedora 44, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ mysql_stmt_attr_set(3) ✨

okay so bestie β€” this is a page out of the MariaDB Connector/C manual, and it's literally about tweaking the vibe of a prepared statement. no cap. let's get into it πŸ’…


🌸 NAME 🌸

mysql_stmt_attr_set β€” sets an attribute of a statement. it's giving "customize your statement's whole personality." ✨


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <mysql.h>

my_bool mysql_stmt_attr_set(MYSQL_STMT * stmt,
                            enum enum_stmt_attr_type,
                            const void * attr);

πŸ’– DESCRIPTION πŸ’–

So like, this one is used to modify the behavior of a prepared statement. and the way that you can just call it multiple times to set several attributes?? obsessed. one function, many little settings, we love a multitasker.

it returns zero on success, non-zero on failure. periodt. πŸŽ€


πŸ“ PARAMETERS πŸ“

  • stmt β€” a statement handle, which was previously allocated by mysql_stmt_init(3). like, it has to already exist, bestie, you can't manifest it out of nowhere πŸ’«
  • enum_stmt_attr_type β€” the attribute that you want to set. See below πŸ‘‡
  • attr β€” the value to assign to the attribute. this is the lil payload, the actual thing you're handing over πŸ“¦

πŸ‘‘ ATTRIBUTE TYPES πŸ‘‘

The enum_stmt_attr_type attribute can have one of the following values (and yes, each one has a type and a whole description, we're doing all of them, no skipping):

  • STMT_ATTR_UPDATE_MAX_LENGTH β€” type: my_bool * β€” If set to 1, mysql_stmt_store_result(3) will update the max_length value of MYSQL_FIELD structures. πŸ”₯
  • STMT_ATTR_CURSOR_TYPE β€” type: unsigned long * β€” cursor type when mysql_stmt_execute(3) is invoked. Possible values are CURSOR_TYPE_READ_ONLY or default value CURSOR_TYPE_NO_CURSOR. πŸŒ€
  • STMT_ATTR_PREFETCH_ROWS β€” type: unsigned long * β€” number of rows which will be prefetched. The default value is 1. πŸ™ˆ
  • STMT_ATTR_PREBIND_PARAMS β€” type: unsigned int * β€” number of parameter markers when using mariadb_stmt_execute_direct(3). If the statement handle is reused it will be reset automatically to the state after mysql_stmt_init(). This option was added in Connector/C 3.0 ⭐
  • STMT_ATTR_ARRAY_SIZE β€” type: unsigned int * β€” number of array elements. This option was added in Connector/C 3.0 and requires MariaDB 10.2 or later 🌈
  • STMT_ATTR_ROW_SIZE β€” type: size_t * β€” 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 πŸ’œ

🧚 NOTES 🧚

  • If you use the MYSQL_STMT_ATTR_CURSOR_TYPE option with MYSQL_CURSOR_TYPE_READ_ONLY, a cursor is opened for the statement when you invoke mysql_stmt_execute(3). If there is already an open cursor from a previous mysql_stmt_execute(3) call, it closes the cursor before opening a new one. mysql_stmt_reset(3) also closes any open cursor before preparing the statement for re-execution. πŸ”„
  • If you open a cursor for a prepared statement it is unnecessary to call mysql_stmt_store_result(3). ok so like, don't do extra work for no reason, bestie, we're efficient here πŸ’…
  • mysql_stmt_free_result(3) closes any open cursor. bye cursor πŸ‘‹

πŸ’€ SEE ALSO πŸ’€


quick reminder that the enum value names in the descriptions above are exactly as the page gives them, so copy them character for character and don't get creative, iykyk 🫢

and that's the whole page!! this was Version 3.4 of the MariaDB Connector/C docs, so shoutout to that version for serving us this knowledge, mwah πŸ’–

πŸ“¦ where this page comes from