~ubuntu-branches/ubuntu/karmic/mysql-dfsg-5.1/karmic

« back to all changes in this revision

Viewing changes to sql/tztime.cc

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug
  • Date: 2009-06-25 12:55:45 UTC
  • mfrom: (0.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20090625125545-v27uqh8rlsj8uh2y
Tags: upstream-5.1.34
ImportĀ upstreamĀ versionĀ 5.1.34

Show diffs side-by-side

added added

removed removed

Lines of Context:
1825
1825
#ifdef ABBR_ARE_USED
1826
1826
  char chars[max(TZ_MAX_CHARS + 1, (2 * (MY_TZNAME_MAX + 1)))];
1827
1827
#endif
 
1828
  /* 
 
1829
    Used as a temporary tz_info until we decide that we actually want to
 
1830
    allocate and keep the tz info and tz name in tz_storage.
 
1831
  */
 
1832
  TIME_ZONE_INFO tmp_tz_info;
 
1833
  memset(&tmp_tz_info, 0, sizeof(TIME_ZONE_INFO));
 
1834
 
1828
1835
  DBUG_ENTER("tz_load_from_open_tables");
1829
1836
 
1830
1837
  /* Prepare tz_info for loading also let us make copy of time zone name */
1866
1873
      Most probably user has mistyped time zone name, so no need to bark here
1867
1874
      unless we need it for debugging.
1868
1875
    */
1869
 
    sql_print_error("Can't find description of time zone '%s'", tz_name_buff);
 
1876
     sql_print_error("Can't find description of time zone '%.*s'", 
 
1877
                     tz_name->length(), tz_name->ptr());
1870
1878
#endif
1871
1879
    goto end;
1872
1880
  }
1895
1903
  /* If Uses_leap_seconds == 'Y' */
1896
1904
  if (table->field[1]->val_int() == 1)
1897
1905
  {
1898
 
    tz_info->leapcnt= tz_leapcnt;
1899
 
    tz_info->lsis= tz_lsis;
 
1906
    tmp_tz_info.leapcnt= tz_leapcnt;
 
1907
    tmp_tz_info.lsis= tz_lsis;
1900
1908
  }
1901
1909
 
1902
1910
  (void)table->file->ha_index_end();
1932
1940
#ifdef ABBR_ARE_USED
1933
1941
    // FIXME should we do something with duplicates here ?
1934
1942
    table->field[4]->val_str(&abbr, &abbr);
1935
 
    if (tz_info->charcnt + abbr.length() + 1 > sizeof(chars))
 
1943
    if (tmp_tz_info.charcnt + abbr.length() + 1 > sizeof(chars))
1936
1944
    {
1937
1945
      sql_print_error("Error while loading time zone description from "
1938
1946
                      "mysql.time_zone_transition_type table: not enough "
1939
1947
                      "room for abbreviations");
1940
1948
      goto end;
1941
1949
    }
1942
 
    ttis[ttid].tt_abbrind= tz_info->charcnt;
1943
 
    memcpy(chars + tz_info->charcnt, abbr.ptr(), abbr.length());
1944
 
    tz_info->charcnt+= abbr.length();
1945
 
    chars[tz_info->charcnt]= 0;
1946
 
    tz_info->charcnt++;
 
1950
    ttis[ttid].tt_abbrind= tmp_tz_info.charcnt;
 
1951
    memcpy(chars + tmp_tz_info.charcnt, abbr.ptr(), abbr.length());
 
1952
    tmp_tz_info.charcnt+= abbr.length();
 
1953
    chars[tmp_tz_info.charcnt]= 0;
 
1954
    tmp_tz_info.charcnt++;
1947
1955
 
1948
1956
    DBUG_PRINT("info",
1949
1957
      ("time_zone_transition_type table: tz_id=%u tt_id=%u tt_gmtoff=%ld "
1956
1964
#endif
1957
1965
 
1958
1966
    /* ttid is increasing because we are reading using index */
1959
 
    DBUG_ASSERT(ttid >= tz_info->typecnt);
 
1967
    DBUG_ASSERT(ttid >= tmp_tz_info.typecnt);
1960
1968
 
1961
 
    tz_info->typecnt= ttid + 1;
 
1969
    tmp_tz_info.typecnt= ttid + 1;
1962
1970
 
1963
1971
    res= table->file->index_next_same(table->record[0],
1964
1972
                                      table->field[0]->ptr, 4);
1990
1998
    ttime= (my_time_t)table->field[1]->val_int();
1991
1999
    ttid= (uint)table->field[2]->val_int();
1992
2000
 
1993
 
    if (tz_info->timecnt + 1 > TZ_MAX_TIMES)
 
2001
    if (tmp_tz_info.timecnt + 1 > TZ_MAX_TIMES)
1994
2002
    {
1995
2003
      sql_print_error("Error while loading time zone description from "
1996
2004
                      "mysql.time_zone_transition table: "
1997
2005
                      "too much transitions");
1998
2006
      goto end;
1999
2007
    }
2000
 
    if (ttid + 1 > tz_info->typecnt)
 
2008
    if (ttid + 1 > tmp_tz_info.typecnt)
2001
2009
    {
2002
2010
      sql_print_error("Error while loading time zone description from "
2003
2011
                      "mysql.time_zone_transition table: "
2005
2013
      goto end;
2006
2014
    }
2007
2015
 
2008
 
    ats[tz_info->timecnt]= ttime;
2009
 
    types[tz_info->timecnt]= ttid;
2010
 
    tz_info->timecnt++;
 
2016
    ats[tmp_tz_info.timecnt]= ttime;
 
2017
    types[tmp_tz_info.timecnt]= ttid;
 
2018
    tmp_tz_info.timecnt++;
2011
2019
 
2012
2020
    DBUG_PRINT("info",
2013
2021
      ("time_zone_transition table: tz_id: %u  tt_time: %lu  tt_id: %u",
2032
2040
  table= 0;
2033
2041
 
2034
2042
  /*
 
2043
    Let us check how correct our time zone description is. We don't check for
 
2044
    tz->timecnt < 1 since it is ok for GMT.
 
2045
  */
 
2046
  if (tmp_tz_info.typecnt < 1)
 
2047
  {
 
2048
    sql_print_error("loading time zone without transition types");
 
2049
    goto end;
 
2050
  }
 
2051
 
 
2052
  /* Allocate memory for the timezone info and timezone name in tz_storage. */
 
2053
  if (!(alloc_buff= (char*) alloc_root(&tz_storage, sizeof(TIME_ZONE_INFO) +
 
2054
                                       tz_name->length() + 1)))
 
2055
  {
 
2056
    sql_print_error("Out of memory while loading time zone description");
 
2057
    return 0;
 
2058
  }
 
2059
 
 
2060
  /* Move the temporary tz_info into the allocated area */
 
2061
  tz_info= (TIME_ZONE_INFO *)alloc_buff;
 
2062
  memcpy(tz_info, &tmp_tz_info, sizeof(TIME_ZONE_INFO));
 
2063
  tz_name_buff= alloc_buff + sizeof(TIME_ZONE_INFO);
 
2064
  /*
 
2065
    By writing zero to the end we guarantee that we can call ptr()
 
2066
    instead of c_ptr() for time zone name.
 
2067
  */
 
2068
  strmake(tz_name_buff, tz_name->ptr(), tz_name->length());
 
2069
 
 
2070
  /*
2035
2071
    Now we will allocate memory and init TIME_ZONE_INFO structure.
2036
2072
  */
2037
2073
  if (!(alloc_buff= (char*) alloc_root(&tz_storage,
2062
2098
  tz_info->ttis= (TRAN_TYPE_INFO *)alloc_buff;
2063
2099
  memcpy(tz_info->ttis, ttis, tz_info->typecnt * sizeof(TRAN_TYPE_INFO));
2064
2100
 
2065
 
  /*
2066
 
    Let us check how correct our time zone description and build
2067
 
    reversed map. We don't check for tz->timecnt < 1 since it ok for GMT.
2068
 
  */
2069
 
  if (tz_info->typecnt < 1)
2070
 
  {
2071
 
    sql_print_error("loading time zone without transition types");
2072
 
    goto end;
2073
 
  }
 
2101
  /* Build reversed map. */
2074
2102
  if (prepare_tz_info(tz_info, &tz_storage))
2075
2103
  {
2076
2104
    sql_print_error("Unable to build mktime map for time zone");