---
name: "DBIx::DBSchema::DBD"
section: "3pm"
platform: "linux"
package: "libdbix-dbschema-perl"
version: "0.47-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/DBIx::DBSchema::DBD"
---

# DBIx::DBSchema::DBD(3pm)

DBIx::DBSchema Driver Writer's Guide and Base Class

## NAME

DBIx::DBSchema::DBD - DBIx::DBSchema Driver Writer's Guide and Base Class

## SYNOPSIS

```
  perldoc DBIx::DBSchema::DBD
  package DBIx::DBSchema::DBD::FooBase
  use DBIx::DBSchema::DBD;
  @ISA = qw(DBIx::DBSchema::DBD);
```

## DESCRIPTION

Drivers should be named DBIx::DBSchema::DBD::DatabaseName, where DatabaseName is the same as the DBD:: driver for this database.  Drivers should implement the following class methods:

- columns CLASS DBI\_DBH TABLE

  Given an active DBI database handle, return a listref of listrefs (see perllol), each containing six elements: column name, column type, nullability, column length, column default, and a field reserved for driver-specific use.

- column CLASS DBI\_DBH TABLE COLUMN

  Same as **columns** above, except return the listref for a single column.  You can inherit from DBIx::DBSchema::DBD to provide this function.

- primary\_key CLASS DBI\_DBH TABLE

  Given an active DBI database handle, return the primary key for the specified table.

- unique CLASS DBI\_DBH TABLE

  Deprecated method - see the **indices** method for new drivers.

  Given an active DBI database handle, return a hashref of unique indices.  The keys of the hashref are index names, and the values are arrayrefs which point a list of column names for each.  See "HASHES OF LISTS" in perldsc and DBIx::DBSchema::Index.

- index CLASS DBI\_DBH TABLE

  Deprecated method - see the **indices** method for new drivers.

  Given an active DBI database handle, return a hashref of (non-unique) indices. The keys of the hashref are index names, and the values are arrayrefs which point a list of column names for each.  See "HASHES OF LISTS" in perldsc and DBIx::DBSchema::Index.

- indices CLASS DBI\_DBH TABLE

  Given an active DBI database handle, return a hashref of all indices, both unique and non-unique.  The keys of the hashref are index names, and the values are again hashrefs with the following keys:

  - name - Index name (redundant)

    - using - Optional index method

    - unique - Boolean indicating whether or not this is a unique index

    - columns - List reference of column names (or expressions)

    (See FS::DBIx::DBSchema::Index)

  New drivers are advised to implement this method, and existing drivers are advised to (eventually) provide this method instead of **index** and **unique**.

  For backwards-compatibility with current drivers, the base DBIx::DBSchema::DBD class provides an **indices** method which uses the old **index** and **unique** methods to provide this data.

- default\_db\_catalog

  Returns the default database catalog for the DBI table\_info command. Inheriting from DBIx::DBSchema::DBD will provide the default empty string.

- default\_db\_schema

  Returns the default database schema for the DBI table\_info command. Inheriting from DBIx::DBSchema::DBD will provide the default empty string.

- constraints CLASS DBI\_DBH TABLE

  Given an active DBI database handle, return the constraints (currently, foreign keys) for the specified table, as a list of hash references.

  Each hash reference has the following keys:

  - constraint - contraint name

    - columns - List refrence of column names

    - table - Foreign taable name

    - references - List reference of column names in foreign table

    - match -

    - on\_delete -

    - on\_update -

    - column\_callback DBH TABLE\_NAME COLUMN\_OBJ

  Optional callback for driver-specific overrides to SQL column definitions.

  Should return a hash reference, empty for no action, or with one or more of the following keys defined:

  effective\_type - Optional type override used during column creation.

  explicit\_null - Set true to have the column definition declare NULL columns explicitly

  effective\_default - Optional default override used during column creation.

  effective\_local - Optional local override used during column creation.

- add\_column\_callback DBH TABLE\_NAME COLUMN\_OBJ

  Optional callback for additional SQL statments to be called when adding columns to an existing table.

  Should return a hash reference, empty for no action, or with one or more of the following keys defined:

  effective\_type - Optional type override used during column creation.

  effective\_null - Optional nullability override used during column creation.

  sql\_after - Array reference of SQL statements to be executed after the column is added.

- alter\_column\_callback DBH TABLE\_NAME OLD\_COLUMN\_OBJ NEW\_COLUMN\_OBJ

  Optional callback for overriding the SQL statments to be called when altering columns to an existing table.

  Should return a hash reference, empty for no action, or with one or more of the following keys defined:

  sql\_alter - Alter SQL statement(s) for changing everything about a column.  Specifying this overrides processing of individual changes (type, nullability, default, etc.).

  sql\_alter\_type - Alter SQL statement(s) for changing type and length (there is no default).

  sql\_alter\_null - Alter SQL statement(s) for changing nullability to be used instead of the default.

- column\_value\_needs\_quoting COLUMN\_OBJ

  Optional callback for determining if a column's default value require quoting. Returns true if it does, false otherwise.

## TYPE MAPPING

You can define a `%typemap` array for your driver to map "standard" data     types to database-specific types.  For example, the MySQL TIMESTAMP field has non-standard auto-updating semantics; the MySQL DATETIME type is  what other databases and the ODBC standard call TIMESTAMP, so one of the    entries in the MySQL `%typemap` is:

```
  'TIMESTAMP' => 'DATETIME',
```

Another example is the Pg `%typemap` which maps the standard types BLOB and LONG VARBINARY to the Pg-specific BYTEA:

```
  'BLOB' => 'BYTEA',
  'LONG VARBINARY' => 'BYTEA',
```

Make sure you use all uppercase-keys.

## AUTHOR

Ivan Kohler \<ivan-dbix-dbschema@420.am\>

## COPYRIGHT

Copyright (c) 2000-2005 Ivan Kohler Copyright (c) 2007-2017 Freeside Internet Services, Inc. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

## BUGS

## SEE ALSO

DBIx::DBSchema, DBIx::DBSchema::DBD::mysql, DBIx::DBSchema::DBD::Pg, DBIx::DBSchema::Index, DBI, DBI::DBD, perllol, "HASHES OF LISTS" in perldsc
