Hello monks, I have written a module inserter.pm which inserts a data stored in hash in to database.The module works works in such a way that there is a separate subroutine for each table.I wants to insert value in table named user_scenario.In which two fields are there i.e. name & description.In the case when there is no description exist I want nothing to insert in to it.
The corresponding subroutine is as follows:
Input:user_scenario_name,Us_result_type,description
sub _get_user_scenario { my ($self, $schema, $user_scenario) = @_; my $user_scenario_rs = undef; if(! ($user_scenario->{description} eq 'Not_exposed')) { eval { #get the number of user scenarios in the database table my $count = $schema->resultset("UserScenario")->count(); #insert user scenario, or if already in database, update the d +escription $user_scenario_rs = $schema->resultset("UserScenario")->update_or_create( { name => $user_scenario->{name}, description => $user_scenario->{description}, }, { key => "u_user_scenario_name" }, ) || die "Unable to update/insert data to table UserScenar +io: $!\n"; }; } else { // I don't wants to insert the empty description and I don't wants to + update the database for Not_exposed type of user scenario...So what +I supposed to do here? // } if($@) { #warn(); $self->log_writer()->write_error_row("Unable to get/insert dat +a to table UserScenario: $@"); return undef; } else { return $user_scenario_rs; } }
IF anybody knows how not to write in the database for a particular value then kindly let me know how to achieve this...Because I don't wants to update_or_create function to work on the database where description is Null or empty value.
In reply to A question on DBIx and inserting vales in Database by siddheshsawant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |