_geo_field_save

geo/modules/geo_field/geo_field.module, line 238

Versions
6
_geo_field_save($op, $node, $field, $items)

Save function for Geo fields. Because the storage function includes some calls to database functions, they include quotes that are escaped by the default query substitutions. Save the value manually instead.

▾ 2 functions call _geo_field_save()

geo_field in geo/modules/geo_field/geo_field.module
Implementation of hook_field().
geo_field in geo/modules/geo_field/geo_field.module
Implementation of hook_field().

Code

<?php
function _geo_field_save($op, $node, $field, $items) {
  $table = $table  = _geo_field_tablename($field);
  $schema = drupal_get_schema($table);

  db_query("DELETE FROM {". $table ."} WHERE vid = %d", $node->vid);
  foreach ($items as $delta => $item) {
    if (geo_content_is_empty($item, $field)) continue;
    $columns = $values = $holders = array();
    $record = array(
      'nid' => $node->nid,
      'vid' => $node->vid,
      'delta' => $delta,
    );
    foreach ($schema['fields'] as $column => $info) {
      $key = str_replace($field['field_name'] .'_', '', $column);
      $columns[] = $column;

      if (substr($column, -4) == '_geo') {
        // No substitution for our geo column and omit the corresponding value.
        $srid = (int) $field['srid'] ? $field['srid'] : GEO_SRID_DEFAULT;
        $holders[] = "GeomFromText('". db_escape_string($item['wkt']) ."', $srid)";
      }
      else {
        $holders[] = db_type_placeholder($info['type']);
        $values[] = isset($record[$column]) ? $record[$column] : $item[$key];
      }
    }

    db_query("INSERT INTO {". $table ."} (". implode(', ', $columns) .') 
      VALUES ('. implode(', ', $holders) .')', $values);
  }
}
?>