PHP Classes

null values lost

Recommend this page to a friend!

      SQL Backup  >  All threads  >  null values lost  >  (Un) Subscribe thread alerts  
Subject:null values lost
Summary:see subject ;)
Messages:4
Author:G. Miernicki
Date:2009-01-13 20:57:04
Update:2009-04-20 18:14:57
 

  1. null values lost   Reply   Report abuse  
Picture of G. Miernicki G. Miernicki - 2009-01-13 20:57:04
This class is great as I've used it in the past on many occasions to backup and restore databases. However, I have just only recently come across a peculiar behavior that it exhibits that is most unexpected and unwanted.

During a backup of the database, all NULL values that are stored are either converted to 0 (INT variable types) or an emptry string (VARCHAR data types).

This is a serious implementation flaw in my mind as you are basically casting the data and destroying it for the most part in these values.

What can be done to correct this? I'm not very familiar with the inderlying code or else I would recommend something....

  2. Re: null values lost   Reply   Report abuse  
Picture of G. Miernicki G. Miernicki - 2009-02-03 18:39:55 - In reply to message 1 from G. Miernicki
been a few weeks... anyone else had this problem?

  3. Re: null values lost   Reply   Report abuse  
Picture of G. Miernicki G. Miernicki - 2009-02-03 21:06:53 - In reply to message 1 from G. Miernicki
I did some research and found the source of the problem. In the _sqlBackup() function, there was no check for NULL values in the code. As such, the insert statements where being made like INSERT ... VALUE("NULL") instead of INSERT ... VALUE(NULL). The quotes are what was the problem, it causes the integer and string fields in some cases to use default values instead of the actual value.

I have corrected the code in class.SQLBackup.php around 173 with the following:

foreach ($theDataRow as $theValue)
{
if ( $theValue == NULL )
{
$theData[] = "NULL";
} else {
$theData[] = $theDB->escape_string($theValue) ;
}
}

$theData = '"'. implode('", "', $theData) .'"' ;
$theData = str_replace('"NULL"', 'NULL', $theData);

Inserting this should correct the problem.

Let's hope the author still checks these forums and updates his code!

-Greg


  4. Re: null values lost   Reply   Report abuse  
Picture of G. Miernicki G. Miernicki - 2009-04-20 18:14:57 - In reply to message 3 from G. Miernicki
3 years to the day since the last update of this class... i'd say the author is on a long vacation if not dead :P