[Dbix-class] Q: Differing column names in DBIC and SQL

Bernhard Graf dbic3 at augensalat.de
Tue Oct 21 13:44:43 BST 2008


Jess Robinson wrote:

> On Tue, 21 Oct 2008, Bernhard Graf wrote:
> > Peter Rabbitson wrote:
> >>> - AFAIR their usage slows down db access once more.
> >>
> >> Please bring some evidence for your last claim. If this turns out
> >> to be true, someone will be happy to investigate this matter
> >> further. However for now I and people whose opinion I value,
> >> consider this as shameless FUD spread.
> >
> > AFAIR means that I don't have a source at hand, though it is quite
> > obvious, that regex'ing each name in an SQL handle to insert
> > quote_char-s and name_sep-s will slow down the process somehow.
>
> Regex, what regex? Have you looked at the code that does this, or are
> you just guessing wildy? Cos it seems like the latter.
>
> >From SQL/Abstract.pm:
>
> $opt{quote_char} ||= '';
> $self->{quote_char} . $label . $self->{quote_char}
>
> So, it *always* runs that code, whether you set one or not!

1. As you already noted yourself, DBIC overwrites this behaviour.
2. If I'm not completely wrong, you cannot use quote_char without
   char_sep or you get broken SQL code. And with char_sep a regex
   is run for every name in the query.

> I haven't heard/seen this "common practice" anywhere.. But if you're

Well I did. The only I remember right now is Lyris list server.

> determined, you want to define your columns as:
>
>    _name => {
>       accessor => 'name',
>       data_type => 'varchar',
>       ..
>    }
>
> To get the deploy system to create them with underscores in your
> database, while accessing them using the non-underscored versions in
> your code.

Thank you Jess. Finally I get an answer to my actual question.

I tried the above, but this seems half-baken:
While deploy() works as expected, and also accessing the column with 
$rs->name() works, using the name in an argument list is not supported. 
You still have to say:
$rs->create({_name => '...'});

-- 
Bernhard Graf



More information about the DBIx-Class mailing list