Commit 29a62c11 authored by unknown's avatar unknown
Browse files

Merge bk-internal.mysql.com:/home/bk/mysql-4.1

into mysql.com:/home/dlenev/src/mysql-4.1-ryan


sql/field.cc:
  Auto merged
sql/field.h:
  Auto merged
sql/ha_innodb.cc:
  Auto merged
sql/ha_ndbcluster.cc:
  Auto merged
sql/sql_base.cc:
  Auto merged
sql/sql_show.cc:
  Auto merged
sql/sql_table.cc:
  Auto merged
parents 0db72d6e 7b511544
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -365,6 +365,35 @@ select * from t1;
t1	i
2004-04-01 00:00:00	10
drop table t1;
create table t1 (a timestamp null, b timestamp null);
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `a` timestamp NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `b` timestamp NULL default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
insert into t1 values (NULL, NULL);
SET TIMESTAMP=1000000017;
insert into t1 values ();
select * from t1;
a	b
NULL	NULL
2001-09-09 04:46:57	NULL
drop table t1;
create table t1 (a timestamp null default null, b timestamp null default '2003-01-01 00:00:00');
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `a` timestamp NULL default NULL,
  `b` timestamp NULL default '2003-01-01 00:00:00'
) ENGINE=MyISAM DEFAULT CHARSET=latin1
insert into t1 values (NULL, NULL);
insert into t1 values (DEFAULT, DEFAULT);
select * from t1;
a	b
NULL	NULL
NULL	2003-01-01 00:00:00
drop table t1;
create table t1 (ts timestamp(19));
show create table t1;
Table	Create Table
+20 −0
Original line number Diff line number Diff line
@@ -234,7 +234,27 @@ alter table t1 add i int default 10;
select * from t1;
drop table t1;

#
# Test for TIMESTAMP columns which are able to store NULLs
# (Auto-set property should work for them and NULL values
#  should be OK as default values)
#
create table t1 (a timestamp null, b timestamp null);
show create table t1;
insert into t1 values (NULL, NULL);
SET TIMESTAMP=1000000017;
insert into t1 values ();
select * from t1;
drop table t1;

create table t1 (a timestamp null default null, b timestamp null default '2003-01-01 00:00:00');
show create table t1;
insert into t1 values (NULL, NULL);
insert into t1 values (DEFAULT, DEFAULT);
select * from t1;
drop table t1;

#
# Test for bug #4491, TIMESTAMP(19) should be possible to create and not
# only read in 4.0
#
+30 −17
Original line number Diff line number Diff line
@@ -2932,11 +2932,12 @@ void Field_double::sql_type(String &res) const
 */

Field_timestamp::Field_timestamp(char *ptr_arg, uint32 len_arg,
                                 uchar *null_ptr_arg, uchar null_bit_arg,
				 enum utype unireg_check_arg,
				 const char *field_name_arg,
				 struct st_table *table_arg,
				 CHARSET_INFO *cs)
  :Field_str(ptr_arg, 19, (uchar*) 0,0,
  :Field_str(ptr_arg, 19, null_ptr_arg, null_bit_arg,
	     unireg_check_arg, field_name_arg, table_arg, cs)
{
  /* For 4.0 MYD and 4.0 InnoDB compatibility */
@@ -2952,23 +2953,33 @@ Field_timestamp::Field_timestamp(char *ptr_arg, uint32 len_arg,


/*
    Sets TABLE::timestamp_default_now and TABLE::timestamp_on_update_now 
    members according to unireg type of this TIMESTAMP field.
  Get auto-set type for TIMESTAMP field.

  SYNOPSIS
    Field_timestamp::set_timestamp_offsets()
    get_auto_set_type()

  DESCRIPTION
    Returns value indicating during which operations this TIMESTAMP field
    should be auto-set to current timestamp.
*/
void Field_timestamp::set_timestamp_offsets()
timestamp_auto_set_type Field_timestamp::get_auto_set_type() const
{
  ulong timestamp= (ulong) (ptr - (char*) table->record[0]) + 1;
  
  DBUG_ASSERT(table->timestamp_field == this && unireg_check != NONE);

  table->timestamp_default_now= 
    (unireg_check == TIMESTAMP_UN_FIELD)? 0 : timestamp;
  table->timestamp_on_update_now= 
    (unireg_check == TIMESTAMP_DN_FIELD)? 0 : timestamp;
  switch (unireg_check)
  {
  case TIMESTAMP_DN_FIELD:
    return TIMESTAMP_AUTO_SET_ON_INSERT;
  case TIMESTAMP_UN_FIELD:
    return TIMESTAMP_AUTO_SET_ON_UPDATE;
  case TIMESTAMP_DNUN_FIELD:
    return TIMESTAMP_AUTO_SET_ON_BOTH;
  default:
    /*
      Normally this function should not be called for TIMESTAMPs without
      auto-set property.
    */
    DBUG_ASSERT(0);
    return TIMESTAMP_NO_AUTO_SET;
  }
}


@@ -3267,6 +3278,7 @@ void Field_timestamp::sql_type(String &res) const
void Field_timestamp::set_time()
{
  long tmp= (long) table->in_use->query_start();
  set_notnull();
#ifdef WORDS_BIGENDIAN
  if (table->db_low_byte_first)
  {
@@ -5985,8 +5997,9 @@ Field *make_field(char *ptr, uint32 field_length,
			      f_is_zerofill(pack_flag) != 0,
			      f_is_dec(pack_flag) == 0);
  case FIELD_TYPE_TIMESTAMP:
    return new Field_timestamp(ptr,field_length,
			       unireg_check, field_name, table, field_charset);
    return new Field_timestamp(ptr,field_length, null_pos, null_bit,
                               unireg_check, field_name, table,
                               field_charset);
  case FIELD_TYPE_YEAR:
    return new Field_year(ptr,field_length,null_pos,null_bit,
			  unireg_check, field_name, table);
+6 −2
Original line number Diff line number Diff line
@@ -683,6 +683,7 @@ class Field_null :public Field_str {
class Field_timestamp :public Field_str {
public:
  Field_timestamp(char *ptr_arg, uint32 len_arg,
                  uchar *null_ptr_arg, uchar null_bit_arg,
		  enum utype unireg_check_arg, const char *field_name_arg,
		  struct st_table *table_arg,
		  CHARSET_INFO *cs);
@@ -712,8 +713,11 @@ class Field_timestamp :public Field_str {
    else
      Field::set_default();
  }
  inline long get_timestamp()
  /* Get TIMESTAMP field value as seconds since begging of Unix Epoch */
  inline long get_timestamp(my_bool *null_value)
  {
    if ((*null_value= is_null()))
      return 0;
#ifdef WORDS_BIGENDIAN
    if (table->db_low_byte_first)
      return sint4korr(ptr);
@@ -725,7 +729,7 @@ class Field_timestamp :public Field_str {
  bool get_date(TIME *ltime,uint fuzzydate);
  bool get_time(TIME *ltime);
  field_cast_enum field_cast_type() { return FIELD_CAST_TIMESTAMP; }
  void set_timestamp_offsets();
  timestamp_auto_set_type get_auto_set_type() const;
};


+2 −1
Original line number Diff line number Diff line
@@ -164,7 +164,8 @@ set_field_to_null_with_conversions(Field *field, bool no_conversions)

  /*
    Check if this is a special type, which will get a special walue
    when set to NULL
    when set to NULL (TIMESTAMP fields which allow setting to NULL
    are handled by first check).
  */
  if (field->type() == FIELD_TYPE_TIMESTAMP)
  {
Loading