[Dbix-class] Quoting for MySQL

Jason Galea lists at eightdegrees.com.au
Sun Apr 1 15:36:43 GMT 2007


You want to add in the name separator as well..

eg

__PACKAGE__->connection($dsn, $user, $pass, { quote_char => '`', 
name_sep => '.' });

cheers,

J

Peter Edwards wrote:
> I was wondering if it was possible to use 'group' as a field name in MySQL.
> I know, pretty dumb and should be avoided unless you're looking for trouble.
> Anyway, I was looking at post 2847 regarding quoting fields
> http://www.mail-archive.com/dbix-class@lists.rawmode.org/msg02847.html
> and tried a couple of things out.
> 
> I found that using connection info quote_char like this in my model class:
> 
> use base qw/DBIx::Class::Schema::Loader/;
> ...	
> __PACKAGE__->loader_options(
>     relationships => 1,
>   );
> __PACKAGE__->connection($dsn, $user, $pass, { quote_char => '`' });
> 
> Gave me SQL on table "user" like this:
> 
> DBIx::Class::ResultSet::find(): Error executing 'SELECT `me.id`, `me.login`,
> `me.password`, `me.group`, `me.salutation`, `me.forename`, `me.initials`,
> `me.surname`, `me.name`, `me.email`, `me.tel`, `me.fax`, `me.mobile`,
> `me.account_status` FROM `user` `me` WHERE ( ( `me.login` = ? ) )': Unknown
> column 'me.id' in 'field list'
> 
> This gives an error in MySQL because it expects `me`.`id` not `me.id`.
> http://dev.mysql.com/doc/refman/4.1/en/identifier-qualifiers.html
> "If any components of a multiple-part name require quoting, quote them
> individually rather than quoting the name as a whole. For example, write
> `my-table`.`my-column`, not `my-table.my-column`."
> 
> Is this style common across other databases? If so I could send in a patch
> to handle it.
> 
> Regards, Peter
> www.dragonstaff.com
> 
> 
> 
> 
> 
> _______________________________________________
> List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> Wiki: http://dbix-class.shadowcatsystems.co.uk/
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
> Searchable Archive: http://www.mail-archive.com/dbix-class@lists.rawmode.org/
> 



More information about the Dbix-class mailing list