Uploaded image for project: 'CUBRID APIs'
  1. CUBRID APIs
  2. APIS-585

HandleError subroutine is NOT called on ERROR

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: Perl-Aprium
    • Fix Version/s: Perl 9.1.0.0002
    • Component/s: Perl Driver
    • Labels:
      None
    • Environment:

      Description

      Originally posted on CUBRID Forum http://www.cubrid.org/forum/690454.

      Hi,

      I'm using the DBD::cubrid module v9.1.0.0001 and server v9.1.0, here is a short test:

      {code}
      #!/bin/env perl

      use strict;
      use warnings;
      use DBI;

      my $dbname = 'sqitchmeta';
      my $user = 'user';
      my $pass = 'pass';

      my $dsn = qq{dbi:cubrid:database=$dbname;host=localhost;port=33000};

      my $dbh = DBI->connect(
      $dsn, $user, $pass,
      { AutoCommit => 1,
      RaiseError => 0,
      PrintError => 0,
      HandleError => sub { print "!!! Handle Error !!! "; },
      }
      ); # or die $DBI::errstr;

      $dbh->do('INSERT blah INTO _bar____');{code}

      I have noticed that HandleError subroutine is called on connection errors but NOT on other errors.

      The idea is to turn errors into exceptions, like in the example from the DBI manual:

      {code}
      use Exception; # or your own favourite exception module
      $h->{HandleError} = sub { Exception->new('DBI')->raise($_[0]) };{code}

      But that won't happen if the sub doesn't get called.
      Setting RaiseError and/or PrintErorr to 1 doesn't help, neither checking for errors.

      BTW, this works for PostgreSQL.

      FWIW, other DBDs, including DBD::Pg, DBD::mysql, DBD::SQLite, and DBD::Oracle, call the error handler when RaiseError is false.

      Thanks,
      Stefan

        Issue Links

          Activity

          Hide
          kadishmal Esen Sagynov added a comment -

          The user has added a comment saying:

          Not just for do, also the same problem for prepare, if the last line is changed to:

          {code}
          my $sth = $dbh->prepare('INSERT blah INTO _bar____');# or die $DBI::errstr;
          $sth->execute();# or die $DBI::errstr;{code}
          Show
          kadishmal Esen Sagynov added a comment - The user has added a comment saying: Not just for do , also the same problem for prepare , if the last line is changed to: {code} my $sth = $dbh->prepare('INSERT blah INTO _ bar ____');# or die $DBI::errstr; $sth->execute();# or die $DBI::errstr;{code}
          Hide
          cn15800 谢韦华[Bert] added a comment -

          Official does not offer method how to handle these attribute, so wo need to resarch the attribute

          http://search.cpan.org/~timb/DBI-1.622/lib/DBI/DBD.pm

          $h->

          {RaiseError}

          The DBD driver does not need to worry about this attribute at all.

          $h->

          {PrintError}

          The DBD driver does not need to worry about this attribute at all.

          Show
          cn15800 谢韦华[Bert] added a comment - Official does not offer method how to handle these attribute, so wo need to resarch the attribute http://search.cpan.org/~timb/DBI-1.622/lib/DBI/DBD.pm $h-> {RaiseError} The DBD driver does not need to worry about this attribute at all. $h-> {PrintError} The DBD driver does not need to worry about this attribute at all.
          Hide
          cn15800 谢韦华[Bert] added a comment -

          I found we need to specified value of attribute, as follow:

          if (strEQ("RaiseError", key))

          { DBIc_set (imp_dbh, DBIcf_RaiseError, on); }

          if (strEQ("PrintError", key))

          { DBIc_set (imp_dbh, DBIcf_PrintError, on); }
          Show
          cn15800 谢韦华[Bert] added a comment - I found we need to specified value of attribute, as follow: if (strEQ("RaiseError", key)) { DBIc_set (imp_dbh, DBIcf_RaiseError, on); } if (strEQ("PrintError", key)) { DBIc_set (imp_dbh, DBIcf_PrintError, on); }
          Hide
          cn15800 谢韦华[Bert] added a comment - - edited

          If we do not specified the value, the default value is 0 and can not modify by connect

          Show
          cn15800 谢韦华[Bert] added a comment - - edited If we do not specified the value, the default value is 0 and can not modify by connect
          Hide
          kadishmal Esen Sagynov added a comment -

          The user says that other DBs correctly handle this situation. So, please see what they are doing, then propose your solution.

          Show
          kadishmal Esen Sagynov added a comment - The user says that other DBs correctly handle this situation. So, please see what they are doing, then propose your solution.
          Hide
          cn15800 谢韦华[Bert] added a comment -

          RaiseError,PrintError and other common attribute are implemented by DBI, no driver-specific impact.

          So we need to return false in dbd_db_STORE_attrib, it's mean the driver doesn't implement the function,

          But cubrid driver return ture,now. We can return ture when the attribute is private.

          Show
          cn15800 谢韦华[Bert] added a comment - RaiseError,PrintError and other common attribute are implemented by DBI, no driver-specific impact. So we need to return false in dbd_db_STORE_attrib, it's mean the driver doesn't implement the function, But cubrid driver return ture,now. We can return ture when the attribute is private.
          Hide
          cn15800 谢韦华[Bert] added a comment -

          fixed

          Show
          cn15800 谢韦华[Bert] added a comment - fixed

            People

            • Assignee:
              cn15800 谢韦华[Bert]
              Reporter:
              kadishmal Esen Sagynov
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: