Debian Codegraph @

mysql-test/suite/x/t/prep_stmt_crud_find.test

raw
1 ## Test of general functionality of prepare statement crud find message
2
3 ## Preamble
4 --source include/xplugin_preamble.inc
5 --source include/xplugin_create_user.inc
6 ## Test starts here
7
8 CREATE SCHEMA IF NOT EXISTS xtest;
9
10 --write_file $MYSQL_TMP_DIR/prep_stmt_crud_find.xpl
11 -->quiet
12
13 -->macro Insert %NAME% %VALUE%
14 Mysqlx.Crud.Insert {
15 collection {
16 name: "%NAME%"
17 schema: "xtest"
18 }
19 data_model: DOCUMENT
20 row {
21 field {
22 type: LITERAL
23 literal {
24 type: V_STRING
25 v_string {
26 value: %VALUE%
27 }
28 }
29 }
30 }
31 }
32 -->recvresult
33 -->endmacro
34
35
36 -->stmtadmin create_collection {"schema":"xtest","name":"expr"}
37 -->recvresult
38
39 -->callmacro Insert expr '{"_id":"0000616daea30000000000000001", "name": "foo"}'
40 -->callmacro Insert expr '{"_id":"0000616daea30000000000000002", "name": "bar"}'
41 -->callmacro Insert expr '{"_id":"0000616daea30000000000000003", "name": "buz"}'
42
43 -->echo
44 -->echo ## x. Prepare find with OP in [==, !=, <, <=, >, >=]
45 -->echo # a. Try to execute (no params)
46 -->echo # b. Execute with ...001
47 -->echo # c. Execute with ...002
48 -->echo # d. Execute with ...003
49 -->echo # e. Deallocate
50 -->echo
51
52 -->macro PrepareFindIdOpPlaceHolder %ID% %OP%
53 -->title =Stmt %ID%: Prepare find with '_id %OP% ?'
54
55 Mysqlx.Prepare.Prepare {
56 stmt_id: %ID%
57 stmt: {
58 type: FIND
59 find: {
60 collection {
61 schema: "xtest",
62 name: "expr"
63 }
64 data_model: DOCUMENT
65 criteria {
66 type: OPERATOR
67 operator {
68 name: "%OP%"
69 param {
70 type: IDENT
71 identifier {
72 document_path {
73 type: MEMBER
74 value: "_id"
75 }
76 }
77 }
78 param {
79 type: PLACEHOLDER
80 position: 0
81 }
82 }
83 }
84 }
85 }
86 }
87 -->recvok
88 -->endmacro
89
90
91 -->macro PrepareFindPlaceHolderOpId %ID% %OP%
92 -->title =Stmt %ID%: Prepare find with '? %OP% _id'
93
94 Mysqlx.Prepare.Prepare {
95 stmt_id: %ID%
96 stmt: {
97 type: FIND
98 find: {
99 collection {
100 schema: "xtest",
101 name: "expr"
102 }
103 data_model: DOCUMENT
104 criteria {
105 type: OPERATOR
106 operator {
107 name: "%OP%"
108 param {
109 type: PLACEHOLDER
110 position: 0
111 }
112 param {
113 type: IDENT
114 identifier {
115 document_path {
116 type: MEMBER
117 value: "_id"
118 }
119 }
120 }
121 }
122 }
123 }
124 }
125 }
126 -->recvok
127 -->endmacro
128
129 -->macro ExecuteNoArgs %ID%
130 -->title =Stmt %ID%.a. Try to execute (no params)
131
132 Mysqlx.Prepare.Execute {
133 stmt_id: %ID%
134 }
135 -->expecterror ER_X_PREPARED_EXECUTE_ARGUMENT_CONSISTENCY
136 -->recvresult
137 -->endmacro
138
139 -->macro Execute %ID% %OP% %VAL%
140 -->title =Stmt %ID%.b. Execute %OP% with %VAL%
141
142 Mysqlx.Prepare.Execute {
143 stmt_id: %ID%
144 args {
145 type: SCALAR scalar {
146 type: V_STRING v_string {
147 value: %VAL%
148 }
149 }
150 }
151 }
152 -->recvresult
153 -->endmacro
154
155 -->macro Deallocate %ID%
156 -->title =Stmt %ID%.d. Deallocate
157
158 Mysqlx.Prepare.Deallocate {
159 stmt_id: %ID%
160 }
161 -->recvok
162 -->endmacro
163
164 -->macro Find %ID% %OP%
165 -->callmacro PrepareFindPlaceHolderOpId %ID% %OP%
166 -->callmacro ExecuteNoArgs %ID%
167 -->callmacro Execute %ID% %OP% '0000616daea30000000000000001'
168 -->callmacro Execute %ID% %OP% '0000616daea30000000000000002'
169 -->callmacro Execute %ID% %OP% '0000616daea30000000000000003'
170 -->callmacro Deallocate %ID%
171
172 -->callmacro PrepareFindIdOpPlaceHolder %ID% %OP%
173 -->callmacro ExecuteNoArgs %ID%
174 -->callmacro Execute %ID% %OP% '0000616daea30000000000000001'
175 -->callmacro Execute %ID% %OP% '0000616daea30000000000000002'
176 -->callmacro Execute %ID% %OP% '0000616daea30000000000000003'
177 -->callmacro Deallocate %ID%
178 -->endmacro
179
180
181 -->callmacro Find 1 ==
182 -->callmacro Find 2 !=
183 -->callmacro Find 3 >
184 -->callmacro Find 4 >=
185 -->callmacro Find 5 <
186 -->callmacro Find 6 <=
187 EOF
188
189
190 --replace_regex /([0-9a-f]{4})[0-9a-f]{8}([0-9a-f]{16})/\1XXXXXXXX\2/
191 exec $MYSQLXTEST
192 -ux_root --password='' --schema=xtest
193 --file=$MYSQL_TMP_DIR/prep_stmt_crud_find.xpl 2>&1;
194
195 ## running the prepared statements via classic-protocol
196 ## should result in the same results as the xprotocol
197 ## Crud::Find statements
198
199 SET @id1 = '0000616daea30000000000000001',
200 @id2 = '0000616daea30000000000000002',
201 @id3 = '0000616daea30000000000000003';
202
203 PREPARE s1 FROM "SELECT doc FROM xtest.expr WHERE JSON_UNQUOTE(JSON_EXTRACT(doc, '$._id')) = ?";
204 EXECUTE s1 using @id1;
205 EXECUTE s1 using @id2;
206 EXECUTE s1 using @id3;
207 DEALLOCATE PREPARE s1;
208
209 PREPARE s1 FROM "SELECT doc FROM xtest.expr WHERE JSON_UNQUOTE(JSON_EXTRACT(doc, '$._id')) != ?";
210 EXECUTE s1 using @id1;
211 EXECUTE s1 using @id2;
212 EXECUTE s1 using @id3;
213 DEALLOCATE PREPARE s1;
214
215 PREPARE s1 FROM "SELECT doc FROM xtest.expr WHERE JSON_UNQUOTE(JSON_EXTRACT(doc, '$._id')) > ?";
216 EXECUTE s1 using @id1;
217 EXECUTE s1 using @id2;
218 EXECUTE s1 using @id3;
219 DEALLOCATE PREPARE s1;
220
221 PREPARE s1 FROM "SELECT doc FROM xtest.expr WHERE JSON_UNQUOTE(JSON_EXTRACT(doc, '$._id')) >= ?";
222 EXECUTE s1 using @id1;
223 EXECUTE s1 using @id2;
224 EXECUTE s1 using @id3;
225 DEALLOCATE PREPARE s1;
226
227 PREPARE s1 FROM "SELECT doc FROM xtest.expr WHERE JSON_UNQUOTE(JSON_EXTRACT(doc, '$._id')) < ?";
228 EXECUTE s1 using @id1;
229 EXECUTE s1 using @id2;
230 EXECUTE s1 using @id3;
231 DEALLOCATE PREPARE s1;
232
233 PREPARE s1 FROM "SELECT doc FROM xtest.expr WHERE JSON_UNQUOTE(JSON_EXTRACT(doc, '$._id')) <= ?";
234 EXECUTE s1 using @id1;
235 EXECUTE s1 using @id2;
236 EXECUTE s1 using @id3;
237 DEALLOCATE PREPARE s1;
238
239 ## Cleanup
240 --source ../include/xplugin_cleanup.inc