function views_db_object::save_row

Write the row to the database.

Parameters

bool $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.

File

includes/view.inc, line 2290

Class

views_db_object
Base class for views' database objects.

Code

public 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;
        }
    }
}