diff options
author | Anel Husakovic <anel@mariadb.org> | 2019-05-23 06:13:55 -0700 |
---|---|---|
committer | Anel Husakovic <anel@mariadb.org> | 2019-07-08 08:53:28 -0700 |
commit | f17d605da70e162dc3bfff72d472cf7ba45e6d2c (patch) | |
tree | de285def8fa5bb98fce4d401a6b3726ada03034d | |
parent | b3b20907725ed3a00901e5947831d1653fa77d04 (diff) | |
download | mariadb-git-f17d605da70e162dc3bfff72d472cf7ba45e6d2c.tar.gz |
Add parsing of mysql json object with string values(0xc)
- Added parsing of mysql binary wrt KEY_ENTRY_SIZE and VALUE_ENTRY_SIZE
of json object only (@todo- json array)
- Added parsing of string value (@todo- add new function)
- (todo- add all other types supported by mysql)
- @todos- after review
- Output:
```
(gdb) p buffer->Ptr
$1 = 0x7fffe004ae48 "key1:val1,key2:val2"
```
-rw-r--r-- | sql/mysql_json.cc | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/sql/mysql_json.cc b/sql/mysql_json.cc index 25d8f5cf44c..78fdfe6134f 100644 --- a/sql/mysql_json.cc +++ b/sql/mysql_json.cc @@ -57,7 +57,57 @@ bool parse_array_or_object(Field_mysql_json::enum_type t, const char *data, // The header should not be larger than the full size of the value. if (header_size > *bytes) return true; /* purecov: inspected */ - //return Value(t, data, bytes, element_count, large); + + + if (t==Field_mysql_json::enum_type::OBJECT) + { + size_t key_json_offset, key_json_start, key_json_len; + size_t value_type_offset, value_counter(0); + size_t value_length, value_length_ptr; + //size_t value_json_type; + //String *buffer=(String *)malloc(sizeof(String)); // @anel v1 + String *buffer= new String(); // @anel v2 which construction ? + + char *key_element, *value_element; + for (uint i=0; i<*element_count; i++) + { + + key_json_offset= 2*offset_size+i*(large?KEY_ENTRY_SIZE_LARGE:KEY_ENTRY_SIZE_SMALL); + key_json_start= read_offset_or_size(data+key_json_offset,large); + key_json_len= read_offset_or_size(data+key_json_offset+offset_size, large); + + //key_element=(char *)malloc(sizeof(char)*key_json_len+1); // v1 + key_element= new char[key_json_len+1]; // v2 + memmove(key_element, const_cast<char*>(&data[key_json_start]), key_json_len); + key_element[key_json_len]= '\0'; + + // @anel method: String::apppend(const char*) is not working + //keys->append((const char*)key_element); // generating error + //keys->append(STRING_WITH_LEN(key_element)); + + buffer->append(String((const char *)key_element, &my_charset_bin)); + delete key_element; + + // @anel calculate value type and get a value + value_type_offset= 2*offset_size+ (large?KEY_ENTRY_SIZE_LARGE:KEY_ENTRY_SIZE_SMALL)*(*element_count)+(large ? VALUE_ENTRY_SIZE_LARGE : VALUE_ENTRY_SIZE_SMALL)*value_counter; + // value_json_type= data[value_type_offset]; + value_counter++; + + // this will go in separete function and depens on value_json_type + // For now value_json_type=12(0xc) is json_object + value_length_ptr= read_offset_or_size(data+value_type_offset+1, large); + value_length= (uint) data[value_length_ptr]; + value_element= new char[value_length+1]; + memmove(value_element, const_cast<char*>(&data[value_length_ptr+1]), value_length); + value_element[value_length]= '\0'; + buffer->append(":"); + buffer->append(String((const char *)value_element, &my_charset_bin)); + delete value_element; + if(i!=(*element_count-1)) + buffer->append(","); + } + } + return 1; } /** @@ -87,7 +137,7 @@ bool get_mysql_string(String* buffer, size_t type, const char *data, size_t len, return true; switch(type) { - case J_OBJECT: + case JSONB_TYPE_STRING: { if (buffer->append('{')) return true; /* purecov: inspected */ |