bug #22372 (LOAD DATA crashes the table with the geometry field)

The problem is that the GEOMETRY NOT NULL can't automatically set
any value as a default one. We always tried to complete LOAD DATA
command even if there's not enough data in file. That doesn't work
for GEOMETRY NOT NULL. Now Field_*::reset() returns an error sign
and it's checked in mysql_load()
parent e6a2d184
...@@ -671,3 +671,9 @@ Catalog Database Table Table_alias Column Column_alias Type Length Max length Is ...@@ -671,3 +671,9 @@ Catalog Database Table Table_alias Column Column_alias Type Length Max length Is
def asbinary(g) 252 8192 0 Y 128 0 63 def asbinary(g) 252 8192 0 Y 128 0 63
asbinary(g) asbinary(g)
drop table t1; drop table t1;
create table t1 (a TEXT, b GEOMETRY NOT NULL, SPATIAL KEY(b));
alter table t1 disable keys;
load data infile '../../std_data/bad_gis_data.dat' into table t1;
ERROR 01000: Data truncated; NULL supplied to NOT NULL column 'b' at row 1
alter table t1 enable keys;
drop table t1;
...@@ -363,11 +363,18 @@ drop table t1; ...@@ -363,11 +363,18 @@ drop table t1;
select (asWKT(geomfromwkb((0x000000000140240000000000004024000000000000)))); select (asWKT(geomfromwkb((0x000000000140240000000000004024000000000000))));
select (asWKT(geomfromwkb((0x010100000000000000000024400000000000002440)))); select (asWKT(geomfromwkb((0x010100000000000000000024400000000000002440))));
# End of 4.1 tests
--enable_metadata --enable_metadata
create table t1 (g GEOMETRY); create table t1 (g GEOMETRY);
select * from t1; select * from t1;
select asbinary(g) from t1; select asbinary(g) from t1;
--disable_metadata --disable_metadata
drop table t1; drop table t1;
create table t1 (a TEXT, b GEOMETRY NOT NULL, SPATIAL KEY(b));
alter table t1 disable keys;
--error 1263
load data infile '../../std_data/bad_gis_data.dat' into table t1;
alter table t1 enable keys;
drop table t1;
# End of 4.1 tests
...@@ -1137,10 +1137,11 @@ void Field_null::sql_type(String &res) const ...@@ -1137,10 +1137,11 @@ void Field_null::sql_type(String &res) const
This is an number stored as a pre-space (or pre-zero) string This is an number stored as a pre-space (or pre-zero) string
****************************************************************************/ ****************************************************************************/
void int
Field_decimal::reset(void) Field_decimal::reset(void)
{ {
Field_decimal::store("0",1,&my_charset_bin); Field_decimal::store("0",1,&my_charset_bin);
return 0;
} }
void Field_decimal::overflow(bool negative) void Field_decimal::overflow(bool negative)
......
This diff is collapsed.
...@@ -527,7 +527,12 @@ read_sep_field(THD *thd,COPY_INFO &info,TABLE *table, ...@@ -527,7 +527,12 @@ read_sep_field(THD *thd,COPY_INFO &info,TABLE *table,
(enclosed_length && length == 4 && !memcmp(pos,"NULL",4)) || (enclosed_length && length == 4 && !memcmp(pos,"NULL",4)) ||
(length == 1 && read_info.found_null)) (length == 1 && read_info.found_null))
{ {
field->reset(); if (field->reset())
{
my_error(ER_WARN_NULL_TO_NOTNULL, MYF(0), field->field_name,
thd->row_count);
DBUG_RETURN(1);
}
field->set_null(); field->set_null();
if (!field->maybe_null()) if (!field->maybe_null())
{ {
...@@ -560,7 +565,12 @@ read_sep_field(THD *thd,COPY_INFO &info,TABLE *table, ...@@ -560,7 +565,12 @@ read_sep_field(THD *thd,COPY_INFO &info,TABLE *table,
for (; sql_field ; sql_field=(Item_field*) it++) for (; sql_field ; sql_field=(Item_field*) it++)
{ {
sql_field->field->set_null(); sql_field->field->set_null();
sql_field->field->reset(); if (sql_field->field->reset())
{
my_error(ER_WARN_NULL_TO_NOTNULL, MYF(0),sql_field->field->field_name,
thd->row_count);
DBUG_RETURN(1);
}
thd->cuted_fields++; thd->cuted_fields++;
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARN_TOO_FEW_RECORDS, ER_WARN_TOO_FEW_RECORDS,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment