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