Subclassing DBI, and PrintError messages

From: David Viner (dviner_at_yahoo-inc.com)
Date: 11/18/04


To: "'dbi-users@perl.org'" <dbi-users@perl.org>
Date: Wed, 17 Nov 2004 18:46:49 -0800

Hi,

I am attempting to write a simple subclass of DBI which will handle some
auto-reconnect behavior. In this case, I am connecting to a MySQL server,
and I can properly reconnect. However, if the user sets 'PrintError' to
true, then DBI will print out:

DBD::mysql::st execute failed: Lost connection to MySQL server during query
at C:/Perl/site/lib/Harvester/DBI.pm line 177, <> line 1.

Immediately after that, it will reconnect, and re-execute the statement
handle successfully. I would like to print a message after the "lost
connection" message so that the user knows that the class is attempting to
reconnect. Since I can already detect when the connection is lost, I can
just use something like warn to handle this. However, I'd like to use the
same mechanism that DBI and DBD::mysql::st are using.

In order to discover how (or where exactly) DBI or DBD::mysql::st emits the
warning statement, I set DBI->trace(15) to see exactly what was happening.
Here's that output:

>> execute DISPATCH (Harvester::DBI::st=HASH(0x1d7dac0) rc1/2 @1 g0
ima1041 pid#5864)at C:/Perl/site/lib/Harvester/DBI.pm line 177
    -> execute for DBD::mysql::st
(Harvester::DBI::st=HASH(0x1d7dac0)~0x1d7a230) thr#224374
    -> dbd_st_execute for 01d7a158
Lost connection to MySQL server during query error 2013 recorded: Lost
connection to MySQL server during query
    <- dbd_st_execute -2 rows
    !! ERROR: 2013 'Lost connection to MySQL server during query' (err#0)
    <- execute= undef at C:/Perl/site/lib/Harvester/DBI.pm line 177
DBD::mysql::st execute failed: Lost connection to MySQL server during query
at C:/Perl/site/lib/Harvester/DBI.pm line 177, <> line 1.

I can't seem to find anything that emits this warning. From slow debugging,
I can tell that this occurs when $sth->execute() is invoked. However, I
can't seem to pinpoint the code which actually emits the message.

Can anyone point me in the right direction?

thanks
dave



Relevant Pages

  • Re: RDB limitations: from Jimmy Gavan
    ... Your DBI QUESTION: ... Bearing in mind no compiler to reference or even test my thoughts, ... The unique Id is used as a DB connection ... move SQLSTATE to MOST-SQLSTATE ...
    (comp.lang.cobol)
  • RE: :Oracle - with ora10g oci.dll
    ... I agree it's not a DBD or DBI error. ... your connection descriptor seems suspect: ... how to get to our nameservers. ... 10g installation is really just a few files in the /perl/bin directory. ...
    (perl.dbi.users)
  • MAC address changed while using machine on net?????
    ... stuff on the interwebnet I suddenly lost my connection to the lan on ... Stopped the SuSE Firewall and all was returned back to normal, ... How the devil can Suse change the MAC on my nic while it is in use, ... this also had lost its settings and video was missing. ...
    (alt.os.linux.suse)
  • Re: Problems with access to a web page
    ... Ethernet adapter Local Area Connection: ... > Connection to host lost. ... > and got exactly the same 0 length response ... Ping at least still works ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: about the TIME_WAIT
    ... When a socket is closed, ... Assume that a connection is in ESTABLISHED state, ... whether the client got the data, but that is not an issue for TCP; ... where data may or may not have been lost. ...
    (perl.beginners)