NULL values returning as empty string

NULL values returning as empty string

am 23.10.2007 18:59:24 von Larry Low

I am unable to figure out why but NULL values which from what I read should
be undefined are being defined. See the example below for the column
thold_hi which shows as NULL in the database but the reference
$row->{'thold_hi'} being defined.

I am running mysql 5.0.22 and DBI 1.58.

Example:

my $sql = "SELECT t.lastread,t.thold_hi,t.thold_low,thold_alert,bl_alert
FROM host h LEFT JOIN data_local dl ON h.id=dl.host_id LEFT JOIN
data_template_rrd dr ON dr.local_data_id=dl.id LEFT JOIN thold_data t ON
t.data_id=dr.id WHERE h.description='something' AND
dr.data_source_name='hdd_free'";

my $sth = $dbh->prepare($sql);
$sth->execute();
my $row = $sth->fetchrow_hasref();

if (!defined($row->{'thold_hi'})) {
print "Not Defined\n";
} else {
print "Defined\n";
}


mysql> SELECT t.lastread,t.thold_hi,t.thold_low,thold_alert,bl_alert FROM
host
h LEFT JOIN data_local dl ON h.id=dl.host_id LEFT JOIN data_template_rrd dr
ON
dr.local_data_id=dl.id LEFT JOIN thold_data t ON t.data_id=dr.id WHERE
h.description='something' AND dr.data_source_name='hdd_free';
+----------+----------+-----------+-------------+----------+
| lastread | thold_hi | thold_low | thold_alert | bl_alert |
+----------+----------+-----------+-------------+----------+
| 24997856 | NULL | 25000000 | 1 | 0 |
+----------+----------+-----------+-------------+----------+
1 row in set (0.00 sec)


----
Larry Low
4150 N Drinkwater Blvd., 5th Floor
Scottsdale, AZ 85251
E-mail: llow@telesphere.com'

Telesphere Networks, Inc




--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

RE: NULL values returning as empty string

am 23.10.2007 19:02:29 von Larry Low

Nevermind it seems the thold_hi field is a VARCHAR and the program filling
it is putting in the string NULL.

----
Larry Low
4150 N Drinkwater Blvd., 5th Floor
Scottsdale, AZ 85251
Office: 480.385.7045
E-mail: llow@telesphere.com'

Telesphere Networks, Inc


-----Original Message-----
From: Larry Low [mailto:llow@telesphere.com]
Sent: Tuesday, October 23, 2007 9:59 AM
To: perl@lists.mysql.com
Subject: NULL values returning as empty string

I am unable to figure out why but NULL values which from what I read should
be undefined are being defined. See the example below for the column
thold_hi which shows as NULL in the database but the reference
$row->{'thold_hi'} being defined.

I am running mysql 5.0.22 and DBI 1.58.

Example:

my $sql = "SELECT t.lastread,t.thold_hi,t.thold_low,thold_alert,bl_alert
FROM host h LEFT JOIN data_local dl ON h.id=dl.host_id LEFT JOIN
data_template_rrd dr ON dr.local_data_id=dl.id LEFT JOIN thold_data t ON
t.data_id=dr.id WHERE h.description='something' AND
dr.data_source_name='hdd_free'";

my $sth = $dbh->prepare($sql);
$sth->execute();
my $row = $sth->fetchrow_hasref();

if (!defined($row->{'thold_hi'})) {
print "Not Defined\n";
} else {
print "Defined\n";
}


mysql> SELECT t.lastread,t.thold_hi,t.thold_low,thold_alert,bl_alert FROM
host
h LEFT JOIN data_local dl ON h.id=dl.host_id LEFT JOIN data_template_rrd dr
ON
dr.local_data_id=dl.id LEFT JOIN thold_data t ON t.data_id=dr.id WHERE
h.description='something' AND dr.data_source_name='hdd_free';
+----------+----------+-----------+-------------+----------+
| lastread | thold_hi | thold_low | thold_alert | bl_alert |
+----------+----------+-----------+-------------+----------+
| 24997856 | NULL | 25000000 | 1 | 0 |
+----------+----------+-----------+-------------+----------+
1 row in set (0.00 sec)


----
Larry Low
4150 N Drinkwater Blvd., 5th Floor
Scottsdale, AZ 85251
E-mail: llow@telesphere.com'

Telesphere Networks, Inc




--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=llow@telesphere.com


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

RE: NULL values returning as empty string

am 23.10.2007 19:34:26 von Larry Low

Actually this was a bug in 5.0.22 client showing empty strings as NULL.

----
Larry Low
4150 N Drinkwater Blvd., 5th Floor
Scottsdale, AZ 85251
Office: 480.385.7045
E-mail: llow@telesphere.com'

Telesphere Networks, Inc


-----Original Message-----
From: Larry Low [mailto:llow@telesphere.com]
Sent: Tuesday, October 23, 2007 10:02 AM
To: perl@lists.mysql.com
Subject: RE: NULL values returning as empty string

Nevermind it seems the thold_hi field is a VARCHAR and the program filling
it is putting in the string NULL.

----
Larry Low
4150 N Drinkwater Blvd., 5th Floor
Scottsdale, AZ 85251
Office: 480.385.7045
E-mail: llow@telesphere.com'

Telesphere Networks, Inc


-----Original Message-----
From: Larry Low [mailto:llow@telesphere.com]
Sent: Tuesday, October 23, 2007 9:59 AM
To: perl@lists.mysql.com
Subject: NULL values returning as empty string

I am unable to figure out why but NULL values which from what I read should
be undefined are being defined. See the example below for the column
thold_hi which shows as NULL in the database but the reference
$row->{'thold_hi'} being defined.

I am running mysql 5.0.22 and DBI 1.58.

Example:

my $sql = "SELECT t.lastread,t.thold_hi,t.thold_low,thold_alert,bl_alert
FROM host h LEFT JOIN data_local dl ON h.id=dl.host_id LEFT JOIN
data_template_rrd dr ON dr.local_data_id=dl.id LEFT JOIN thold_data t ON
t.data_id=dr.id WHERE h.description='something' AND
dr.data_source_name='hdd_free'";

my $sth = $dbh->prepare($sql);
$sth->execute();
my $row = $sth->fetchrow_hasref();

if (!defined($row->{'thold_hi'})) {
print "Not Defined\n";
} else {
print "Defined\n";
}


mysql> SELECT t.lastread,t.thold_hi,t.thold_low,thold_alert,bl_alert FROM
host
h LEFT JOIN data_local dl ON h.id=dl.host_id LEFT JOIN data_template_rrd dr
ON
dr.local_data_id=dl.id LEFT JOIN thold_data t ON t.data_id=dr.id WHERE
h.description='something' AND dr.data_source_name='hdd_free';
+----------+----------+-----------+-------------+----------+
| lastread | thold_hi | thold_low | thold_alert | bl_alert |
+----------+----------+-----------+-------------+----------+
| 24997856 | NULL | 25000000 | 1 | 0 |
+----------+----------+-----------+-------------+----------+
1 row in set (0.00 sec)


----
Larry Low
4150 N Drinkwater Blvd., 5th Floor
Scottsdale, AZ 85251
E-mail: llow@telesphere.com'

Telesphere Networks, Inc




--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=llow@telesphere.com


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=llow@telesphere.com


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org