summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <hf@deer.(none)>2003-06-24 10:53:21 +0500
committerunknown <hf@deer.(none)>2003-06-24 10:53:21 +0500
commit78c24b2bbc5c5ceee870ee31d4a63643617d385d (patch)
tree31d4acfcfe7089167f37ea80cf5d57bc207f9240
parentd00c0544a677cfffb2a69159eefe4994efcb02db (diff)
downloadmariadb-git-78c24b2bbc5c5ceee870ee31d4a63643617d385d.tar.gz
Another bugfix for #615
Looks a bit nicer than previous one mysql-test/r/insert.result: Test results added mysql-test/t/insert.test: testcase for the bug added sql/field.h: Field::set_default fixed sql/field_conv.cc: Now we can just replace field->reset() with field->set_default() here
-rw-r--r--mysql-test/r/insert.result10
-rw-r--r--mysql-test/t/insert.test12
-rw-r--r--sql/field.h6
-rw-r--r--sql/field_conv.cc6
4 files changed, 28 insertions, 6 deletions
diff --git a/mysql-test/r/insert.result b/mysql-test/r/insert.result
index 69b790ff35b..d019cfcbfa9 100644
--- a/mysql-test/r/insert.result
+++ b/mysql-test/r/insert.result
@@ -58,6 +58,16 @@ skr 2
test 1
test 2
drop table t1;
+create table t1 (id int NOT NULL DEFAULT 8);
+insert into t1 values(NULL);
+Column 'id' cannot be null
+insert into t1 values (1), (NULL), (2);
+select * from t1;
+id
+1
+8
+2
+drop table t1;
drop database if exists foo;
create database foo;
use foo;
diff --git a/mysql-test/t/insert.test b/mysql-test/t/insert.test
index 9b06b522028..be585157e63 100644
--- a/mysql-test/t/insert.test
+++ b/mysql-test/t/insert.test
@@ -51,6 +51,17 @@ select * from t1;
drop table t1;
#
+#Test of behaviour with INSERT VALUES (NULL)
+#
+
+create table t1 (id int NOT NULL DEFAULT 8);
+-- error 1048
+insert into t1 values(NULL);
+insert into t1 values (1), (NULL), (2);
+select * from t1;
+drop table t1;
+
+#
# Test of mysqld crash with fully qualified column names
#
@@ -60,3 +71,4 @@ use foo;
create table t1 (c int);
insert into foo.t1 set foo.t1.c = '1';
drop database foo;
+
diff --git a/sql/field.h b/sql/field.h
index e63802d8c00..3186f9f5275 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -72,10 +72,12 @@ public:
virtual void reset_fields() {}
virtual void set_default()
{
- memcpy(ptr, ptr + table->rec_buff_length, pack_length());
+ my_ptrdiff_t offset = (my_ptrdiff_t) (table->record[2] -
+ table->record[0]);
+ memcpy(ptr, ptr + offset, pack_length());
if (null_ptr)
*null_ptr= ((*null_ptr & (uchar) ~null_bit) |
- null_ptr[table->rec_buff_length] & null_bit);
+ null_ptr[offset] & null_bit);
}
virtual bool binary() const { return 1; }
virtual bool zero_pack() const { return 1; }
diff --git a/sql/field_conv.cc b/sql/field_conv.cc
index a32a635ac05..ce67455881b 100644
--- a/sql/field_conv.cc
+++ b/sql/field_conv.cc
@@ -118,10 +118,9 @@ set_field_to_null(Field *field)
field->reset();
return 0;
}
- field->reset();
+ field->set_default();
if (current_thd->count_cuted_fields)
{
- field->set_default();
current_thd->cuted_fields++; // Increment error counter
return 0;
}
@@ -171,12 +170,11 @@ set_field_to_null_with_conversions(Field *field, bool no_conversions)
((Field_timestamp*) field)->set_time();
return 0; // Ok to set time to NULL
}
- field->reset();
+ field->set_default();
if (field == field->table->next_number_field)
return 0; // field is set in handler.cc
if (current_thd->count_cuted_fields)
{
- field->set_default();
current_thd->cuted_fields++; // Increment error counter
return 0;
}