• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #define LOG_TAG "RelationalPredicatesObjects"
16 #include "relational_predicates_objects.h"
17 
18 #include "logger.h"
19 #include "oh_value_object.h"
20 #include "relational_store_error_code.h"
21 
22 namespace OHOS {
23 namespace RdbNdk {
24 // The class id used to uniquely identify the OH_VObject class.
25 constexpr int RDB_PREDICATES_OBJECTS_CID = 1234565;
PutInt64(OH_VObject * objects,int64_t * value,uint32_t count)26 int RelationalPredicatesObjects::PutInt64(OH_VObject *objects, int64_t *value, uint32_t count)
27 {
28     auto self = GetSelf(objects);
29     if (self == nullptr || value == nullptr || count == 0) {
30         return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
31     }
32     self->values_.clear();
33     self->values_.reserve(count);
34     for (uint32_t i = 0; i < count; i++) {
35         self->values_.push_back(value[i]);
36     }
37     return OH_Rdb_ErrCode::RDB_OK;
38 }
39 
PutDouble(OH_VObject * objects,double * value,uint32_t count)40 int RelationalPredicatesObjects::PutDouble(OH_VObject *objects, double *value, uint32_t count)
41 {
42     auto self = GetSelf(objects);
43     if (self == nullptr || value == nullptr || count == 0) {
44         return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
45     }
46     self->values_.clear();
47     self->values_.reserve(count);
48     for (uint32_t i = 0; i < count; i++) {
49         self->values_.push_back(value[i]);
50     }
51     return OH_Rdb_ErrCode::RDB_OK;
52 }
53 
PutText(OH_VObject * objects,const char * value)54 int RelationalPredicatesObjects::PutText(OH_VObject *objects, const char *value)
55 {
56     auto self = GetSelf(objects);
57     if (self == nullptr || value == nullptr) {
58         return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
59     }
60 
61     self->values_.clear();
62     self->values_.push_back(value);
63     return OH_Rdb_ErrCode::RDB_OK;
64 }
65 
PutTexts(OH_VObject * objects,const char ** value,uint32_t count)66 int RelationalPredicatesObjects::PutTexts(OH_VObject *objects, const char **value, uint32_t count)
67 {
68     auto self = GetSelf(objects);
69     if (self == nullptr || value == nullptr || count == 0) {
70         return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
71     }
72 
73     self->values_.clear();
74     self->values_.reserve(count);
75     for (uint32_t i = 0; i < count; i++) {
76         self->values_.push_back(value[i]);
77     }
78     return OH_Rdb_ErrCode::RDB_OK;
79 }
80 
Destroy(OH_VObject * objects)81 int RelationalPredicatesObjects::Destroy(OH_VObject *objects)
82 {
83     auto self = GetSelf(objects);
84     if (self == nullptr) {
85         return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
86     }
87     delete self;
88     return OH_Rdb_ErrCode::RDB_OK;
89 }
90 
RelationalPredicatesObjects()91 RelationalPredicatesObjects::RelationalPredicatesObjects()
92 {
93     id = RDB_PREDICATES_OBJECTS_CID;
94     putInt64 = PutInt64;
95     putDouble = PutDouble;
96     putText = PutText;
97     putTexts = PutTexts;
98     destroy = Destroy;
99 }
100 
GetSelf(OH_VObject * valueObject)101 RelationalPredicatesObjects *RelationalPredicatesObjects::GetSelf(OH_VObject *valueObject)
102 {
103     if (valueObject == nullptr || valueObject->id != OHOS::RdbNdk::RDB_PREDICATES_OBJECTS_CID) {
104         LOG_ERROR("predicates objects invalid. is null %{public}d", (valueObject == nullptr));
105         return nullptr;
106     }
107     return static_cast<OHOS::RdbNdk::RelationalPredicatesObjects *>(valueObject);
108 }
109 
Get()110 std::vector<ValueObject> &RelationalPredicatesObjects::Get()
111 {
112     return values_;
113 }
114 } // namespace RdbNdk
115 } // namespace OHOS