| 1 |
## Using Mysqlx::Expr::OBJECT in collection |
| 2 |
|
| 3 |
## Preamble |
| 4 |
--source include/xplugin_preamble.inc |
| 5 |
--source include/xplugin_create_user.inc |
| 6 |
## Test starts here |
| 7 |
--write_file $MYSQL_TMP_DIR/crud_doc_expr_object.xpl |
| 8 |
|
| 9 |
## Test data |
| 10 |
-->sql |
| 11 |
DROP SCHEMA IF EXISTS xtest; |
| 12 |
CREATE SCHEMA xtest; |
| 13 |
-->endsql |
| 14 |
|
| 15 |
-->stmtadmin create_collection {"schema":"xtest", "name":"xcoll"} |
| 16 |
-->recvresult |
| 17 |
|
| 18 |
|
| 19 |
-->echo Inserting object into collection |
| 20 |
Mysqlx.Crud.Insert { |
| 21 |
collection { |
| 22 |
name: "xcoll" |
| 23 |
schema: "xtest" |
| 24 |
} |
| 25 |
data_model: DOCUMENT |
| 26 |
row { |
| 27 |
field { |
| 28 |
type: OBJECT object { |
| 29 |
fld { |
| 30 |
key: "_id" |
| 31 |
value { |
| 32 |
type: LITERAL literal { type: V_OCTETS v_octets {value:"1"} } |
| 33 |
} |
| 34 |
} |
| 35 |
fld { |
| 36 |
key: "first_name" |
| 37 |
value { |
| 38 |
type: LITERAL literal { type: V_OCTETS v_octets {value:"John"} } |
| 39 |
} |
| 40 |
} |
| 41 |
fld { |
| 42 |
key: "last_name" |
| 43 |
value { |
| 44 |
type: LITERAL literal { type: V_OCTETS v_octets {value:"Snow"} } |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
#-- Mysqlx.Sql.StmtExecuteOk |
| 53 |
-->recvresult |
| 54 |
|
| 55 |
-->sql |
| 56 |
SELECT doc FROM xtest.xcoll; |
| 57 |
-->endsql |
| 58 |
|
| 59 |
-->echo Selecting object from collection |
| 60 |
Mysqlx.Crud.Find { |
| 61 |
collection { |
| 62 |
name: "xcoll" |
| 63 |
schema: "xtest" |
| 64 |
} |
| 65 |
data_model: DOCUMENT |
| 66 |
projection { |
| 67 |
source { |
| 68 |
type: OBJECT object { |
| 69 |
fld { |
| 70 |
key: "name" |
| 71 |
value { |
| 72 |
type: FUNC_CALL function_call { |
| 73 |
name { |
| 74 |
name: "concat" |
| 75 |
} |
| 76 |
param { |
| 77 |
type: IDENT identifier { |
| 78 |
document_path { |
| 79 |
type: MEMBER |
| 80 |
value: "first_name" |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
param { |
| 85 |
type: LITERAL literal { type: V_OCTETS v_octets {value:" "} } |
| 86 |
} |
| 87 |
param { |
| 88 |
type: IDENT identifier { |
| 89 |
document_path { |
| 90 |
type: MEMBER value: "last_name" |
| 91 |
} |
| 92 |
} |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
fld { |
| 98 |
key: "number" |
| 99 |
value { |
| 100 |
type: OPERATOR operator { |
| 101 |
name: "+" |
| 102 |
param { |
| 103 |
type: LITERAL literal {type: V_SINT v_signed_int: 1} |
| 104 |
} |
| 105 |
param { |
| 106 |
type: LITERAL literal { type: V_SINT v_signed_int: 1} |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
#-- Mysqlx.Sql.StmtExecuteOk |
| 117 |
-->recvresult |
| 118 |
|
| 119 |
|
| 120 |
-->echo Selecting object from collection with alias |
| 121 |
Mysqlx.Crud.Find { |
| 122 |
collection { |
| 123 |
name: "xcoll" |
| 124 |
schema: "xtest" |
| 125 |
} |
| 126 |
data_model: DOCUMENT |
| 127 |
projection { |
| 128 |
alias: "hero" |
| 129 |
source { |
| 130 |
type: OBJECT object { |
| 131 |
fld { |
| 132 |
key: "name" |
| 133 |
value { |
| 134 |
type: FUNC_CALL function_call { |
| 135 |
name { |
| 136 |
name: "concat" |
| 137 |
} |
| 138 |
param { |
| 139 |
type: IDENT identifier { |
| 140 |
document_path { |
| 141 |
type: MEMBER |
| 142 |
value: "first_name" |
| 143 |
} |
| 144 |
} |
| 145 |
} |
| 146 |
param { |
| 147 |
type: LITERAL literal { type: V_OCTETS v_octets {value:" "} } |
| 148 |
} |
| 149 |
param { |
| 150 |
type: IDENT identifier { |
| 151 |
document_path { |
| 152 |
type: MEMBER |
| 153 |
value: "last_name" |
| 154 |
} |
| 155 |
} |
| 156 |
} |
| 157 |
} |
| 158 |
} |
| 159 |
} |
| 160 |
} |
| 161 |
} |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
#-- Mysqlx.Sql.StmtExecuteOk |
| 166 |
-->recvresult |
| 167 |
|
| 168 |
|
| 169 |
-->echo Selecting object with sub-object from collection |
| 170 |
Mysqlx.Crud.Find { |
| 171 |
collection { |
| 172 |
name: "xcoll" |
| 173 |
schema: "xtest" |
| 174 |
} |
| 175 |
data_model: DOCUMENT |
| 176 |
projection { |
| 177 |
source { |
| 178 |
type: OBJECT object { |
| 179 |
fld { |
| 180 |
key: "name" |
| 181 |
value { |
| 182 |
type: FUNC_CALL function_call { |
| 183 |
name { |
| 184 |
name: "concat" |
| 185 |
} |
| 186 |
param { |
| 187 |
type: IDENT identifier { |
| 188 |
document_path { |
| 189 |
type: MEMBER |
| 190 |
value: "first_name" |
| 191 |
} |
| 192 |
} |
| 193 |
} |
| 194 |
param { |
| 195 |
type: LITERAL literal { type: V_OCTETS v_octets {value:" "} } |
| 196 |
} |
| 197 |
param { |
| 198 |
type: IDENT identifier { |
| 199 |
document_path { |
| 200 |
type: MEMBER |
| 201 |
value: "last_name" |
| 202 |
} |
| 203 |
} |
| 204 |
} |
| 205 |
} |
| 206 |
} |
| 207 |
} |
| 208 |
fld { |
| 209 |
key: "detail" |
| 210 |
value { |
| 211 |
type: OBJECT object { |
| 212 |
fld { |
| 213 |
key: "first" |
| 214 |
value { |
| 215 |
type: IDENT identifier { |
| 216 |
document_path { type: MEMBER value: "first_name" } |
| 217 |
} |
| 218 |
} |
| 219 |
} |
| 220 |
fld { |
| 221 |
key: "last" |
| 222 |
value { |
| 223 |
type: IDENT identifier { |
| 224 |
document_path { type: MEMBER value: "last_name" } |
| 225 |
} |
| 226 |
} |
| 227 |
} |
| 228 |
} |
| 229 |
} |
| 230 |
} |
| 231 |
} |
| 232 |
} |
| 233 |
} |
| 234 |
} |
| 235 |
|
| 236 |
#-- Mysqlx.Sql.StmtExecuteOk |
| 237 |
-->recvresult |
| 238 |
|
| 239 |
|
| 240 |
-->echo Updating collection by object |
| 241 |
Mysqlx.Crud.Update { |
| 242 |
collection { |
| 243 |
name: "xcoll" |
| 244 |
schema: "xtest" |
| 245 |
} |
| 246 |
data_model: DOCUMENT |
| 247 |
operation { |
| 248 |
source { |
| 249 |
document_path { type: MEMBER value: "occupation" } |
| 250 |
} |
| 251 |
operation: ITEM_SET |
| 252 |
value { |
| 253 |
type: OBJECT object { |
| 254 |
fld { |
| 255 |
key: "location" |
| 256 |
value { |
| 257 |
type: LITERAL literal { type: V_OCTETS v_octets {value:"the wall"} } |
| 258 |
} |
| 259 |
} |
| 260 |
fld { |
| 261 |
key: "title" |
| 262 |
value { |
| 263 |
type: LITERAL literal { type: V_OCTETS v_octets {value:"lord commander"} } |
| 264 |
} |
| 265 |
} |
| 266 |
} |
| 267 |
} |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
#-- Mysqlx.Sql.StmtExecuteOk |
| 272 |
-->recvresult |
| 273 |
|
| 274 |
-->sql |
| 275 |
SELECT doc FROM xtest.xcoll; |
| 276 |
-->endsql |
| 277 |
|
| 278 |
|
| 279 |
-->echo NOT Error: empty object |
| 280 |
Mysqlx.Crud.Find { |
| 281 |
collection { |
| 282 |
name: "xcoll" |
| 283 |
schema: "xtest" |
| 284 |
} |
| 285 |
data_model: DOCUMENT |
| 286 |
projection { |
| 287 |
source { |
| 288 |
type: OBJECT object { |
| 289 |
} |
| 290 |
} |
| 291 |
} |
| 292 |
} |
| 293 |
|
| 294 |
-->recvresult |
| 295 |
|
| 296 |
|
| 297 |
-->echo Error: empty object key |
| 298 |
Mysqlx.Crud.Find { |
| 299 |
collection { |
| 300 |
name: "xcoll" |
| 301 |
schema: "xtest" |
| 302 |
} |
| 303 |
data_model: DOCUMENT |
| 304 |
projection { |
| 305 |
source { |
| 306 |
type: OBJECT object { |
| 307 |
fld { |
| 308 |
key: "" |
| 309 |
value { |
| 310 |
type: IDENT identifier { |
| 311 |
document_path { type: MEMBER value: "first_name" } |
| 312 |
} |
| 313 |
} |
| 314 |
} |
| 315 |
} |
| 316 |
} |
| 317 |
} |
| 318 |
} |
| 319 |
|
| 320 |
-->recverror 5154 |
| 321 |
|
| 322 |
|
| 323 |
## Cleanup |
| 324 |
-->sql |
| 325 |
drop schema if exists xtest; |
| 326 |
-->endsql |
| 327 |
EOF |
| 328 |
|
| 329 |
--exec $MYSQLXTEST -ux_root --password='' --file=$MYSQL_TMP_DIR/crud_doc_expr_object.xpl 2>&1 |
| 330 |
|
| 331 |
## Cleanup |
| 332 |
--source ../include/xplugin_cleanup.inc |