function views_db_object::save_row

3.x view.inc views_db_object::save_row($update = NULL)
2.x view.inc views_db_object::save_row($update = NULL)

Write the row to the database.

Parameters

$update: If true this will be an UPDATE query. Otherwise it will be an INSERT.

1 call to views_db_object::save_row()
view::save in includes/view.inc
Save the view to the database. If the view does not already exist, A vid will be assigned to the view and also returned from this function.

File

includes/view.inc, line 2199
Provides the view object type and associated methods.

Class

views_db_object
Base class for views' database objects.

Code

function save_row($update = NULL) {
  $fields = $defs = $values = $serials = array();
  $schema = drupal_get_schema($this->db_table);

  // Go through our schema and build correlations.
  foreach ($schema['fields'] as $field => $info) {
    // special case -- skip serial types if we are updating.
    if ($info['type'] == 'serial') {
      $serials[] = $field;
      continue;
    }
    elseif ($info['type'] == 'int') {
      $this->$field = (int) $this->$field;
    }
    $fields[$field] = empty($info['serialize']) ? $this->$field : serialize($this->$field);
  }
  if (!$update) {
    $query = db_insert($this->db_table);
  }
  else {
    $query = db_update($this->db_table)
      ->condition($update, $this->$update);
  }
  $return = $query
  ->fields($fields)
    ->execute();

  if ($serials && !$update) {
    // get last insert ids and fill them in.
    // Well, one ID.
    foreach ($serials as $field) {
      $this->$field = $return;
    }
  }
}