Current Path : /home/usr.opt/mysql57/mysql-test/suite/x/t/ |
FreeBSD hs32.drive.ne.jp 9.1-RELEASE FreeBSD 9.1-RELEASE #1: Wed Jan 14 12:18:08 JST 2015 root@hs32.drive.ne.jp:/sys/amd64/compile/hs32 amd64 |
Current File : //home/usr.opt/mysql57/mysql-test/suite/x/t/update_crud_replace_o.test |
########### ../t/update_crud_replace_o.test ############ ### # ### This test runs aims to run UPDATE REPLACE operation statement # ### variant with mysqlxtest client. # ### Test covers # ### - update with different operators # ### - update on multiple rows # ### - update (ITEM_REPLACE) with data model as document # ### - update with transaction (rollback/commit) # ### # ######################################################################## # --echo ============================================= --echo CRUD UPDATE ITEM_REPLACE SCENARIOS --echo ============================================= --echo --echo ================================================================================ --echo PREAMBLE --echo ================================================================================ ## Preamble --source ../include/xplugin_preamble.inc create user upditemreplace@localhost identified by 'upditemreplace'; grant all on *.* to upditemreplace@localhost; ## TEST STARTS HERE --echo ================================================================================ --echo TEST START --echo ================================================================================ --write_file $MYSQL_TMP_DIR/mysqlx-update_itemreplace.tmp -->sql SET SQL_SAFE_UPDATES = 0; DROP SCHEMA if EXISTS mysqlxcoll; CREATE SCHEMA mysqlxcoll; USE mysqlxcoll; CREATE TABLE maincoll (doc JSON, _id VARCHAR(32) NOT NULL PRIMARY KEY); INSERT INTO maincoll (doc, _id) values ('{"_id": "1", "name": "Victor", "last_name": "Otero","amount": 4.99}',json_unquote(json_extract(doc, '$._id'))); INSERT INTO maincoll (doc, _id) values ('{"_id": "2", "name": "Gonzalo", "last_name": "Chrystens","amount": 120.57}',json_unquote(json_extract(doc, '$._id'))); INSERT INTO maincoll (doc, _id) values ('{"_id": "3", "name": "Abraham", "last_name": "Vega","amount": 74.56}',json_unquote(json_extract(doc, '$._id'))); INSERT INTO maincoll (doc, _id) values ('{"_id": "4", "name": "Jennifer", "last_name": "Leon","amount": 387.14}',json_unquote(json_extract(doc, '$._id'))); INSERT INTO maincoll (doc, _id) values ('{"_id": "5", "name": "Jhonny", "last_name": "Test","amount": 125.45}',json_unquote(json_extract(doc, '$._id'))); INSERT INTO maincoll (doc, _id) values ('{"_id": "0"}',json_unquote(json_extract(doc, '$._id'))); -->endsql -->echo Update a valid collection with == operator Mysqlx.Crud.Update { collection { name: "maincoll" schema: "mysqlxcoll" } data_model: DOCUMENT criteria { type: OPERATOR operator { name: "==" param { type: IDENT identifier { name: "_id" } } param { type: LITERAL literal { type: V_OCTETS v_octets {value:"1"} } } } } operation { source { document_path { type: MEMBER value: "name" } } operation: ITEM_REPLACE value { type: LITERAL literal { type: V_STRING v_string { value: "\"VictorReplaced\"" } } } } } -- Mysqlx.Sql.StmtExecuteOk -->recvresult -->sql select * from maincoll; -->endsql -->echo Update a valid collection with string value and > operator for multiple docs Mysqlx.Crud.Update { collection { name: "maincoll" schema: "mysqlxcoll" } data_model: DOCUMENT criteria { type: OPERATOR operator { name: ">" param { type: IDENT identifier { document_path { type: MEMBER value: "_id" } } } param { type: LITERAL literal { type: V_OCTETS v_octets {value:"3"} } } } } operation { source { document_path { type: MEMBER value: "name" } } operation: ITEM_REPLACE value { type: LITERAL literal { type: V_STRING v_string { value: "\"xtest_>\"" } } } } } -- Mysqlx.Sql.StmtExecuteOk -->recvresult -->sql select * from maincoll; -->endsql -->echo Update a valid collection with string value and < operator for multiple docs Mysqlx.Crud.Update { collection { name: "maincoll" schema: "mysqlxcoll" } data_model: DOCUMENT criteria { type: OPERATOR operator { name: "<" param { type: IDENT identifier { document_path { type: MEMBER value: "_id" } } } param { type: LITERAL literal { type: V_OCTETS v_octets {value:"3"} } } } } operation { source { document_path { type: MEMBER value: "name" } } operation: ITEM_REPLACE value { type: LITERAL literal { type: V_STRING v_string { value: "\"xtest_<\"" } } } } } -- Mysqlx.Sql.StmtExecuteOk -->recvresult -->sql select * from maincoll; -->endsql -->echo Update a valid collection with string value and <= operator for multiple docs Mysqlx.Crud.Update { collection { name: "maincoll" schema: "mysqlxcoll" } data_model: DOCUMENT criteria { type: OPERATOR operator { name: "<=" param { type: IDENT identifier { document_path { type: MEMBER value: "_id" } } } param { type: LITERAL literal { type: V_OCTETS v_octets {value:"3"} } } } } operation { source { document_path { type: MEMBER value: "last_name" } } operation: ITEM_REPLACE value { type: LITERAL literal { type: V_STRING v_string { value: "\"xtest_<=\"" } } } } } -- Mysqlx.Sql.StmtExecuteOk -->recvresult -->sql select * from maincoll; -->endsql -->echo Update a valid collection with string value and >= operator for multiple docs Mysqlx.Crud.Update { collection { name: "maincoll" schema: "mysqlxcoll" } data_model: DOCUMENT criteria { type: OPERATOR operator { name: ">=" param { type: IDENT identifier { document_path { type: MEMBER value: "_id" } } } param { type: LITERAL literal { type: V_OCTETS v_octets {value:"4"} } } } } operation { source { document_path { type: MEMBER value: "last_name" } } operation: ITEM_REPLACE value { type: LITERAL literal { type: V_STRING v_string { value: "\"xtest_>=\"" } } } } } -- Mysqlx.Sql.StmtExecuteOk -->recvresult -->sql select * from maincoll; -->endsql -->echo Update a valid collection with string value and != operator for multiple docs Mysqlx.Crud.Update { collection { name: "maincoll" schema: "mysqlxcoll" } data_model: DOCUMENT criteria { type: OPERATOR operator { name: "!=" param { type: IDENT identifier { document_path { type: MEMBER value: "_id" } } } param { type: LITERAL literal { type: V_OCTETS v_octets {value:"2"} } } } } operation { source { document_path { type: MEMBER value: "amount" } } operation: ITEM_REPLACE value { type: LITERAL literal { type: V_STRING v_string { value: "\"xtest_!=\"" } } } } } -- Mysqlx.Sql.StmtExecuteOk -->recvresult -->sql select * from maincoll; -->endsql -->echo Update with non existing doc member Mysqlx.Crud.Update { collection { name: "maincoll" schema: "mysqlxcoll" } data_model: DOCUMENT criteria { type: OPERATOR operator { name: "!=" param { type: IDENT identifier { document_path { type: MEMBER value: "_id" } } } param { type: LITERAL literal { type: V_OCTETS v_octets {value:"2"} } } } } operation { source { document_path { type: MEMBER value: "notamember" } } operation: ITEM_REPLACE value { type: LITERAL literal { type: V_STRING v_string { value: "\"xtest_notmemberdoc\"" } } } } } -- Mysqlx.Sql.StmtExecuteOk -->recvresult -->sql select * from maincoll; -->endsql -->echo unsigned int data type update for Document Mysqlx.Crud.Update { collection { name: "maincoll" schema: "mysqlxcoll" } data_model: DOCUMENT criteria { type: OPERATOR operator { name: ">" param { type: IDENT identifier { document_path { type: MEMBER value: "_id" } } } param { type: LITERAL literal { type: V_OCTETS v_octets {value:"3"} } } } } operation { source { document_path { type: MEMBER value: "amount" } } operation: ITEM_REPLACE value { type: LITERAL literal { type: V_UINT v_unsigned_int: 23 } } } } -- Mysqlx.Sql.StmtExecuteOk -->recvresult -->sql select * from maincoll; -->endsql -->echo signed int data type update for Document Mysqlx.Crud.Update { collection { name: "maincoll" schema: "mysqlxcoll" } data_model: DOCUMENT criteria { type: OPERATOR operator { name: ">" param { type: IDENT identifier { document_path { type: MEMBER value: "_id" } } } param { type: LITERAL literal { type: V_OCTETS v_octets {value:"3"} } } } } operation { source { document_path { type: MEMBER value: "amount" } } operation: ITEM_REPLACE value { type: LITERAL literal { type: V_SINT v_signed_int: 25 } } } } -- Mysqlx.Sql.StmtExecuteOk -->recvresult -->sql select * from maincoll; -->endsql -->echo double data type update for Document Mysqlx.Crud.Update { collection { name: "maincoll" schema: "mysqlxcoll" } data_model: DOCUMENT criteria { type: OPERATOR operator { name: ">" param { type: IDENT identifier { document_path { type: MEMBER value: "_id" } } } param { type: LITERAL literal { type: V_OCTETS v_octets {value:"3"} } } } } operation { source { document_path { type: MEMBER value: "amount" } } operation: ITEM_REPLACE value { type: LITERAL literal { type: V_DOUBLE v_double: 26.53 } } } } -- Mysqlx.Sql.StmtExecuteOk -->recvresult -->sql select * from maincoll; -->endsql -->echo float data type update for Document Mysqlx.Crud.Update { collection { name: "maincoll" schema: "mysqlxcoll" } data_model: DOCUMENT criteria { type: OPERATOR operator { name: ">" param { type: IDENT identifier { document_path { type: MEMBER value: "_id" } } } param { type: LITERAL literal { type: V_OCTETS v_octets {value:"3"} } } } } operation { source { document_path { type: MEMBER value: "amount" } } operation: ITEM_REPLACE value { type: LITERAL literal { type: V_FLOAT v_float: 27.75 } } } } -- Mysqlx.Sql.StmtExecuteOk -->recvresult -->sql select * from maincoll; -->endsql -->echo Update with order clause update last _id in desc order (_id = 5) Mysqlx.Crud.Update { collection { name: "maincoll" schema: "mysqlxcoll" } data_model: DOCUMENT criteria { type: OPERATOR operator { name: "!=" param { type: IDENT identifier { document_path { type: MEMBER value: "_id" } } } param { type: LITERAL literal { type: V_OCTETS v_octets {value:"0"} } } } } limit { row_count: 1 } order { expr { type: IDENT identifier { name: "_id" } } direction: DESC } operation { source { document_path { type: MEMBER value: "amount" } } operation: ITEM_REPLACE value { type: LITERAL literal { type: V_DOUBLE v_double: 1234.567 } } } } -- Mysqlx.Sql.StmtExecuteOk -->recvresult -->sql select * from maincoll; -->endsql -->echo Update with order clause update first two _id in asc order (_id = 1,2) Mysqlx.Crud.Update { collection { name: "maincoll" schema: "mysqlxcoll" } data_model: DOCUMENT criteria { type: OPERATOR operator { name: "!=" param { type: IDENT identifier { document_path { type: MEMBER value: "_id" } } } param { type: LITERAL literal { type: V_OCTETS v_octets {value:"0"} } } } } limit { row_count: 2 } order { expr { type: IDENT identifier { name: "_id" } } direction: ASC } operation { source { document_path { type: MEMBER value: "amount" } } operation: ITEM_REPLACE value { type: LITERAL literal { type: V_DOUBLE v_double: 9876.543 } } } } -- Mysqlx.Sql.StmtExecuteOk -->recvresult -->sql select * from maincoll; -->endsql -->echo Null value for Document Mysqlx.Crud.Update { collection { name: "maincoll" schema: "mysqlxcoll" } data_model: DOCUMENT criteria { type: OPERATOR operator { name: ">" param { type: IDENT identifier { document_path { type: MEMBER value: "_id" } } } param { type: LITERAL literal { type: V_OCTETS v_octets {value:"3"} } } } } operation { source { document_path { type: MEMBER value: "amount" } } operation: ITEM_REPLACE value { type: LITERAL literal { type: V_NULL } } } } -- Mysqlx.Sql.StmtExecuteOk -->recvresult -->sql select * from maincoll; START TRANSACTION; -->endsql -->echo Update Transaction Rollback Mysqlx.Crud.Update { collection { name: "maincoll" schema: "mysqlxcoll" } data_model: DOCUMENT criteria { type: OPERATOR operator { name: "==" param { type: IDENT identifier { document_path { type: MEMBER value: "_id" } } } param { type: LITERAL literal { type: V_OCTETS v_octets {value:"5"} } } } } operation { source { document_path { type: MEMBER value: "last_name" } } operation: ITEM_REPLACE value { type: LITERAL literal { type: V_STRING v_string { value: "\"Iam_rollback\"" } } } } } -- Mysqlx.Sql.StmtExecuteOk -->recvresult -->sql select * from maincoll; ROLLBACK; select * from maincoll; -->endsql -->sql START TRANSACTION; -->endsql -->echo Update Transaction and Commit Mysqlx.Crud.Update { collection { name: "maincoll" schema: "mysqlxcoll" } data_model: DOCUMENT criteria { type: OPERATOR operator { name: "==" param { type: IDENT identifier { document_path { type: MEMBER value: "_id" } } } param { type: LITERAL literal { type: V_OCTETS v_octets {value:"5"} } } } } operation { source { document_path { type: MEMBER value: "last_name" } } operation: ITEM_REPLACE value { type: LITERAL literal { type: V_STRING v_string { value: "\"Iam_commit\"" } } } } } -- Mysqlx.Sql.StmtExecuteOk -->recvresult -->sql COMMIT; select * from maincoll; -->endsql -->echo Invalid type of update for Document Mysqlx.Crud.Update { collection { name: "maincoll" schema: "mysqlxcoll" } data_model: DOCUMENT criteria { type: OPERATOR operator { name: ">" param { type: IDENT identifier { document_path { type: MEMBER value: "_id" } } } param { type: LITERAL literal { type: V_OCTETS v_octets {value:"3"} } } } } operation { source { document_path { type: MEMBER value: "name" } } operation: SET value { type: LITERAL literal { type: V_STRING v_string { value: "xtest" } } } } } -- Mysqlx.Error -->recverror 5051 ## Cleanup -->echo ================================================================================ -->echo CLEAN UP -->echo ================================================================================ -->sql DROP SCHEMA if EXISTS mysqlxcoll; DROP USER upditemreplace@localhost; SET SQL_SAFE_UPDATES = 1; -->endsql EOF --exec $MYSQLXTEST -u upditemreplace --password='upditemreplace' --file=$MYSQL_TMP_DIR/mysqlx-update_itemreplace.tmp 2>&1 --remove_file $MYSQL_TMP_DIR/mysqlx-update_itemreplace.tmp ## Postamble --echo ================================================================================ --echo POSTAMBLE --echo ================================================================================ uninstall plugin mysqlx;