List:Internals« Previous MessageNext Message »
From:jimw Date:January 14 2005 3:23am
Subject:bk commit into 5.0 tree (jimw:1.1761)
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of jimw. When jimw 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.1761 05/01/13 18:23:34 jimw@stripped +5 -0
  In TRADITIONAL mode, don't allow a NOT NULL field with no default be set to
  DEFAULT (with no argument) or to the field's type's default by not being
  listed in the list of fields being inserted. (Bug #5986)                    

  mysql-test/r/strict.result
    1.13 05/01/13 17:53:05 jimw@stripped +37 -0
    Add results

  mysql-test/t/strict.test
    1.10 05/01/13 17:52:45 jimw@stripped +34 -0
    Add tests for setting fields to DEFAULT in traditional and regular modes

  sql/sql_insert.cc
    1.137 05/01/13 17:51:45 jimw@stripped +2 -1
    Call check_that_all_fields_are_given_values() if no values were
    given and we would be filling row with all default values

  sql/item.h
    1.96 05/01/13 10:49:13 jimw@stripped +1 -9
    Implementation of Item_default_value::save_in_field moved to item.cc

  sql/item.cc
    1.105 05/01/13 10:48:31 jimw@stripped +22 -0
    Add Item_default_value::save_in_field(), with check for setting fields
    with no default value set.

# 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:	jimw
# Host:	rama.(none)
# Root:	/home/jimw/my/mysql-5.0-5986

--- 1.104/sql/item.cc	2005-01-06 02:59:58 -08:00
+++ 1.105/sql/item.cc	2005-01-13 10:48:31 -08:00
@@ -3204,6 +3204,7 @@
   return FALSE;
 }
 
+
 void Item_default_value::print(String *str)
 {
   if (!arg)
@@ -3215,6 +3216,27 @@
   arg->print(str);
   str->append(')');
 }
+
+
+int Item_default_value::save_in_field(Field *field_arg, bool no_conversions)
+{
+  if (!arg)
+  {
+    if (field_arg->flags & NO_DEFAULT_VALUE_FLAG)
+    {
+      push_warning_printf(field_arg->table->in_use,
+                          MYSQL_ERROR::WARN_LEVEL_WARN,
+                          ER_NO_DEFAULT_FOR_FIELD,
+                          ER(ER_NO_DEFAULT_FOR_FIELD),
+                          field_arg->field_name);
+      return 1;
+    }
+    field_arg->set_default();
+    return 0;
+  }
+  return Item_field::save_in_field(field_arg, no_conversions);
+}
+
 
 bool Item_insert_value::eq(const Item *item, bool binary_cmp) const
 {

--- 1.95/sql/item.h	2004-12-30 14:41:16 -08:00
+++ 1.96/sql/item.h	2005-01-13 10:49:13 -08:00
@@ -1316,15 +1316,7 @@
   bool eq(const Item *item, bool binary_cmp) const;
   bool fix_fields(THD *, struct st_table_list *, Item **);
   void print(String *str);
-  int save_in_field(Field *field_arg, bool no_conversions)
-  {
-    if (!arg)
-    {
-      field_arg->set_default();
-      return 0;
-    }
-    return Item_field::save_in_field(field_arg, no_conversions);
-  }
+  int save_in_field(Field *field_arg, bool no_conversions);
   table_map used_tables() const { return (table_map)0L; }
   
   bool walk(Item_processor processor, byte *args)

--- 1.136/sql/sql_insert.cc	2005-01-10 11:54:43 -08:00
+++ 1.137/sql/sql_insert.cc	2005-01-13 17:51:45 -08:00
@@ -311,7 +311,8 @@
                            (MODE_STRICT_TRANS_TABLES |
                             MODE_STRICT_ALL_TABLES)));
 
-  if (fields.elements && check_that_all_fields_are_given_values(thd, table))
+  if ((fields.elements || !value_count) &&
+      check_that_all_fields_are_given_values(thd, table))
   {
     /* thd->net.report_error is now set, which will abort the next loop */
     error= 1;

--- 1.12/mysql-test/r/strict.result	2005-01-11 10:52:13 -08:00
+++ 1.13/mysql-test/r/strict.result	2005-01-13 17:53:05 -08:00
@@ -921,3 +921,40 @@
 3	
 99	
 DROP TABLE t1;
+SET @@sql_mode = 'traditional';
+CREATE TABLE t1 (i int not null);
+INSERT INTO t1 VALUES ();
+ERROR HY000: Field 'i' doesn't have a default value
+INSERT INTO t1 VALUES (DEFAULT);
+ERROR HY000: Field 'i' doesn't have a default value
+INSERT INTO t1 VALUES (DEFAULT(i));
+ERROR HY000: Field 'i' doesn't have a default value
+ALTER TABLE t1 ADD j int;
+INSERT INTO t1 SET j = 1;
+ERROR HY000: Field 'i' doesn't have a default value
+INSERT INTO t1 SET j = 1, i = DEFAULT;
+ERROR HY000: Field 'i' doesn't have a default value
+INSERT INTO t1 SET j = 1, i = DEFAULT(i);
+ERROR HY000: Field 'i' doesn't have a default value
+INSERT INTO t1 VALUES (DEFAULT,1);
+ERROR HY000: Field 'i' doesn't have a default value
+DROP TABLE t1;
+SET @@sql_mode = '';
+CREATE TABLE t1 (i int not null);
+INSERT INTO t1 VALUES ();
+INSERT INTO t1 VALUES (DEFAULT);
+Warnings:
+Warning	1364	Field 'i' doesn't have a default value
+INSERT INTO t1 VALUES (DEFAULT(i));
+ERROR HY000: Field 'i' doesn't have a default value
+ALTER TABLE t1 ADD j int;
+INSERT INTO t1 SET j = 1;
+INSERT INTO t1 SET j = 1, i = DEFAULT;
+Warnings:
+Warning	1364	Field 'i' doesn't have a default value
+INSERT INTO t1 SET j = 1, i = DEFAULT(i);
+ERROR HY000: Field 'i' doesn't have a default value
+INSERT INTO t1 VALUES (DEFAULT,1);
+Warnings:
+Warning	1364	Field 'i' doesn't have a default value
+DROP TABLE t1;

--- 1.9/mysql-test/t/strict.test	2005-01-11 10:51:52 -08:00
+++ 1.10/mysql-test/t/strict.test	2005-01-13 17:52:45 -08:00
@@ -638,3 +638,37 @@
 INSERT IGNORE INTO t1 () values ();
 SELECT * FROM t1;
 DROP TABLE t1;
+
+# Test fields with no default value that are NOT NULL (Bug #5986)
+SET @@sql_mode = 'traditional';
+CREATE TABLE t1 (i int not null);
+--error 1364
+INSERT INTO t1 VALUES ();
+--error 1364
+INSERT INTO t1 VALUES (DEFAULT);
+--error 1364
+INSERT INTO t1 VALUES (DEFAULT(i));
+ALTER TABLE t1 ADD j int;
+--error 1364
+INSERT INTO t1 SET j = 1;
+--error 1364
+INSERT INTO t1 SET j = 1, i = DEFAULT;
+--error 1364
+INSERT INTO t1 SET j = 1, i = DEFAULT(i);
+--error 1364
+INSERT INTO t1 VALUES (DEFAULT,1);
+DROP TABLE t1;
+SET @@sql_mode = '';
+CREATE TABLE t1 (i int not null);
+INSERT INTO t1 VALUES ();
+INSERT INTO t1 VALUES (DEFAULT);
+# DEFAULT(i) is an error even with the default sql_mode
+--error 1364
+INSERT INTO t1 VALUES (DEFAULT(i));
+ALTER TABLE t1 ADD j int;
+INSERT INTO t1 SET j = 1;
+INSERT INTO t1 SET j = 1, i = DEFAULT;
+--error 1364
+INSERT INTO t1 SET j = 1, i = DEFAULT(i);
+INSERT INTO t1 VALUES (DEFAULT,1);
+DROP TABLE t1;
Thread
bk commit into 5.0 tree (jimw:1.1761)jimw14 Jan