NAME

DBIO::MySQL::Introspect::Columns - Introspect MySQL/MariaDB columns

VERSION

version 0.900004

DESCRIPTION

Fetches column metadata from information_schema.columns, scoped to the current DATABASE() and filtered to the tables surfaced by DBIO::MySQL::Introspect::Tables. The column_type size parser and the $tables filter are the shared helpers in DBIO::MySQL::Introspect::Util.

METHODS

fetch

my $columns = DBIO::MySQL::Introspect::Columns->fetch($dbh, $tables);

Given the tables hashref from DBIO::MySQL::Introspect::Tables, returns a hashref keyed by table name. Each value is an arrayref of column hashrefs (in ordinal_position order) with keys: column_name, data_type, column_type, size, not_null, default_value, is_auto_increment, is_pk, pk_position, character_set, collation, comment, extra. pk_position is the position of the column in the primary key (seq_in_index, 1 for a single-column key), not its position in the table.

default_value is COLUMN_DEFAULT, and undef for a column that has no default; default_is_expression is 1 when it is an expression (CURRENT_TIMESTAMP, uuid()) and 0 when it is a value, which a diff writes as a string literal (DBIO::MySQL::DefaultValue). The two servers report it differently:

  • MySQL reports the value itself -- abc for DEFAULT 'abc' -- and SQL NULL for a column without a default.

  • MariaDB, from 10.2.7 on, reports an expression: a string in quotes ('abc'), a function the way it writes it (current_timestamp()), and for a nullable column without a default, or with DEFAULT NULL, the keyword NULL -- a text of four letters. A NOT NULL column without a default is SQL NULL there as well.

That keyword is read as what it says, so default_value is undef on either server for a column without a default. A literal comes back as its value on both servers -- MariaDB's quotes are taken off and its escapes undone -- and an expression as its text, told apart by default_is_expression ("catalog_default" in DBIO::MySQL::DefaultValue). The text NULL from a MySQL stays, because there it is the string a column defaults to (DEFAULT 'NULL', which MariaDB reports as 'NULL' in quotes and is read as NULL, a value).

Which of the two the server is, it says in SELECT VERSION() -- what "_is_mariadb" in DBIO::MySQL::Storage asks through a storage is asked of the handle here, because this reader has no storage. DBD::mysql and DBD::MariaDB both hand on what the server reports, so the driver in use says nothing about it.

on_update is the ON UPDATE of the column, read from EXTRA and spelled the same on both servers (CURRENT_TIMESTAMP, CURRENT_TIMESTAMP(6)), or undef for a column without one; the key is there on every column ("catalog_on_update" in DBIO::MySQL::DefaultValue).

is_pk is true for the columns of the index PRIMARY in information_schema.statistics. COLUMN_KEY is not used for it: both servers report PRI there for the first column of a UNIQUE key over NOT NULL columns in a table that has no primary key.

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.