Hello Monks
I am working on Perl Database project and I am stuck at one problem. In my project I am using DBIx::Class to perform the database operations.But for the following function my script is getting aborted.The function causing problem is as follows:
sub _get_user_scenario { my ($self, $schema, $user_scenario) = @_; my $user_scenario_rs = undef; my $user_scenario_desc; # In the case where the description is not Null if($user_scenario->{description}){ $user_scenario_desc= $user_scenario->{description}; }else{ Line #799 ===> $user_scenario_desc = $schema->resultset("UserS +cenario")->search({ "name" =>$user_scenario->{name}, })->first->description; } 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_o +r_create( { name => $user_scenario->{name}, description => $user_scenario_desc, }, { key => "u_user_scenario_name" }, ) || die "Unable to update/insert data to table UserScena +rio: $!\n"; }; if($@){ #warn(); $self->log_writer()->write_error_row("Unable to get/insert da +ta to table UserScenario: $@"); return undef; }else{ $self->log_writer()->write_row("Inserted values into user_sce +nario table"); print"Inserted values into user_scenario table\n"; return $user_scenario_rs; } }
Here I am trying to insert some values into user_scenario table.Among those values I am trying to insert the value for description if it is already defined in the hash else I am trying to extract it's value using search function. But this case is not working for the user_scenarios whose description is not stored in the hash as well as not present in the database.I am getting an error like this for line # 799 is as follows(in the code line # is specified)
Can't call method "description" on an undefined value at DataLoader/Inserter.pm line 799.
Kindly help me out to deal with this DBIx error. Thanks in advance !!!!
In reply to A doubt about DBIx::Class by siddheshsawant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |