NAME
DBIO::MySQL::Identifier - MySQL/MariaDB identifier quoting for generated DDL
VERSION
version 0.900004
DESCRIPTION
Single source of truth for how the name of a database, table, view, column, index or constraint is written into a DDL statement this driver generates.
MySQL and MariaDB quote an identifier with backticks. A name that is a reserved word (order, key, group, rank, ...) or that is no plain word (my-col) is a syntax error without them, and double quotes are no substitute: unless the session runs in ANSI_QUOTES, "my-col" is a string literal. That is why core's ANSI helper, DBIO::SQL::Util::_quote_ident, which leaves a plain name bare and puts any other into double quotes, is not used by this driver.
The quoting is needed wherever DDL is rendered -- the desired-state DDL (DBIO::MySQL::DDL), the four diff operations (DBIO::MySQL::Diff::Table, DBIO::MySQL::Diff::Column, DBIO::MySQL::Diff::Index, DBIO::MySQL::Diff::ForeignKey) and the temporary database of DBIO::MySQL::Deploy -- so it lives here once.
Queries are not rendered through this module. DBIO::MySQL::SQLMaker quotes their identifiers itself, with the same character (DBIO::MySQL::Storage sets sql_quote_char to a backtick).
METHODS
quote_ident
use DBIO::MySQL::Identifier qw(quote_ident);
my $sql_name = quote_ident($name);
quote_ident('users'); # `users`
quote_ident('order'); # `order`
quote_ident('my-col'); # `my-col`
quote_ident('we`ird'); # `we``ird`
Returns $name between backticks, every backtick inside it doubled. That is all the escaping the server asks for there: neither a quote of either kind nor a backslash is special between backticks, and backticks quote an identifier whatever the sql_mode -- ANSI_QUOTES and NO_BACKSLASH_ESCAPES change nothing about it (checked on MySQL 8.0 and MariaDB 11.8).
Every name is quoted, a plain one as well. Quoting only where it is needed would take a list of reserved words, and that list differs between MySQL and MariaDB and grows with their versions (rank and groups became reserved in MySQL 8.0).
The argument is one identifier. A dot is part of the name and is not read as the separator of a qualified one: quote_ident('db.t') is the name db.t and not the table t of the database db. The name of a table of a source goes through "quote_table" instead, which splits it at the dot.
split_table_name
my ($database, $table) = split_table_name('other.t'); # ('other', 't')
my ($database, $table) = split_table_name('t'); # (undef, 't')
Splits the name a source gives its table at its dot: database.table to MySQL. A name without a dot is the table alone. Throws a DBIO::Exception for a name with more than one dot or with an empty half (.t, db.), which names nothing.
quote_table
quote_table('t'); # `t`
quote_table('other.t'); # `other`.`t`
The name of a table as DDL writes it: both halves quoted by "quote_ident", the database in front when the name has one ("split_table_name").
quote_table_in
quote_table_in(undef, 't'); # `t`
quote_table_in('other', 't'); # `other`.`t`
The table $table as a diff operation writes it: in the database $database when one is given (the operation belongs to a table of another database), else as "quote_ident" writes it. The table is one identifier in both cases -- a dot in it is part of the name -- because the database is given apart; this is what tells the table other.t from a table in the current database that is literally called other.t.
check_table_name
check_table_name($name); # a table
check_table_name($name, 'view');
Returns $name when it is a name the DDL can write, and throws a DBIO::Exception when it is not. A table name is table or database.table ("split_table_name"): table('db.t') and \'db.t' create the table t in the database db, written `db`.`t` as a query through the SQLMaker reads it. The driver creates no database: whether db exists is asked of the server by DBIO::MySQL::Deploy, which refuses an install naming the table and the database when it does not. A view name with a dot is still refused, as is a name with two dots or an empty half. A name that is not a plain string (a subquery source) is passed through.
AUTHOR
DBIO & DBIx::Class Authors
COPYRIGHT AND LICENSE
Copyright (C) 2026 DBIO Authors Portions Copyright (C) 2005-2025 DBIx::Class Authors Based on DBIx::Class, heavily modified.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.