mariadb-prepare

Guides writing and reviewing MariaDB server-side PREPARE, EXECUTE, and EXECUTE IMMEDIATE statements.

28|115|Updated Jan 28, 2025
One-click install
npx skills add https://github.com/mariadb-corporation/mariadb-docs --skill mariadb-prepare-mariadb-corporation
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: mariadb-prepare
Source: https://github.com/mariadb-corporation/mariadb-docs/tree/main/agent-skills/granular/statements/mariadb-prepare
Command: npx skills add https://github.com/mariadb-corporation/mariadb-docs --skill mariadb-prepare-mariadb-corporation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? LLMs frequently generate incorrect MariaDB dynamic SQL — claiming EXECUTE..USING only accepts user variables, trying to bind identifiers with placeholders, or placing PREPARE inside stored functions where it is banned. This Skill supplies the correct MariaDB-specific semantics for server-side prepared statements so generated and reviewed SQL actually runs. ## Core Features & Use Cases - Correct syntax guidance: Covers PREPARE / EXECUTE / DEALLOCATE PREPARE and the EXECUTE IMMEDIATE shorthand, including Oracle-mode placeholders and DEFAULT/IGNORE bind values. - Common-mistake corrections: Documents the broad preparable-statement allow-list, arbitrary expressions in USING, session-local statement lifetime, and the stored-function/trigger ban on dynamic SQL. - Use Case: When writing a stored procedure that builds dynamic SQL with a caller-supplied table name, use this Skill to correctly concatenate the identifier into the PREPARE source and bind data values via EXECUTE..USING. ## Quick Start Ask the AI to write a MariaDB stored procedure that prepares and executes a dynamic SELECT with a parameterized table name and placeholder filter.

Frequently Asked Questions about mariadb-prepare

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use PREPARE and EXECUTE in MariaDB?▼

PREPARE a named statement from a string literal or user variable, then EXECUTE it with optional USING parameters bound positionally to ? placeholders, and finish with DEALLOCATE PREPARE. EXECUTE IMMEDIATE combines all three steps into one statement.

Can EXECUTE USING bind expressions or only user variables in MariaDB?▼

In current MariaDB, EXECUTE ... USING accepts arbitrary expressions — literals, arithmetic, and function calls — not just @variables. The user-variable-only restriction was removed before the 10.6 baseline.

Can I use PREPARE inside a MariaDB stored function or trigger?▼

No. MariaDB raises 'Dynamic SQL is not allowed in stored function or trigger' for PREPARE, EXECUTE, EXECUTE IMMEDIATE, and DEALLOCATE PREPARE in functions and triggers. These statements are only allowed inside stored procedures.

How do I parameterize a table name in MariaDB dynamic SQL?▼

Placeholders can only bind data values, never identifiers. Concatenate the table or column name into the PREPARE or EXECUTE IMMEDIATE source string itself, typically with CONCAT inside a stored procedure.

Why does MariaDB report max_prepared_stmt_count errors?▼

max_prepared_stmt_count is a single global counter (default 16382) shared across all sessions, not per-connection. Statements prepared inside procedures persist after the procedure returns, so repeated calls without DEALLOCATE PREPARE can exhaust the limit.