[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mysql-internals
Subject:    bk commit into 4.0 tree (dlenev:1.1690)
From:       dlenev () mysql ! com
Date:       2004-01-30 12:13:20
Message-ID: 20040130121320.DEE60C2520 () dlenev ! mshome
[Download RAW message or body]

Below is the list of changes that have just been committed into a local
4.0 repository of dlenev. When dlenev does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://www.mysql.com/doc/I/n/Installing_source_tree.html

ChangeSet
  1.1690 04/01/30 15:13:19 dlenev@mysql.com +6 -0
  Fix for bugs #1885, #2464, #2539. Proper handling of default
  values for TIMESTAMP columns. The solution is not perfect since
  we just silently ignoring default value for first TIMESTAMP 
  column and properly reflecting this fact in SHOW CREATE TABLE.
  We can't give a warning or simply support standard syntax 
  (niladic functions as legal value for default) for first field 
  since it is 4.0 tree.

  sql/sql_show.cc
    1.118 04/01/30 15:13:16 dlenev@mysql.com +12 -2
    Enabled printing of default values in SHOW CREATE TABLE and 
    SHOW COLUMNS for all TIMESTAMP columns except first one.

  sql/sql_parse.cc
    1.358 04/01/30 15:13:16 dlenev@mysql.com +6 -6
    Allowed default values for TIMESTAMP column.

  sql/field.h
    1.54 04/01/30 15:13:16 dlenev@mysql.com +4 -1
    Set proper DEFAULT value for non-first TIMESTAMP column.

  sql/field.cc
    1.84 04/01/30 15:13:16 dlenev@mysql.com +1 -2
    Enabled copying of defaults for TIMESTAMP fields when we are 
    creating table with CREATE TABLE x (SELECT ...)

  mysql-test/t/type_timestamp.test
    1.10 04/01/30 15:13:16 dlenev@mysql.com +30 -3
    Added test for bugs #1885, #2464, #2539
    (proper support of default values for TIMESTAMP columns)

  mysql-test/r/type_timestamp.result
    1.12 04/01/30 15:13:16 dlenev@mysql.com +45 -2
    Added test for bugs #1885, #2464, #2539
    (proper support of default values for TIMESTAMP columns)

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	dlenev
# Host:	dlenev.mshome
# Root:	/home/dlenev/src/mysql-4.0-bg2464

--- 1.83/sql/field.cc	Thu Dec 18 02:13:50 2003
+++ 1.84/sql/field.cc	Fri Jan 30 15:13:16 2004
@@ -5124,8 +5124,7 @@
     interval=0;
   def=0;
   if (!old_field->is_real_null() && ! (flags & BLOB_FLAG) &&
-      old_field->type() != FIELD_TYPE_TIMESTAMP && old_field->ptr &&
-      orig_field)
+      old_field->ptr && orig_field)
   {
     char buff[MAX_FIELD_WIDTH],*pos;
     String tmp(buff,sizeof(buff));

--- 1.53/sql/field.h	Sun Jan 11 13:12:29 2004
+++ 1.54/sql/field.h	Fri Jan 30 15:13:16 2004
@@ -564,7 +564,10 @@
   void set_time();
   virtual void set_default()
   {
-    set_time();
+    if (table->timestamp_field == this)
+      set_time();
+    else
+      Field::set_default();
   }
   inline long get_timestamp()
   {

--- 1.357/sql/sql_parse.cc	Tue Dec 30 14:14:18 2003
+++ 1.358/sql/sql_parse.cc	Fri Jan 30 15:13:16 2004
@@ -3056,12 +3056,12 @@
 
   if (default_value)
   {
-    if (type == FIELD_TYPE_TIMESTAMP)
-    {
-      net_printf(&thd->net, ER_INVALID_DEFAULT, field_name);
-      DBUG_RETURN(1);
-    }
-    else if (default_value->type() == Item::NULL_ITEM)
+    /*
+      We allow specifying value for first TIMESTAMP column 
+      altough it is silently ignored. This should be fixed in 4.1
+      (by proper warning or real support for default values)
+    */
+    if (default_value->type() == Item::NULL_ITEM)
     {
       default_value=0;
       if ((type_modifier & (NOT_NULL_FLAG | AUTO_INCREMENT_FLAG)) ==

--- 1.117/sql/sql_show.cc	Tue Dec 30 14:14:18 2003
+++ 1.118/sql/sql_show.cc	Fri Jan 30 15:13:16 2004
@@ -508,6 +508,12 @@
         field->sql_type(type);
         net_store_data(packet,convert,type.ptr(),type.length());
 
+        /*
+          Altough TIMESTAMP fields can't contain NULL as its value they
+          will accept NULL if you will try to insert such value and will
+          convert it to current TIMESTAMP. So YES here means that NULL 
+          is allowed for assignment but can't be returned.
+        */
         pos=(byte*) ((flags & NOT_NULL_FLAG) &&
                      field->type() != FIELD_TYPE_TIMESTAMP ?
                      "" : "YES");
@@ -517,7 +523,11 @@
                      (field->flags & MULTIPLE_KEY_FLAG) ? "MUL":"");
         net_store_data(packet,convert,(char*) pos);
 
-        if (field->type() == FIELD_TYPE_TIMESTAMP ||
+        /*
+          We handle first TIMESTAMP column in special way because its
+          default value is ignored and current timestamp used instead.
+        */
+        if (table->timestamp_field == field ||
             field->unireg_check == Field::NEXT_NUMBER)
           null_default_value=1;
         if (!null_default_value && !field->is_null())
@@ -888,7 +898,7 @@
     packet->append(type.ptr(),type.length());
 
     has_default= (field->type() != FIELD_TYPE_BLOB &&
-		  field->type() != FIELD_TYPE_TIMESTAMP &&
+		  table->timestamp_field != field &&
 		  field->unireg_check != Field::NEXT_NUMBER);
     if (flags & NOT_NULL_FLAG)
       packet->append(" NOT NULL", 9);

--- 1.11/mysql-test/r/type_timestamp.result	Tue Dec  9 11:58:58 2003
+++ 1.12/mysql-test/r/type_timestamp.result	Fri Jan 30 15:13:16 2004
@@ -122,5 +122,48 @@
 0000-00-00 00:00:00	0000-00-00 00:00:00	0000-00-00 00:00:00	0000-00-00 \
00:00:00	0000-00-00 00:00:00	0000-00-00 00:00:00	0000-00-00 00:00:00  1997-12-31 \
23:47:59	1997-12-31 23:47:59	1997-12-31 23:47:59	1997-12-31 23:47:59	1997-12-31 \
23:47:59	1997-12-31 23:47:59	1997-12-31 23:47:59  drop table t1;
-create table t1 (a timestamp default 1);
-Invalid default value for 'a'
+create table t1 (t1 timestamp default '2003-01-01 00:00:00', 
+t2 timestamp default '2003-01-01 00:00:00');
+set TIMESTAMP=1000000000;
+insert into t1 values();
+select * from t1;
+t1	t2
+2001-09-09 04:46:40	2003-01-01 00:00:00
+show create table t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `t1` timestamp(14) NOT NULL,
+  `t2` timestamp(14) NOT NULL default '2003-01-01 00:00:00'
+) TYPE=MyISAM
+show columns from t1;
+Field	Type	Null	Key	Default	Extra
+t1	timestamp(14)	YES		NULL	
+t2	timestamp(14)	YES		2003-01-01 00:00:00	
+show columns from t1 like 't2';
+Field	Type	Null	Key	Default	Extra
+t2	timestamp(14)	YES		2003-01-01 00:00:00	
+create table t2 (select * from t1);
+show create table t2;
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `t1` timestamp(14) NOT NULL,
+  `t2` timestamp(14) NOT NULL default '2003-01-01 00:00:00'
+) TYPE=MyISAM
+alter table t1 add column t0 timestamp first;
+show create table t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `t0` timestamp(14) NOT NULL,
+  `t1` timestamp(14) NOT NULL default '2003-01-01 00:00:00',
+  `t2` timestamp(14) NOT NULL default '2003-01-01 00:00:00'
+) TYPE=MyISAM
+drop table t1,t2;
+create table t1 (ts1 timestamp, ts2 timestamp);
+set TIMESTAMP=1000000000;
+insert into t1 values ();
+insert into t1 values (DEFAULT, DEFAULT);
+select * from t1;
+ts1	ts2
+2001-09-09 04:46:40	0000-00-00 00:00:00
+2001-09-09 04:46:40	0000-00-00 00:00:00
+drop table t1;

--- 1.9/mysql-test/t/type_timestamp.test	Tue Dec  9 11:58:58 2003
+++ 1.10/mysql-test/t/type_timestamp.test	Fri Jan 30 15:13:16 2004
@@ -73,8 +73,35 @@
 drop table t1;
 
 #
-# Bug #1885
+# Bug #1885, bug #2539. 
+# Not perfect but still sensible attitude towards defaults for TIMESTAMP
+# We will ignore default value for first TIMESTAMP column.
 #
+create table t1 (t1 timestamp default '2003-01-01 00:00:00', 
+                 t2 timestamp default '2003-01-01 00:00:00');
+set TIMESTAMP=1000000000;
+insert into t1 values();
+select * from t1;
+show create table t1;
+show columns from t1;
+show columns from t1 like 't2';
+create table t2 (select * from t1);
+show create table t2;
 
---error 1067
-create table t1 (a timestamp default 1);
+# Ugly, but we can't do anything about this in 4.0
+alter table t1 add column t0 timestamp first;
+show create table t1;
+
+drop table t1,t2;
+
+#
+# Test for bug 2464, DEFAULT keyword in INSERT statement should return
+# default value for column.
+#
+
+create table t1 (ts1 timestamp, ts2 timestamp);
+set TIMESTAMP=1000000000;
+insert into t1 values ();
+insert into t1 values (DEFAULT, DEFAULT);
+select * from t1;
+drop table t1;

-- 
MySQL Internals Mailing List
For list archives: http://lists.mysql.com/internals
To unsubscribe:    http://lists.mysql.com/internals?unsub=mysql-internals@progressive-comp.com



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic