2 * Copyright (C) 2013-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
16 #define DATABASEQUERY_RULE_VALUE_SEPARATOR " / "
22 class CDatabaseQueryRule
26 virtual ~CDatabaseQueryRule() = default;
32 OPERATOR_DOES_NOT_CONTAIN
,
34 OPERATOR_DOES_NOT_EQUAL
,
37 OPERATOR_GREATER_THAN
,
42 OPERATOR_NOT_IN_THE_LAST
,
61 virtual bool Load(const TiXmlNode
* node
, const std::string
& encoding
= "UTF-8");
62 virtual bool Load(const CVariant
& obj
);
63 virtual bool Save(TiXmlNode
* parent
) const;
64 virtual bool Save(CVariant
& obj
) const;
66 static std::string
GetLocalizedOperator(SEARCH_OPERATOR oper
);
67 static void GetAvailableOperators(std::vector
<std::string
>& operatorList
);
69 std::string
GetParameter() const;
70 void SetParameter(const std::string
& value
);
71 void SetParameter(const std::vector
<std::string
>& values
);
73 virtual std::string
GetWhereClause(const CDatabase
& db
, const std::string
& strType
) const;
76 SEARCH_OPERATOR m_operator
;
77 std::vector
<std::string
> m_parameter
;
80 virtual std::string
GetField(int field
, const std::string
& type
) const = 0;
81 virtual FIELD_TYPE
GetFieldType(int field
) const = 0;
82 virtual int TranslateField(const char* field
) const = 0;
83 virtual std::string
TranslateField(int field
) const = 0;
84 std::string
ValidateParameter(const std::string
& parameter
) const;
85 virtual std::string
FormatParameter(const std::string
& negate
,
86 const std::string
& oper
,
88 const std::string
& type
) const;
89 virtual std::string
FormatWhereClause(const std::string
& negate
,
90 const std::string
& oper
,
91 const std::string
& param
,
93 const std::string
& type
) const;
94 virtual SEARCH_OPERATOR
GetOperator(const std::string
& type
) const { return m_operator
; }
95 virtual std::string
GetOperatorString(SEARCH_OPERATOR op
) const;
96 virtual std::string
GetBooleanQuery(const std::string
& negate
, const std::string
& strType
) const
101 static SEARCH_OPERATOR
TranslateOperator(const char* oper
);
102 static std::string
TranslateOperator(SEARCH_OPERATOR oper
);
105 class CDatabaseQueryRuleCombination
;
107 typedef std::vector
<std::shared_ptr
<CDatabaseQueryRule
>> CDatabaseQueryRules
;
108 typedef std::vector
<std::shared_ptr
<CDatabaseQueryRuleCombination
>> CDatabaseQueryRuleCombinations
;
110 class IDatabaseQueryRuleFactory
113 virtual ~IDatabaseQueryRuleFactory() = default;
114 virtual CDatabaseQueryRule
* CreateRule() const = 0;
115 virtual CDatabaseQueryRuleCombination
* CreateCombination() const = 0;
118 class CDatabaseQueryRuleCombination
121 virtual ~CDatabaseQueryRuleCombination() = default;
130 virtual bool Load(const TiXmlNode
* node
, const std::string
& encoding
= "UTF-8") { return false; }
131 virtual bool Load(const CVariant
& obj
, const IDatabaseQueryRuleFactory
* factory
);
132 virtual bool Save(TiXmlNode
* parent
) const;
133 virtual bool Save(CVariant
& obj
) const;
135 std::string
GetWhereClause(const CDatabase
& db
, const std::string
& strType
) const;
136 std::string
TranslateCombinationType() const;
138 Combination
GetType() const { return m_type
; }
139 void SetType(Combination combination
) { m_type
= combination
; }
141 bool empty() const { return m_combinations
.empty() && m_rules
.empty(); }
144 friend class CGUIDialogSmartPlaylistEditor
;
145 friend class CGUIDialogMediaFilter
;
147 Combination m_type
= CombinationAnd
;
148 CDatabaseQueryRuleCombinations m_combinations
;
149 CDatabaseQueryRules m_rules
;