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