1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17
18 #include <string>
19
20 #include "common.h"
21 #include "rdb_errno.h"
22 #include "rdb_helper.h"
23 #include "rdb_open_callback.h"
24
25 using namespace testing::ext;
26 using namespace OHOS::NativeRdb;
27
28 class RdbExecuteTest : public testing::Test {
29 public:
30 static void SetUpTestCase(void);
31 static void TearDownTestCase(void);
32 void SetUp();
33 void TearDown();
34
35 static const std::string DATABASE_NAME;
36 static std::shared_ptr<RdbStore> store;
37 static const std::string CREATE_TABLE_TEST;
38 };
39
40 const std::string RdbExecuteTest::DATABASE_NAME = RDB_TEST_PATH + "execute_test.db";
41 std::shared_ptr<RdbStore> RdbExecuteTest::store = nullptr;
42
43 class ExecuteTestOpenCallback : public RdbOpenCallback {
44 public:
45 int OnCreate(RdbStore &store) override;
46 int OnUpgrade(RdbStore &store, int oldVersion, int newVersion) override;
47 };
48
49 const std::string RdbExecuteTest::CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test "
50 "(id INTEGER PRIMARY KEY AUTOINCREMENT, "
51 "name TEXT NOT NULL, age INTEGER, salary REAL, "
52 "blobType BLOB)";
53
OnCreate(RdbStore & store)54 int ExecuteTestOpenCallback::OnCreate(RdbStore &store)
55 {
56 return E_OK;
57 }
58
OnUpgrade(RdbStore & store,int oldVersion,int newVersion)59 int ExecuteTestOpenCallback::OnUpgrade(RdbStore &store, int oldVersion, int newVersion)
60 {
61 return E_OK;
62 }
63
SetUpTestCase(void)64 void RdbExecuteTest::SetUpTestCase(void)
65 {
66 int errCode = E_OK;
67 RdbHelper::DeleteRdbStore(RdbExecuteTest::DATABASE_NAME);
68 RdbStoreConfig config(RdbExecuteTest::DATABASE_NAME);
69 ExecuteTestOpenCallback helper;
70 RdbExecuteTest::store = RdbHelper::GetRdbStore(config, 1, helper, errCode);
71 EXPECT_NE(RdbExecuteTest::store, nullptr);
72 EXPECT_EQ(errCode, E_OK);
73 }
74
TearDownTestCase(void)75 void RdbExecuteTest::TearDownTestCase(void)
76 {
77 RdbHelper::DeleteRdbStore(RdbExecuteTest::DATABASE_NAME);
78 store = nullptr;
79 }
80
SetUp(void)81 void RdbExecuteTest::SetUp(void)
82 {
83 store->ExecuteSql(CREATE_TABLE_TEST);
84 }
85
TearDown(void)86 void RdbExecuteTest::TearDown(void)
87 {
88 store->ExecuteSql("DROP TABLE test");
89 }
90
91 /**
92 * @tc.name: RdbStore_Execute_001
93 * @tc.desc: test RdbStore Execute
94 * @tc.type: FUNC
95 */
96 HWTEST_F(RdbExecuteTest, RdbStore_Execute_001, TestSize.Level1)
97 {
98 std::shared_ptr<RdbStore> &store = RdbExecuteTest::store;
99
100 int64_t id;
101 ValuesBucket values;
102
103 values.PutInt("id", 1);
104 values.PutString("name", std::string("zhangsan"));
105 values.PutInt("age", 18);
106 values.PutDouble("salary", 100.5);
107 values.PutBlob("blobType", std::vector<uint8_t>{ 1, 2, 3 });
108 int ret = store->Insert(id, "test", values);
109 EXPECT_EQ(ret, E_OK);
110 EXPECT_EQ(1, id);
111
112 values.Clear();
113 values.PutInt("id", 2);
114 values.PutString("name", std::string("lisi"));
115 values.PutInt("age", 19);
116 values.PutDouble("salary", 200.5);
117 values.PutBlob("blobType", std::vector<uint8_t>{ 4, 5, 6 });
118 ret = store->Insert(id, "test", values);
119 EXPECT_EQ(ret, E_OK);
120 EXPECT_EQ(2, id);
121
122 values.Clear();
123 values.PutInt("id", 3);
124 values.PutString("name", std::string("wangyjing"));
125 values.PutInt("age", 20);
126 values.PutDouble("salary", 300.5);
127 values.PutBlob("blobType", std::vector<uint8_t>{ 7, 8, 9 });
128 ret = store->Insert(id, "test", values);
129 EXPECT_EQ(ret, E_OK);
130 EXPECT_EQ(3, id);
131
132 int64_t count;
133 ret = store->ExecuteAndGetLong(count, "SELECT COUNT(*) FROM test");
134 EXPECT_EQ(ret, E_OK);
135 EXPECT_EQ(count, 3);
136
137 ret = store->ExecuteSql("DELETE FROM test WHERE age = ? OR age = ?",
138 std::vector<ValueObject>{ ValueObject(std::string("18")), ValueObject(std ::string("20")) });
139 EXPECT_EQ(ret, E_OK);
140
141 ret = store->ExecuteAndGetLong(count, "SELECT COUNT(*) FROM test where age = 19");
142 EXPECT_EQ(ret, E_OK);
143 EXPECT_EQ(count, 1);
144
145 ret = store->ExecuteSql("DELETE FROM test WHERE age = 19");
146 EXPECT_EQ(ret, E_OK);
147
148 ret = store->ExecuteAndGetLong(count, "SELECT COUNT(*) FROM test");
149 EXPECT_EQ(ret, E_OK);
150 EXPECT_EQ(count, 0);
151 }
152
153 /**
154 * @tc.name: RdbStore_Execute_002
155 * @tc.desc: test RdbStore Execute
156 * @tc.type: FUNC
157 */
158 HWTEST_F(RdbExecuteTest, RdbStore_Execute_002, TestSize.Level1)
159 {
160 std::shared_ptr<RdbStore> &store = RdbExecuteTest::store;
161
162 int64_t id;
163 ValuesBucket values;
164
165 int ret = store->Insert(id, "test", UTUtils::SetRowData(UTUtils::g_rowData[0]));
166 EXPECT_EQ(ret, E_OK);
167 EXPECT_EQ(1, id);
168
169 ret = store->Insert(id, "test", UTUtils::SetRowData(UTUtils::g_rowData[1]));
170 EXPECT_EQ(ret, E_OK);
171 EXPECT_EQ(2, id);
172
173 ret = store->Insert(id, "test", UTUtils::SetRowData(UTUtils::g_rowData[2]));
174 EXPECT_EQ(ret, E_OK);
175 EXPECT_EQ(3, id);
176
177 int64_t count;
178 ret = store->ExecuteAndGetLong(count, "SELECT COUNT(*) FROM test", std::vector<ValueObject>());
179 EXPECT_EQ(ret, E_OK);
180 EXPECT_EQ(count, 3);
181
182 ret = store->ExecuteSql("DELETE FROM test WHERE age = ? OR age = ?",
183 std::vector<ValueObject>{ ValueObject(std::string("18")), ValueObject(std ::string("20")) });
184 EXPECT_EQ(ret, E_OK);
185
186 ret = store->ExecuteAndGetLong(
187 count, "SELECT COUNT(*) FROM test where age = ?", std::vector<ValueObject>{ ValueObject(std::string("19")) });
188 EXPECT_EQ(ret, E_OK);
189 EXPECT_EQ(count, 1);
190
191 ret = store->ExecuteSql("DELETE FROM test WHERE age = 19");
192 EXPECT_EQ(ret, E_OK);
193
194 ret = store->ExecuteAndGetLong(count, "SELECT COUNT(*) FROM test", std::vector<ValueObject>());
195 EXPECT_EQ(ret, E_OK);
196 EXPECT_EQ(count, 0);
197
198 ret = store->ExecuteSql("DROP TABLE IF EXISTS test");
199 EXPECT_EQ(ret, E_OK);
200
201 ret = store->ExecuteAndGetLong(count, "SELECT COUNT(*) FROM test");
202 EXPECT_EQ(ret, E_SQLITE_ERROR);
203 }
204
205 /**
206 * @tc.name: RdbStore_Execute_003
207 * @tc.desc: test RdbStore Execute
208 * @tc.type: FUNC
209 */
210 HWTEST_F(RdbExecuteTest, RdbStore_Execute_003, TestSize.Level1)
211 {
212 std::shared_ptr<RdbStore> &store = RdbExecuteTest::store;
213
214 int64_t pageSize;
215 int ret = store->ExecuteAndGetLong(pageSize, "PRAGMA page_size");
216 EXPECT_EQ(ret, E_OK);
217 EXPECT_EQ(pageSize, 4096);
218
219 int64_t journalSize;
220 ret = store->ExecuteAndGetLong(journalSize, "PRAGMA journal_size_limit");
221 EXPECT_EQ(ret, E_OK);
222 EXPECT_EQ(journalSize, 1048576);
223
224 std::string journalMode;
225 ret = store->ExecuteAndGetString(journalMode, "PRAGMA journal_mode");
226 EXPECT_EQ(ret, E_OK);
227 EXPECT_EQ(journalMode, "wal");
228 }
229
230 /**
231 * @tc.name: RdbStore_Execute_004
232 * @tc.desc: Abnormal testCase for ExecuteAndGetString, if sqlstatementtype is special
233 * @tc.type: FUNC
234 */
235 HWTEST_F(RdbExecuteTest, RdbStore_Execute_004, TestSize.Level4)
236 {
237 std::shared_ptr<RdbStore> &store = RdbExecuteTest::store;
238
239 std::string outValue;
240 int ret = store->ExecuteAndGetString(outValue, "BEGIN;");
241 EXPECT_NE(E_OK, ret);
242 }
243
244 /**
245 * @tc.name: RdbStore_Execute_005
246 * @tc.desc: Abnormal testCase for ExecuteForLastInsertedRowId, if sql is invalid
247 * @tc.type: FUNC
248 * @tc.type: FUNC
249 */
250 HWTEST_F(RdbExecuteTest, RdbStore_Execute_005, TestSize.Level4)
251 {
252 std::shared_ptr<RdbStore> &store = RdbExecuteTest::store;
253 int64_t outValue;
254 int ret = store->ExecuteForLastInsertedRowId(outValue, "", {});
255 EXPECT_NE(E_OK, ret);
256 }
257
258 /**
259 * @tc.name: RdbStore_Execute_006
260 * @tc.desc: Abnormal testCase for ExecuteForChangedRowCount, if sql is invalid
261 * @tc.type: FUNC
262 */
263 HWTEST_F(RdbExecuteTest, RdbStore_Execute_006, TestSize.Level4)
264 {
265 std::shared_ptr<RdbStore> &store = RdbExecuteTest::store;
266 int64_t outValue;
267 int ret = store->ExecuteForChangedRowCount(outValue, "", {});
268 EXPECT_NE(E_OK, ret);
269 }
270
271 /**
272 * @tc.name: RdbStore_Execute_007
273 * @tc.desc: Normal testCase for ExecuteAndGetString, check integrity for store
274 * @tc.type: FUNC
275 */
276 HWTEST_F(RdbExecuteTest, RdbStore_Execute_007, TestSize.Level1)
277 {
278 std::shared_ptr<RdbStore> &store = RdbExecuteTest::store;
279
280 auto [ret, outValue] = store->Execute("PRAGMA integrity_check");
281 EXPECT_EQ(E_OK, ret);
282 EXPECT_EQ(ValueObjectType::TYPE_STRING, outValue.GetType());
283
284 std::string outputResult;
285 outValue.GetString(outputResult);
286 EXPECT_EQ("ok", outputResult);
287 }
288
289 /**
290 * @tc.name: RdbStore_Execute_008
291 * @tc.desc: Normal testCase for Execute, check integrity for store
292 * @tc.type: FUNC
293 */
294 HWTEST_F(RdbExecuteTest, RdbStore_Execute_008, TestSize.Level1)
295 {
296 std::shared_ptr<RdbStore> &store = RdbExecuteTest::store;
297
298 auto [ret, outValue] = store->Execute("PRAGMA quick_check");
299 EXPECT_EQ(E_OK, ret);
300 EXPECT_EQ(ValueObjectType::TYPE_STRING, outValue.GetType());
301
302 std::string outputResult;
303 outValue.GetString(outputResult);
304 EXPECT_EQ("ok", outputResult);
305 }
306
307 /**
308 * @tc.name: RdbStore_Execute_009
309 * @tc.desc: Normal testCase for Execute, get user_version of store
310 * @tc.type: FUNC
311 */
312 HWTEST_F(RdbExecuteTest, RdbStore_Execute_009, TestSize.Level1)
313 {
314 std::shared_ptr<RdbStore> &store = RdbExecuteTest::store;
315
316 // set user_version as 5
317 store->SetVersion(5);
318 auto [ret, outValue] = store->Execute("PRAGMA user_version");
319 EXPECT_EQ(E_OK, ret);
320 EXPECT_EQ(ValueObjectType::TYPE_INT, outValue.GetType());
321
322 int64_t outputResult{ 0 };
323 outValue.GetLong(outputResult);
324 EXPECT_EQ(5, outputResult);
325
326 // set user_version as 0
327 store->SetVersion(0);
328 }
329
330 /**
331 * @tc.name: RdbStore_Execute_0010
332 * @tc.desc: AbNormal testCase for Execute, execute select sql
333 * @tc.type: FUNC
334 */
335 HWTEST_F(RdbExecuteTest, RdbStore_Execute_0010, TestSize.Level1)
336 {
337 std::shared_ptr<RdbStore> &store = RdbExecuteTest::store;
338
339 auto [ret, outValue] = store->Execute("SELECT * FROM test");
340 EXPECT_EQ(E_NOT_SUPPORT_THE_SQL, ret);
341 }
342
343 /**
344 * @tc.name: RdbStore_Execute_0011
345 * @tc.desc: Normal testCase for Execute, execute sql for inserting data
346 * @tc.type: FUNC
347 */
348 HWTEST_F(RdbExecuteTest, RdbStore_Execute_0011, TestSize.Level1)
349 {
350 std::shared_ptr<RdbStore> &store = RdbExecuteTest::store;
351
352 std::vector<ValueObject> args = { ValueObject(std::string("tt")), ValueObject(int(28)),
353 ValueObject(double(50000.0)) };
354 auto [ret, outValue] = store->Execute("INSERT INTO test(name, age, salary) VALUES (?, ?, ?);", args);
355 EXPECT_EQ(E_OK, ret);
356 EXPECT_EQ(ValueObjectType::TYPE_INT, outValue.GetType());
357
358 int64_t outputResult;
359 outValue.GetLong(outputResult);
360 // 1 represent that the last data is inserted in the first row
361 EXPECT_EQ(1, outputResult);
362 }
363
364 /**
365 * @tc.name: RdbStore_Execute_0012
366 * @tc.desc: Normal testCase for Execute, execute sql for batch insert data
367 * @tc.type: FUNC
368 */
369 HWTEST_F(RdbExecuteTest, RdbStore_Execute_0012, TestSize.Level1)
370 {
371 std::shared_ptr<RdbStore> &store = RdbExecuteTest::store;
372
373 std::vector<ValueObject> args = { ValueObject(std::string("tt")), ValueObject(int(28)),
374 ValueObject(double(50000.0)), ValueObject(std::string("ttt")), ValueObject(int(58)),
375 ValueObject(double(500080.0)) };
376 auto [ret, outValue] = store->Execute("INSERT INTO test(name, age, salary) VALUES (?, ?, ?), (?, ?, ?)", args);
377 EXPECT_EQ(E_OK, ret);
378
379 EXPECT_EQ(ValueObjectType::TYPE_INT, outValue.GetType());
380
381 int64_t outputResult;
382 outValue.GetLong(outputResult);
383 // 2 represent that the last data is inserted in the second row
384 EXPECT_EQ(2, outputResult);
385 }
386
387 /**
388 * @tc.name: RdbStore_Execute_0013
389 * @tc.desc: Normal testCase for Execute, execute sql for updating data
390 * @tc.type: FUNC
391 */
392 HWTEST_F(RdbExecuteTest, RdbStore_Execute_0013, TestSize.Level1)
393 {
394 std::shared_ptr<RdbStore> &store = RdbExecuteTest::store;
395
396 std::vector<ValueObject> args = { ValueObject(std::string("tt")), ValueObject(int(28)),
397 ValueObject(double(50000.0)), ValueObject(std::string("ttt")), ValueObject(int(58)),
398 ValueObject(double(500080.0)) };
399 auto [ret1, outValue1] = store->Execute("INSERT INTO test(name, age, salary) VALUES (?, ?, ?), (?, ?, ?)", args);
400 EXPECT_EQ(E_OK, ret1);
401 EXPECT_EQ(ValueObjectType::TYPE_INT, outValue1.GetType());
402
403 int64_t outputResult;
404 outValue1.GetLong(outputResult);
405 // 2 represent that the last data is inserted in the second row
406 EXPECT_EQ(2, outputResult);
407
408 auto [ret2, outValue2] = store->Execute("UPDATE test SET name='dd' WHERE id = 2");
409 EXPECT_EQ(E_OK, ret2);
410 EXPECT_EQ(ValueObjectType::TYPE_INT, outValue2.GetType());
411
412 outValue2.GetLong(outputResult);
413 // 1 represent that effected row id
414 EXPECT_EQ(1, outputResult);
415 }
416
417 /**
418 * @tc.name: RdbStore_Execute_0014
419 * @tc.desc: Normal testCase for Execute, execute sql for deleting data
420 * @tc.type: FUNC
421 */
422 HWTEST_F(RdbExecuteTest, RdbStore_Execute_0014, TestSize.Level1)
423 {
424 std::shared_ptr<RdbStore> &store = RdbExecuteTest::store;
425
426 std::vector<ValueObject> args = { ValueObject(std::string("tt")), ValueObject(int(28)),
427 ValueObject(double(50000.0)), ValueObject(std::string("ttt")), ValueObject(int(82)),
428 ValueObject(double(500080.0)) };
429 auto [ret1, outValue1] = store->Execute("INSERT INTO test(name, age, salary) VALUES (?, ?, ?), (?, ?, ?)", args);
430 EXPECT_EQ(E_OK, ret1);
431 EXPECT_EQ(ValueObjectType::TYPE_INT, outValue1.GetType());
432
433 int64_t outputResult;
434 outValue1.GetLong(outputResult);
435 // 2 represent that the last data is inserted in the second row
436 EXPECT_EQ(2, outputResult);
437
438 auto [ret2, outValue2] = store->Execute("DELETE FROM test");
439 EXPECT_EQ(E_OK, ret2);
440 EXPECT_EQ(ValueObjectType::TYPE_INT, outValue2.GetType());
441
442 outValue2.GetLong(outputResult);
443 // 2 represent that effected row id
444 EXPECT_EQ(2, outputResult);
445 }
446
447 /**
448 * @tc.name: RdbStore_Execute_0015
449 * @tc.desc: AbNormal testCase for Execute, execute sql for attaching database and transaction
450 * @tc.type: FUNC
451 */
452 HWTEST_F(RdbExecuteTest, RdbStore_Execute_0015, TestSize.Level1)
453 {
454 std::shared_ptr<RdbStore> &store = RdbExecuteTest::store;
455
456 auto [ret1, outValue1] = store->Execute("ATTACH DATABASE 'execute_attach_test.db' AS 'attach.db'");
457 EXPECT_EQ(E_NOT_SUPPORT_THE_SQL, ret1);
458
459 auto [ret2, outValue2] = store->Execute("DETACH DATABASE 'attach.db'");
460 EXPECT_EQ(E_NOT_SUPPORT_THE_SQL, ret2);
461
462 auto [ret3, outValue3] = store->Execute("BEGIN TRANSACTION");
463 EXPECT_EQ(E_NOT_SUPPORT_THE_SQL, ret3);
464
465 auto [ret4, outValue4] = store->Execute("COMMIT");
466 EXPECT_EQ(E_NOT_SUPPORT_THE_SQL, ret4);
467
468 auto [ret5, outValue5] = store->Execute("ROLLBACK");
469 EXPECT_EQ(E_NOT_SUPPORT_THE_SQL, ret5);
470 }
471
472 /**
473 * @tc.name: RdbStore_Execute_0016
474 * @tc.desc: Normal testCase for Execute, execute DDL sql for creating and dropping table
475 * @tc.type: FUNC
476 */
477 HWTEST_F(RdbExecuteTest, RdbStore_Execute_0016, TestSize.Level1)
478 {
479 std::shared_ptr<RdbStore> &store = RdbExecuteTest::store;
480 int64_t intOutValue;
481
482 const std::string CREATE_TABLE_TEST2 = "CREATE TABLE IF NOT EXISTS test2 "
483 "(id INTEGER PRIMARY KEY AUTOINCREMENT, "
484 "name TEXT NOT NULL, age INTEGER, salary REAL, "
485 "blobType BLOB)";
486 const std::string DROP_TABLE_TEST2 = "DROP TABLE test2";
487 const std::string TEST_TABLE_IS_EXIST = "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='test2'";
488
489 auto [ret1, outValue1] = store->Execute(CREATE_TABLE_TEST2);
490 EXPECT_EQ(E_OK, ret1);
491 EXPECT_EQ(ValueObjectType::TYPE_NULL, outValue1.GetType());
492
493 std::shared_ptr<ResultSet> resultSet = store->QuerySql(TEST_TABLE_IS_EXIST);
494 EXPECT_NE(nullptr, resultSet);
495 resultSet->GoToFirstRow();
496 // 0 represent that get count of table test in the first row
497 resultSet->GetLong(0, intOutValue);
498 // 1 represent that the table exists
499 EXPECT_EQ(1, intOutValue);
500 resultSet->Close();
501
502 auto [ret2, outValue2] = store->Execute(DROP_TABLE_TEST2);
503 EXPECT_EQ(E_OK, ret2);
504 EXPECT_EQ(ValueObjectType::TYPE_NULL, outValue2.GetType());
505
506 resultSet = store->QuerySql(TEST_TABLE_IS_EXIST);
507 EXPECT_NE(nullptr, resultSet);
508 resultSet->GoToFirstRow();
509 // 0 represent that get count of table test in the first column
510 resultSet->GetLong(0, intOutValue);
511 // 0 represent the table does not exist
512 EXPECT_EQ(0, intOutValue);
513 resultSet->Close();
514 }
515
516 /**
517 * @tc.name: RdbStore_Execute_0017
518 * @tc.desc: Normal testCase for Execute, execute sql for creating table and insert, query data
519 * @tc.type: FUNC
520 */
521 HWTEST_F(RdbExecuteTest, RdbStore_Execute_0017, TestSize.Level1)
522 {
523 std::shared_ptr<RdbStore> &store = RdbExecuteTest::store;
524 int64_t intOutValue;
525 int intOutResultSet;
526
527 const std::string CREATE_TABLE_TEST2 = "CREATE TABLE IF NOT EXISTS test2 "
528 "(id INTEGER PRIMARY KEY AUTOINCREMENT, "
529 "name TEXT NOT NULL, age INTEGER, salary REAL, "
530 "blobType BLOB)";
531 const std::string DROP_TABLE_TEST2 = "DROP TABLE test2";
532
533 auto [ret1, outValue1] = store->Execute(CREATE_TABLE_TEST2);
534 EXPECT_EQ(E_OK, ret1);
535
536 std::vector<ValueObject> args = { ValueObject("tt"), ValueObject(28), ValueObject(50000) };
537 auto [ret2, outValue2] = store->Execute("INSERT INTO test2(name, age, salary) VALUES (?, ?, ?)", args);
538 EXPECT_EQ(E_OK, ret2);
539 outValue2.GetLong(intOutValue);
540 // 1 represent that the last data is inserted in the first row
541 EXPECT_EQ(1, intOutValue);
542
543 std::shared_ptr<ResultSet> resultSet = store->QuerySql("SELECT * FROM test2");
544 EXPECT_NE(nullptr, resultSet);
545 EXPECT_EQ(E_OK, resultSet->GetRowCount(intOutResultSet));
546 // 1 represent that the row number of resultSet
547 EXPECT_EQ(1, intOutResultSet);
548 resultSet->Close();
549
550 auto [ret3, outValue3] = store->Execute(DROP_TABLE_TEST2);
551 EXPECT_EQ(E_OK, ret3);
552 }
553
554 /**
555 * @tc.name: RdbStore_Execute_0018
556 * @tc.desc: AbNormal testCase for Execute, execute sql for inserting data but args is []
557 * @tc.type: FUNC
558 */
559 HWTEST_F(RdbExecuteTest, RdbStore_Execute_0018, TestSize.Level1)
560 {
561 std::shared_ptr<RdbStore> &store = RdbExecuteTest::store;
562 ValueObject outValue;
563
564 auto [ret1, outValue1] = store->Execute("INSERT INTO test(name, age, salary) VALUES (?, ?, ?), (?, ?, ?)");
565 EXPECT_NE(E_OK, ret1);
566 }
567
568 /**
569 * @tc.name: RdbStore_Execute_0019
570 * @tc.desc: Normal testCase for Execute, set user_version of store
571 * @tc.type: FUNC
572 */
573 HWTEST_F(RdbExecuteTest, RdbStore_Execute_0019, TestSize.Level1)
574 {
575 std::shared_ptr<RdbStore> &store = RdbExecuteTest::store;
576
577 // set user_version as 5
578 auto [ret, outValue] = store->Execute("PRAGMA user_version=5");
579 EXPECT_EQ(E_OK, ret);
580 EXPECT_EQ(ValueObjectType::TYPE_NULL, outValue.GetType());
581
582 // set user_version as 0
583 std::tie(ret, outValue) = store->Execute("PRAGMA user_version=0");
584 EXPECT_EQ(E_OK, ret);
585 EXPECT_EQ(ValueObjectType::TYPE_NULL, outValue.GetType());
586 }
587
588 /**
589 * @tc.name: RdbStore_Execute_0020
590 * @tc.desc: AbNormal testCase for Execute, get table_info
591 * @tc.type: FUNC
592 */
593 HWTEST_F(RdbExecuteTest, RdbStore_Execute_0020, TestSize.Level1)
594 {
595 std::shared_ptr<RdbStore> &store = RdbExecuteTest::store;
596
597 auto [ret, outValue] = store->Execute("PRAGMA table_info(test)");
598 EXPECT_EQ(E_NOT_SUPPORT_THE_SQL, ret);
599 }