NAME

DBIx::Dialect - Auto-detection of SQL quirks.

SYNOPSIS

use DBIx::Dialect;

my $dialect = DBIx::Dialect->new( $dbh );

if ($dialect->supports('limit-xy')) { ... }
print $dialect->quote_char();
...

DESCRIPTION

This module detects the SQL dialect of a DBI database handle and exposes a handful of properties describing the features and quirks of that dialect.

CONSTRUCTOR

# Auto-detect the appropriate dialect from a DBI handle:
my $dialect = DBIx::Dialect->new( $dbh );

# Explicitly set the dialect that you want:
my $dialect = DBIx::Dialect->new( 'oracle' );

# The "default" dialect is the default:
my $dialect = DBIx::Dialect->new();

Each implementation, or dialect, of SQL has quirks that slightly (or in some cases drastically) change the way that the SQL must be written to get a particular task done. In order for this module to know which particular set of quirks it should use a dialect must be declared. The dialect will default to "default" which is very limited and only declares the bare minimum of features.

Currently a dialect type can be one of:

default
mysql
oracle
postgresql
sqlite

When declaring the dialecti type that you want you can either specify one of the dialects above, or you can just pass a DBI handle ($dbh) and it will be auto-detected. Currently the list of supported DBI Driver is limited to:

DBD::mysql  (mysql)
DBD::Oracle (oracle)
DBD::Pg     (postgresql)
DBD::PgPP   (postgresql)
DBD::SQLite (sqlite)

If the driver that you are using is not in the above list then please contact the author and work with them to get it added.

STATEMENT ATTRIBUTES

These attributes describe the supported statement clauses and quirks.

limit

The dialect of the LIMIT clause.

offset (postgresql, sqlite)
xy     (mysql)

returning

The dialect of INSERT/UPDATE/DELETE ... RETURNING syntax.

into   (oracle)
select (postgresql)

DATABASE ATTRIBUTES

sequences

Whether the database supports sequences.

postgresql
oracle

FUNCTION ATTRIBUTES

last_insert_id

Whether the LAST_INSERT_ID() function is supported.

mysql

last_insert_rowid

Whether the LAST_INSERT_ROWID() function is supported.

sqlite

OTHER ATTRIBUTES

rownum

Returns true if the dialect supports the rownum pseudo column.

oracle

quote_char

The character that is used to quote identifiers, such as table and column names.

sep_char

The character that is used to separate linked identifiers, such as a table name followed by a column name.

METHODS

supports

# Do something if the dialect supports any form of limit and
# only the select flavor of returning:
if ($dialect->supports('limit', 'returning-select')) { ... }

Given a list of feature names, optionally dash-suffixed with a specific quirk, this will return true or false if the dialect supports them all.

TODO

  • Add more dialects and supported DBI drivers! If anyone wants to help with this I'd greatly appreciate it.

  • Add more information about other quirks that the dialects have, such as whether PLSQL is supported, what kind of bulk loading interface is available (MySQL's LOAD INFILE versus O;racle SQL*Loader, etc), information about what functions to use for date math, which DBD drivers return the number of records inserted/deleted/selected, etc.

REFERENCES

AUTHOR

Aran Clary Deltac <bluefeet@gmail.com>

LICENSE

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.