mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
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)
This commit is contained in:
@@ -921,3 +921,40 @@ col1 col2
|
|||||||
3
|
3
|
||||||
99
|
99
|
||||||
DROP TABLE t1;
|
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;
|
||||||
|
@@ -638,3 +638,37 @@ INSERT IGNORE INTO t1 (col1) values (3);
|
|||||||
INSERT IGNORE INTO t1 () values ();
|
INSERT IGNORE INTO t1 () values ();
|
||||||
SELECT * FROM t1;
|
SELECT * FROM t1;
|
||||||
DROP TABLE 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;
|
||||||
|
22
sql/item.cc
22
sql/item.cc
@@ -3204,6 +3204,7 @@ bool Item_default_value::fix_fields(THD *thd,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Item_default_value::print(String *str)
|
void Item_default_value::print(String *str)
|
||||||
{
|
{
|
||||||
if (!arg)
|
if (!arg)
|
||||||
@@ -3216,6 +3217,27 @@ void Item_default_value::print(String *str)
|
|||||||
str->append(')');
|
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
|
bool Item_insert_value::eq(const Item *item, bool binary_cmp) const
|
||||||
{
|
{
|
||||||
return item->type() == INSERT_VALUE_ITEM &&
|
return item->type() == INSERT_VALUE_ITEM &&
|
||||||
|
10
sql/item.h
10
sql/item.h
@@ -1316,15 +1316,7 @@ public:
|
|||||||
bool eq(const Item *item, bool binary_cmp) const;
|
bool eq(const Item *item, bool binary_cmp) const;
|
||||||
bool fix_fields(THD *, struct st_table_list *, Item **);
|
bool fix_fields(THD *, struct st_table_list *, Item **);
|
||||||
void print(String *str);
|
void print(String *str);
|
||||||
int save_in_field(Field *field_arg, bool no_conversions)
|
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);
|
|
||||||
}
|
|
||||||
table_map used_tables() const { return (table_map)0L; }
|
table_map used_tables() const { return (table_map)0L; }
|
||||||
|
|
||||||
bool walk(Item_processor processor, byte *args)
|
bool walk(Item_processor processor, byte *args)
|
||||||
|
@@ -311,7 +311,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
|
|||||||
(MODE_STRICT_TRANS_TABLES |
|
(MODE_STRICT_TRANS_TABLES |
|
||||||
MODE_STRICT_ALL_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 */
|
/* thd->net.report_error is now set, which will abort the next loop */
|
||||||
error= 1;
|
error= 1;
|
||||||
|
Reference in New Issue
Block a user