On Mon May 30 05:15:02 2011, MJEVANS wrote:
Show quoted text> On Fri May 27 14:45:04 2011, MJEVANS wrote:
> > On Fri May 27 11:38:30 2011, pedrinho@gmail.com wrote:
> > > I'm using DBD::ODBC's but I've tried the DBI handler - neither
seems
Show quoted text> > to fire
> > > (unless I'm doing it wrong. The DBI documentation for the
handlers
Show quoted text> > isn't as
> > > explicit as I'd like:
> > >
> > > use DBI;
> > > use Data::Dumper;
> > > my $sev = $ARGV[0];
> > > if ($#ARGV == -1) {
> > > print "Usage: need a severity (number between 1 and 20)\n";
> > > exit(2);
> > > }
> > > $dbh = DBI->connect("dbi:ODBC:DSN=FOOSERVER;APP=errorout",
"foouser",
Show quoted text> > > "foopassword",
> > > {RaiseError=>1,
> > > HandleError=>sub {print Dumper(\@_) . "\n"}});
> > > $dbh->do("raiserror('This is a test', $sev, 1)")
> > >
> > >
> > > This results in the following:
> > > $ perl ~/tmp/raiserror_simple.pl
> > > Usage: need a severity (number between 1 and 20)
> > > $ perl ~/tmp/raiserror_simple.pl 4
> > > $ perl ~/tmp/raiserror_simple.pl 5
> > > $ perl ~/tmp/raiserror_simple.pl 10
> > > $ perl ~/tmp/raiserror_simple.pl 11
> > > $VAR1 = [
> > > 'DBD::ODBC::db do failed: [unixODBC][FreeTDS][SQL
> > Server]This is a
> > > test (SQL-42000)',
> > > bless( {}, 'DBI::db' ),
> > > undef
> > > ];
> > >
> > > The same results happen with the easysoft driver.
> > >
> > > Thanks,
> > >
> > > -Peter
> >
> > Just a quick reply as I've not looked at it properly yet.
> >
> > In you example you are using DBI's error handler I see.
> >
> > In ODBC terms numbers less than 11 are SQL_SUCCESS_WITH_INFO
returns.
Show quoted text> > Numbers > 10 are errors and if I take your script as it is then for
me
Show quoted text> > it does not enter the error handler at all but the do fails with:
> >
> > DBD::ODBC::db do failed: [Microsoft][ODBC SQL Server Driver][SQL
> > Server]This is a test (SQL-42000) at rt68510.t line 11. (See later).
> >
> > I'd expect the error handler to be called at least for errors but
> > warnings are different in DBI.
> >
> > Also, for me, your code does not work as it seems to for you. I
needed
Show quoted text> > to set HandleError after connect.
> >
> > Hopefully, I can find some time to look at this over the weekend.
> >
> > Martin
>
> It appears DBI does not call its error handler for warnings and when
an
Show quoted textit
Show quoted text> says HandleError is called at the same point PrintError or RaiseError
> would be called so I'm not surprised DBI does not call the HandleError
> routine for warnings.
>
> You can change DBD::ODBC to cause the odbc_err_handler if you change
the
Show quoted text> following code in dbdimp.c:
>
> Index: dbdimp.c
> ===================================================================
> --- dbdimp.c (revision 14879)
> +++ dbdimp.c (working copy)
> @@ -457,13 +457,15 @@
> else {
> if (ret == SQL_NO_DATA) {
> rows = 0;
> - } else {
> - ret = SQLRowCount(stmt, &rows);
> - if (!SQL_SUCCEEDED(ret)) {
> - dbd_error( dbh, ret, "SQLRowCount failed" );
> - rows = -1;
> - }
> + } else if (ret != SQL_SUCCESS) {
> + dbd_error2(dbh, ret, "Execute immediate success with info",
> + imp_dbh->henv, imp_dbh->hdbc, stmt );
> }
> + ret = SQLRowCount(stmt, &rows);
> + if (!SQL_SUCCEEDED(ret)) {
> + dbd_error( dbh, ret, "SQLRowCount failed" );
> + rows = -1;
> + }
> }
> ret = SQLFreeHandle(SQL_HANDLE_STMT,stmt);
> if (!SQL_SUCCEEDED(ret)) {
>
> but you'll see that although thay causes the ODBC error handler to be
> called (and assuming that handler returns 1) it still does not get in
> the DBI error handler as it is a warning.
>
> If you want to capture warnings in DBI you can use HandleSetErr - see
>
http://search.cpan.org/~timb/DBI-1.616/DBI.pm#HandleSetErr which
despite
Show quoted text> its name is called for warnings too.
>
> So, to summarise. It is possible DBD::ODBC should call its internal
> handler when SQLExecDirect returns SQL_SUCCESS_WITH_INFO but there is
no
Show quoted text> precident in DBI to do so. If I changed it (above code) it may affect
> others who have odbc error handlers and do not expect to get
> informational/warning states. Whether I change it or not it will make
no
Show quoted text> difference to DBI's HandleError as it is only used for errors and not
> warnings. Is raiseerror(<11) a warning - I'm afraid it is as
> SQLExecDirect will return SQL_SUCCESS_WITH_INFO which is success but
> there is something you might want to note. The most portable way of
> catching the warning is with HandleSetErr. If you have a problem with
> any of this it is probably best submitting a post to the dbi-users
list
Show quoted text> where other DBD authors and Tim Bunce hang out as they may have an
> opinion as to whether something is wrong in DBD::ODBC or DBI.
>
> Martin
I am happy to do more on this rt but I need some feedback as to what you
are trying to achieve and what you think of my comments so far.
If you have moved on and no longer want to pursue this rt could you let
me know so I can close it.
Martin
--
Martin J. Evans
Wetherby, UK