| 1 |
## Inserting with upsert |
| 2 |
|
| 3 |
## Preamble |
| 4 |
--source include/xplugin_preamble.inc |
| 5 |
--source include/xplugin_create_user.inc |
| 6 |
## Test starts here |
| 7 |
|
| 8 |
--write_file $MYSQL_TMP_DIR/crud_insert_docid.xpl |
| 9 |
## Test data |
| 10 |
-->quiet |
| 11 |
-->import crud_insert.macro |
| 12 |
-->import crud_find.macro |
| 13 |
|
| 14 |
-->varlet %DOC_S1% type:V_OCTETS v_octets{value:'{"_id": "1", "one":1}' content_type:2} |
| 15 |
-->varlet %DOC_S2% type:V_OCTETS v_octets{value:'{"two":2}' content_type:2} |
| 16 |
|
| 17 |
-->varlet %DOC_1% type:LITERAL literal{%DOC_S1%} |
| 18 |
-->varlet %DOC_2% type:LITERAL literal{%DOC_S2%} |
| 19 |
-->varlet %DOC_3% type:LITERAL literal{type:V_OCTETS v_octets{value:'{"three":3}' content_type:2}} |
| 20 |
|
| 21 |
-->varlet %DOC_BAD% type:LITERAL literal{type:V_SINT v_signed_int:42} |
| 22 |
|
| 23 |
-->varlet %DOC_O1% type:OBJECT object{fld{key:"_id" value{type:LITERAL literal{type: V_OCTETS v_octets{value:"1"}}}} fld{key:"one" value{type:LITERAL literal{type:V_SINT v_signed_int:1}}}} |
| 24 |
-->varlet %DOC_O2% type:OBJECT object{fld{key:"two" value{type:LITERAL literal{type:V_SINT v_signed_int:2}}}} |
| 25 |
|
| 26 |
|
| 27 |
-->macro Setup %NAME% |
| 28 |
-->stmtadmin ensure_collection {"schema":"xtest","name":"%NAME%"} |
| 29 |
-->recvresult |
| 30 |
-->stmtsql truncate table xtest.%NAME% |
| 31 |
-->recvresult |
| 32 |
-->endmacro |
| 33 |
|
| 34 |
|
| 35 |
-->macro Insert_via_placeholder %MODEL% %TABLE% %ARG% %ERROR% |
| 36 |
-->callmacro Insert_raw %MODEL% %TABLE% row{field {type:PLACEHOLDER position:0}} args{ %ARG% } |
| 37 |
-->expecterror %ERROR% |
| 38 |
-->recvresult |
| 39 |
-->endmacro |
| 40 |
|
| 41 |
|
| 42 |
-->macro Check_notice_for_insert_one %MODEL% %TABLE% %ROW% |
| 43 |
-->callmacro Insert_raw %MODEL% %TABLE% row{field{%ROW%}} |
| 44 |
#-->recvuntil Mysqlx.Notice.Frame |
| 45 |
-->recvuntil Mysqlx.Sql.StmtExecuteOk |
| 46 |
-->endmacro |
| 47 |
|
| 48 |
|
| 49 |
-->macro Check_notice_for_insert_two %MODEL% %TABLE% %ROW1% %ROW2% |
| 50 |
-->callmacro Insert_raw %MODEL% %TABLE% row{field{%ROW1%}} row{field{%ROW2%}} |
| 51 |
#-->recvuntil Mysqlx.Notice.Frame |
| 52 |
-->recvuntil Mysqlx.Sql.StmtExecuteOk |
| 53 |
-->endmacro |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
-->title -Insert: doc with _id (literal) |
| 58 |
-->callmacro Setup coll |
| 59 |
-->callmacro Insert_one DOCUMENT coll %DOC_1% ER_SUCCESS |
| 60 |
-->callmacro Show coll |
| 61 |
|
| 62 |
|
| 63 |
-->title -Insert: doc without _id (literal) |
| 64 |
-->callmacro Setup coll |
| 65 |
-->callmacro Insert_one DOCUMENT coll %DOC_2% ER_SUCCESS |
| 66 |
-->callmacro Show coll |
| 67 |
|
| 68 |
|
| 69 |
-->title -Insert: doc with _id (object) |
| 70 |
-->callmacro Setup coll |
| 71 |
-->callmacro Insert_one DOCUMENT coll %DOC_O1% ER_SUCCESS |
| 72 |
-->callmacro Show coll |
| 73 |
|
| 74 |
|
| 75 |
-->title -Insert: doc without _id (object) |
| 76 |
-->callmacro Setup coll |
| 77 |
-->callmacro Insert_one DOCUMENT coll %DOC_O2% ER_SUCCESS |
| 78 |
-->callmacro Show coll |
| 79 |
|
| 80 |
|
| 81 |
-->title -Insert: doc with _id (placeholder) |
| 82 |
-->callmacro Setup coll |
| 83 |
-->callmacro Insert_via_placeholder DOCUMENT coll %DOC_S1% ER_SUCCESS |
| 84 |
-->callmacro Show coll |
| 85 |
|
| 86 |
|
| 87 |
-->title -Insert: doc without _id (placeholder) |
| 88 |
-->callmacro Setup coll |
| 89 |
-->callmacro Insert_via_placeholder DOCUMENT coll %DOC_S2% ER_SUCCESS |
| 90 |
-->callmacro Show coll |
| 91 |
|
| 92 |
|
| 93 |
-->title -Insert: 2 doc without _id (literal) |
| 94 |
-->callmacro Setup coll |
| 95 |
-->callmacro Insert_two DOCUMENT coll %DOC_2% %DOC_3% ER_SUCCESS |
| 96 |
-->callmacro Show coll |
| 97 |
|
| 98 |
|
| 99 |
-->title -Insert: 2 doc without _id (literal/object) |
| 100 |
-->callmacro Setup coll |
| 101 |
-->callmacro Insert_two DOCUMENT coll %DOC_3% %DOC_O2% ER_SUCCESS |
| 102 |
-->callmacro Show coll |
| 103 |
|
| 104 |
|
| 105 |
-->title -Insert: 2 doc with/without _id (literal) |
| 106 |
-->callmacro Setup coll |
| 107 |
-->callmacro Insert_two DOCUMENT coll %DOC_1% %DOC_3% ER_SUCCESS |
| 108 |
-->callmacro Show coll |
| 109 |
|
| 110 |
|
| 111 |
-->title -Insert: 2 doc with/without _id (object) |
| 112 |
-->callmacro Setup coll |
| 113 |
-->callmacro Insert_two DOCUMENT coll %DOC_O1% %DOC_O2% ER_SUCCESS |
| 114 |
-->callmacro Show coll |
| 115 |
|
| 116 |
|
| 117 |
-->title -Insert: bad doc (literal) no insert |
| 118 |
-->callmacro Setup coll |
| 119 |
-->callmacro Insert_one DOCUMENT coll %DOC_BAD% ER_INVALID_JSON_TEXT |
| 120 |
-->callmacro Show coll |
| 121 |
|
| 122 |
|
| 123 |
-->title -Insert: 2 doc (literal) one bad, no insert |
| 124 |
-->callmacro Setup coll |
| 125 |
-->callmacro Insert_two DOCUMENT coll %DOC_BAD% %DOC_1% ER_INVALID_JSON_TEXT |
| 126 |
-->callmacro Show coll |
| 127 |
|
| 128 |
|
| 129 |
-->title -Insert: change of "unique_prefix" |
| 130 |
-->stmtsql set global mysqlx_document_id_unique_prefix = 255 |
| 131 |
-->recvresult |
| 132 |
-->callmacro Setup coll |
| 133 |
-->callmacro Insert_two DOCUMENT coll %DOC_2% %DOC_3% ER_SUCCESS |
| 134 |
-->callmacro Show coll |
| 135 |
|
| 136 |
|
| 137 |
-->title -Insert: change of "auto_increment_increment" |
| 138 |
-->stmtsql set auto_increment_increment = 256 |
| 139 |
-->recvresult |
| 140 |
-->callmacro Setup coll |
| 141 |
-->callmacro Insert_two DOCUMENT coll %DOC_2% %DOC_3% ER_SUCCESS |
| 142 |
-->callmacro Show coll |
| 143 |
|
| 144 |
|
| 145 |
-->title -Insert: change of "auto_increment_offset" |
| 146 |
-->stmtsql set auto_increment_offset = 128 |
| 147 |
-->recvresult |
| 148 |
-->callmacro Setup coll |
| 149 |
-->callmacro Insert_two DOCUMENT coll %DOC_2% %DOC_3% ER_SUCCESS |
| 150 |
-->callmacro Show coll |
| 151 |
|
| 152 |
|
| 153 |
-->title -Insert: reset of "unique_prefix", "auto_increment_increment" and "auto_increment_offset" |
| 154 |
-->sql |
| 155 |
set global mysqlx_document_id_unique_prefix = DEFAULT; |
| 156 |
set auto_increment_increment = DEFAULT; |
| 157 |
set auto_increment_offset = DEFAULT; |
| 158 |
-->endsql |
| 159 |
-->callmacro Setup coll |
| 160 |
-->callmacro Insert_two DOCUMENT coll %DOC_2% %DOC_3% ER_SUCCESS |
| 161 |
-->callmacro Show coll |
| 162 |
|
| 163 |
|
| 164 |
-->title -Notice: insert doc with _id |
| 165 |
-->callmacro Setup coll |
| 166 |
-->callmacro Check_notice_for_insert_one DOCUMENT coll %DOC_1% |
| 167 |
|
| 168 |
|
| 169 |
-->title -Notice: insert doc without _id |
| 170 |
-->callmacro Setup coll |
| 171 |
-->callmacro Check_notice_for_insert_one DOCUMENT coll %DOC_2% |
| 172 |
|
| 173 |
|
| 174 |
-->title -Notice: insert 2 doc with/without _id |
| 175 |
-->callmacro Setup coll |
| 176 |
-->callmacro Check_notice_for_insert_two DOCUMENT coll %DOC_1% %DOC_3% |
| 177 |
|
| 178 |
|
| 179 |
-->title -Notice: insert 2 doc without _id |
| 180 |
-->callmacro Setup coll |
| 181 |
-->callmacro Check_notice_for_insert_two DOCUMENT coll %DOC_2% %DOC_3% |
| 182 |
|
| 183 |
-->title -Notice: insert bad doc |
| 184 |
-->callmacro Setup coll |
| 185 |
-->callmacro Insert_raw DOCUMENT coll row{field{ %DOC_BAD% }} |
| 186 |
-->recvuntil Mysqlx.Error |
| 187 |
EOF |
| 188 |
|
| 189 |
CREATE SCHEMA xtest; |
| 190 |
|
| 191 |
--replace_regex /([0-9a-f]{4})[0-9a-f]{8}([0-9a-f]{16})/\1XXXXXXXX\2/ |
| 192 |
exec $MYSQLXTEST |
| 193 |
-ux_root --password='' |
| 194 |
--file=$MYSQL_TMP_DIR/crud_insert_docid.xpl 2>&1; |
| 195 |
|
| 196 |
## Cleanup |
| 197 |
--source ../include/xplugin_cleanup.inc |
| 198 |
set global mysqlx_document_id_unique_prefix = DEFAULT; |