diff options
author | unknown <ram@mysql.r18.ru> | 2003-04-03 15:13:14 +0500 |
---|---|---|
committer | unknown <ram@mysql.r18.ru> | 2003-04-03 15:13:14 +0500 |
commit | 7835ff508331e46f9983912c2d1ddffde42c2685 (patch) | |
tree | 3e563294225fa9f9c646d386809ffd3e66999c9f | |
parent | 1e8cc909de55b33b7a73ebfa7186598c1a7dbba3 (diff) | |
download | mariadb-git-7835ff508331e46f9983912c2d1ddffde42c2685.tar.gz |
AsWKB() function has been added.
-rw-r--r-- | mysql-test/r/gis.result | 5 | ||||
-rw-r--r-- | mysql-test/t/gis.test | 4 | ||||
-rw-r--r-- | sql/item_create.cc | 5 | ||||
-rw-r--r-- | sql/item_create.h | 1 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 21 | ||||
-rw-r--r-- | sql/item_strfunc.h | 9 | ||||
-rw-r--r-- | sql/lex.h | 1 |
7 files changed, 44 insertions, 2 deletions
diff --git a/mysql-test/r/gis.result b/mysql-test/r/gis.result index 12a1428d514..a5a280b974f 100644 --- a/mysql-test/r/gis.result +++ b/mysql-test/r/gis.result @@ -43,7 +43,7 @@ INSERT INTO pt VALUES (101, PointFromText('POINT(10 10)')), (102, PointFromText('POINT(20 10)')), (103, PointFromText('POINT(20 20)')), -(104, PointFromText('POINT(10 20)')); +(104, PointFromWKB(AsWKB(PointFromText('POINT(10 20)')))); INSERT INTO ls VALUES (105, LineFromText('LINESTRING(0 0,0 10,10 0)')), (106, LineStringFromText('LINESTRING(10 10,20 10,20 20,10 20,10 10)')), @@ -388,3 +388,6 @@ gc geometrycollection binary YES NULL gm geometry binary YES NULL fid int(11) binary 0 DROP TABLE g1; +SELECT AsText(GeometryFromWKB(AsWKB(GeometryFromText('POINT(1 4)')))); +AsText(GeometryFromWKB(AsWKB(GeometryFromText('POINT(1 4)')))) +POINT(1 4) diff --git a/mysql-test/t/gis.test b/mysql-test/t/gis.test index f1fe8b33cc5..b7c41135123 100644 --- a/mysql-test/t/gis.test +++ b/mysql-test/t/gis.test @@ -29,7 +29,7 @@ INSERT INTO pt VALUES (101, PointFromText('POINT(10 10)')), (102, PointFromText('POINT(20 10)')), (103, PointFromText('POINT(20 20)')), -(104, PointFromText('POINT(10 20)')); +(104, PointFromWKB(AsWKB(PointFromText('POINT(10 20)')))); INSERT INTO ls VALUES (105, LineFromText('LINESTRING(0 0,0 10,10 0)')), @@ -140,3 +140,5 @@ SHOW FIELDS FROM g1; ALTER TABLE g1 ADD fid INT NOT NULL; SHOW FIELDS FROM g1; DROP TABLE g1; + +SELECT AsText(GeometryFromWKB(AsWKB(GeometryFromText('POINT(1 4)')))); diff --git a/sql/item_create.cc b/sql/item_create.cc index 3bc6fa47e83..b9179a84c12 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -491,6 +491,11 @@ Item *create_func_as_text(Item *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) { return new Item_func_srid(a); diff --git a/sql/item_create.h b/sql/item_create.h index 0e2295b6d4f..f1f9c4673d8 100644 --- a/sql/item_create.h +++ b/sql/item_create.h @@ -105,6 +105,7 @@ Item *create_func_quote(Item* a); Item *create_func_geometry_from_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_startpoint(Item *a); Item *create_func_endpoint(Item *a); diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 5b2706e3eef..31ae5a3d437 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -2585,6 +2585,27 @@ void Item_func_as_text::fix_length_and_dec() 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 *swkb= args[0]->val_str(str); diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index e403b970fe1..6c5dbe49915 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -665,6 +665,15 @@ public: 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 { public: diff --git a/sql/lex.h b/sql/lex.h index aab530251b8..98a802f5c4a 100644 --- a/sql/lex.h +++ b/sql/lex.h @@ -429,6 +429,7 @@ static SYMBOL sql_functions[] = { { "AREA", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_area)}, { "ASIN", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_asin)}, { "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}, { "ATAN2", SYM(ATAN),0,0}, { "BENCHMARK", SYM(BENCHMARK_SYM),0,0}, |