Reputation: 923
I have some old tables I wanted to work on using Class::DBI
however when I tried setting it up with a table with a hyphen in the name I got a SQL error back when I try to use my class.
My class definition:
MyClass->table('table-name');
Shortened error message:
DBD::mysql::st execute failed [..] near '-name [..]
(My setup works fine with tables with no hyphen in the name.)
Is there a way to tell Class::DBI
the table names that have hyphens?
I also notice the rest of the SQL that's spat out does not have fields enclosed in backticks ``
possibly meaning any column names with hyphens would also fail.
Upvotes: 0
Views: 201
Reputation: 923
Giving MySQL its backticks did the trick:
MyClass->table('`table-name`')
As an aside, column names with hyphens can be defined the following way in order not to break Perl:
__PACKAGE__->add_columns('`col-name`' => {accessor => 'col_name'}); # or w/e valid Perl sub name like instead of col_name
Upvotes: 1