anirudh_sml has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I am new to catalyst framework please help me out.
I want to update a table in mysql but i dont knw how to do it as i am able to insert values in mysql table ,read the values but i don't know how to update
For insert i am using
my $data= $c->model('DBXyz::Table')->create({ customer_id => $customer_id, userid => $user_id, date => $date, entry_type => $commentType, history_entry => $comment, });
This is working fine but i dont know wat i shuld write to update in table .
Thanks

Replies are listed 'Best First'.
Re: Syntax to update a table in mysql using catalyst framework
by Corion (Patriarch) on Jan 07, 2009 at 08:35 UTC

    As you mention MySQL, I assume that your model class is a class derived from DBIx::Class. Hence, I further assume that you would update your elements like you would date any other instance of a DBIx::Class derivative. See DBIx::Class::Manual::Intro for a basic introduction to DBIx::Class.

      Hi monks my problem is not solved yet please help me .
      The problem is i am updating the table through
      my $profile_update= $c->model('DBMain::Table')->update( { table_feild1 => $value, table_feild2 => $value2, }, { key => $value3} );
      This is updating all the records how to put where clause in it .
      Thanks

        DBIx::Class comes with lots of documentation. I guess you will have to read it, instead of asking us to read it for you.

        In your specific case, I would assume that you would first ->search() for the rows you want to change, and then do $resultset->update(), to change these rows.

        But, to reiterate, you will have to learn lots and lots about DBIx::Class. Or, if you "just" want to write some SQL, you will have to ditch using DBIx::Class as your model in Catalyst and write your own model. This should be possible, but I haven't done any of this, as I find that writing my own framework is about as much hassle as using one of the premade frameworks.