On Sat, Oct 30, 2004 at 10:31:01AM -0400, Guest via RT wrote:
Show quoted text> I am having trouble using imports with DBI. It could be due to DBI's use of "groups" of symbols. You will see that :sql_types imports numerous symbols when using DBI directly. Maybe I'm not using it correctly? It will print SQL_TYPE_TIMESTAMP when incorrect and print 93 when correct. Use the following script to reproduce:
If you turn on warnings you get a hint as to what's going on.
$ perl -wle 'use Test::More tests => 1; use_ok 'DBI', qw(:sql_types); print SQL_TYPE_TIMESTAMP'
1..1
Name "main::SQL_TYPE_TIMESTAMP" used only once: possible typo at -e line 1.
ok 1 - use DBI;
print() on unopened filehandle SQL_TYPE_TIMESTAMP at -e line 1.
Perl thinks SQL_TYPE_TIMESTAMP is a filehandle not a function. This is a
parsing issue. Its because SQL_TYPE_TIMESTAMP wasn't declared early enough.
If you do "print &SQL_TYPE_TIMESTAMP" it works, so its getting exported.
In order for constants to work properly they have to be declared at compile
time. "use" happens at compile time before anything else happens, even
before the rest of the program is compiled. use_ok() does not. In order
for exports to work properly its recommended you place use_ok() in a BEGIN
block to force it to happen at compile time.
use Test::More tests => 1;
BEGIN { use_ok 'DBI', qw(:sql_types) }
print SQL_TYPE_TIMESTAMP;
--
Michael G Schwern schwern@pobox.com
http://www.pobox.com/~schwern/
The eye opening delightful morning taste of expired cheese bits in sour milk!