106694b06Sopenharmony_ci/*
206694b06Sopenharmony_ci * Copyright (c) 2023 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#define LOG_TAG "RelationalPredicate"
1606694b06Sopenharmony_ci#include "relational_predicates.h"
1706694b06Sopenharmony_ci
1806694b06Sopenharmony_ci#include <variant>
1906694b06Sopenharmony_ci
2006694b06Sopenharmony_ci#include "logger.h"
2106694b06Sopenharmony_ci#include "oh_predicates.h"
2206694b06Sopenharmony_ci#include "relational_predicates_objects.h"
2306694b06Sopenharmony_ci#include "relational_store_error_code.h"
2406694b06Sopenharmony_ci#include "sqlite_global_config.h"
2506694b06Sopenharmony_ci
2606694b06Sopenharmony_ciusing namespace OHOS::NativeRdb;
2706694b06Sopenharmony_cinamespace OHOS {
2806694b06Sopenharmony_cinamespace RdbNdk {
2906694b06Sopenharmony_ciOH_Predicates *RelationalPredicate::EqualTo(OH_Predicates *predicates, const char *field, OH_VObject *valueObject)
3006694b06Sopenharmony_ci{
3106694b06Sopenharmony_ci    auto self = GetSelf(predicates);
3206694b06Sopenharmony_ci    auto selfObjects = RelationalPredicatesObjects::GetSelf(valueObject);
3306694b06Sopenharmony_ci    if (self == nullptr || selfObjects == nullptr || field == nullptr) {
3406694b06Sopenharmony_ci        return self;
3506694b06Sopenharmony_ci    }
3606694b06Sopenharmony_ci    std::vector<ValueObject> values = selfObjects->Get();
3706694b06Sopenharmony_ci    if (!values.empty()) {
3806694b06Sopenharmony_ci        self->predicates_.EqualTo(field, values[0]);
3906694b06Sopenharmony_ci    }
4006694b06Sopenharmony_ci    return self;
4106694b06Sopenharmony_ci}
4206694b06Sopenharmony_ci
4306694b06Sopenharmony_ciOH_Predicates *RelationalPredicate::NotEqualTo(OH_Predicates *predicates, const char *field,
4406694b06Sopenharmony_ci    OH_VObject *valueObject)
4506694b06Sopenharmony_ci{
4606694b06Sopenharmony_ci    auto self = GetSelf(predicates);
4706694b06Sopenharmony_ci    auto selfObjects = RelationalPredicatesObjects::GetSelf(valueObject);
4806694b06Sopenharmony_ci    if (self == nullptr || selfObjects == nullptr || field == nullptr) {
4906694b06Sopenharmony_ci        return self;
5006694b06Sopenharmony_ci    }
5106694b06Sopenharmony_ci    std::vector<ValueObject> values = selfObjects->Get();
5206694b06Sopenharmony_ci    if (!values.empty()) {
5306694b06Sopenharmony_ci        self->predicates_.NotEqualTo(field, values[0]);
5406694b06Sopenharmony_ci    }
5506694b06Sopenharmony_ci    return self;
5606694b06Sopenharmony_ci}
5706694b06Sopenharmony_ci
5806694b06Sopenharmony_ciOH_Predicates *RelationalPredicate::BeginWrap(OH_Predicates *predicates)
5906694b06Sopenharmony_ci{
6006694b06Sopenharmony_ci    auto self = GetSelf(predicates);
6106694b06Sopenharmony_ci    if (self == nullptr) {
6206694b06Sopenharmony_ci        return self;
6306694b06Sopenharmony_ci    }
6406694b06Sopenharmony_ci    self->predicates_.BeginWrap();
6506694b06Sopenharmony_ci    return self;
6606694b06Sopenharmony_ci}
6706694b06Sopenharmony_ci
6806694b06Sopenharmony_ciOH_Predicates *RelationalPredicate::EndWrap(OH_Predicates *predicates)
6906694b06Sopenharmony_ci{
7006694b06Sopenharmony_ci    auto self = GetSelf(predicates);
7106694b06Sopenharmony_ci    if (self == nullptr) {
7206694b06Sopenharmony_ci        return self;
7306694b06Sopenharmony_ci    }
7406694b06Sopenharmony_ci    self->predicates_.EndWrap();
7506694b06Sopenharmony_ci    return self;
7606694b06Sopenharmony_ci}
7706694b06Sopenharmony_ci
7806694b06Sopenharmony_ciOH_Predicates *RelationalPredicate::Or(OH_Predicates *predicates)
7906694b06Sopenharmony_ci{
8006694b06Sopenharmony_ci    auto self = GetSelf(predicates);
8106694b06Sopenharmony_ci    if (self == nullptr) {
8206694b06Sopenharmony_ci        return self;
8306694b06Sopenharmony_ci    }
8406694b06Sopenharmony_ci    self->predicates_.Or();
8506694b06Sopenharmony_ci    return self;
8606694b06Sopenharmony_ci}
8706694b06Sopenharmony_ci
8806694b06Sopenharmony_ciOH_Predicates *RelationalPredicate::And(OH_Predicates *predicates)
8906694b06Sopenharmony_ci{
9006694b06Sopenharmony_ci    auto self = GetSelf(predicates);
9106694b06Sopenharmony_ci    if (self == nullptr) {
9206694b06Sopenharmony_ci        return self;
9306694b06Sopenharmony_ci    }
9406694b06Sopenharmony_ci    self->predicates_.And();
9506694b06Sopenharmony_ci    return self;
9606694b06Sopenharmony_ci}
9706694b06Sopenharmony_ci
9806694b06Sopenharmony_ciOH_Predicates *RelationalPredicate::IsNull(OH_Predicates *predicates, const char *field)
9906694b06Sopenharmony_ci{
10006694b06Sopenharmony_ci    auto self = GetSelf(predicates);
10106694b06Sopenharmony_ci    if (self == nullptr || field == nullptr) {
10206694b06Sopenharmony_ci        return self;
10306694b06Sopenharmony_ci    }
10406694b06Sopenharmony_ci    self->predicates_.IsNull(field);
10506694b06Sopenharmony_ci    return self;
10606694b06Sopenharmony_ci}
10706694b06Sopenharmony_ci
10806694b06Sopenharmony_ciOH_Predicates *RelationalPredicate::IsNotNull(OH_Predicates *predicates, const char *field)
10906694b06Sopenharmony_ci{
11006694b06Sopenharmony_ci    auto self = GetSelf(predicates);
11106694b06Sopenharmony_ci    if (self == nullptr || field == nullptr) {
11206694b06Sopenharmony_ci        return self;
11306694b06Sopenharmony_ci    }
11406694b06Sopenharmony_ci    self->predicates_.IsNotNull(field);
11506694b06Sopenharmony_ci    return self;
11606694b06Sopenharmony_ci}
11706694b06Sopenharmony_ci
11806694b06Sopenharmony_ciOH_Predicates *RelationalPredicate::Like(OH_Predicates *predicates, const char *field, OH_VObject *valueObject)
11906694b06Sopenharmony_ci{
12006694b06Sopenharmony_ci    auto self = GetSelf(predicates);
12106694b06Sopenharmony_ci    auto selfObjects = RelationalPredicatesObjects::GetSelf(valueObject);
12206694b06Sopenharmony_ci    if (self == nullptr || selfObjects == nullptr || field == nullptr) {
12306694b06Sopenharmony_ci        return self;
12406694b06Sopenharmony_ci    }
12506694b06Sopenharmony_ci    std::vector<ValueObject> values = selfObjects->Get();
12606694b06Sopenharmony_ci    if (!values.empty()) {
12706694b06Sopenharmony_ci        if (auto pval = std::get_if<std::string>(&values[0].value)) {
12806694b06Sopenharmony_ci            self->predicates_.Like(field, std::move(*pval));
12906694b06Sopenharmony_ci        }
13006694b06Sopenharmony_ci    }
13106694b06Sopenharmony_ci    return self;
13206694b06Sopenharmony_ci}
13306694b06Sopenharmony_ci
13406694b06Sopenharmony_ciOH_Predicates *RelationalPredicate::Between(OH_Predicates *predicates, const char *field, OH_VObject *valueObject)
13506694b06Sopenharmony_ci{
13606694b06Sopenharmony_ci    auto self = GetSelf(predicates);
13706694b06Sopenharmony_ci    auto selfObjects = RelationalPredicatesObjects::GetSelf(valueObject);
13806694b06Sopenharmony_ci    if (self == nullptr || selfObjects == nullptr || field == nullptr) {
13906694b06Sopenharmony_ci        return self;
14006694b06Sopenharmony_ci    }
14106694b06Sopenharmony_ci    std::vector<ValueObject> values = selfObjects->Get();
14206694b06Sopenharmony_ci    // The number of arguments required for the between method is 2
14306694b06Sopenharmony_ci    if (values.size() != 2) {
14406694b06Sopenharmony_ci        LOG_ERROR("size is %{public}zu", values.size());
14506694b06Sopenharmony_ci        return self;
14606694b06Sopenharmony_ci    }
14706694b06Sopenharmony_ci
14806694b06Sopenharmony_ci    self->predicates_.Between(field, values[0], values[1]);
14906694b06Sopenharmony_ci    return self;
15006694b06Sopenharmony_ci}
15106694b06Sopenharmony_ci
15206694b06Sopenharmony_ciOH_Predicates *RelationalPredicate::NotBetween(OH_Predicates *predicates, const char *field,
15306694b06Sopenharmony_ci    OH_VObject *valueObject)
15406694b06Sopenharmony_ci{
15506694b06Sopenharmony_ci    auto self = GetSelf(predicates);
15606694b06Sopenharmony_ci    auto selfObjects = RelationalPredicatesObjects::GetSelf(valueObject);
15706694b06Sopenharmony_ci    if (self == nullptr || selfObjects == nullptr || field == nullptr) {
15806694b06Sopenharmony_ci        return self;
15906694b06Sopenharmony_ci    }
16006694b06Sopenharmony_ci    std::vector<ValueObject> values = selfObjects->Get();
16106694b06Sopenharmony_ci    // The number of arguments required for the between method is 2
16206694b06Sopenharmony_ci    if (values.size() != 2) {
16306694b06Sopenharmony_ci        LOG_ERROR("size is %{public}zu", values.size());
16406694b06Sopenharmony_ci        return self;
16506694b06Sopenharmony_ci    }
16606694b06Sopenharmony_ci    self->predicates_.NotBetween(field, values[0], values[1]);
16706694b06Sopenharmony_ci    return self;
16806694b06Sopenharmony_ci}
16906694b06Sopenharmony_ci
17006694b06Sopenharmony_ciOH_Predicates *RelationalPredicate::GreaterThan(OH_Predicates *predicates, const char *field,
17106694b06Sopenharmony_ci    OH_VObject *valueObject)
17206694b06Sopenharmony_ci{
17306694b06Sopenharmony_ci    auto self = GetSelf(predicates);
17406694b06Sopenharmony_ci    auto selfObjects = RelationalPredicatesObjects::GetSelf(valueObject);
17506694b06Sopenharmony_ci    if (self == nullptr || selfObjects == nullptr || field == nullptr) {
17606694b06Sopenharmony_ci        return self;
17706694b06Sopenharmony_ci    }
17806694b06Sopenharmony_ci    std::vector<ValueObject> values = selfObjects->Get();
17906694b06Sopenharmony_ci    if (!values.empty()) {
18006694b06Sopenharmony_ci        self->predicates_.GreaterThan(field, values[0]);
18106694b06Sopenharmony_ci    }
18206694b06Sopenharmony_ci    return self;
18306694b06Sopenharmony_ci}
18406694b06Sopenharmony_ci
18506694b06Sopenharmony_ciOH_Predicates *RelationalPredicate::LessThan(OH_Predicates *predicates, const char *field,
18606694b06Sopenharmony_ci    OH_VObject *valueObject)
18706694b06Sopenharmony_ci{
18806694b06Sopenharmony_ci    auto self = GetSelf(predicates);
18906694b06Sopenharmony_ci    auto selfObjects = RelationalPredicatesObjects::GetSelf(valueObject);
19006694b06Sopenharmony_ci    if (self == nullptr || selfObjects == nullptr || field == nullptr) {
19106694b06Sopenharmony_ci        return self;
19206694b06Sopenharmony_ci    }
19306694b06Sopenharmony_ci    std::vector<ValueObject> values = selfObjects->Get();
19406694b06Sopenharmony_ci    if (!values.empty()) {
19506694b06Sopenharmony_ci        self->predicates_.LessThan(field, values[0]);
19606694b06Sopenharmony_ci    }
19706694b06Sopenharmony_ci    return self;
19806694b06Sopenharmony_ci}
19906694b06Sopenharmony_ci
20006694b06Sopenharmony_ciOH_Predicates *RelationalPredicate::GreaterThanOrEqualTo(OH_Predicates *predicates, const char *field,
20106694b06Sopenharmony_ci    OH_VObject *valueObject)
20206694b06Sopenharmony_ci{
20306694b06Sopenharmony_ci    auto self = GetSelf(predicates);
20406694b06Sopenharmony_ci    auto selfObjects = RelationalPredicatesObjects::GetSelf(valueObject);
20506694b06Sopenharmony_ci    if (self == nullptr || selfObjects == nullptr || field == nullptr) {
20606694b06Sopenharmony_ci        return self;
20706694b06Sopenharmony_ci    }
20806694b06Sopenharmony_ci    std::vector<ValueObject> values = selfObjects->Get();
20906694b06Sopenharmony_ci    if (!values.empty()) {
21006694b06Sopenharmony_ci        self->predicates_.GreaterThanOrEqualTo(field, values[0]);
21106694b06Sopenharmony_ci    }
21206694b06Sopenharmony_ci    return self;
21306694b06Sopenharmony_ci}
21406694b06Sopenharmony_ciOH_Predicates *RelationalPredicate::LessThanOrEqualTo(OH_Predicates *predicates, const char *field,
21506694b06Sopenharmony_ci    OH_VObject *valueObject)
21606694b06Sopenharmony_ci{
21706694b06Sopenharmony_ci    auto self = GetSelf(predicates);
21806694b06Sopenharmony_ci    auto selfObjects = RelationalPredicatesObjects::GetSelf(valueObject);
21906694b06Sopenharmony_ci    if (self == nullptr || selfObjects == nullptr || field == nullptr) {
22006694b06Sopenharmony_ci        return self;
22106694b06Sopenharmony_ci    }
22206694b06Sopenharmony_ci    std::vector<ValueObject> values = selfObjects->Get();
22306694b06Sopenharmony_ci    if (!values.empty()) {
22406694b06Sopenharmony_ci        self->predicates_.LessThanOrEqualTo(field, values[0]);
22506694b06Sopenharmony_ci    }
22606694b06Sopenharmony_ci    return self;
22706694b06Sopenharmony_ci}
22806694b06Sopenharmony_ci
22906694b06Sopenharmony_ciOH_Predicates *RelationalPredicate::OrderBy(OH_Predicates *predicates, const char *field, OH_OrderType type)
23006694b06Sopenharmony_ci{
23106694b06Sopenharmony_ci    auto self = GetSelf(predicates);
23206694b06Sopenharmony_ci    if (self == nullptr || field == nullptr) {
23306694b06Sopenharmony_ci        return self;
23406694b06Sopenharmony_ci    }
23506694b06Sopenharmony_ci    if (type == OH_OrderType::DESC) {
23606694b06Sopenharmony_ci        self->predicates_.OrderByDesc(field);
23706694b06Sopenharmony_ci        return self;
23806694b06Sopenharmony_ci    }
23906694b06Sopenharmony_ci    self->predicates_.OrderByAsc(field);
24006694b06Sopenharmony_ci    return self;
24106694b06Sopenharmony_ci}
24206694b06Sopenharmony_ci
24306694b06Sopenharmony_ciOH_Predicates *RelationalPredicate::Distinct(OH_Predicates *predicates)
24406694b06Sopenharmony_ci{
24506694b06Sopenharmony_ci    auto self = GetSelf(predicates);
24606694b06Sopenharmony_ci    if (self == nullptr) {
24706694b06Sopenharmony_ci        return self;
24806694b06Sopenharmony_ci    }
24906694b06Sopenharmony_ci    self->predicates_.Distinct();
25006694b06Sopenharmony_ci    return self;
25106694b06Sopenharmony_ci}
25206694b06Sopenharmony_ci
25306694b06Sopenharmony_ciOH_Predicates *RelationalPredicate::Limit(OH_Predicates *predicates, unsigned int value)
25406694b06Sopenharmony_ci{
25506694b06Sopenharmony_ci    auto self = GetSelf(predicates);
25606694b06Sopenharmony_ci    if (self == nullptr) {
25706694b06Sopenharmony_ci        return self;
25806694b06Sopenharmony_ci    }
25906694b06Sopenharmony_ci    self->predicates_.Limit(value);
26006694b06Sopenharmony_ci    return self;
26106694b06Sopenharmony_ci}
26206694b06Sopenharmony_ci
26306694b06Sopenharmony_ciOH_Predicates *RelationalPredicate::Offset(OH_Predicates *predicates, unsigned int rowOffset)
26406694b06Sopenharmony_ci{
26506694b06Sopenharmony_ci    auto self = GetSelf(predicates);
26606694b06Sopenharmony_ci    if (self == nullptr) {
26706694b06Sopenharmony_ci        return self;
26806694b06Sopenharmony_ci    }
26906694b06Sopenharmony_ci    self->predicates_.Offset(rowOffset);
27006694b06Sopenharmony_ci    return self;
27106694b06Sopenharmony_ci}
27206694b06Sopenharmony_ci
27306694b06Sopenharmony_ciOH_Predicates *RelationalPredicate::GroupBy(OH_Predicates *predicates, char const *const *fields, int length)
27406694b06Sopenharmony_ci{
27506694b06Sopenharmony_ci    auto self = GetSelf(predicates);
27606694b06Sopenharmony_ci    if (self == nullptr || fields == nullptr || length <= 0) {
27706694b06Sopenharmony_ci        return self;
27806694b06Sopenharmony_ci    }
27906694b06Sopenharmony_ci    std::vector<std::string> vec;
28006694b06Sopenharmony_ci    vec.reserve(length);
28106694b06Sopenharmony_ci    for (int i = 0; i < length; i++) {
28206694b06Sopenharmony_ci        vec.push_back(std::string(fields[i]));
28306694b06Sopenharmony_ci    }
28406694b06Sopenharmony_ci    self->predicates_.GroupBy(vec);
28506694b06Sopenharmony_ci    return self;
28606694b06Sopenharmony_ci}
28706694b06Sopenharmony_ci
28806694b06Sopenharmony_ciOH_Predicates *RelationalPredicate::In(OH_Predicates *predicates, const char *field, OH_VObject *valueObject)
28906694b06Sopenharmony_ci{
29006694b06Sopenharmony_ci    auto self = GetSelf(predicates);
29106694b06Sopenharmony_ci    auto selfObjects = RelationalPredicatesObjects::GetSelf(valueObject);
29206694b06Sopenharmony_ci    if (self == nullptr || selfObjects == nullptr || field == nullptr) {
29306694b06Sopenharmony_ci        return self;
29406694b06Sopenharmony_ci    }
29506694b06Sopenharmony_ci    std::vector<ValueObject> values = selfObjects->Get();
29606694b06Sopenharmony_ci    if (values.size() > OHOS::NativeRdb::GlobalExpr::SQLITE_MAX_COLUMN) {
29706694b06Sopenharmony_ci        return self;
29806694b06Sopenharmony_ci    }
29906694b06Sopenharmony_ci
30006694b06Sopenharmony_ci    self->predicates_.In(field, values);
30106694b06Sopenharmony_ci    return self;
30206694b06Sopenharmony_ci}
30306694b06Sopenharmony_ci
30406694b06Sopenharmony_ciOH_Predicates *RelationalPredicate::NotIn(OH_Predicates *predicates, const char *field, OH_VObject *valueObject)
30506694b06Sopenharmony_ci{
30606694b06Sopenharmony_ci    auto self = GetSelf(predicates);
30706694b06Sopenharmony_ci    auto selfObjects = RelationalPredicatesObjects::GetSelf(valueObject);
30806694b06Sopenharmony_ci    if (self == nullptr || selfObjects == nullptr || field == nullptr) {
30906694b06Sopenharmony_ci        return self;
31006694b06Sopenharmony_ci    }
31106694b06Sopenharmony_ci    std::vector<ValueObject> values = selfObjects->Get();
31206694b06Sopenharmony_ci    if (values.size() > OHOS::NativeRdb::GlobalExpr::SQLITE_MAX_COLUMN) {
31306694b06Sopenharmony_ci        return self;
31406694b06Sopenharmony_ci    }
31506694b06Sopenharmony_ci
31606694b06Sopenharmony_ci    self->predicates_.NotIn(field, values);
31706694b06Sopenharmony_ci    return self;
31806694b06Sopenharmony_ci}
31906694b06Sopenharmony_ci
32006694b06Sopenharmony_ciOH_Predicates *RelationalPredicate::Clear(OH_Predicates *predicates)
32106694b06Sopenharmony_ci{
32206694b06Sopenharmony_ci    auto self = GetSelf(predicates);
32306694b06Sopenharmony_ci    if (self == nullptr) {
32406694b06Sopenharmony_ci        return self;
32506694b06Sopenharmony_ci    }
32606694b06Sopenharmony_ci    self->predicates_.Clear();
32706694b06Sopenharmony_ci    return self;
32806694b06Sopenharmony_ci}
32906694b06Sopenharmony_ci
33006694b06Sopenharmony_ciint RelationalPredicate::Destroy(OH_Predicates *predicates)
33106694b06Sopenharmony_ci{
33206694b06Sopenharmony_ci    auto self = GetSelf(predicates);
33306694b06Sopenharmony_ci    if (self == nullptr) {
33406694b06Sopenharmony_ci        return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
33506694b06Sopenharmony_ci    }
33606694b06Sopenharmony_ci    delete self;
33706694b06Sopenharmony_ci    return OH_Rdb_ErrCode::RDB_OK;
33806694b06Sopenharmony_ci}
33906694b06Sopenharmony_ci
34006694b06Sopenharmony_ciRelationalPredicate::RelationalPredicate(const char *table) : predicates_(table)
34106694b06Sopenharmony_ci{
34206694b06Sopenharmony_ci    id = RDB_PREDICATES_CID;
34306694b06Sopenharmony_ci    equalTo = EqualTo;
34406694b06Sopenharmony_ci    notEqualTo = NotEqualTo;
34506694b06Sopenharmony_ci    beginWrap = BeginWrap;
34606694b06Sopenharmony_ci    endWrap = EndWrap;
34706694b06Sopenharmony_ci    orOperate = Or;
34806694b06Sopenharmony_ci    andOperate = And;
34906694b06Sopenharmony_ci    isNull = IsNull;
35006694b06Sopenharmony_ci    isNotNull = IsNotNull;
35106694b06Sopenharmony_ci    like = Like;
35206694b06Sopenharmony_ci    between = Between;
35306694b06Sopenharmony_ci    notBetween = NotBetween;
35406694b06Sopenharmony_ci    greaterThan = GreaterThan;
35506694b06Sopenharmony_ci    lessThan = LessThan;
35606694b06Sopenharmony_ci    greaterThanOrEqualTo = GreaterThanOrEqualTo;
35706694b06Sopenharmony_ci    lessThanOrEqualTo = LessThanOrEqualTo;
35806694b06Sopenharmony_ci    orderBy = OrderBy;
35906694b06Sopenharmony_ci    distinct = Distinct;
36006694b06Sopenharmony_ci    limit = Limit;
36106694b06Sopenharmony_ci    offset = Offset;
36206694b06Sopenharmony_ci    groupBy = GroupBy;
36306694b06Sopenharmony_ci    in = In;
36406694b06Sopenharmony_ci    notIn = NotIn;
36506694b06Sopenharmony_ci    clear = Clear;
36606694b06Sopenharmony_ci    destroy = Destroy;
36706694b06Sopenharmony_ci}
36806694b06Sopenharmony_ci
36906694b06Sopenharmony_ciOHOS::NativeRdb::RdbPredicates &RelationalPredicate::Get()
37006694b06Sopenharmony_ci{
37106694b06Sopenharmony_ci    return predicates_;
37206694b06Sopenharmony_ci}
37306694b06Sopenharmony_ci
37406694b06Sopenharmony_ciRelationalPredicate* RelationalPredicate::GetSelf(OH_Predicates *predicates)
37506694b06Sopenharmony_ci{
37606694b06Sopenharmony_ci    if (predicates == nullptr || predicates->id != OHOS::RdbNdk::RDB_PREDICATES_CID) {
37706694b06Sopenharmony_ci        LOG_ERROR("cursor invalid. is null %{public}d", (predicates == nullptr));
37806694b06Sopenharmony_ci        return nullptr;
37906694b06Sopenharmony_ci    }
38006694b06Sopenharmony_ci    return static_cast<OHOS::RdbNdk::RelationalPredicate *>(predicates);
38106694b06Sopenharmony_ci}
38206694b06Sopenharmony_ci} // namespace RdbNdk
38306694b06Sopenharmony_ci} // namespace OHOS