P is for Practical | |
PerlMonks |
Re^8: DBI placeholders for spatial databy afoken (Chancellor) |
on Jun 27, 2021 at 01:50 UTC ( [id://11134360]=note: print w/replies, xml ) | Need Help?? |
I just wanted to demonstrate that DBI can't connect with DBI->connect('DBD:MariaDB:...',...), but it can and does, if environment variables are set. I think that should not happen. DBI's connect method is pure perl. It contains some legacy stuff, but I don't really want to analyse every single line of it. So I just cleared the environment and ran a test:
There is a hint hiding in the error message. The relevant part of the connect() documentation is this, at the very end:
connect() assumes an old-style call, despite being called with an unblessed hash reference as fourth argument, not a string. The old-style call should have a driver name as fourth argument. This smells like a bug. What happens if $ENV{'DBI_DRIVER'} is set?
Again, DBI->connect() treats a new-style call with \%attr, but an invalid $data_source, as an old-style call. What happens to the attributes?
PrintError is on, even by default. For "old-style" connects, it should be off. See the quoted documentation above. What happens for a real old-style call?
We get the expected deprecation warning, and PrintError is off (defined and empty). What happens without \%attr? This:
This is acceptable, as there is no fourth argument containing either a driver name or \%attr. So this could be an old-style call. The first argument lacks a "dbi:" prefix, so it must be an old-style call. (Or a confused coder.) So, an invalid modern-style $data_source confuses connect() to use the fall-back to old-style driver name handling, but at the same time to respect the \%attr parameter and to omit the deprecation warning. I think this is a bug. Bod's system obviously behaves the same, and someone must have set up DBI environment variables that hide the problem. My DBI version:
I'm a little bit behind (CPAN currently has 1.643), but the relevant parts in DBI.pm are connect() and installl_driver(). The former has some changes related to the password, and keeps a copy of the original $data_source for an error message, but has no other changes. The latter is unchanged. So I think this bug still exists. Unfortunately, I don't have a spare system at hand to test the current version of DBI. Alexander
-- Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
In Section
Seekers of Perl Wisdom
|
|