NAME

DBIO::Introspect::DBI - DBI-based introspection via standard metadata APIs

VERSION

version 0.900004

DESCRIPTION

DBIO::Introspect::DBI wraps DBI metadata APIs (column_info, primary_key, foreign_key_info, table_info) into the normalized contract defined in DBIO::Introspect::Base.

Driver-specific introspectors (DBIO::PostgreSQL::Introspect, DBIO::SQLite::Introspect, etc.) inherit from this when they want to override with native queries for accuracy or features.

ATTRIBUTES

dbms_name

The DBI driver name (e.g., Pg, SQLite, mysql). Auto-detected from dbh if not provided.

METHODS

class_for_dbh

my $class = DBIO::Introspect::DBI->class_for_dbh($dbh);
my $intro = $class->new(dbh => $dbh);

The most accurate introspector class available for $dbh: the installed driver's own (DBIO::MySQL::Introspect, DBIO::SQLite::Introspect, ...) if there is one, otherwise DBIO::Introspect::DBI itself.

The driver is resolved through the one registry that already maps DBD names to DBIO classes, "driver_storage_class" in DBIO::Storage::DBI -- mysql gives DBIO::MySQL::Storage, whose namespace DBIO::MySQL gives DBIO::MySQL::Introspect. Only the class name is taken from the registry; the driver's storage stack is never loaded, so introspection does not depend on the DBD-level machinery being usable.

The candidate is returned only if it loads and is a DBIO::Introspect::Base, so an unregistered DBD, an uninstalled driver distribution or a class that does not honour the contract all fall back to the generic path rather than failing the caller. A driver that is installed but does not compile is a broken installation, not an absent one: it warns before falling back, because the generated classes will silently be the less accurate ones.

The returned class is already loaded.

table_keys

Returns all tables and views as [schema.]table strings.

table_columns

my \@names = $intro->table_columns($key);

Ordered list of column names for $key.

table_columns_info

my $info = $intro->table_columns_info($key);

Hashref { col_name = { data_type, size, is_nullable, default_value, is_auto_increment, ... } }>.

data_type is the DBI TYPE_NAME of the column -- the readable type name, not the numeric DATA_TYPE code. A DBD that reports no TYPE_NAME gets varchar guessed for that column, with a warning naming it: the guess is invisible in the generated class once it is written.

is_nullable is the DBI NULLABLE flag combined with primary-key membership from "table_pk_info": a key column is is_nullable => 0 however the DBD reports it. NULLABLE answers only whether the column carries a NOT NULL attribute, and that is not the same question -- SQLite keeps the primary-key constraint separate from the attribute, so DBD::SQLite reports NULLABLE = 1 for id INTEGER PRIMARY KEY.

A NULLABLE of 2 (DBI's "unknown"), or no NULLABLE at all, gives is_nullable => 1 with a warning naming the column. Of the two possible guesses only 0 can do damage: it makes the generated class refuse an INSERT the database would have accepted, while 1 leaves the engine's own constraint to reject it with a real error.

table_pk_info

my \@pk_cols = @{ $intro->table_pk_info($key) };

Ordered list of primary key column names.

table_uniq_info

my \@constraints = @{ $intro->table_uniq_info($key) };

List of [ $constraint_name, \@col_names ] pairs.

table_fk_info

my \@fks = @{ $intro->table_fk_info($key) };

Each FK is a hashref:

{
  local_columns  => [qw/author_id/],
  remote_table   => 'authors',
  remote_schema  => 'public',   # may be undef
  remote_columns => [qw/id/],   # may be [] (use remote PK)
  attrs          => {},
}

table_is_view

Returns true if $key is a view rather than a base table.

view_definition

SQL text of the view definition, or undef.

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.