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 "common.h"
17 #include <string>
18 #include "rdb_errno.h"
19
20 namespace OHOS {
21 namespace NativeRdb {
22
SetRowData(const RowData & rowData)23 ValuesBucket UTUtils::SetRowData(const RowData &rowData)
24 {
25 ValuesBucket value;
26 value.PutInt("id", rowData.id);
27 value.PutString("name", rowData.name);
28 value.PutInt("age", rowData.age);
29 value.PutDouble("salary", rowData.salary);
30 value.PutBlob("blobType", rowData.blobType);
31 return value;
32 }
33
34 const RowData UTUtils::g_rowData[3] = {
35 {1, "zhangsan", 18, 100.5, std::vector<uint8_t>{ 1, 2, 3 }},
36 {2, "lisi", 19, 200.5, std::vector<uint8_t>{ 4, 5, 6 }},
37 {3, "wangyjing", 20, 300.5, std::vector<uint8_t>{ 7, 8, 9 }}
38 };
39
SetRowDatas(const RowDatas & rowDatas)40 ValuesBucket UTUtils::SetRowDatas(const RowDatas &rowDatas)
41 {
42 ValuesBucket value;
43 ValueObjectType typeMgr = rowDatas.mgr.GetType();
44 ValueObjectType typeBonus = rowDatas.bonus.GetType();
45
46 int outputMgr = 0;
47 double outputBonus = 0.0;
48
49 value.PutInt("id", rowDatas.id);
50 value.PutString("eName", rowDatas.eName);
51 value.PutInt("jobId", rowDatas.jobId);
52
53 if (typeMgr == ValueObjectType::TYPE_NULL) {
54 value.PutNull("mgr");
55 } else {
56 int ret = rowDatas.mgr.GetInt(outputMgr);
57 if (ret == E_OK) {
58 value.PutInt("mgr", outputMgr);
59 }
60 }
61
62 value.PutString("joinDate", rowDatas.joinDate);
63 value.PutDouble("salary", rowDatas.salary);
64
65 if (typeBonus == ValueObjectType::TYPE_NULL) {
66 value.PutNull("bonus");
67 } else {
68 int ret = rowDatas.bonus.GetDouble(outputBonus);
69 if (ret == E_OK) {
70 value.PutDouble("bonus", outputBonus);
71 }
72 }
73
74 value.PutInt("deptId", rowDatas.deptId);
75 return value;
76 }
77
78 const RowDatas UTUtils::gRowDatas[14] = {
79 { 1001, "SunWuKong", 4, ValueObject(1004), "2000-12-17", 8000.00, ValueObject(), 20 },
80 { 1002, "LuJunYi", 3, ValueObject(1006), "2001-02-20", 16000.00, ValueObject(3000.00), 30 },
81 { 1003, "LinChong", 3, ValueObject(1006), "2001-02-22", 12500.00, ValueObject(5000.00), 30 },
82 { 1004, "TangCeng", 2, ValueObject(1009), "2001-04-02", 29750.00, ValueObject(), 20 },
83 { 1005, "LiKui", 4, ValueObject(1006), "2001-09-28", 12500.00, ValueObject(14000.00), 30 },
84 { 1006, "SongJiang", 2, ValueObject(1009), "2001-05-01", 28500.00, ValueObject(), 30 },
85 { 1007, "LiuBei", 2, ValueObject(1009), "2001-09-01", 24500.00, ValueObject(), 10 },
86 { 1008, "ZhuBaJie", 4, ValueObject(1004), "2007-04-19", 30000.00, ValueObject(), 20 },
87 { 1009, "LuoGuanZhong", 1, ValueObject(), "2001-11-17", 50000.00, ValueObject(), 10 },
88 { 1010, "WuYong", 3, ValueObject(1006), "2001-09-08", 15000.00, ValueObject(), 30 },
89 { 1011, "ShaCeng", 4, ValueObject(1004), "2007-05-23", 11000.00, ValueObject(), 20 },
90 { 1012, "LiKui", 4, ValueObject(1006), "2001-12-03", 9500.00, ValueObject(), 30 },
91 { 1013, "XiaoBaiLong", 4, ValueObject(1004), "2001-12-03", 30000.00, ValueObject(), 20 },
92 { 1014, "GuanYu", 4, ValueObject(1007), "2002-01-23", 13000.00, ValueObject(), 10 } };
93 }
94 }
95