/[drupal]/contributions/modules/importexportapi/engines/importexportapi_db_put.inc
ViewVC logotype

Diff of /contributions/modules/importexportapi/engines/importexportapi_db_put.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.29.4.1, Tue May 5 17:48:44 2009 UTC revision 1.29.4.2, Tue Jul 7 14:08:50 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: importexportapi_db_put.inc,v 1.29 2007/02/07 13:09:25 douggreen Exp $  // $Id: importexportapi_db_put.inc,v 1.29.4.1 2009/05/05 17:48:44 earnie Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 237  function _importexportapi_db_put_sequenc Line 237  function _importexportapi_db_put_sequenc
237  }  }
238    
239  /**  /**
  * Helper function for importexportapi_db_put(). Updates the sequences table to  
  * reflect the value of an ID field being inserted into the database.  
  *  
  * @param $field  
  *   The field for which to update the sequences table.  
  * @param $table  
  *   The table that the field belongs in (with curly brackets already added).  
  * @param $value  
  *   The value that this field has. This value will get added to the sequences  
  *   table, if there is no existing value in the sequences table, or if the  
  *   existing value in the sequences table is lower than this value.  
  * @param $placeholder_map  
  *   A map of field type placeholders.  
  */  
 function _importexportapi_db_put_sequences_update($field, $table, $value, $placeholder_map) {  
   $field_put = $field['#put'];  
   
   if ($field_put['#db_uses_sequences'] && $GLOBALS['db_type'] != 'pgsql') {  
     $sequence_name = $table .'_'. $field_put['#db_field_unaliased'];  
     $result = db_fetch_object(db_query("SELECT id FROM {sequences} WHERE name = '%s'", $sequence_name));  
     if (!empty($result)) {  
       $curr_value = (int) $result->id;  
   
       if ($curr_value < $value) {  
         db_query('UPDATE {sequences} SET id = '. $placeholder_map[$field['#type']] ." WHERE name = '$sequence_name'", $value);  
       }  
     }  
     else {  
       db_query("INSERT INTO {sequences} (name, id) VALUES ('%s', %d)", $sequence_name, $value);  
     }  
   }  
   elseif ($GLOBALS['db_type'] == 'pgsql') {  
     $sequence_name = $table .'_'. $field_put['#db_field_unaliased'] .'_seq';  
     $result = db_fetch_object(db_query('SELECT last_value AS id from '. $sequence_name));  
     if (!empty($result)) {  
       $curr_value = (int) $result->id;  
   
       if ($curr_value < $value) {  
         db_query('SELECT SETVAL(\''. $sequence_name .'\', '. $placeholder_map[$field['#type']] .', FALSE)', $value);  
       }  
     }  
   }  
 }  
   
 /**  
240   * Helper function for importexportapi_db_put(). Converts a data set into an   * Helper function for importexportapi_db_put(). Converts a data set into an
241   * array representation of a set of queries.   * array representation of a set of queries.
242   *   *
# Line 616  function _importexportapi_db_put_generat Line 571  function _importexportapi_db_put_generat
571              }              }
572            }            }
573            else {            else {
574              if (!$force_generate_id) {              if ($force_generate_id) {
               // Case 4  
               _importexportapi_db_put_sequences_update($key_field, $into, $value, $placeholder_map);  
             }  
             else {  
575                // Case 4a: force ID generation for new field                // Case 4a: force ID generation for new field
576                $new_id = _importexportapi_db_put_sequences($key_field, $into, $is_insert, $value, $placeholder_map);                $new_id = _importexportapi_db_put_sequences($key_field, $into, $is_insert, $value, $placeholder_map);
577    

Legend:
Removed from v.1.29.4.1  
changed lines
  Added in v.1.29.4.2

  ViewVC Help
Powered by ViewVC 1.1.2