List:MySQL and Perl« Previous MessageNext Message »
From:Paul Sharpe Date:February 19 2000 7:44pm
Subject:Re: Mysql.pm??
View as plain text  

Thomas Stevenson wrote:
> 
> Hello -
> 
> The stage- MySQL version 3.22.25
> We have been replicating an Access database to a Mysql (web) db
> successfully for some months now. We recently created a flag field that is
> a boolean. MS Access sets this field to -1 for false by default. We want 1
> or 0. We cannot overcome this problem so we are dealing with it in the
> Mysql DB and that is fine, but....
> 
> We use a replace test of this field for what to "web display":
> 
> IF (b.article_show=-1, b.article_file_name,'file.html')
> 
> Now this test/replace works just fine in the Mysql monitor but when the
> same sql is run in our Perl script it fails...
> 
> Escapes were tried out of desperation and do not work and they really
> shouldn't need to be used anyway.
> 
> If I update these fields from -1 to 1 after replication, all works fine.
> 
> Our test is now:
> IF (b.article_show=1, b.article_file_name,'file.html')
> That is our current fix right now, post field update.
> 
> I feel the problem is in Mysql.pm but I can't for the life of me see it
> there.
> 
> If anyone would be so kind as to shed some light on this, I'd appreciate it
> greatly. Our fix is fine for now but an understanding of what is happening
> would be more desireable.
> 
> Tom

DBI seems to do the logical thing:

select * from bar;
+------+-----------+
| bar  | foo       |
+------+-----------+
|    1 | one       |
|    0 | zero      |
|   -1 | minus one |
+------+-----------+
3 rows in set (0.00 sec)

#!/usr/local/bin/perl -w
use DBI;
my $dbh = DBI->connect('DBI:mysql:database=test');
my $sql = "SELECT * FROM bar";
my $sth = $dbh->prepare($sql) || die $DBH::errstr;
$sth->execute;
while ( @row = $sth->fetchrow_array ) {
  $row[0] && print "$row[1]\n";
}
$dbh->disconnect;

$ ./minus.pl
Name "DBH::errstr" used only once: possible typo at ./minus.pl line 6.
one
minus one

paul

--
paul@stripped
Thread
Mysql.pm??Thomas Stevenson19 Feb
  • Re: Mysql.pm??Paul Sharpe19 Feb