Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Now postgres works as it should, returned primarykeys are correct.

  • Loading branch information...
commit 9655b654a5f1273dda01fde096eaa9215a21772e 1 parent 6492992
authored April 28, 2003

Showing 1 changed file with 13 additions and 2 deletions. Show diff stats Hide diff stats

  1. 15  lib/datalib.php
15  lib/datalib.php
@@ -567,13 +567,15 @@ function insert_record($table, $dataobject, $returnid=true) {
567 567
     if (! $columns = $db->MetaColumns("$CFG->prefix$table")) {
568 568
         return false;
569 569
     }
570  
-
571 570
     $data = (array)$dataobject;
572 571
 
573 572
     // Pull out data from the dataobject that matches the fields in the table.
574 573
     // If fields are missing or empty, then try to set the defaults explicitly
575 574
     // because some databases (eg PostgreSQL) don't always set them properly
576 575
     foreach ($columns as $column) {
  576
+        if(isset($column->primary_key) and $column->primary_key == 1) {
  577
+            $pkey = $column->name; // take column name of primary key
  578
+        }    
577 579
         if ($column->name <> "id") {
578 580
             if (isset($data[$column->name])) { 
579 581
                 if ((string)$data[$column->name] == "" and !empty($column->has_default) and !empty($column->default_value)) {
@@ -622,7 +624,16 @@ function insert_record($table, $dataobject, $returnid=true) {
622 624
             return $db->Insert_ID();   // ADOdb has stored the ID for us, but it isn't reliable
623 625
         }
624 626
         
625  
-        
  627
+        if ($CFG->dbtype == "postgres7" and isset($pkey)){
  628
+            $oid = $db->Insert_ID();
  629
+            if ($rs = $db->Execute("SELECT $pkey FROM $CFG->prefix$table WHERE 'oid' = $oid")) {
  630
+                if ($rs->RecordCount() == 1) {
  631
+                    return $rs->fields[0];
  632
+                } else {
  633
+                    return false;
  634
+                }
  635
+            }
  636
+        }    
626 637
         // Try to pull the record out again to find the id.  This is the most cross-platform method.
627 638
         if ($rs = $db->Execute("SELECT id FROM $CFG->prefix$table WHERE $select")) {
628 639
             if ($rs->RecordCount() == 1) {

0 notes on commit 9655b65

Please sign in to comment.
Something went wrong with that request. Please try again.