in reply to Re^2: Dancer2::Plugin::Database and database errors
in thread Dancer2::Plugin::Database and database errors

In the interest of documenting the debugging process I'm going through (please overlook some stupidity, given that I've been up at least 60 of the last 72 hours), I tried this:

my @last_records = database('current')->quick_select('states', { host_name => $data->{'host_name'}, name => $data->{'service_description'} }, { order_by => { desc => 'id' } } ) or $delstatus .= '/error from quick_select call;' . ' ERR [' . Dancer::Plugin::Database::Core::DBI->err . +'];' . ' ERRSTR [' . Dancer::Plugin::Database::Core::DBI->err +str . ']';

And got this error:

[NagiosToServiceNow::json:40284] error @2018-09-22 20:32:46> Route exc +eption: Can't locate object method "err" via package "Dancer::Plugin: +:Database::Core::DBI" (perhaps you forgot to load "Dancer::Plugin::Da +tabase::Core::DBI"?) at /home/svcanagios/n2s/bin/../lib/NagiosToServi +ceNow/json.pm line 707. in /home/svcanagios/n2s/bin/../local/lib/perl +5/Dancer2/Core/App.pm l. 1473

I was trying to fully-quality the variable. So that didn't work, so I tried:

my @last_records = database('current')->quick_select('states', { host_name => $data->{'host_name'}, name => $data->{'service_description'} }, { order_by => { desc => 'id' } } ) or $delstatus .= '/error from quick_select call;' . ' ERR [' . $Dancer::Plugin::Database::Core::DBI::err . + '];' . ' ERRSTR [' . $Dancer::Plugin::Database::Core::DBI::er +rstr . ']';

and got:

Use of uninitialized value $Dancer::Plugin::Database::Core::DBI::err i +n concatenation (.) or string at /home/svcanagios/n2s/bin/../lib/Nagi +osToServiceNow/json.pm line 707. Use of uninitialized value $Dancer::Plugin::Database::Core::DBI::errst +r in concatenation (.) or string at /home/svcanagios/n2s/bin/../lib/N +agiosToServiceNow/json.pm line 707. [NagiosToServiceNow::json:57311] debug @2018-09-22 20:39:02> QUICK SEL +ECT STATUS: --=> checking for: [tibintprdsac2p.wsgc.com][AIXERRPT] fo +r last output entry./error from quick_select call; ERR []; ERRSTR []/ +found [0] to delete <=-- in /home/svcanagios/n2s/bin/../lib/NagiosToS +erviceNow/json.pm l. 719

asdf

my @last_records = database('current')->quick_select('states', { host_name => $data->{'host_name'}, name => $data->{'service_description'} }, { order_by => { desc => 'id' } } ) or $delstatus .= '/error from quick_select call;' . ' ERR [' . $Dancer::Plugin::Database::Core::DBI->err . + '];' . ' ERRSTR [' . $Dancer::Plugin::Database::Core::DBI->er +rstr . ']';

and got:

[NagiosToServiceNow::json:40572] error @2018-09-22 20:43:11> Route exc +eption: Can't call method "err" on an undefined value at /home/svcana +gios/n2s/bin/../lib/NagiosToServiceNow/json.pm line 707. in /home/svc +anagios/n2s/bin/../local/lib/perl5/Dancer2/Core/App.pm l. 1473

By now you're probably realizing that my frenzied mind is lost. Sadly, I am in serious need of some very real help from my fellow monks on this, or I'm afraid I'll just go crazy... :(

David Lee Crites, Author and DevOps Dude
Devops: lee@critesclan.com
Author: davidlee@adoniah.co
quad alii ut vivere

Replies are listed 'Best First'.
Re^4: Dancer2::Plugin::Database and database errors
by lee_crites (Scribe) on Sep 23, 2018 at 05:57 UTC

    An Answer Found!!!

    This isn't pretty, and I don't really like it, but I found an answer, and so I can move forward with my project. Here it is:

    • Get the database handle:
      my $dbh = database('current');
    • Build a "do" command:
      my $dbhstatus = ''; my $rows_deleted = $dbh->do( 'DELETE FROM states WHERE host_name = ? and service_description = +?', undef, ( $data->{'host_name'}, $data->{'service_description'} ) ) or $dbhstatus = 'delete error; [' . $dbh->errstr . ']';

    So when things simply don't seem to be working using the module, I can now slip back to using the DBI processing. It's not ideal, in that the module itself is not reliable -- it is actually the quick_delete that is not working, not the quick_select, but you do what'cha gotta do...

    If others have a better way of getting around this, then I'd love to know. I'm still convinced that there is a "clean and simple" way to get the database error code, but my testing simply did not get it.

    David Lee Crites, Author and DevOps Dude
    Devops: lee@critesclan.com
    Author: davidlee@adoniah.co
    quad alii ut vivere