106694b06Sopenharmony_ci/* 206694b06Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 306694b06Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 406694b06Sopenharmony_ci * you may not use this file except in compliance with the License. 506694b06Sopenharmony_ci * You may obtain a copy of the License at 606694b06Sopenharmony_ci * 706694b06Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 806694b06Sopenharmony_ci * 906694b06Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1006694b06Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1106694b06Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1206694b06Sopenharmony_ci * See the License for the specific language governing permissions and 1306694b06Sopenharmony_ci * limitations under the License. 1406694b06Sopenharmony_ci */ 1506694b06Sopenharmony_ci 1606694b06Sopenharmony_ci#include "common.h" 1706694b06Sopenharmony_ci#include <string> 1806694b06Sopenharmony_ci#include "rdb_errno.h" 1906694b06Sopenharmony_ci 2006694b06Sopenharmony_cinamespace OHOS { 2106694b06Sopenharmony_cinamespace NativeRdb { 2206694b06Sopenharmony_ci 2306694b06Sopenharmony_ciValuesBucket UTUtils::SetRowData(const RowData &rowData) 2406694b06Sopenharmony_ci{ 2506694b06Sopenharmony_ci ValuesBucket value; 2606694b06Sopenharmony_ci value.PutInt("id", rowData.id); 2706694b06Sopenharmony_ci value.PutString("name", rowData.name); 2806694b06Sopenharmony_ci value.PutInt("age", rowData.age); 2906694b06Sopenharmony_ci value.PutDouble("salary", rowData.salary); 3006694b06Sopenharmony_ci value.PutBlob("blobType", rowData.blobType); 3106694b06Sopenharmony_ci return value; 3206694b06Sopenharmony_ci} 3306694b06Sopenharmony_ci 3406694b06Sopenharmony_ciconst RowData UTUtils::g_rowData[3] = { 3506694b06Sopenharmony_ci {1, "zhangsan", 18, 100.5, std::vector<uint8_t>{ 1, 2, 3 }}, 3606694b06Sopenharmony_ci {2, "lisi", 19, 200.5, std::vector<uint8_t>{ 4, 5, 6 }}, 3706694b06Sopenharmony_ci {3, "wangyjing", 20, 300.5, std::vector<uint8_t>{ 7, 8, 9 }} 3806694b06Sopenharmony_ci}; 3906694b06Sopenharmony_ci 4006694b06Sopenharmony_ciValuesBucket UTUtils::SetRowDatas(const RowDatas &rowDatas) 4106694b06Sopenharmony_ci{ 4206694b06Sopenharmony_ci ValuesBucket value; 4306694b06Sopenharmony_ci ValueObjectType typeMgr = rowDatas.mgr.GetType(); 4406694b06Sopenharmony_ci ValueObjectType typeBonus = rowDatas.bonus.GetType(); 4506694b06Sopenharmony_ci 4606694b06Sopenharmony_ci int outputMgr = 0; 4706694b06Sopenharmony_ci double outputBonus = 0.0; 4806694b06Sopenharmony_ci 4906694b06Sopenharmony_ci value.PutInt("id", rowDatas.id); 5006694b06Sopenharmony_ci value.PutString("eName", rowDatas.eName); 5106694b06Sopenharmony_ci value.PutInt("jobId", rowDatas.jobId); 5206694b06Sopenharmony_ci 5306694b06Sopenharmony_ci if (typeMgr == ValueObjectType::TYPE_NULL) { 5406694b06Sopenharmony_ci value.PutNull("mgr"); 5506694b06Sopenharmony_ci } else { 5606694b06Sopenharmony_ci int ret = rowDatas.mgr.GetInt(outputMgr); 5706694b06Sopenharmony_ci if (ret == E_OK) { 5806694b06Sopenharmony_ci value.PutInt("mgr", outputMgr); 5906694b06Sopenharmony_ci } 6006694b06Sopenharmony_ci } 6106694b06Sopenharmony_ci 6206694b06Sopenharmony_ci value.PutString("joinDate", rowDatas.joinDate); 6306694b06Sopenharmony_ci value.PutDouble("salary", rowDatas.salary); 6406694b06Sopenharmony_ci 6506694b06Sopenharmony_ci if (typeBonus == ValueObjectType::TYPE_NULL) { 6606694b06Sopenharmony_ci value.PutNull("bonus"); 6706694b06Sopenharmony_ci } else { 6806694b06Sopenharmony_ci int ret = rowDatas.bonus.GetDouble(outputBonus); 6906694b06Sopenharmony_ci if (ret == E_OK) { 7006694b06Sopenharmony_ci value.PutDouble("bonus", outputBonus); 7106694b06Sopenharmony_ci } 7206694b06Sopenharmony_ci } 7306694b06Sopenharmony_ci 7406694b06Sopenharmony_ci value.PutInt("deptId", rowDatas.deptId); 7506694b06Sopenharmony_ci return value; 7606694b06Sopenharmony_ci} 7706694b06Sopenharmony_ci 7806694b06Sopenharmony_ciconst RowDatas UTUtils::gRowDatas[14] = { 7906694b06Sopenharmony_ci { 1001, "SunWuKong", 4, ValueObject(1004), "2000-12-17", 8000.00, ValueObject(), 20 }, 8006694b06Sopenharmony_ci { 1002, "LuJunYi", 3, ValueObject(1006), "2001-02-20", 16000.00, ValueObject(3000.00), 30 }, 8106694b06Sopenharmony_ci { 1003, "LinChong", 3, ValueObject(1006), "2001-02-22", 12500.00, ValueObject(5000.00), 30 }, 8206694b06Sopenharmony_ci { 1004, "TangCeng", 2, ValueObject(1009), "2001-04-02", 29750.00, ValueObject(), 20 }, 8306694b06Sopenharmony_ci { 1005, "LiKui", 4, ValueObject(1006), "2001-09-28", 12500.00, ValueObject(14000.00), 30 }, 8406694b06Sopenharmony_ci { 1006, "SongJiang", 2, ValueObject(1009), "2001-05-01", 28500.00, ValueObject(), 30 }, 8506694b06Sopenharmony_ci { 1007, "LiuBei", 2, ValueObject(1009), "2001-09-01", 24500.00, ValueObject(), 10 }, 8606694b06Sopenharmony_ci { 1008, "ZhuBaJie", 4, ValueObject(1004), "2007-04-19", 30000.00, ValueObject(), 20 }, 8706694b06Sopenharmony_ci { 1009, "LuoGuanZhong", 1, ValueObject(), "2001-11-17", 50000.00, ValueObject(), 10 }, 8806694b06Sopenharmony_ci { 1010, "WuYong", 3, ValueObject(1006), "2001-09-08", 15000.00, ValueObject(), 30 }, 8906694b06Sopenharmony_ci { 1011, "ShaCeng", 4, ValueObject(1004), "2007-05-23", 11000.00, ValueObject(), 20 }, 9006694b06Sopenharmony_ci { 1012, "LiKui", 4, ValueObject(1006), "2001-12-03", 9500.00, ValueObject(), 30 }, 9106694b06Sopenharmony_ci { 1013, "XiaoBaiLong", 4, ValueObject(1004), "2001-12-03", 30000.00, ValueObject(), 20 }, 9206694b06Sopenharmony_ci { 1014, "GuanYu", 4, ValueObject(1007), "2002-01-23", 13000.00, ValueObject(), 10 } }; 9306694b06Sopenharmony_ci} 9406694b06Sopenharmony_ci} 95