mysql_stmt_attr_set(3)
β¨ 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 bymysql_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 to1,mysql_stmt_store_result(3)will update themax_lengthvalue ofMYSQL_FIELDstructures. π₯STMT_ATTR_CURSOR_TYPEβ type:unsigned long *β cursor type whenmysql_stmt_execute(3)is invoked. Possible values areCURSOR_TYPE_READ_ONLYor default valueCURSOR_TYPE_NO_CURSOR. πSTMT_ATTR_PREFETCH_ROWSβ type:unsigned long *β number of rows which will be prefetched. The default value is1. πSTMT_ATTR_PREBIND_PARAMSβ type:unsigned int *β number of parameter markers when usingmariadb_stmt_execute_direct(3). If the statement handle is reused it will be reset automatically to the state aftermysql_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 thesizeofoperator 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_TYPEoption withMYSQL_CURSOR_TYPE_READ_ONLY, a cursor is opened for the statement when you invokemysql_stmt_execute(3). If there is already an open cursor from a previousmysql_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
- alpine 3.22: mariadb-doc 11.4.13-r0 Β· GPL-2.0-or-later
- alpine 3.23: mariadb-doc 11.4.13-r0 Β· GPL-2.0-or-later
- alpine 3.24: mariadb-doc 11.8.9-r0 Β· GPL-2.0-only
- arch rolling: mariadb 13.0.2-2 Β· GPL-2.0-only
- arch rolling: mariadb-lts 12.3.3-2 Β· GPL-2.0-only
- centos-stream 10: mariadb-connector-c-doc 3.4.4-2.el10 Β· LGPL-2.1-or-later
- debian trixie: libmariadb-dev 1:11.8.6-0+deb13u1 Β· GPL-2.0-only
- fedora 43: mariadb-connector-c-doc 3.4.5-2.fc43 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01
- fedora 43: mariadb-connector-c-doc 3.4.9-2.fc43 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01 AND LicenseRef-Fedora-Public-Domain
- fedora 44: mariadb-connector-c-doc 3.4.8-3.fc44 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01
- fedora 44: mariadb-connector-c-doc 3.4.9-2.fc44 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01 AND LicenseRef-Fedora-Public-Domain
- nixpkgs unstable: mariadb-server 11.8.8
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- ubuntu questing: libmariadb-dev 1:11.8.3-1build1
- ubuntu resolute: libmariadb-dev 1:11.8.6-5 Β· GPL-2.0-only
- ubuntu resolute: libmariadb-dev 1:11.8.6-5ubuntu0.1 Β· GPL-2.0-only
- ubuntu stonking: libmariadb-dev 1:11.8.9+ds-4ubuntu2 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms