You are here

function yr_verdata_update_6101 in Yr Weatherdata 6

Implementation of hook_update_N().

File

./yr_verdata.install, line 104
The install schema and hooks for yr_verdata.module.

Code

function yr_verdata_update_6101() {
  $ret = array();
  db_add_field($ret, 'yr_verdata', 'location', array(
    'type' => 'varchar',
    'length' => 20,
    'not null' => TRUE,
    'default' => '',
  ));
  db_add_field($ret, 'yr_verdata', 'subregion', array(
    'type' => 'varchar',
    'length' => 20,
    'not null' => TRUE,
    'default' => '',
  ));
  db_add_field($ret, 'yr_verdata', 'region', array(
    'type' => 'varchar',
    'length' => 20,
    'not null' => TRUE,
    'default' => '',
  ));
  db_add_field($ret, 'yr_verdata', 'country', array(
    'type' => 'varchar',
    'length' => 20,
    'not null' => TRUE,
    'default' => '',
  ));
  $sql = "SELECT * FROM {yr_verdata}";
  $result = db_query($sql);
  while ($row = db_fetch_object($result)) {
    $comps = explode('/', $row->url);
    $location = !empty($comps[4]) ? $comps[4] : 'x';
    $args = array(
      $comps[1],
      $comps[2],
      $comps[3],
      $location,
      $row->yid,
    );
    update_sql("UPDATE {yr_verdata} SET location = '{$location}', subregion = '{$comps[3]}', region = '{$comps[2]}', country = '{$comps[1]}' WHERE yid = {$row->yid}");
  }
  return $ret;
}