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

Thanks for the reply. The $DBI::err and $DBI::errstr were also uninitialized. But looking at that, it kind of tells me something -- because I know blinking good and well that these are not "undefined." They are just in a different namespace. So at least this gave me an idea to start hacking on...

Use of uninitialized value $DBI::err in concatenation (.) or string at + /home/svcanagios/n2s/bin/../lib/NagiosToServiceNow/json.pm line 698.

As for the trace, I'm not sure how that'd work since this is a web server. I might try that, but at this time, there variables are not in scope, so I'm not sure running a trace would help. As always, I'm open for suggestions.

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^3: Dancer2::Plugin::Database and database errors
by 1nickt (Canon) on Sep 23, 2018 at 12:46 UTC

    "because I know blinking good and well that these are not "undefined." They are just in a different namespace."

    No, they really are undefined, almost certainly for the reason I stated: they are reset by DBI after another call on the handle is made subsequent to the one you are interested in, and before you check them. (Those variables cannot be in a "different namespace" as they are global.)

    Hope this helps!


    The way forward always starts with a minimal test.
Re^3: Dancer2::Plugin::Database and database errors
by 1nickt (Canon) on Sep 23, 2018 at 13:08 UTC

    "As for the trace, I'm not sure how that'd work ..."

    Did you try it?

    $ DBI_TRACE=1 plackup bin/app.psgi

    Hope this helps!


    The way forward always starts with a minimal test.
Re^3: Dancer2::Plugin::Database and database errors
by lee_crites (Scribe) on Sep 23, 2018 at 03:47 UTC

    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

      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