Fixes to insert_record (from Petri) to explicitly use field default

values if we know them from ADOdb, to avoid some problems with PostgreSQL 7.2 onwards
This commit is contained in:
moodler
2002-12-30 03:25:48 +00:00
parent 4fd7ccc0fe
commit b3fa6684ea
+16 -3
View File
@@ -406,13 +406,26 @@ function insert_record($table, $dataobject, $returnid=true) {
$data = (array)$dataobject;
// Pull out data matching these fields
// Pull out data from the dataobject that matches the fields in the table.
// If fields are missing or empty, then try to set the defaults explicitly
// because some databases (eg PostgreSQL) don't always set them properly
foreach ($columns as $column) {
if ($column->name <> "id" && isset($data[$column->name]) ) {
$ddd[$column->name] = $data[$column->name];
if ($column->name <> "id") {
if (isset($data[$column->name])) {
if ($data[$column->name] == "" and isset($column->has_default)) {
$ddd[$column->name] = $column->default_value;
} else {
$ddd[$column->name] = $data[$column->name];
}
} else {
if (isset($column->has_default)) {
$ddd[$column->name] = $column->default_value;
}
}
}
}
// Construct SQL queries
if (! $numddd = count($ddd)) {
return false;