Commit 9237d65d authored by unknown's avatar unknown
Browse files

Merge epotemkin@bk-internal.mysql.com:/home/bk/mysql-4.1-opt

into moonbone.local:/home/evgen/bk-trees/mysql-4.1-opt

parents 8d332655 6297d1ab
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -192,7 +192,7 @@ cast("2001-1-1" as datetime) = "2001-01-01 00:00:00"
1
select cast("1:2:3" as TIME) = "1:02:03";
cast("1:2:3" as TIME) = "1:02:03"
0
1
select cast(NULL as DATE);
cast(NULL as DATE)
NULL
+41 −0
Original line number Diff line number Diff line
@@ -630,3 +630,44 @@ select monthname(str_to_date(null, '%m')), monthname(str_to_date(null, '%m')),
monthname(str_to_date(1, '%m')), monthname(str_to_date(0, '%m'));
monthname(str_to_date(null, '%m'))	monthname(str_to_date(null, '%m'))	monthname(str_to_date(1, '%m'))	monthname(str_to_date(0, '%m'))
NULL	NULL	January	NULL
create table t1(f1 date, f2 time, f3 datetime);
insert into t1 values ("2006-01-01", "12:01:01", "2006-01-01 12:01:01");
insert into t1 values ("2006-01-02", "12:01:02", "2006-01-02 12:01:02");
select f1 from t1 where f1 between "2006-1-1" and 20060101;
f1
2006-01-01
select f1 from t1 where f1 between "2006-1-1" and "2006.1.1";
f1
2006-01-01
select f1 from t1 where date(f1) between "2006-1-1" and "2006.1.1";
f1
2006-01-01
select f2 from t1 where f2 between "12:1:2" and "12:2:2";
f2
12:01:02
select f2 from t1 where time(f2) between "12:1:2" and "12:2:2";
f2
12:01:02
select f3 from t1 where f3 between "2006-1-1 12:1:1" and "2006-1-1 12:1:2";
f3
2006-01-01 12:01:01
select f3 from t1 where timestamp(f3) between "2006-1-1 12:1:1" and "2006-1-1 12:1:2";
f3
2006-01-01 12:01:01
select f1 from t1 where "2006-1-1" between f1 and f3;
f1
2006-01-01
select f1 from t1 where "2006-1-1" between date(f1) and date(f3);
f1
2006-01-01
select f1 from t1 where "2006-1-1" between f1 and 'zzz';
f1
Warnings:
Warning	1292	Truncated incorrect date value: 'zzz'
select f1 from t1 where makedate(2006,1) between date(f1) and date(f3);
f1
2006-01-01
select f1 from t1 where makedate(2006,2) between date(f1) and date(f3);
f1
2006-01-02
drop table t1;
+20 −0
Original line number Diff line number Diff line
@@ -322,4 +322,24 @@ select last_day('2005-01-00');
select monthname(str_to_date(null, '%m')), monthname(str_to_date(null, '%m')),
       monthname(str_to_date(1, '%m')), monthname(str_to_date(0, '%m'));

#
# Bug#16377 result of DATE/TIME functions were compared as strings which
#           can lead to a wrong result.
#
create table t1(f1 date, f2 time, f3 datetime);
insert into t1 values ("2006-01-01", "12:01:01", "2006-01-01 12:01:01");
insert into t1 values ("2006-01-02", "12:01:02", "2006-01-02 12:01:02");
select f1 from t1 where f1 between "2006-1-1" and 20060101;
select f1 from t1 where f1 between "2006-1-1" and "2006.1.1";
select f1 from t1 where date(f1) between "2006-1-1" and "2006.1.1";
select f2 from t1 where f2 between "12:1:2" and "12:2:2";
select f2 from t1 where time(f2) between "12:1:2" and "12:2:2";
select f3 from t1 where f3 between "2006-1-1 12:1:1" and "2006-1-1 12:1:2";
select f3 from t1 where timestamp(f3) between "2006-1-1 12:1:1" and "2006-1-1 12:1:2";
select f1 from t1 where "2006-1-1" between f1 and f3;
select f1 from t1 where "2006-1-1" between date(f1) and date(f3);
select f1 from t1 where "2006-1-1" between f1 and 'zzz';
select f1 from t1 where makedate(2006,1) between date(f1) and date(f3);
select f1 from t1 where makedate(2006,2) between date(f1) and date(f3);
drop table t1;
# End of 4.1 tests
+11 −5
Original line number Diff line number Diff line
@@ -6841,7 +6841,11 @@ create_field::create_field(Field *old_field,Field *orig_field)
bool 
Field::set_warning(const uint level, const uint code, int cuted_increment)
{
  THD *thd= table->in_use;
  /*
    If this field was created only for type conversion purposes it
    will have table == NULL.
  */
  THD *thd= table ? table->in_use : current_thd;
  if (thd->count_cuted_fields)
  {
    thd->cuted_fields+= cuted_increment;
@@ -6876,7 +6880,8 @@ Field::set_datetime_warning(const uint level, const uint code,
                            timestamp_type ts_type, int cuted_increment)
{
  if (set_warning(level, code, cuted_increment))
    make_truncated_value_warning(table->in_use, str, str_length, ts_type);
    make_truncated_value_warning(table ? table->in_use : current_thd,
                                 str, str_length, ts_type);
}


@@ -6905,8 +6910,8 @@ Field::set_datetime_warning(const uint level, const uint code,
  {
    char str_nr[22];
    char *str_end= longlong10_to_str(nr, str_nr, -10);
    make_truncated_value_warning(table->in_use, str_nr, str_end - str_nr, 
                                 ts_type);
    make_truncated_value_warning(table ? table->in_use : current_thd,
                                 str_nr, str_end - str_nr, ts_type);
  }
}

@@ -6935,7 +6940,8 @@ Field::set_datetime_warning(const uint level, const uint code,
    /* DBL_DIG is enough to print '-[digits].E+###' */
    char str_nr[DBL_DIG + 8];
    uint str_len= my_sprintf(str_nr, (str_nr, "%g", nr));
    make_truncated_value_warning(table->in_use, str_nr, str_len, ts_type);
    make_truncated_value_warning(table ? table->in_use : current_thd,
                                 str_nr, str_len, ts_type);
  }
}

+16 −0
Original line number Diff line number Diff line
@@ -327,6 +327,14 @@ class Item {
    cleanup();
    delete this;
  }
  /*
    result_as_longlong() must return TRUE for Items representing DATE/TIME
    functions and DATE/TIME table fields.
    Those Items have result_type()==STRING_RESULT (and not INT_RESULT), but
    their values should be compared as integers (because the integer
    representation is more precise than the string one).
  */
  virtual bool result_as_longlong() { return FALSE; }
};


@@ -450,6 +458,10 @@ class Item_field :public Item_ident
  Item *get_tmp_table_item(THD *thd);
  void cleanup();
  inline uint32 max_disp_length() { return field->max_length(); }
  bool result_as_longlong()
  {
    return field->can_be_compared_as_longlong();
  }
  friend class Item_default_value;
  friend class Item_insert_value;
  friend class st_select_lex_unit;
@@ -973,6 +985,10 @@ class Item_ref :public Item_ident
  }
  Item *real_item() { return *ref; }
  void print(String *str);
  bool result_as_longlong()
  {
    return (*ref)->result_as_longlong();
  }
};


Loading