On Sat, Feb 24, 2007 at 09:20:35PM +0000, Will Parsons wrote:
> I'm trying to change the text of error messages, for example the following:
> 
> DBD::SQLite::db do failed: table X already exists(1) at dbdimp.c line 269
> 
> >From the user's point of view, "table X already exists" is valuable
> information, but "at dbdimp.c line 269" is useless.
> 
> I've attempted to do this using the HandleError attribute with a function:
> 
> sub handle_error {
>    $_[0] =~ s/ at dbdimp.c line \d+//;
>    print STDERR "db error: $_[0]\n";   # for debug
>    return 0;
> }
> 
> The print statement shows the handler is changing the error text, but
> the contents of $DBI:errstr on return from an offending statement show
> the original text.
> 
> How can I do this?

Umm. I'd expect it to work. $_[0] is the same SV that's passed to
warn/croak for PrintError/RaiseError.

If you send me a patch that moves the HandleError tests from t/10examp.t
into a separate file and adds a new test for this problem, then I'll
try to fix it :)

Having said that, I don't see any value in the _sqlite_error() function
in DBD::SQLite adding the file and line number into the error message.

In fact the code needs changing anyway to use the newer way to record
errors. That'll mean you could use the DBI's SetErrHandler hook.
I'll do that and post a patch including the above change.

Tim.

Reply via email to