Skip Menu |

This queue is for tickets about the DBIx-Simple CPAN distribution.

Report information
The Basics
Id: 106222
Status: new
Priority: 0/
Queue: DBIx-Simple

Owner: Nobody in particular
Requestors: chrispbs.rt [...]

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)

Subject: Line 271 of lib/DBIx/ erroneously calls DBI statement handle object's finish() method, destroying first query error message returned by DBMS
Date: Mon, 3 Aug 2015 01:45:56 +0100
To: bug-DBIx-Simple [...]
From: Chris Pibbs <chrispbs.rt [...]>
Download (untitled) / with headers
text/plain 1.9k
Line 271 of lib/DBIx/ makes a call to the finish() method on a DBI statement handle object. For whatever reason, DBIx::Simple::Statement's _die() method is called whenever a DBMS error is encountered for the first time while executing a query, and because finish() is not a method that preserves the values of DBI's err and errstr, the call nulls DBI's error message before the calling code has a chance to read it (e.g., via DBIx::Simple's error() method). The end result is that the calling code knows an error occurred on the DBMS when a query fails for the first time, but has no way of knowing what the nature of the error was. Error messages for future queries are retained as expected. Minimum working example demonstrating the problem (this shows the bug happening with an SQLite backend, although I initially ran into it on a PostgreSQL backend using DBD::Pg): use DBIx::Simple; my $db = DBIx::Simple->connect("dbi:SQLite:dbname=test.db", "", "", { RaiseError => 0 }); $db->query("CREATE TABLE test(a NUMERIC PRIMARY KEY)"); print "1 "; $db->query("INSERT INTO test (a) VALUES (42)") or print $db->error; print "\n"; print "2 "; $db->query("INSERT INTO test (a) VALUES (42)") or print $db->error; print "\n"; print "3 "; $db->query("INSERT INTO test (a) VALUES (42)") or print $db->error; print "\n"; Expected output: 1 2 DBI error: UNIQUE constraint failed: test.a 3 DBI error: UNIQUE constraint failed: test.a Actual output: 1 2 DBI error: 3 DBI error: UNIQUE constraint failed: test.a The DBI documentation [1] states that finish() should not be called on statement handle objects outside of driver code without an extremely good reason. Removing the call to finish() on line 271 (e.g., by commenting out the line altogether) fixes the bug and produces the expected output in the MWE above, with no other apparent side-effects. Perl 5.18.1, Linux x86_64 Relevant modules: DBIx-Simple-1.35, DBI-1.633, DBD-SQLite-1.48 (or DBD-Pg-3.5.1) [1]

This service is sponsored and maintained by Best Practical Solutions and runs on infrastructure.

Please report any issues with to