NAME

Class::DBI::SQL::Transformer::Quotify - Quote column and table names in Class::DBI-generated SQL

VERSION

Version 0.02

SYNOPSIS

package Foo;
use base qw/Class::DBI/;
__PACKAGE__->connection('DBI:Mock:', '', '');
__PACKAGE__->sql_transformer_class('Class::DBI::SQL::Transformer::Quotify');
__PACKAGE__->table('table name');
__PACKAGE__->columns( Essential => 'my id', 'my name' );
package main;
my $row = Foo->retrieve( 3 );

DESCRIPTION

This is an attempt to solve the problem of spaces and/or reserved words in table and/or column names. Normally, Class::DBI does not quote these, so it results in sql such as the following (which clearly will error out):

SELECT my id, my name
FROM table name
WHERE my id = ?

This is implemented by subclassing Class::DBI::SQL::Transformer and notifying Class::DBI via its sql_transformer_class() attribute. Note that some of the methods are completely replaced.

BACKGROUND/EVOLUTION

I first came upon Class::DBI::Plugin::Backtickify, which worked great, except the naming of the schema was so bad I hit an edge case that needed fixing first, which got me looking under the hood: http://rt.cpan.org/Public/Bug/Display.html?id=32133

Since that version of Class::DBI::Plugin::Backtickify, Class::DBI (as of v3.0.8) had refactored the Class::DBI::SQL::Transformer class and introduced the Class::DBIsql_transformer_class() method. Which is why this module has the namespace it does instead of Class::DBI::Plugin:: and why I didn't just submit a patch for Backtickify.

Drawing heavily from Backtickify, i generalized it to this module by using DBI::quote_identifier() instead of a hardcoded backtick.

This potentially is (at least a partial) solution (or workaround) for Class::DBI RT ticket 7715 Class::DBI does not correctly quote column names (Pg, maybe others): http://rt.cpan.org/Ticket/Display.html?id=7715

In the course of investigation, also reported this Class::DBI issue, which this module also resolves: http://rt.cpan.org/Ticket/Display.html?id=32115

AUTHOR

David Westbrook (CPAN: davidrw), <dwestbrook at gmail.com>

BUGS

Please report any bugs or feature requests to bug-class-dbi-sql-transformer-quotify at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Class-DBI-SQL-Transformer-Quotify. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Class::DBI::SQL::Transformer::Quotify

You can also look for information at:

SEE ALSO

Class::DBI, Class::DBI::SQL::Transformer, DBI, Class::DBI::Plugin::Backtickify

ACKNOWLEDGEMENTS

David Baird for the groundwork of Class::DBI::Plugin::Backtickify

COPYRIGHT & LICENSE

Copyright 2008 David Westbrook, all rights reserved.

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