Commit 5150bd8f authored by hf@deer.(none)'s avatar hf@deer.(none)

Merge bk@192.168.21.1:/usr/home/bk/mysql-4.1

into deer.(none):/home/hf/work/mysql-4.1.12839
parents b919b29d 16c66d49
...@@ -655,3 +655,9 @@ t1 where object_id=85984; ...@@ -655,3 +655,9 @@ t1 where object_id=85984;
object_id geometrytype(geo) ISSIMPLE(GEO) ASTEXT(centroid(geo)) object_id geometrytype(geo) ISSIMPLE(GEO) ASTEXT(centroid(geo))
85984 MULTIPOLYGON 0 POINT(-114.87787186923 36.33101763469) 85984 MULTIPOLYGON 0 POINT(-114.87787186923 36.33101763469)
drop table t1; drop table t1;
select (asWKT(geomfromwkb((0x000000000140240000000000004024000000000000))));
(asWKT(geomfromwkb((0x000000000140240000000000004024000000000000))))
POINT(10 10)
select (asWKT(geomfromwkb((0x010100000000000000000024400000000000002440))));
(asWKT(geomfromwkb((0x010100000000000000000024400000000000002440))))
POINT(10 10)
...@@ -360,4 +360,7 @@ t1 where object_id=85984; ...@@ -360,4 +360,7 @@ t1 where object_id=85984;
drop table t1; drop table t1;
select (asWKT(geomfromwkb((0x000000000140240000000000004024000000000000))));
select (asWKT(geomfromwkb((0x010100000000000000000024400000000000002440))));
# End of 4.1 tests # End of 4.1 tests
...@@ -5745,8 +5745,7 @@ void Field_blob::get_key_image(char *buff,uint length, ...@@ -5745,8 +5745,7 @@ void Field_blob::get_key_image(char *buff,uint length,
return; return;
} }
get_ptr(&blob); get_ptr(&blob);
gobj= Geometry::create_from_wkb(&buffer, gobj= Geometry::construct(&buffer, blob, blob_length);
blob + SRID_SIZE, blob_length - SRID_SIZE);
if (gobj->get_mbr(&mbr, &dummy)) if (gobj->get_mbr(&mbr, &dummy))
bzero(buff, SIZEOF_STORED_DOUBLE*4); bzero(buff, SIZEOF_STORED_DOUBLE*4);
else else
...@@ -6039,8 +6038,7 @@ void Field_geom::get_key_image(char *buff, uint length, CHARSET_INFO *cs, ...@@ -6039,8 +6038,7 @@ void Field_geom::get_key_image(char *buff, uint length, CHARSET_INFO *cs,
return; return;
} }
get_ptr(&blob); get_ptr(&blob);
gobj= Geometry::create_from_wkb(&buffer, gobj= Geometry::construct(&buffer, blob, blob_length);
blob + SRID_SIZE, blob_length - SRID_SIZE);
if (gobj->get_mbr(&mbr, &dummy)) if (gobj->get_mbr(&mbr, &dummy))
bzero(buff, SIZEOF_STORED_DOUBLE*4); bzero(buff, SIZEOF_STORED_DOUBLE*4);
else else
...@@ -6100,7 +6098,7 @@ int Field_geom::store(const char *from, uint length, CHARSET_INFO *cs) ...@@ -6100,7 +6098,7 @@ int Field_geom::store(const char *from, uint length, CHARSET_INFO *cs)
uint32 wkb_type; uint32 wkb_type;
if (length < SRID_SIZE + WKB_HEADER_SIZE + SIZEOF_STORED_DOUBLE*2) if (length < SRID_SIZE + WKB_HEADER_SIZE + SIZEOF_STORED_DOUBLE*2)
goto err; goto err;
wkb_type= uint4korr(from + WKB_HEADER_SIZE); wkb_type= uint4korr(from + SRID_SIZE + 1);
if (wkb_type < (uint32) Geometry::wkb_point || if (wkb_type < (uint32) Geometry::wkb_point ||
wkb_type > (uint32) Geometry::wkb_end) wkb_type > (uint32) Geometry::wkb_end)
return -1; return -1;
......
...@@ -78,8 +78,7 @@ String *Item_func_geometry_from_wkb::val_str(String *str) ...@@ -78,8 +78,7 @@ String *Item_func_geometry_from_wkb::val_str(String *str)
str->q_append(srid); str->q_append(srid);
if ((null_value= if ((null_value=
(args[0]->null_value || (args[0]->null_value ||
!Geometry::create_from_wkb(&buffer, wkb->ptr(), wkb->length()) || !Geometry::create_from_wkb(&buffer, wkb->ptr(), wkb->length(), str))))
str->append(*wkb))))
return 0; return 0;
return str; return str;
} }
...@@ -96,8 +95,7 @@ String *Item_func_as_wkt::val_str(String *str) ...@@ -96,8 +95,7 @@ String *Item_func_as_wkt::val_str(String *str)
if ((null_value= if ((null_value=
(args[0]->null_value || (args[0]->null_value ||
!(geom= Geometry::create_from_wkb(&buffer, swkb->ptr() + SRID_SIZE, !(geom= Geometry::construct(&buffer, swkb->ptr(), swkb->length())))))
swkb->length() - SRID_SIZE)))))
return 0; return 0;
str->length(0); str->length(0);
...@@ -123,8 +121,7 @@ String *Item_func_as_wkb::val_str(String *str) ...@@ -123,8 +121,7 @@ String *Item_func_as_wkb::val_str(String *str)
if ((null_value= if ((null_value=
(args[0]->null_value || (args[0]->null_value ||
!(Geometry::create_from_wkb(&buffer, swkb->ptr() + SRID_SIZE, !(Geometry::construct(&buffer, swkb->ptr(), swkb->length())))))
swkb->length() - SRID_SIZE)))))
return 0; return 0;
str->copy(swkb->ptr() + SRID_SIZE, swkb->length() - SRID_SIZE, str->copy(swkb->ptr() + SRID_SIZE, swkb->length() - SRID_SIZE,
...@@ -142,8 +139,7 @@ String *Item_func_geometry_type::val_str(String *str) ...@@ -142,8 +139,7 @@ String *Item_func_geometry_type::val_str(String *str)
if ((null_value= if ((null_value=
(args[0]->null_value || (args[0]->null_value ||
!(geom= Geometry::create_from_wkb(&buffer, swkb->ptr() + SRID_SIZE, !(geom= Geometry::construct(&buffer, swkb->ptr(), swkb->length())))))
swkb->length() - SRID_SIZE)))))
return 0; return 0;
/* String will not move */ /* String will not move */
str->copy(geom->get_class_info()->m_name.str, str->copy(geom->get_class_info()->m_name.str,
...@@ -164,8 +160,7 @@ String *Item_func_envelope::val_str(String *str) ...@@ -164,8 +160,7 @@ String *Item_func_envelope::val_str(String *str)
if ((null_value= if ((null_value=
args[0]->null_value || args[0]->null_value ||
!(geom= Geometry::create_from_wkb(&buffer, swkb->ptr() + SRID_SIZE, !(geom= Geometry::construct(&buffer, swkb->ptr(), swkb->length()))))
swkb->length() - SRID_SIZE))))
return 0; return 0;
srid= uint4korr(swkb->ptr()); srid= uint4korr(swkb->ptr());
...@@ -188,8 +183,7 @@ String *Item_func_centroid::val_str(String *str) ...@@ -188,8 +183,7 @@ String *Item_func_centroid::val_str(String *str)
uint32 srid; uint32 srid;
if ((null_value= args[0]->null_value || if ((null_value= args[0]->null_value ||
!(geom= Geometry::create_from_wkb(&buffer, swkb->ptr() + SRID_SIZE, !(geom= Geometry::construct(&buffer, swkb->ptr(), swkb->length()))))
swkb->length() - SRID_SIZE))))
return 0; return 0;
str->set_charset(&my_charset_bin); str->set_charset(&my_charset_bin);
...@@ -218,8 +212,7 @@ String *Item_func_spatial_decomp::val_str(String *str) ...@@ -218,8 +212,7 @@ String *Item_func_spatial_decomp::val_str(String *str)
if ((null_value= if ((null_value=
(args[0]->null_value || (args[0]->null_value ||
!(geom= Geometry::create_from_wkb(&buffer, swkb->ptr() + SRID_SIZE, !(geom= Geometry::construct(&buffer, swkb->ptr(), swkb->length())))))
swkb->length() - SRID_SIZE)))))
return 0; return 0;
srid= uint4korr(swkb->ptr()); srid= uint4korr(swkb->ptr());
...@@ -267,8 +260,7 @@ String *Item_func_spatial_decomp_n::val_str(String *str) ...@@ -267,8 +260,7 @@ String *Item_func_spatial_decomp_n::val_str(String *str)
if ((null_value= if ((null_value=
(args[0]->null_value || args[1]->null_value || (args[0]->null_value || args[1]->null_value ||
!(geom= Geometry::create_from_wkb(&buffer, swkb->ptr() + SRID_SIZE, !(geom= Geometry::construct(&buffer, swkb->ptr(), swkb->length())))))
swkb->length() - SRID_SIZE)))))
return 0; return 0;
str->set_charset(&my_charset_bin); str->set_charset(&my_charset_bin);
...@@ -475,10 +467,8 @@ longlong Item_func_spatial_rel::val_int() ...@@ -475,10 +467,8 @@ longlong Item_func_spatial_rel::val_int()
if ((null_value= if ((null_value=
(args[0]->null_value || (args[0]->null_value ||
args[1]->null_value || args[1]->null_value ||
!(g1= Geometry::create_from_wkb(&buffer1, res1->ptr() + SRID_SIZE, !(g1= Geometry::construct(&buffer1, res1->ptr(), res1->length())) ||
res1->length() - SRID_SIZE)) || !(g2= Geometry::construct(&buffer2, res2->ptr(), res2->length())) ||
!(g2= Geometry::create_from_wkb(&buffer2, res2->ptr() + SRID_SIZE,
res2->length() - SRID_SIZE)) ||
g1->get_mbr(&mbr1, &dummy) || g1->get_mbr(&mbr1, &dummy) ||
g2->get_mbr(&mbr2, &dummy)))) g2->get_mbr(&mbr2, &dummy))))
return 0; return 0;
...@@ -543,8 +533,7 @@ longlong Item_func_isclosed::val_int() ...@@ -543,8 +533,7 @@ longlong Item_func_isclosed::val_int()
null_value= (!swkb || null_value= (!swkb ||
args[0]->null_value || args[0]->null_value ||
!(geom= !(geom=
Geometry::create_from_wkb(&buffer, swkb->ptr() + SRID_SIZE, Geometry::construct(&buffer, swkb->ptr(), swkb->length())) ||
swkb->length() - SRID_SIZE)) ||
geom->is_closed(&isclosed)); geom->is_closed(&isclosed));
return (longlong) isclosed; return (longlong) isclosed;
...@@ -566,9 +555,7 @@ longlong Item_func_dimension::val_int() ...@@ -566,9 +555,7 @@ longlong Item_func_dimension::val_int()
null_value= (!swkb || null_value= (!swkb ||
args[0]->null_value || args[0]->null_value ||
!(geom= Geometry::create_from_wkb(&buffer, !(geom= Geometry::construct(&buffer, swkb->ptr(), swkb->length())) ||
swkb->ptr() + SRID_SIZE,
swkb->length() - SRID_SIZE)) ||
geom->dimension(&dim, &dummy)); geom->dimension(&dim, &dummy));
return (longlong) dim; return (longlong) dim;
} }
...@@ -583,9 +570,8 @@ longlong Item_func_numinteriorring::val_int() ...@@ -583,9 +570,8 @@ longlong Item_func_numinteriorring::val_int()
Geometry *geom; Geometry *geom;
null_value= (!swkb || null_value= (!swkb ||
!(geom= Geometry::create_from_wkb(&buffer, !(geom= Geometry::construct(&buffer,
swkb->ptr() + SRID_SIZE, swkb->ptr(), swkb->length())) ||
swkb->length() - SRID_SIZE)) ||
geom->num_interior_ring(&num)); geom->num_interior_ring(&num));
return (longlong) num; return (longlong) num;
} }
...@@ -600,9 +586,8 @@ longlong Item_func_numgeometries::val_int() ...@@ -600,9 +586,8 @@ longlong Item_func_numgeometries::val_int()
Geometry *geom; Geometry *geom;
null_value= (!swkb || null_value= (!swkb ||
!(geom= Geometry::create_from_wkb(&buffer, !(geom= Geometry::construct(&buffer,
swkb->ptr() + SRID_SIZE, swkb->ptr(), swkb->length())) ||
swkb->length() - SRID_SIZE)) ||
geom->num_geometries(&num)); geom->num_geometries(&num));
return (longlong) num; return (longlong) num;
} }
...@@ -618,9 +603,8 @@ longlong Item_func_numpoints::val_int() ...@@ -618,9 +603,8 @@ longlong Item_func_numpoints::val_int()
null_value= (!swkb || null_value= (!swkb ||
args[0]->null_value || args[0]->null_value ||
!(geom= Geometry::create_from_wkb(&buffer, !(geom= Geometry::construct(&buffer,
swkb->ptr() + SRID_SIZE, swkb->ptr(), swkb->length())) ||
swkb->length() - SRID_SIZE)) ||
geom->num_points(&num)); geom->num_points(&num));
return (longlong) num; return (longlong) num;
} }
...@@ -635,9 +619,8 @@ double Item_func_x::val() ...@@ -635,9 +619,8 @@ double Item_func_x::val()
Geometry *geom; Geometry *geom;
null_value= (!swkb || null_value= (!swkb ||
!(geom= Geometry::create_from_wkb(&buffer, !(geom= Geometry::construct(&buffer,
swkb->ptr() + SRID_SIZE, swkb->ptr(), swkb->length())) ||
swkb->length() - SRID_SIZE)) ||
geom->get_x(&res)); geom->get_x(&res));
return res; return res;
} }
...@@ -652,9 +635,8 @@ double Item_func_y::val() ...@@ -652,9 +635,8 @@ double Item_func_y::val()
Geometry *geom; Geometry *geom;
null_value= (!swkb || null_value= (!swkb ||
!(geom= Geometry::create_from_wkb(&buffer, !(geom= Geometry::construct(&buffer,
swkb->ptr() + SRID_SIZE, swkb->ptr(), swkb->length())) ||
swkb->length() - SRID_SIZE)) ||
geom->get_y(&res)); geom->get_y(&res));
return res; return res;
} }
...@@ -670,9 +652,8 @@ double Item_func_area::val() ...@@ -670,9 +652,8 @@ double Item_func_area::val()
const char *dummy; const char *dummy;
null_value= (!swkb || null_value= (!swkb ||
!(geom= Geometry::create_from_wkb(&buffer, !(geom= Geometry::construct(&buffer,
swkb->ptr() + SRID_SIZE, swkb->ptr(), swkb->length())) ||
swkb->length() - SRID_SIZE)) ||
geom->area(&res, &dummy)); geom->area(&res, &dummy));
return res; return res;
} }
...@@ -686,9 +667,8 @@ double Item_func_glength::val() ...@@ -686,9 +667,8 @@ double Item_func_glength::val()
Geometry *geom; Geometry *geom;
null_value= (!swkb || null_value= (!swkb ||
!(geom= Geometry::create_from_wkb(&buffer, !(geom= Geometry::construct(&buffer,
swkb->ptr() + SRID_SIZE, swkb->ptr(), swkb->length())) ||
swkb->length() - SRID_SIZE)) ||
geom->length(&res)); geom->length(&res));
return res; return res;
} }
...@@ -700,9 +680,8 @@ longlong Item_func_srid::val_int() ...@@ -700,9 +680,8 @@ longlong Item_func_srid::val_int()
Geometry_buffer buffer; Geometry_buffer buffer;
null_value= (!swkb || null_value= (!swkb ||
!Geometry::create_from_wkb(&buffer, !Geometry::construct(&buffer,
swkb->ptr() + SRID_SIZE, swkb->ptr(), swkb->length()));
swkb->length() - SRID_SIZE));
if (null_value) if (null_value)
return 0; return 0;
......
This diff is collapsed.
...@@ -202,6 +202,10 @@ public: ...@@ -202,6 +202,10 @@ public:
virtual const Class_info *get_class_info() const=0; virtual const Class_info *get_class_info() const=0;
virtual uint32 get_data_size() const=0; virtual uint32 get_data_size() const=0;
virtual bool init_from_wkt(Gis_read_stream *trs, String *wkb)=0; virtual bool init_from_wkt(Gis_read_stream *trs, String *wkb)=0;
/* returns the length of the wkb that was read */
virtual uint init_from_wkb(const char *wkb, uint len, wkbByteOrder bo,
String *res)=0;
virtual bool get_data_as_wkt(String *txt, const char **end) const=0; virtual bool get_data_as_wkt(String *txt, const char **end) const=0;
virtual bool get_mbr(MBR *mbr, const char **end) const=0; virtual bool get_mbr(MBR *mbr, const char **end) const=0;
virtual bool dimension(uint32 *dim, const char **end) const=0; virtual bool dimension(uint32 *dim, const char **end) const=0;
...@@ -231,11 +235,13 @@ public: ...@@ -231,11 +235,13 @@ public:
return my_reinterpret_cast(Geometry *)(buffer); return my_reinterpret_cast(Geometry *)(buffer);
} }
static Geometry *create_from_wkb(Geometry_buffer *buffer, static Geometry *construct(Geometry_buffer *buffer,
const char *data, uint32 data_len); const char *data, uint32 data_len);
static Geometry *create_from_wkt(Geometry_buffer *buffer, static Geometry *create_from_wkt(Geometry_buffer *buffer,
Gis_read_stream *trs, String *wkt, Gis_read_stream *trs, String *wkt,
bool init_stream=1); bool init_stream=1);
static int Geometry::create_from_wkb(Geometry_buffer *buffer,
const char *wkb, uint32 len, String *res);
int as_wkt(String *wkt, const char **end) int as_wkt(String *wkt, const char **end)
{ {
uint32 len= get_class_info()->m_name.length; uint32 len= get_class_info()->m_name.length;
...@@ -249,7 +255,7 @@ public: ...@@ -249,7 +255,7 @@ public:
return 0; return 0;
} }
inline void init_from_wkb(const char *data, uint32 data_len) inline void set_data_ptr(const char *data, uint32 data_len)
{ {
m_data= data; m_data= data;
m_data_end= data + data_len; m_data_end= data + data_len;
...@@ -293,6 +299,7 @@ class Gis_point: public Geometry ...@@ -293,6 +299,7 @@ class Gis_point: public Geometry
public: public:
uint32 get_data_size() const; uint32 get_data_size() const;
bool init_from_wkt(Gis_read_stream *trs, String *wkb); bool init_from_wkt(Gis_read_stream *trs, String *wkb);
uint init_from_wkb(const char *wkb, uint len, wkbByteOrder bo, String *res);
bool get_data_as_wkt(String *txt, const char **end) const; bool get_data_as_wkt(String *txt, const char **end) const;
bool get_mbr(MBR *mbr, const char **end) const; bool get_mbr(MBR *mbr, const char **end) const;
...@@ -339,6 +346,7 @@ class Gis_line_string: public Geometry ...@@ -339,6 +346,7 @@ class Gis_line_string: public Geometry
public: public:
uint32 get_data_size() const; uint32 get_data_size() const;
bool init_from_wkt(Gis_read_stream *trs, String *wkb); bool init_from_wkt(Gis_read_stream *trs, String *wkb);
uint init_from_wkb(const char *wkb, uint len, wkbByteOrder bo, String *res);
bool get_data_as_wkt(String *txt, const char **end) const; bool get_data_as_wkt(String *txt, const char **end) const;
bool get_mbr(MBR *mbr, const char **end) const; bool get_mbr(MBR *mbr, const char **end) const;
int length(double *len) const; int length(double *len) const;
...@@ -364,6 +372,7 @@ class Gis_polygon: public Geometry ...@@ -364,6 +372,7 @@ class Gis_polygon: public Geometry
public: public:
uint32 get_data_size() const; uint32 get_data_size() const;
bool init_from_wkt(Gis_read_stream *trs, String *wkb); bool init_from_wkt(Gis_read_stream *trs, String *wkb);
uint init_from_wkb(const char *wkb, uint len, wkbByteOrder bo, String *res);
bool get_data_as_wkt(String *txt, const char **end) const; bool get_data_as_wkt(String *txt, const char **end) const;
bool get_mbr(MBR *mbr, const char **end) const; bool get_mbr(MBR *mbr, const char **end) const;
int area(double *ar, const char **end) const; int area(double *ar, const char **end) const;
...@@ -389,6 +398,7 @@ class Gis_multi_point: public Geometry ...@@ -389,6 +398,7 @@ class Gis_multi_point: public Geometry
public: public:
uint32 get_data_size() const; uint32 get_data_size() const;
bool init_from_wkt(Gis_read_stream *trs, String *wkb); bool init_from_wkt(Gis_read_stream *trs, String *wkb);
uint init_from_wkb(const char *wkb, uint len, wkbByteOrder bo, String *res);
bool get_data_as_wkt(String *txt, const char **end) const; bool get_data_as_wkt(String *txt, const char **end) const;
bool get_mbr(MBR *mbr, const char **end) const; bool get_mbr(MBR *mbr, const char **end) const;
int num_geometries(uint32 *num) const; int num_geometries(uint32 *num) const;
...@@ -410,6 +420,7 @@ class Gis_multi_line_string: public Geometry ...@@ -410,6 +420,7 @@ class Gis_multi_line_string: public Geometry
public: public:
uint32 get_data_size() const; uint32 get_data_size() const;
bool init_from_wkt(Gis_read_stream *trs, String *wkb); bool init_from_wkt(Gis_read_stream *trs, String *wkb);
uint init_from_wkb(const char *wkb, uint len, wkbByteOrder bo, String *res);
bool get_data_as_wkt(String *txt, const char **end) const; bool get_data_as_wkt(String *txt, const char **end) const;
bool get_mbr(MBR *mbr, const char **end) const; bool get_mbr(MBR *mbr, const char **end) const;
int num_geometries(uint32 *num) const; int num_geometries(uint32 *num) const;
...@@ -433,6 +444,7 @@ class Gis_multi_polygon: public Geometry ...@@ -433,6 +444,7 @@ class Gis_multi_polygon: public Geometry
public: public:
uint32 get_data_size() const; uint32 get_data_size() const;
bool init_from_wkt(Gis_read_stream *trs, String *wkb); bool init_from_wkt(Gis_read_stream *trs, String *wkb);
uint init_from_wkb(const char *wkb, uint len, wkbByteOrder bo, String *res);
bool get_data_as_wkt(String *txt, const char **end) const; bool get_data_as_wkt(String *txt, const char **end) const;
bool get_mbr(MBR *mbr, const char **end) const; bool get_mbr(MBR *mbr, const char **end) const;
int num_geometries(uint32 *num) const; int num_geometries(uint32 *num) const;
...@@ -456,6 +468,7 @@ class Gis_geometry_collection: public Geometry ...@@ -456,6 +468,7 @@ class Gis_geometry_collection: public Geometry
public: public:
uint32 get_data_size() const; uint32 get_data_size() const;
bool init_from_wkt(Gis_read_stream *trs, String *wkb); bool init_from_wkt(Gis_read_stream *trs, String *wkb);
uint init_from_wkb(const char *wkb, uint len, wkbByteOrder bo, String *res);
bool get_data_as_wkt(String *txt, const char **end) const; bool get_data_as_wkt(String *txt, const char **end) const;
bool get_mbr(MBR *mbr, const char **end) const; bool get_mbr(MBR *mbr, const char **end) const;
int num_geometries(uint32 *num) const; int num_geometries(uint32 *num) const;
......
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