Commit 2180fa85 authored by ram@mysql.r18.ru's avatar ram@mysql.r18.ru

AsWKB() function has been added.

parent b5af8d77
...@@ -43,7 +43,7 @@ INSERT INTO pt VALUES ...@@ -43,7 +43,7 @@ INSERT INTO pt VALUES
(101, PointFromText('POINT(10 10)')), (101, PointFromText('POINT(10 10)')),
(102, PointFromText('POINT(20 10)')), (102, PointFromText('POINT(20 10)')),
(103, PointFromText('POINT(20 20)')), (103, PointFromText('POINT(20 20)')),
(104, PointFromText('POINT(10 20)')); (104, PointFromWKB(AsWKB(PointFromText('POINT(10 20)'))));
INSERT INTO ls VALUES INSERT INTO ls VALUES
(105, LineFromText('LINESTRING(0 0,0 10,10 0)')), (105, LineFromText('LINESTRING(0 0,0 10,10 0)')),
(106, LineStringFromText('LINESTRING(10 10,20 10,20 20,10 20,10 10)')), (106, LineStringFromText('LINESTRING(10 10,20 10,20 20,10 20,10 10)')),
...@@ -388,3 +388,6 @@ gc geometrycollection binary YES NULL ...@@ -388,3 +388,6 @@ gc geometrycollection binary YES NULL
gm geometry binary YES NULL gm geometry binary YES NULL
fid int(11) binary 0 fid int(11) binary 0
DROP TABLE g1; DROP TABLE g1;
SELECT AsText(GeometryFromWKB(AsWKB(GeometryFromText('POINT(1 4)'))));
AsText(GeometryFromWKB(AsWKB(GeometryFromText('POINT(1 4)'))))
POINT(1 4)
...@@ -29,7 +29,7 @@ INSERT INTO pt VALUES ...@@ -29,7 +29,7 @@ INSERT INTO pt VALUES
(101, PointFromText('POINT(10 10)')), (101, PointFromText('POINT(10 10)')),
(102, PointFromText('POINT(20 10)')), (102, PointFromText('POINT(20 10)')),
(103, PointFromText('POINT(20 20)')), (103, PointFromText('POINT(20 20)')),
(104, PointFromText('POINT(10 20)')); (104, PointFromWKB(AsWKB(PointFromText('POINT(10 20)'))));
INSERT INTO ls VALUES INSERT INTO ls VALUES
(105, LineFromText('LINESTRING(0 0,0 10,10 0)')), (105, LineFromText('LINESTRING(0 0,0 10,10 0)')),
...@@ -140,3 +140,5 @@ SHOW FIELDS FROM g1; ...@@ -140,3 +140,5 @@ SHOW FIELDS FROM g1;
ALTER TABLE g1 ADD fid INT NOT NULL; ALTER TABLE g1 ADD fid INT NOT NULL;
SHOW FIELDS FROM g1; SHOW FIELDS FROM g1;
DROP TABLE g1; DROP TABLE g1;
SELECT AsText(GeometryFromWKB(AsWKB(GeometryFromText('POINT(1 4)'))));
...@@ -491,6 +491,11 @@ Item *create_func_as_text(Item *a) ...@@ -491,6 +491,11 @@ Item *create_func_as_text(Item *a)
return new Item_func_as_text(a); return new Item_func_as_text(a);
} }
Item *create_func_as_wkb(Item *a)
{
return new Item_func_as_wkb(a);
}
Item *create_func_srid(Item *a) Item *create_func_srid(Item *a)
{ {
return new Item_func_srid(a); return new Item_func_srid(a);
......
...@@ -105,6 +105,7 @@ Item *create_func_quote(Item* a); ...@@ -105,6 +105,7 @@ Item *create_func_quote(Item* a);
Item *create_func_geometry_from_text(Item *a); Item *create_func_geometry_from_text(Item *a);
Item *create_func_as_text(Item *a); Item *create_func_as_text(Item *a);
Item *create_func_as_wkb(Item *a);
Item *create_func_srid(Item *a); Item *create_func_srid(Item *a);
Item *create_func_startpoint(Item *a); Item *create_func_startpoint(Item *a);
Item *create_func_endpoint(Item *a); Item *create_func_endpoint(Item *a);
......
...@@ -2585,6 +2585,27 @@ void Item_func_as_text::fix_length_and_dec() ...@@ -2585,6 +2585,27 @@ void Item_func_as_text::fix_length_and_dec()
max_length=MAX_BLOB_WIDTH; max_length=MAX_BLOB_WIDTH;
} }
String *Item_func_as_wkb::val_str(String *str)
{
String arg_val;
String *swkb= args[0]->val_str(&arg_val);
Geometry geom;
if ((null_value= (args[0]->null_value ||
geom.create_from_wkb(swkb->ptr() + SRID_SIZE,
swkb->length() - SRID_SIZE))))
return 0;
str->copy(swkb->ptr() + SRID_SIZE, swkb->length() - SRID_SIZE,
&my_charset_bin);
return str;
}
void Item_func_as_wkb::fix_length_and_dec()
{
max_length= MAX_BLOB_WIDTH;
}
String *Item_func_geometry_type::val_str(String *str) String *Item_func_geometry_type::val_str(String *str)
{ {
String *swkb= args[0]->val_str(str); String *swkb= args[0]->val_str(str);
......
...@@ -665,6 +665,15 @@ public: ...@@ -665,6 +665,15 @@ public:
void fix_length_and_dec(); void fix_length_and_dec();
}; };
class Item_func_as_wkb :public Item_str_func
{
public:
Item_func_as_wkb(Item *a) :Item_str_func(a) {}
const char *func_name() const { return "aswkb"; }
String *val_str(String *);
void fix_length_and_dec();
};
class Item_func_geometry_type :public Item_str_func class Item_func_geometry_type :public Item_str_func
{ {
public: public:
......
...@@ -429,6 +429,7 @@ static SYMBOL sql_functions[] = { ...@@ -429,6 +429,7 @@ static SYMBOL sql_functions[] = {
{ "AREA", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_area)}, { "AREA", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_area)},
{ "ASIN", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_asin)}, { "ASIN", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_asin)},
{ "ASTEXT", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_as_text)}, { "ASTEXT", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_as_text)},
{ "ASWKB", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_as_wkb)},
{ "ATAN", SYM(ATAN),0,0}, { "ATAN", SYM(ATAN),0,0},
{ "ATAN2", SYM(ATAN),0,0}, { "ATAN2", SYM(ATAN),0,0},
{ "BENCHMARK", SYM(BENCHMARK_SYM),0,0}, { "BENCHMARK", SYM(BENCHMARK_SYM),0,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