- SEE ALSO
- COPYRIGHT & LICENSE
Class::DBI::SQL::Transformer::Quotify - Quote column and table names in Class::DBI-generated SQL
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 );
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 = ?
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
David Westbrook (CPAN: davidrw),
<dwestbrook at gmail.com>
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.
You can find documentation for this module with the perldoc command.
You can also look for information at:
RT: CPAN's request tracker
AnnoCPAN: Annotated CPAN documentation
David Baird for the groundwork of Class::DBI::Plugin::Backtickify
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.