Open Source RDBMS - Seamless, Scalable, Stable and Free

English | Login |Register

author
message
[레벨:2]stefans

Post subject: HandleError subroutine is NOT called on ERROR

registered: 06/28/2012

아이피: *.116.200.27

views: 1

Hi,

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

#!/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_____');

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

Thanks,

Stefan

Quote
[레벨:3]Esen Sagynov

# Post subject:Re: HandleError subroutine is NOT called on ERROR

profile

registered: 05/31/2011

아이피: *.91.139.82

I suppose you have to set RaiseError to 1 (also PrintErorr to 1 to have it print the error to STDERR) in order to be able to handle the error.

On the statement level, if the command fails, it should return undef, meaning the number of affected rows, in which case you need to check the $dbh->errstr().

Quote
[레벨:2]stefans

# Post subject:Re: HandleError subroutine is NOT called on ERROR

profile

registered: 06/28/2012

아이피: *.116.200.27

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

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

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.

Quote
[레벨:3]Esen Sagynov

# Post subject:Re: HandleError subroutine is NOT called on ERROR

profile

registered: 05/31/2011

아이피: *.91.139.82

Ok, we will check it now and find the cause of the problem. Then will get back to you.

Quote
[레벨:8]CUBRID

# Post subject:Re: HandleError subroutine is NOT called on ERROR

profile

registered: 03/28/2010

아이피: *.181.249.254

Hi Stefan,

We tested now in Fedora 17 and encounted the same issue you did initially. Can you please check that the cubrid service is running correctly ? For this login as the cubrid user and type "cubrid service status". Then try a "cubrid service restart" and see if you have a problem starting the broker.

We assume you installed using the yum repository. If you installed from sh or regular rpm, you can run the commands as current user. Please let us know if you encounter any issues with starting the cubrid service.

sudo su -s $SHELL cubrid
cubrid service status
cubrid service restart
cubrid server start switchmeta
cubrid service status

If the broker gives you an error such as "cannot create shared memory", then it is most likely blocked by selinux.

We tested with demodb database, public user and password '' and it worked (no more error occurred). If the database is not running, if the broker is not running or if the database does not exist, then the error is encountered. You can raise the error to see the actual reason.

my $dbh = DBI->connect ($dsn, $user, $pass,
        { RaiseError => 1, PrintError => 1, AutoCommit => 0 });

You must configure selinux to allow the broker to start (it uses ports 30000 and 33000). On our virtual machine we disabled it for testing.

To see if selinux causes the problem, you can run "/usr/sbin/setenforce 0" to temporarely disable it and then restart the cubrid service.

We hope this solves your issue. If it does not, please let us know what you have tried and what environment you have so that we can try to reproduce your situation.

Regards,

The CUBRID Team

Quote
[레벨:0]theory

# Post subject:Re: HandleError subroutine is NOT called on ERROR

profile

registered: 07/02/2013

아이피: *.8.233.200

Quote

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

useException;#oryourownfavouriteexceptionmodule
$h->{HandleError}=sub{Exception->new('DBI')->raise($_[0])};

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.

Quote
[레벨:2]stefans

# Post subject:Re: HandleError subroutine is NOT called on ERROR

profile

registered: 06/28/2012

아이피: *.116.200.27

I have installed CUBRID from the "Linux (x86, 32-bit), Shell Executable" (CUBRID-9.1.0.0212-linux.i386.sh) for my regular user and
my box uses Slackware 14.0, GNU/Linux, kernel 3.2.29-smp.

There is no error regarding the broker and the restart worked nicely, the database server works OK. I suppose this is just a Perl API
problem regarding the DBD::cubrid module.

The test program is supposed to print "!!! Handle Error !!!" because the statement is wrong.

If I check for errors I get:

CUBRID DBMS Error : (-493) Syntax: In line 1, column 13 before ' __bar_____'
Syntax error: unexpected 'INTO', expecting SELECT or VALUE or VALUES or '('  at test-error.pl line 22

Which is OK, but not what I need, I need that the sub defined by HandleError to be called on any error.

Thank you.
Regards,
Stefan

Quote
[레벨:8]CUBRID

# Post subject:Re: HandleError subroutine is NOT called on ERROR

profile

registered: 03/28/2010

아이피: *.181.249.254

Thank you for clarifying the issue. The do function does not properly call the error handler if an exception occurs. We will look into the matter and try to fix it in a future release.

Quote
[레벨:2]stefans

# Post subject:Re: HandleError subroutine is NOT called on ERROR

profile

registered: 06/28/2012

아이피: *.116.213.202

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

my $sth = $dbh->prepare('INSERT blah INTO __bar_____');# or die $DBI::errstr;
$sth->execute();# or die $DBI::errstr;

Quote
[레벨:3]Esen Sagynov

# Post subject:Re: HandleError subroutine is NOT called on ERROR

profile

registered: 05/31/2011

아이피: *.91.139.82

Reported this issue to http://jira.cubrid.org/browse/APIS-585. We'll handle this issue asap. Thank you Stefan for reporting.

Quote




You are either using a very old browser or a browser that is not supported.
In order to browse cubrid.org you need to have one of the following browsers:



Internet Explorer: Mozilla Firefox: Google Chrome: