Replace blank strings with null - see http://www.silverstripe.com/general-discussion/flat/5050?start=8 (merged from 2.1.0 branch, r42173)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@42917 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Andrew O'Neil 2007-10-02 04:46:33 +00:00
parent 3a6556bbd0
commit 5062c955e0

View File

@ -355,6 +355,7 @@ abstract class Database extends Object {
if(!isset($writeInfo['fields']['ID']) && isset($writeInfo['id'])) {
$fieldList .= ", ID = $writeInfo[id]";
}
$fieldList = Database::replace_with_null($fieldList);
$sql = "insert into `$table` SET $fieldList";
$this->query($sql);
break;
@ -367,6 +368,23 @@ abstract class Database extends Object {
}
}
/** Replaces "''" with "null", recursively walks through the given array.
* @param string $array Array where the replacement should happen
*/
static function replace_with_null(&$array) {
$array = str_replace('\'\'', "null", $array);
if(is_array($array)) {
foreach($array as $key => $value) {
if(is_array($value)) {
array_walk($array, array(Database, 'replace_with_null'));
}
}
}
return $array;
}
/**
* Error handler for database errors.
* All database errors will call this function to report the error. It isn't a static function;