mysql_stmt_prepare(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_prepare(3) β€” MariaDB Connector/C

okay bestie, welcome to the MariaDB Connector/C manual, the mysql_stmt_prepare edition πŸŽ€ this is a (3) library call, so it lives in your C code, not your shell. grab a snack, we're preparing SQL strings and it's lowkey iconic ✨


🌸 NAME 🌸

mysql_stmt_prepare β€” prepares an SQL string. that's it, that's the job, and she does it flawlessly πŸ’…


✨ SYNOPSIS ✨

#include <mysql.h>

int mysql_stmt_prepare(MYSQL_STMT * stmt,
                       const char * query,
                       unsigned long length);

πŸ¦‹ DESCRIPTION πŸ¦‹

she prepares the SQL query, periodt. you hand her a statement handle and a query, she gets it all ready to go β€” no cap, this is the step before you actually run anything 🌈


πŸ“ PARAMETER πŸ“

  • stmt β€” a statement handle, which was previously allocated by mysql_stmt_init(3). gotta have her first, she's the whole vibe 🫢
  • query β€” the SQL statement. the actual words, the moment πŸ’–
  • length β€” length of SQL statement. tell her how long it is, she likes specifics ✨

πŸ‘‘ RETURN VALUE πŸ‘‘

Zero on success, non zero on error. that's it. zero = slay, non zero = not slay 😭


πŸ’œ NOTES πŸ’œ

  • The parameter markers must be bound to application variables using mysql_stmt_bind_param(3). like, you have to do this part, it's not optional, no skipping πŸ™ˆ
  • The maximum number of parameters is 65535 (0xFFFF). that's the ceiling, bestie, do not test her πŸ’€
  • The markers are legal only in certain places in SQL statements. For example, they are allowed in the VALUES() list of INSERT statement (to specify column values for a row), or in a comparison with a column in a WHERE clause to specify a comparison value. so like, some spots are giving main character energy and some spots are absolutely not allowed πŸ’…
not me about to explain the banned spots, because there ARE banned spots and they matter:
  • They are not allowed in identifiers (such as table or column names), in the select list that names the columns to be returned by SELECT statement, or to specify both operands of a binary operator such as the equal sign. The latter restriction is necessary because it would be impossible to determine the parameter type. like girl, she literally cannot read your mind on the type 🧚
  • In general, parameters are legal only in Data Manipulation Language (DML) statements, and not in Data Definition Language (DDL) statements. DML yes, DDL no. that's the rule, fr fr ⭐

πŸŽ€ SEE ALSO πŸŽ€

the whole girl group, go read them too πŸ’–


Version 3.4 of MariaDB Connector/C, and that's the mysql_stmt_prepare(3) page, bestie πŸ’… you understood it, you ate, you're literally a C programmer now. go prepare something iconic πŸŒΈπŸ¦‹βœ¨

πŸ“¦ where this page comes from