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