Support NULL values for non-string database fields

develop
Sven Slootweg 11 years ago
parent 6e923629e0
commit 85371b3394

@ -226,76 +226,87 @@ abstract class CPHPDatabaseRecordClass extends CPHPBaseClass
$original_value = $this->uData[$column_name]; $original_value = $this->uData[$column_name];
switch($type) if($original_value === "" && ($type == "timestamp" || $type == "numeric" || $type == "boolean"))
{ {
case "string": $variable_name_safe = "s" . $variable_name;
$value = htmlspecialchars(stripslashes($original_value)); $this->$variable_name_safe = null;
$variable_type = CPHP_VARIABLE_SAFE;
break; $variable_name_unsafe = "u" . $variable_name;
case "html": $this->$variable_name_unsafe = null;
$value = filter_html(stripslashes($original_value)); }
$variable_type = CPHP_VARIABLE_SAFE; else
break; {
case "simplehtml": switch($type)
$value = filter_html_strict(stripslashes($original_value)); {
$variable_type = CPHP_VARIABLE_SAFE; case "string":
break; $value = htmlspecialchars(stripslashes($original_value));
case "nl2br": $variable_type = CPHP_VARIABLE_SAFE;
$value = nl2br(htmlspecialchars(stripslashes($original_value)), false); break;
$variable_type = CPHP_VARIABLE_SAFE; case "html":
break; $value = filter_html(stripslashes($original_value));
case "numeric": $variable_type = CPHP_VARIABLE_SAFE;
$value = (is_numeric($original_value)) ? $original_value : 0; break;
$variable_type = CPHP_VARIABLE_SAFE; case "simplehtml":
break; $value = filter_html_strict(stripslashes($original_value));
case "timestamp": $variable_type = CPHP_VARIABLE_SAFE;
$value = unix_from_mysql($original_value); break;
$variable_type = CPHP_VARIABLE_SAFE; case "nl2br":
break; $value = nl2br(htmlspecialchars(stripslashes($original_value)), false);
case "boolean": $variable_type = CPHP_VARIABLE_SAFE;
$value = (empty($original_value)) ? false : true; break;
$variable_type = CPHP_VARIABLE_SAFE; case "numeric":
break; $value = (is_numeric($original_value)) ? $original_value : 0;
case "none": $variable_type = CPHP_VARIABLE_SAFE;
$value = $original_value; break;
$variable_type = CPHP_VARIABLE_UNSAFE; case "timestamp":
break; $value = unix_from_mysql($original_value);
default: $variable_type = CPHP_VARIABLE_SAFE;
$found = false; break;
foreach(get_object_vars($cphp_config->class_map) as $class_type => $class_name) case "boolean":
{ $value = (empty($original_value)) ? false : true;
if($type == $class_type) $variable_type = CPHP_VARIABLE_SAFE;
break;
case "none":
$value = $original_value;
$variable_type = CPHP_VARIABLE_UNSAFE;
break;
default:
$found = false;
foreach(get_object_vars($cphp_config->class_map) as $class_type => $class_name)
{ {
try if($type == $class_type)
{ {
$value = new $class_name($original_value); try
} {
catch (NotFoundException $e) $value = new $class_name($original_value);
{ }
$e->field = $variable_name; catch (NotFoundException $e)
throw $e; {
$e->field = $variable_name;
throw $e;
}
$variable_type = CPHP_VARIABLE_SAFE;
$found = true;
} }
$variable_type = CPHP_VARIABLE_SAFE;
$found = true;
} }
}
if($found == false)
if($found == false) {
{ $classname = get_class($this);
$classname = get_class($this); throw new Exception("Cannot determine type of dataset ({$type}) passed on to {$classname}.BindDataset.");
throw new Exception("Cannot determine type of dataset ({$type}) passed on to {$classname}.BindDataset."); break;
break; }
} }
}
if($variable_type == CPHP_VARIABLE_SAFE)
if($variable_type == CPHP_VARIABLE_SAFE) {
{ $variable_name_safe = "s" . $variable_name;
$variable_name_safe = "s" . $variable_name; $this->$variable_name_safe = $value;
$this->$variable_name_safe = $value; }
$variable_name_unsafe = "u" . $variable_name;
$this->$variable_name_unsafe = $original_value;
} }
$variable_name_unsafe = "u" . $variable_name;
$this->$variable_name_unsafe = $original_value;
} }
public function FillDefaults() public function FillDefaults()

Loading…
Cancel
Save