Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Selecting date using DBIx::Class and InflateColumn

by nybble_1 (Novice)
on Jul 11, 2008 at 19:21 UTC ( #697061=perlquestion: print w/replies, xml ) Need Help??
nybble_1 has asked for the wisdom of the Perl Monks concerning the following question:

I beseech you to right my wrongs!

I am unable retrieve a row using DBIx::Class when specifying the datatype as 'datetime' to use with InflateColumns. The SQL that is generated gives me an error: "You have an error in your SQL syntax;" ... blah blah blah; the key error in the SQL is the datatype hash below:
SELECT me.id, me.token, me.old_invoice, me.date, me.=>, me.{data_type, + me.'datetime'} FROM invoices me ...
I am able to save date data flawlessly; I am also able to retrieve data from this field when I remove the datetime datatype from my column declaration. My Class is:
package SEM::Main::Invoices; use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/PK::Auto InflateColumn::DateTime C +ore/); __PACKAGE__->table('invoices'); __PACKAGE__->add_columns(qw/id token old_invoice date => {data_type => 'datetime'} /); __PACKAGE__->set_primary_key('id'); 1;
My code retrieving the result set is:
my $rowI = $schema->resultset("Invoices")->search({token=>$sTarget +})->first;
Any thoughts would be welcome;

TIA to those Monks of the digital cloth.

nybble

Replies are listed 'Best First'.
Re: Selecting date using DBIx::Class and InflateColumn
by friedo (Prior) on Jul 11, 2008 at 20:20 UTC

    The problem is that you're using qw in the list that you're passing to add_columns. What you're actually passing is the list ( 'id', 'token', 'old_invoice', 'date', '=>', '{data_type', '=>', \'datetime\'}' )

    In order to pass a list of column-name => hashref pairs, you'll need to write it like this:

    __PACKAGE__->add_columns(id => { }, token => { }, old_invoice => { }, date => {data_type => 'datetime'} );

    Alternatively, you can pass a list of the plain column names (no hashrefs) and specify the date column type later:

    __PACKAGE__->add_columns(qw/id token old_invoice/); __PACKAGE__->add_columns(date => {data_type => 'datetime'});

    Update: Fixed typos

      That was it

      Thanks Friendo

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://697061]
Approved by friedo
help
Chatterbox?
[choroba]: BTW, both the bands I play in performed on Friday (at the same event). Quite an exhausting experience.
[Corion]: choroba: Ooof! I can imagine that ;)
[Corion]: I think at a Perl workshop some years ago I gave two talks on the same day and after that decided to only submit one talk per event ;)
[LanX]: you play the triangle, right?

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2017-03-27 11:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (319 votes). Check out past polls.