Re: Undefined $DBI::errstr on error using MySql on Windows-7-x64

"Martin J. Evans" <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.dbi.general
Organization Easysoft Limited
Message-ID <[email protected]>
On 04/10/11 14:52, tiger peng wrote:
>
>
> Changing {RaiseError=>0,PrintError=>0} to {RaiseError=>1,PrintError=>1} may help you find the issue.
>
> The script must failed on the prepare statement (due to does_not_exist table), but you disabled the DBI's exception handling and did not do the handling by yourself.
>
> There must be some warning messages you did not provided, beause you enabled warning but did not declared the (my) variables; and $s must be a undef value due to the failure of prepare which should have a warning message.
>
>
> Normally, I will enable PrintError (at least in dev environment); and unless I like to do exception handling, I eill not disable RaiseError.

tiger peng,

When you top post like this it is not exactly clear what you are responding to and as you replied to my reply to the OP, to me it looks like you are replying to my reply. I didn't do any of the things you refer to.

Also you said "There must be some warning messages you did not provided, beause you enabled warning but did not declared the (my) variables" and yet:

perl -le 'use warnings; $s = 1; print $s;'
1

It is strict vars which requires you to declare variables not warnings:
perl -le 'use strict vars; $s = 1; print $s;'
Global symbol "$s" requires explicit package name at -e line 1.
Global symbol "$s" requires explicit package name at -e line 1.

Also, some DBD's have a prepare method does almost nothing - certainly not parsing the SQL or checking tables exist - I think some DBD::mysql's are like this depending on how you set your client up.  So it is possible to pass invalid SQL to a prepare and it not fail.

perl -le 'use strict; use warnings; use DBI; my $h = DBI->connect("dbi:mysql:database=test", "xxx","yyy", {RaiseError => 0, PrintError => 0}) or die $DBI::errstr; my $s = $h->prepare(q/select * from does_not_exist/) or die "prepare: " . $DBI::errstr; $s->execute or die "execute DBI:" . $DBI::errstr . " sth:", $s->errstr;'
execute DBI:Table 'test.does_not_exist' doesn't exist sth:Table 'test.does_not_exist' doesn't exist at -e line 1.

Note, the prepare worked, the execute failed even though the table does not exist.

Martin
-- 
Martin J. Evans
Easysoft Limited
http://www.easysoft.com

>
> ________________________________
> From: Martin J. Evans<[email protected]>
> To: [email protected]
> Sent: Tuesday, October 4, 2011 4:51 AM
> Subject: Re: Undefined $DBI::errstr on error using MySql on Windows-7-x64
>
> On 27/09/11 10:51, Tadhg MacCarthy wrote:
>> Hello all,
>>
>> I hope I can get some insight on this issue here.
>>
>> Hello,
>>
>> The following code:
>>
>> use warnings;
>> use DBI;
>> $h=DBI->connect('dbi:mysql:cq','root','password',{RaiseError=>0,PrintError=>0})
>> or die "Connection Failed: $DBI::errstr";
>> $s=$h->prepare("select * from does_not_exist");
>> $s->execute or die 'Execute Failed with error ['. $s->errstr . ']';
>>
>> produces the output:
>>
>> Use of uninitialized value in concatenation (.) or string at
>> testmysql.plline 15.
>> Execute Failed with error [] at testmysql.pl line 5.
>
> Seems to work fine for me:
>
> perl -le 'use strict; use warnings; use DBI; my $h = DBI->connect("dbi:mysql:database=test", "xxx","yyy", {RaiseError =>  0, PrintError =>  0}) or die $DBI::errstr; my $s = $h->prepare(q/select * from does_not_exist/) or die $DBI::errstr; $s->execute or die "DBI:" . $DBI::errstr . " sth:", $s->errstr;'
>
> DBI:Table 'test.does_not_exist' doesn't exist sth:Table 'test.does_not_exist' doesn't exist at -e line 1.
>
>> The environment is:
>>
>> DBD-mysql 4.0.19
>> MySQL: Server version: 5.5.15 MySQL Community Server (GPL)
>> Perl 5.14.1: This is perl 5, version 14, subversion 1 (v5.14.1) built for
>> MSWin32-x64-multi-thread
>> ActivePerl 5.14.1 Build 1401 (64-bit)
>> Windows 7 Professional Sevice Pack 1 64 bit
>
> and DBI version?
>
>
>> The code produces the expected output when the operating system is Windows
>> XP 32-bit.
>>
>> Other information:
>> Valid SQL works as expected on Windows-7-x64 - it just seems that the error
>> string is not set correctly.
>>
>> Bug reported at:
>> https://rt.cpan.org/Public/Bug/Display.html?id=71047
>>
>> Also posted to StackOverflow:
>> http://stackoverflow.com/questions/7432944/undefined-dbierrstr-using-dbi-perl-and-mysql-on-windows-7-x64
>>
>> Thanks in advance,
>> Tadhg
>>
>
> Martin
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.