diff options
Diffstat (limited to 'sql/item_geofunc.cc')
-rw-r--r-- | sql/item_geofunc.cc | 56 |
1 files changed, 52 insertions, 4 deletions
diff --git a/sql/item_geofunc.cc b/sql/item_geofunc.cc index e553af6110a..04952739e85 100644 --- a/sql/item_geofunc.cc +++ b/sql/item_geofunc.cc @@ -122,13 +122,27 @@ String *Item_func_geometry_from_json::val_str(String *str) Geometry_buffer buffer; String *js= args[0]->val_str_ascii(&tmp_js); uint32 srid= 0; + longlong options= 0; json_engine_t je; if ((null_value= args[0]->null_value)) return 0; - if ((arg_count == 2) && !args[1]->null_value) - srid= (uint32)args[1]->val_int(); + if (arg_count > 1 && !args[1]->null_value) + { + options= args[1]->val_int(); + if (options > 4 || options < 1) + { + String *sv= args[1]->val_str(&tmp_js); + my_error(ER_WRONG_VALUE_FOR_TYPE, MYF(0), + "option", sv->c_ptr(), "ST_GeometryFromJSON"); + null_value= 1; + return 0; + } + } + + if ((arg_count == 3) && !args[2]->null_value) + srid= (uint32)args[2]->val_int(); str->set_charset(&my_charset_bin); if (str->reserve(SRID_SIZE, 512)) @@ -139,7 +153,7 @@ String *Item_func_geometry_from_json::val_str(String *str) json_scan_start(&je, js->charset(), (const uchar *) js->ptr(), (const uchar *) js->end()); - if ((null_value= !Geometry::create_from_json(&buffer, &je, str))) + if ((null_value= !Geometry::create_from_json(&buffer, &je, options==1, str))) { int code= 0; @@ -154,6 +168,9 @@ String *Item_func_geometry_from_json::val_str(String *str) case Geometry::GEOJ_POLYGON_NOT_CLOSED: code= ER_GEOJSON_NOT_CLOSED; break; + case Geometry::GEOJ_DIMENSION_NOT_SUPPORTED: + my_error(ER_GIS_INVALID_DATA, MYF(0), "ST_GeometryFromJSON"); + break; default: report_json_error_ex(js, &je, func_name(), 0, Sql_condition::WARN_LEVEL_WARN); return NULL; @@ -233,6 +250,8 @@ String *Item_func_as_geojson::val_str_ascii(String *str) DBUG_ASSERT(fixed == 1); String arg_val; String *swkb= args[0]->val_str(&arg_val); + uint max_dec= FLOATING_POINT_DECIMALS; + longlong options= 0; Geometry_buffer buffer; Geometry *geom= NULL; const char *dummy; @@ -242,12 +261,41 @@ String *Item_func_as_geojson::val_str_ascii(String *str) !(geom= Geometry::construct(&buffer, swkb->ptr(), swkb->length()))))) return 0; + if (arg_count > 1) + { + max_dec= (uint) args[1]->val_int(); + if (args[1]->null_value) + max_dec= FLOATING_POINT_DECIMALS; + if (arg_count > 2) + { + options= args[2]->val_int(); + if (args[2]->null_value) + options= 0; + } + } + str->length(0); str->set_charset(&my_charset_latin1); - if ((null_value= geom->as_json(str, FLOATING_POINT_DECIMALS, &dummy))) + + if (str->reserve(1, 512)) return 0; + str->qs_append('{'); + + if (options & 1) + { + if (geom->bbox_as_json(str) || str->append(", ", 2)) + goto error; + } + + if ((geom->as_json(str, max_dec, &dummy) || str->append("}", 1))) + goto error; + return str; + +error: + null_value= 1; + return 0; } |