diff options
author | Anel Husakovic <anel@mariadb.org> | 2019-06-03 09:29:45 -0700 |
---|---|---|
committer | Anel Husakovic <anel@mariadb.org> | 2019-07-08 08:53:29 -0700 |
commit | 5646bddde893e045c111ff65fbf98b3159055e3f (patch) | |
tree | cf5b6738e05aab9470cb282e0b62905168a72816 | |
parent | afd109e02635632b94b55ad9f97e5ae2954ac7c6 (diff) | |
download | mariadb-git-5646bddde893e045c111ff65fbf98b3159055e3f.tar.gz |
Add temporary function
-rw-r--r-- | mysql-test/main/anel_array.test | 17 | ||||
-rw-r--r-- | mysql-test/main/anel_int.result | 11 | ||||
-rw-r--r-- | mysql-test/main/anel_json.result | 31 | ||||
-rw-r--r-- | mysql-test/std_data/simple_array_table_json_object.MYD | bin | 0 -> 56 bytes | |||
-rw-r--r-- | mysql-test/std_data/simple_array_table_json_object.MYI | bin | 0 -> 1024 bytes | |||
-rw-r--r-- | mysql-test/std_data/simple_array_table_json_object.frm | bin | 0 -> 8554 bytes | |||
-rw-r--r-- | sql/field.cc | 23 | ||||
-rw-r--r-- | sql/mysql_json.cc | 23 | ||||
-rw-r--r-- | sql/mysql_json.h | 2 |
9 files changed, 45 insertions, 62 deletions
diff --git a/mysql-test/main/anel_array.test b/mysql-test/main/anel_array.test new file mode 100644 index 00000000000..389304fc00f --- /dev/null +++ b/mysql-test/main/anel_array.test @@ -0,0 +1,17 @@ +let $datadir=`select @@datadir`; +drop table if exists mysql_json; + +--echo # +--echo # Array test +--echo # + + + +# Make sure you have placed `json.[frm/myd/myi]` files in `source/mysql-test/std_data/` +--copy_file std_data/simple_array_table_json_object.frm $datadir/test/mysql_json.frm +--copy_file std_data/simple_array_table_json_object.MYI $datadir/test/mysql_json.MYI +--copy_file std_data/simple_array_table_json_object.MYD $datadir/test/mysql_json.MYD + +# Now can read +select * from test.mysql_json; +drop table mysql_json; diff --git a/mysql-test/main/anel_int.result b/mysql-test/main/anel_int.result deleted file mode 100644 index b452bbc4625..00000000000 --- a/mysql-test/main/anel_int.result +++ /dev/null @@ -1,11 +0,0 @@ -drop table if exists mysql_json; -Warnings: -Note 1051 Unknown table 'test.mysql_json' -# -# Mix of INT32 and UINT64 -# -select * from test.mysql_json; -t -{"neg":-1234567890,"pos":9876543210} -Finshed -drop table mysql_json; diff --git a/mysql-test/main/anel_json.result b/mysql-test/main/anel_json.result deleted file mode 100644 index 56652e374c1..00000000000 --- a/mysql-test/main/anel_json.result +++ /dev/null @@ -1,31 +0,0 @@ -# -# MDEV-18323: Convert MySQL JSON type to MariaDB TEXT in mysql_upgrade -# Test integers -# -drop table if exists mysql_json; -Warnings: -Note 1051 Unknown table 'test.mysql_json' -# -# String value -# -select * from test.mysql_json; -t -{"key1":"val1","key2":"val2"} -Finshed -drop table mysql_json; -# -# Negative value -# -select * from test.mysql_json; -t -{"neg":-10} -Finshed -drop table mysql_json; -# -# Mix of INT32 and UINT64 -# -select * from test.mysql_json; -t -{"neg":-1234567890,"pos":9876543210} -Finshed -drop table mysql_json; diff --git a/mysql-test/std_data/simple_array_table_json_object.MYD b/mysql-test/std_data/simple_array_table_json_object.MYD Binary files differnew file mode 100644 index 00000000000..0ee8f88ad1b --- /dev/null +++ b/mysql-test/std_data/simple_array_table_json_object.MYD diff --git a/mysql-test/std_data/simple_array_table_json_object.MYI b/mysql-test/std_data/simple_array_table_json_object.MYI Binary files differnew file mode 100644 index 00000000000..51f3416ba96 --- /dev/null +++ b/mysql-test/std_data/simple_array_table_json_object.MYI diff --git a/mysql-test/std_data/simple_array_table_json_object.frm b/mysql-test/std_data/simple_array_table_json_object.frm Binary files differnew file mode 100644 index 00000000000..c55262019fc --- /dev/null +++ b/mysql-test/std_data/simple_array_table_json_object.frm diff --git a/sql/field.cc b/sql/field.cc index dd0e56fb28e..93cd19898c9 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -11225,25 +11225,12 @@ bool Field_mysql_json::parse_mysql(String *s, bool json_quoted, size_t len=length-1; bool large; - switch (type) + large= ((type == JSONB_TYPE_LARGE_OBJECT) || (type == JSONB_TYPE_LARGE_ARRAY)); + if(get_mysql_string(s, type, data1, len, large)) { - case JSONB_TYPE_SMALL_OBJECT: - { - large=false; - parse_array_or_object(s, Field_mysql_json::enum_type::OBJECT, data1, len, large); - break; - } - case JSONB_TYPE_LARGE_OBJECT: - return false; //this->parse_array_or_object(Field_mysql_json::OBJECT, data1, len, true); - case JSONB_TYPE_SMALL_ARRAY: - return false; //this->parse_array_or_object(Field_mysql_json::ARRAY, data1, len, false); - case JSONB_TYPE_LARGE_ARRAY: - return false; //parse_array_or_object(Field_mysql_json::ARRAY, data1, len, true); - default: - return false;//this->parse_scalar(type, data, len); + return true; } - - return true; + return false; } String *Field_mysql_json::val_str(String *buf1_tmp, String *buf2 __attribute__((unused))) @@ -11251,7 +11238,7 @@ bool Field_mysql_json::parse_mysql(String *s, bool json_quoted, ASSERT_COLUMN_MARKED_FOR_READ; String *buf1= Field_blob::val_str(buf1_tmp, buf2); bool parsed= this->parse_mysql(buf1, true, field_name.str); - if(parsed) + if(!parsed) buf1->append("\nFinshed"); else buf1->length(0); diff --git a/sql/mysql_json.cc b/sql/mysql_json.cc index 299e85aa59c..5d3b58e6e58 100644 --- a/sql/mysql_json.cc +++ b/sql/mysql_json.cc @@ -36,7 +36,26 @@ static bool check_json_depth(size_t depth) } return false; } - +bool get_mysql_string(String *buffer, size_t type, const char *data, size_t len, + bool large) +{ + switch (type) + { + case JSONB_TYPE_SMALL_OBJECT: + { + large=false; + return parse_array_or_object(buffer, Field_mysql_json::enum_type::OBJECT, data, len, large); + } + case JSONB_TYPE_LARGE_OBJECT: + return false; //this->parse_array_or_object(Field_mysql_json::OBJECT, data1, len, true); + case JSONB_TYPE_SMALL_ARRAY: + return false; //this->parse_array_or_object(Field_mysql_json::ARRAY, data1, len, false); + case JSONB_TYPE_LARGE_ARRAY: + return false; //parse_array_or_object(Field_mysql_json::ARRAY, data1, len, true); + default: + return false;//this->parse_scalar(type, data, len); + } +} bool parse_array_or_object(String *buffer,Field_mysql_json::enum_type t, const char *data, size_t len, bool large) { @@ -127,7 +146,7 @@ bool parse_array_or_object(String *buffer,Field_mysql_json::enum_type t, const c return true; } - return 1; + return false; } bool check_mysql_value_type_and_append(String* buffer, size_t value_type_offset, const char *data, bool is_last, bool large, size_t depth) diff --git a/sql/mysql_json.h b/sql/mysql_json.h index d6d7d7657e2..58d0b142cbb 100644 --- a/sql/mysql_json.h +++ b/sql/mysql_json.h @@ -140,6 +140,8 @@ enum enum_json_opaque_type { // Prototypes size_t read_offset_or_size(const char *, bool); +bool get_mysql_string(String *buffer, size_t type, const char *data, size_t len, + bool large); bool parse_array_or_object(String * buffer, Field_mysql_json::enum_type, const char *,size_t , bool); bool parse_scalar(); |