Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
moodler committed Dec 30, 2002
1 parent 4fd7ccc commit b3fa668
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/datalib.php
Expand Up @@ -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;
Expand Down

0 comments on commit b3fa668

Please sign in to comment.