Commit 71d0f48f authored by hf@genie.(none)'s avatar hf@genie.(none)

Geometry field type implementation

parent c8627ff1
...@@ -4271,7 +4271,7 @@ void Field_blob::set_key_image(char *buff,uint length) ...@@ -4271,7 +4271,7 @@ void Field_blob::set_key_image(char *buff,uint length)
void Field_geom::get_key_image(char *buff,uint length, imagetype type) void Field_geom::get_key_image(char *buff,uint length, imagetype type)
{ {
length-=HA_KEY_BLOB_LENGTH; /* length-=HA_KEY_BLOB_LENGTH;
ulong blob_length=get_length(ptr); ulong blob_length=get_length(ptr);
char *blob; char *blob;
get_ptr(&blob); get_ptr(&blob);
...@@ -4286,12 +4286,19 @@ void Field_geom::get_key_image(char *buff,uint length, imagetype type) ...@@ -4286,12 +4286,19 @@ void Field_geom::get_key_image(char *buff,uint length, imagetype type)
float8store(buff+16, mbr.ymin); float8store(buff+16, mbr.ymin);
float8store(buff+24, mbr.ymax); float8store(buff+24, mbr.ymax);
return; return;
*/
Field_blob::get_key_image(buff, length, type);
} }
void Field_geom::set_key_image(char *buff,uint length) void Field_geom::set_key_image(char *buff,uint length)
{ {
Field_blob::set_key_image(buff, length);
} }
void Field_geom::sql_type(String &res) const
{
res.set("geometry", 8U, default_charset_info);
}
int Field_blob::key_cmp(const byte *key_ptr, uint max_key_length) int Field_blob::key_cmp(const byte *key_ptr, uint max_key_length)
...@@ -4941,6 +4948,7 @@ uint32 calc_pack_length(enum_field_types type,uint32 length) ...@@ -4941,6 +4948,7 @@ uint32 calc_pack_length(enum_field_types type,uint32 length)
case FIELD_TYPE_BLOB: return 2+portable_sizeof_char_ptr; case FIELD_TYPE_BLOB: return 2+portable_sizeof_char_ptr;
case FIELD_TYPE_MEDIUM_BLOB: return 3+portable_sizeof_char_ptr; case FIELD_TYPE_MEDIUM_BLOB: return 3+portable_sizeof_char_ptr;
case FIELD_TYPE_LONG_BLOB: return 4+portable_sizeof_char_ptr; case FIELD_TYPE_LONG_BLOB: return 4+portable_sizeof_char_ptr;
case FIELD_TYPE_GEOMETRY: return 2+portable_sizeof_char_ptr;
case FIELD_TYPE_SET: case FIELD_TYPE_SET:
case FIELD_TYPE_ENUM: abort(); return 0; // This shouldn't happen case FIELD_TYPE_ENUM: abort(); return 0; // This shouldn't happen
default: return 0; default: return 0;
...@@ -4988,15 +4996,15 @@ Field *make_field(char *ptr, uint32 field_length, ...@@ -4988,15 +4996,15 @@ Field *make_field(char *ptr, uint32 field_length,
f_packtype(pack_flag), f_packtype(pack_flag),
field_length); field_length);
if (f_is_geom(pack_flag))
return new Field_geom(ptr,null_pos,null_bit,
unireg_check, field_name, table,
pack_length,f_is_binary(pack_flag) != 0);
if (f_is_blob(pack_flag)) if (f_is_blob(pack_flag))
return new Field_blob(ptr,null_pos,null_bit, return new Field_blob(ptr,null_pos,null_bit,
unireg_check, field_name, table, unireg_check, field_name, table,
pack_length,f_is_binary(pack_flag) != 0, pack_length,f_is_binary(pack_flag) != 0,
default_charset_info); default_charset_info);
if (f_is_geom(pack_flag))
return new Field_geom(ptr,null_pos,null_bit,
unireg_check, field_name, table,
pack_length,f_is_binary(pack_flag) != 0);
if (interval) if (interval)
{ {
......
...@@ -937,6 +937,8 @@ class Field_geom :public Field_blob { ...@@ -937,6 +937,8 @@ class Field_geom :public Field_blob {
:Field_blob(len_arg, maybe_null_arg, field_name_arg, :Field_blob(len_arg, maybe_null_arg, field_name_arg,
table_arg, binary_arg, default_charset_info) {} table_arg, binary_arg, default_charset_info) {}
enum ha_base_keytype key_type() const { return HA_KEYTYPE_VARBINARY; } enum ha_base_keytype key_type() const { return HA_KEYTYPE_VARBINARY; }
enum_field_types type() const { return FIELD_TYPE_GEOMETRY;}
void sql_type(String &str) const;
void get_key_image(char *buff,uint length, imagetype type); void get_key_image(char *buff,uint length, imagetype type);
void set_key_image(char *buff,uint length); void set_key_image(char *buff,uint length);
......
...@@ -1066,7 +1066,7 @@ int ha_myisam::create(const char *name, register TABLE *table, ...@@ -1066,7 +1066,7 @@ int ha_myisam::create(const char *name, register TABLE *table,
keydef[i].flag|=HA_AUTO_KEY; keydef[i].flag|=HA_AUTO_KEY;
found_auto_increment=1; found_auto_increment=1;
} }
if (field->type() == FIELD_TYPE_BLOB) if ((field->type() == FIELD_TYPE_BLOB) || (field->type() == FIELD_TYPE_GEOMETRY))
{ {
keydef[i].seg[j].flag|=HA_BLOB_PART; keydef[i].seg[j].flag|=HA_BLOB_PART;
/* save number of bytes used to pack length */ /* save number of bytes used to pack length */
......
...@@ -3018,7 +3018,6 @@ bool add_field_to_list(char *field_name, enum_field_types type, ...@@ -3018,7 +3018,6 @@ bool add_field_to_list(char *field_name, enum_field_types type,
case FIELD_TYPE_STRING: case FIELD_TYPE_STRING:
case FIELD_TYPE_VAR_STRING: case FIELD_TYPE_VAR_STRING:
case FIELD_TYPE_NULL: case FIELD_TYPE_NULL:
case FIELD_TYPE_GEOMETRY:
break; break;
case FIELD_TYPE_DECIMAL: case FIELD_TYPE_DECIMAL:
if (!length) if (!length)
...@@ -3031,6 +3030,7 @@ bool add_field_to_list(char *field_name, enum_field_types type, ...@@ -3031,6 +3030,7 @@ bool add_field_to_list(char *field_name, enum_field_types type,
case FIELD_TYPE_TINY_BLOB: case FIELD_TYPE_TINY_BLOB:
case FIELD_TYPE_LONG_BLOB: case FIELD_TYPE_LONG_BLOB:
case FIELD_TYPE_MEDIUM_BLOB: case FIELD_TYPE_MEDIUM_BLOB:
case FIELD_TYPE_GEOMETRY:
if (default_value) // Allow empty as default value if (default_value) // Allow empty as default value
{ {
String str,*res; String str,*res;
...@@ -3166,7 +3166,7 @@ bool add_field_to_list(char *field_name, enum_field_types type, ...@@ -3166,7 +3166,7 @@ bool add_field_to_list(char *field_name, enum_field_types type,
if (new_field->length >= MAX_FIELD_WIDTH || if (new_field->length >= MAX_FIELD_WIDTH ||
(!new_field->length && !(new_field->flags & BLOB_FLAG) && (!new_field->length && !(new_field->flags & BLOB_FLAG) &&
type != FIELD_TYPE_STRING && type != FIELD_TYPE_VAR_STRING)) type != FIELD_TYPE_STRING && type != FIELD_TYPE_VAR_STRING && type != FIELD_TYPE_GEOMETRY))
{ {
net_printf(&thd->net,ER_TOO_BIG_FIELDLENGTH,field_name, net_printf(&thd->net,ER_TOO_BIG_FIELDLENGTH,field_name,
MAX_FIELD_WIDTH-1); /* purecov: inspected */ MAX_FIELD_WIDTH-1); /* purecov: inspected */
......
...@@ -351,6 +351,16 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, ...@@ -351,6 +351,16 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
sql_field->unireg_check=Field::BLOB_FIELD; sql_field->unireg_check=Field::BLOB_FIELD;
blob_columns++; blob_columns++;
break; break;
case FIELD_TYPE_GEOMETRY:
sql_field->pack_flag=FIELDFLAG_GEOM |
pack_length_to_packflag(sql_field->pack_length -
portable_sizeof_char_ptr);
if (sql_field->flags & BINARY_FLAG)
sql_field->pack_flag|=FIELDFLAG_BINARY;
sql_field->length=8; // Unireg field length
sql_field->unireg_check=Field::BLOB_FIELD;
blob_columns++;
break;
case FIELD_TYPE_VAR_STRING: case FIELD_TYPE_VAR_STRING:
case FIELD_TYPE_STRING: case FIELD_TYPE_STRING:
sql_field->pack_flag=0; sql_field->pack_flag=0;
......
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