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