Browse files

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...
1 parent 4fd7ccc commit b3fa6684eaca58482bbdf1bcdafa5f4e3132857c moodler committed Dec 30, 2002
Showing with 16 additions and 3 deletions.
  1. +16 −3 lib/datalib.php
View
19 lib/datalib.php
@@ -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;

0 comments on commit b3fa668

Please sign in to comment.