End Point Home
> Tech News
Tech News
DBD::Pg 1.48 Released
by Greg Sabino Mullane
April 14, 2006
Version 1.48 of DBD::Pg, the Perl DBI/PostgreSQL driver, has been released. The driver (which I maintain) can be found at your nearest CPAN mirror. Recent changes fix a number of
bugs, both small and large, and include some important new features. Some of the biggest:
- Default Execute Values
- Dollar Quoting
- Fork and Statement Handles
- Quote Data Types
- Overhaul of the do() Method
- SIGNATURE File
Default Execute Values
An experimental new feature has been added to allow setting of "default" values by the execute() method. Currently, you can emulate sending a NULL by using an undefined value. In a similar way, you can now emulate sending a DEFAULT by using a special variable called $DBDPG_DEFAULT. So doing this:
$sth = $dbh->prepare("INSERT INTO foobar (a,b,c,d) VALUES (?,?,?,?)");
$sth->execute(123, $DBDPG_DEFAULT, undef, 'turtle');
is the equivalent of doing this from psql:
INSERT INTO foobar (a,b,c,d) VALUES (123, DEFAULT, NULL, 'turtle');
Dollar Quoting
PostgreSQL's new "dollar quoting" is now fully supported by DBD::Pg. This allows you to use your own custom delimiters to perform tasks such as defining functions, and releases you from worrying about escaping anything (e.g., quotes) inside of the function body. The entire internal parser of DBD::Pg had to be rewritten to handle the concept of dollar quoting.
Fork and Statement Handles
Explicit support for forking has been provided by ensuring that InactiveDestroy is honored by both $dbh and $sth. The latter was not checked before (but also never caused problems since it did not contain any persistent database information). Now that we are using server-side prepared statements, however, it becomes important to make sure that $sth is not destroyed too early, as it issues a DEALLOCATE on any prepared statements it has created.
Quote Data Types
The quote() function now fully supports passing in the data type for times when the default cannot be guessed by DBD::Pg.
Overhaul of the do() Method
The do() method was completely overhauled to make it smarter and more efficient. Because you have an option to pass parameters to the do method, we were previously scanning the statement for placeholders, preparing it, and executing it every time. Now, if do has no extra arguments, we do a quick and direct pg_exec on the spot. In particular, this greatly speeds up ill-written scripts that use do() inside tight loops instead of using prepare/execute like they should.
SIGNATURE File
This version now has a SIGNATURE file, which is a wonderful enhancement from Module::Signature. This allows you to cryptographically verify your DBD::Pg installation directory on the spot. It's also built into the test suite now so the "All tests passed" message shouldn't be expected unless Module::Signature is installed.
|