Commit 192715db authored by hf@deer.(none)'s avatar hf@deer.(none)

Fix for bug #6516 (Server crash loading spatial data)

(after discussion with SerG)
parent 4915d196
...@@ -291,6 +291,7 @@ enum ha_base_keytype { ...@@ -291,6 +291,7 @@ enum ha_base_keytype {
#define HA_ERR_NO_SUCH_TABLE 155 /* The table does not exist in engine */ #define HA_ERR_NO_SUCH_TABLE 155 /* The table does not exist in engine */
#define HA_ERR_TABLE_EXIST 156 /* The table existed in storage engine */ #define HA_ERR_TABLE_EXIST 156 /* The table existed in storage engine */
#define HA_ERR_NO_CONNECTION 157 /* Could not connect to storage engine */ #define HA_ERR_NO_CONNECTION 157 /* Could not connect to storage engine */
#define HA_ERR_NULL_IN_SPATIAL 158 /* NULLs are not supported in spatial index */
/* Other constants */ /* Other constants */
......
...@@ -159,7 +159,8 @@ int mi_write(MI_INFO *info, byte *record) ...@@ -159,7 +159,8 @@ int mi_write(MI_INFO *info, byte *record)
err: err:
save_errno=my_errno; save_errno=my_errno;
if (my_errno == HA_ERR_FOUND_DUPP_KEY || my_errno == HA_ERR_RECORD_FILE_FULL) if (my_errno == HA_ERR_FOUND_DUPP_KEY || my_errno == HA_ERR_RECORD_FILE_FULL ||
my_errno == HA_ERR_NULL_IN_SPATIAL)
{ {
if (info->bulk_insert) if (info->bulk_insert)
{ {
......
...@@ -710,7 +710,8 @@ err1: ...@@ -710,7 +710,8 @@ err1:
int rtree_insert(MI_INFO *info, uint keynr, uchar *key, uint key_length) int rtree_insert(MI_INFO *info, uint keynr, uchar *key, uint key_length)
{ {
return (rtree_insert_level(info, keynr, key, key_length, -1) == -1) ? -1 : 0; return (!key_length ||
(rtree_insert_level(info, keynr, key, key_length, -1) == -1)) ? -1 : 0;
} }
......
...@@ -50,6 +50,11 @@ uint sp_make_key(register MI_INFO *info, uint keynr, uchar *key, ...@@ -50,6 +50,11 @@ uint sp_make_key(register MI_INFO *info, uint keynr, uchar *key,
dlen = _mi_calc_blob_length(keyseg->bit_start, pos); dlen = _mi_calc_blob_length(keyseg->bit_start, pos);
memcpy_fixed(&dptr, pos + keyseg->bit_start, sizeof(char*)); memcpy_fixed(&dptr, pos + keyseg->bit_start, sizeof(char*));
if (!dptr)
{
my_errno= HA_ERR_NULL_IN_SPATIAL;
return 0;
}
sp_mbr_from_wkb(dptr + 4, dlen - 4, SPDIMS, mbr); /* SRID */ sp_mbr_from_wkb(dptr + 4, dlen - 4, SPDIMS, mbr); /* SRID */
for (i = 0, keyseg = keyinfo->seg; keyseg->type; keyseg++, i++) for (i = 0, keyseg = keyinfo->seg; keyseg->type; keyseg++, i++)
......
...@@ -798,3 +798,9 @@ INSERT INTO t1 (name, kind, line) VALUES ...@@ -798,3 +798,9 @@ INSERT INTO t1 (name, kind, line) VALUES
ALTER TABLE t1 ENABLE KEYS; ALTER TABLE t1 ENABLE KEYS;
INSERT INTO t1 (name, kind, line) VALUES ("austria", "pp", GeomFromText('LINESTRING(14.9906 48.9887,14.9946 48.9904,14.9947 48.9916)')); INSERT INTO t1 (name, kind, line) VALUES ("austria", "pp", GeomFromText('LINESTRING(14.9906 48.9887,14.9946 48.9904,14.9947 48.9916)'));
drop table t1; drop table t1;
CREATE TABLE t1 (st varchar(100));
INSERT INTO t1 VALUES ("Fake string");
CREATE TABLE t2 (geom GEOMETRY NOT NULL, SPATIAL KEY gk(geom));
INSERT INTO t2 SELECT GeomFromText(st) FROM t1;
ERROR HY000: Unknown error
drop table t1, t2;
...@@ -165,3 +165,10 @@ INSERT INTO t1 (name, kind, line) VALUES ...@@ -165,3 +165,10 @@ INSERT INTO t1 (name, kind, line) VALUES
ALTER TABLE t1 ENABLE KEYS; ALTER TABLE t1 ENABLE KEYS;
INSERT INTO t1 (name, kind, line) VALUES ("austria", "pp", GeomFromText('LINESTRING(14.9906 48.9887,14.9946 48.9904,14.9947 48.9916)')); INSERT INTO t1 (name, kind, line) VALUES ("austria", "pp", GeomFromText('LINESTRING(14.9906 48.9887,14.9946 48.9904,14.9947 48.9916)'));
drop table t1; drop table t1;
CREATE TABLE t1 (st varchar(100));
INSERT INTO t1 VALUES ("Fake string");
CREATE TABLE t2 (geom GEOMETRY NOT NULL, SPATIAL KEY gk(geom));
--error 1105
INSERT INTO t2 SELECT GeomFromText(st) FROM t1;
drop table t1, t2;
...@@ -1083,6 +1083,9 @@ void handler::print_error(int error, myf errflag) ...@@ -1083,6 +1083,9 @@ void handler::print_error(int error, myf errflag)
textno=ER_DUP_KEY; textno=ER_DUP_KEY;
break; break;
} }
case HA_ERR_NULL_IN_SPATIAL:
textno= ER_UNKNOWN_ERROR;
DBUG_VOID_RETURN;
case HA_ERR_FOUND_DUPP_UNIQUE: case HA_ERR_FOUND_DUPP_UNIQUE:
textno=ER_DUP_UNIQUE; textno=ER_DUP_UNIQUE;
break; break;
...@@ -1196,7 +1199,8 @@ uint handler::get_dup_key(int error) ...@@ -1196,7 +1199,8 @@ uint handler::get_dup_key(int error)
{ {
DBUG_ENTER("handler::get_dup_key"); DBUG_ENTER("handler::get_dup_key");
table->file->errkey = (uint) -1; table->file->errkey = (uint) -1;
if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOUND_DUPP_UNIQUE) if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOUND_DUPP_UNIQUE ||
error == HA_ERR_NULL_IN_SPATIAL)
info(HA_STATUS_ERRKEY | HA_STATUS_NO_LOCK); info(HA_STATUS_ERRKEY | HA_STATUS_NO_LOCK);
DBUG_RETURN(table->file->errkey); DBUG_RETURN(table->file->errkey);
} }
......
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