• 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 
16 #ifndef OH_PREDICATES_H
17 #define OH_PREDICATES_H
18 
19 /**
20  * @addtogroup RDB
21  * @{
22  *
23  * @brief The relational database (RDB) store manages data based on relational models.
24  * With the underlying SQLite database, the RDB store provides a complete mechanism for managing local databases.
25  * To satisfy different needs in complicated scenarios, the RDB store offers a series of APIs for performing operations
26  * such as adding, deleting, modifying, and querying data, and supports direct execution of SQL statements.
27  *
28  * @syscap SystemCapability.DistributedDataManager.RelationalStore.Core
29  * @since 10
30  */
31 
32 /**
33  * @file oh_predicates.h
34  *
35  * @brief Declared predicate related functions and enumerations.
36  *
37  * @kit ArkData
38  * @since 10
39  */
40 
41 #ifdef __cplusplus
42 #include <cstdint>
43 #else
44 #include <stdint.h>
45 #endif
46 
47 #include <stddef.h>
48 #include "database/rdb/oh_value_object.h"
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 /**
55  * @brief Result set sort type.
56  *
57  * @since 10
58  */
59 typedef enum OH_OrderType {
60     /**
61      * Ascend order.
62      */
63     ASC = 0,
64     /**
65      * Descend order.
66      */
67     DESC = 1,
68 } OH_OrderType;
69 
70 /**
71  * @brief Define the OH_Predicates structure type.
72  *
73  * @since 10
74  */
75 typedef struct OH_Predicates OH_Predicates;
76 
77 /**
78  * @brief Define the OH_Predicates structure type.
79  *
80  * @since 10
81  */
82 struct OH_Predicates {
83     /**
84      * The id used to uniquely identify the OH_Predicates struct.
85      */
86     int64_t id;
87 
88     /**
89      * @brief Function pointer. Restricts the value of the field to be equal to the specified value to the predicates.
90      *
91      * This method is similar to = of the SQL statement.
92      *
93      * @param predicates Represents a pointer to an {@link OH_Predicates} instance.
94      * @param field Indicates the column name in the database table.
95      * @param valueObject Represents a pointer to an {@link OH_VObject} instance.
96      * @return Returns the self.
97      * @see OH_Predicates, OH_VObject.
98      * @since 10
99      */
100     OH_Predicates *(*equalTo)(OH_Predicates *predicates, const char *field, OH_VObject *valueObject);
101 
102     /**
103      * @brief Function pointer.
104      * Restricts the value of the field to be not equal to the specified value to the predicates.
105      *
106      * This method is similar to != of the SQL statement.
107      *
108      * @param predicates Represents a pointer to an {@link OH_Predicates} instance.
109      * @param field Indicates the column name in the database table.
110      * @param valueObject Represents a pointer to an {@link OH_VObject} instance.
111      * @return Returns the self.
112      * @see OH_Predicates, OH_VObject.
113      * @since 10
114      */
115     OH_Predicates *(*notEqualTo)(OH_Predicates *predicates, const char *field, OH_VObject *valueObject);
116 
117     /**
118      * @brief Function pointer. Add left parenthesis to predicate.
119      *
120      * This method is similar to ( of the SQL statement.
121      *
122      * @param predicates Represents a pointer to an {@link OH_Predicates} instance.
123      * @return Returns the self.
124      * @see OH_Predicates.
125      * @since 10
126      */
127     OH_Predicates *(*beginWrap)(OH_Predicates *predicates);
128 
129     /**
130      * @brief Function pointer. Add right parenthesis to predicate.
131      *
132      * This method is similar to ) of the SQL statement.
133      *
134      * @param predicates Represents a pointer to an {@link OH_Predicates} instance.
135      * @return Returns the self.
136      * @see OH_Predicates.
137      * @since 10
138      */
139     OH_Predicates *(*endWrap)(OH_Predicates *predicates);
140 
141     /**
142      * @brief Function pointer. Adds an or condition to the predicates.
143      *
144      * This method is similar to OR of the SQL statement.
145      *
146      * @param predicates Represents a pointer to an {@link OH_Predicates} instance.
147      * @return Returns the self.
148      * @see OH_Predicates.
149      * @since 10
150      */
151     OH_Predicates *(*orOperate)(OH_Predicates *predicates);
152 
153     /**
154      * @brief Function pointer. Adds an and condition to the predicates.
155      *
156      * This method is similar to AND of the SQL statement.
157      *
158      * @param predicates Represents a pointer to an {@link OH_Predicates} instance.
159      * @return Returns the self.
160      * @see OH_Predicates.
161      * @since 10
162      */
163     OH_Predicates *(*andOperate)(OH_Predicates *predicates);
164 
165     /**
166      * @brief Function pointer. Restricts the value of the field which is null to the predicates.
167      *
168      * This method is similar to IS NULL of the SQL statement.
169      *
170      * @param predicates Represents a pointer to an {@link OH_Predicates} instance.
171      * @param field Indicates the column name in the database table.
172      * @return Returns the self.
173      * @see OH_Predicates.
174      * @since 10
175      */
176     OH_Predicates *(*isNull)(OH_Predicates *predicates, const char *field);
177 
178     /**
179      * @brief Function pointer. Restricts the value of the field which is not null to the predicates.
180      *
181      * This method is similar to IS NOT NULL of the SQL statement.
182      *
183      * @param predicates Represents a pointer to an {@link OH_Predicates} instance.
184      * @param field Indicates the column name in the database table.
185      * @return Returns the self.
186      * @see OH_Predicates.
187      * @since 10
188      */
189     OH_Predicates *(*isNotNull)(OH_Predicates *predicates, const char *field);
190 
191     /**
192      * @brief Function pointer. Restricts the value of the field to be like the specified value to the predicates.
193      *
194      * This method is similar to LIKE of the SQL statement.
195      *
196      * @param predicates Represents a pointer to an {@link OH_Predicates} instance.
197      * @param field Indicates the column name in the database table.
198      * @param valueObject Represents a pointer to an {@link OH_VObject} instance.
199      * @return Returns the self.
200      * @see OH_Predicates, OH_VObject.
201      * @since 10
202      */
203     OH_Predicates *(*like)(OH_Predicates *predicates, const char *field, OH_VObject *valueObject);
204 
205     /**
206      * @brief Function pointer. Restricts the value of the field to be between the specified value to the predicates.
207      *
208      * This method is similar to BETWEEN of the SQL statement.
209      *
210      * @param predicates Represents a pointer to an {@link OH_Predicates} instance.
211      * @param field Indicates the column name in the database table.
212      * @param valueObject Represents a pointer to an {@link OH_VObject} instance.
213      * @return Returns the self.
214      * @see OH_Predicates, OH_VObject.
215      * @since 10
216      */
217     OH_Predicates *(*between)(OH_Predicates *predicates, const char *field, OH_VObject *valueObject);
218 
219     /**
220      * @brief Function pointer.
221      * Restricts the value of the field to be not between the specified value to the predicates.
222      *
223      * This method is similar to NOT BETWEEN of the SQL statement.
224      *
225      * @param predicates Represents a pointer to an {@link OH_Predicates} instance.
226      * @param field Indicates the column name in the database table.
227      * @param valueObject Represents a pointer to an {@link OH_VObject} instance.
228      * @return Returns the self.
229      * @see OH_Predicates, OH_VObject.
230      * @since 10
231      */
232     OH_Predicates *(*notBetween)(OH_Predicates *predicates, const char *field, OH_VObject *valueObject);
233 
234     /**
235      * @brief Function pointer.
236      * Restricts the value of the field to be greater than the specified value to the predicates.
237      *
238      * This method is similar to > of the SQL statement.
239      *
240      * @param predicates Represents a pointer to an {@link OH_Predicates} instance.
241      * @param field Indicates the column name in the database table.
242      * @param valueObject Represents a pointer to an {@link OH_VObject} instance.
243      * @return Returns the self.
244      * @see OH_Predicates, OH_VObject.
245      * @since 10
246      */
247     OH_Predicates *(*greaterThan)(OH_Predicates *predicates, const char *field, OH_VObject *valueObject);
248 
249     /**
250      * @brief Function pointer.
251      * Restricts the value of the field to be less than the specified value to the predicates.
252      *
253      * This method is similar to < of the SQL statement.
254      *
255      * @param predicates Represents a pointer to an {@link OH_Predicates} instance.
256      * @param field Indicates the column name in the database table.
257      * @param valueObject Represents a pointer to an {@link OH_VObject} instance.
258      * @return Returns the self.
259      * @see OH_Predicates, OH_VObject.
260      * @since 10
261      */
262     OH_Predicates *(*lessThan)(OH_Predicates *predicates, const char *field, OH_VObject *valueObject);
263 
264     /**
265      * @brief Function pointer.
266      * Restricts the value of the field to be greater than or equal to the specified value to the predicates.
267      *
268      * This method is similar to >= of the SQL statement.
269      *
270      * @param predicates Represents a pointer to an {@link OH_Predicates} instance.
271      * @param field Indicates the column name in the database table.
272      * @param valueObject Represents a pointer to an {@link OH_VObject} instance.
273      * @return Returns the self.
274      * @see OH_Predicates, OH_VObject.
275      * @since 10
276      */
277     OH_Predicates *(*greaterThanOrEqualTo)(OH_Predicates *predicates, const char *field, OH_VObject *valueObject);
278 
279     /**
280      * @brief Function pointer.
281      * Restricts the value of the field to be less than or equal to the specified value to the predicates.
282      *
283      * This method is similar to <= of the SQL statement.
284      *
285      * @param predicates Represents a pointer to an {@link OH_Predicates} instance.
286      * @param field Indicates the column name in the database table.
287      * @param valueObject Represents a pointer to an {@link OH_VObject} instance.
288      * @return Returns the self.
289      * @see OH_Predicates, OH_VObject.
290      * @since 10
291      */
292     OH_Predicates *(*lessThanOrEqualTo)(OH_Predicates *predicates, const char *field, OH_VObject *valueObject);
293 
294     /**
295      * @brief Function pointer. Restricts the ascending or descending order of the return list.
296      * When there are several orders, the one close to the head has the highest priority.
297      *
298      * This method is similar ORDER BY the SQL statement.
299      *
300      * @param predicates Represents a pointer to an {@link OH_Predicates} instance.
301      * @param field Indicates the column name in the database table.
302      * @param type Indicates the sort {@link OH_OrderType} type.
303      * @return Returns the self.
304      * @see OH_Predicates, OH_OrderType.
305      * @since 10
306      */
307     OH_Predicates *(*orderBy)(OH_Predicates *predicates, const char *field, OH_OrderType type);
308 
309     /**
310      * @brief Function pointer. Configure predicates to filter duplicate records and retain only one of them.
311      *
312      * This method is similar DISTINCT the SQL statement.
313      *
314      * @param predicates Represents a pointer to an {@link OH_Predicates} instance.
315      * @return Returns the self.
316      * @see OH_Predicates.
317      * @since 10
318      */
319     OH_Predicates *(*distinct)(OH_Predicates *predicates);
320 
321     /**
322      * @brief Function pointer. Predicate for setting the maximum number of data records.
323      *
324      * This method is similar LIMIT the SQL statement.
325      *
326      * @param predicates Represents a pointer to an {@link OH_Predicates} instance.
327      * @param value Indicates the maximum number of records.
328      * @return Returns the self.
329      * @see OH_Predicates.
330      * @since 10
331      */
332     OH_Predicates *(*limit)(OH_Predicates *predicates, unsigned int value);
333 
334     /**
335      * @brief Function pointer. Configure the predicate to specify the starting position of the returned result.
336      *
337      * This method is similar OFFSET the SQL statement.
338      *
339      * @param predicates Represents a pointer to an {@link OH_Predicates} instance.
340      * @param rowOffset Indicates the number of rows to offset from the beginning. The value is a positive integer.
341      * @return Returns the self.
342      * @see OH_Predicates.
343      * @since 10
344      */
345     OH_Predicates *(*offset)(OH_Predicates *predicates, unsigned int rowOffset);
346 
347     /**
348      * @brief Function pointer. Configure predicates to group query results by specified columns.
349      *
350      * This method is similar GROUP BY the SQL statement.
351      *
352      * @param predicates Represents a pointer to an {@link OH_Predicates} instance.
353      * @param fields Indicates the column names that the grouping depends on.
354      * @param length Indicates the length of fields.
355      * @return Returns the self.
356      * @see OH_Predicates.
357      * @since 10
358      */
359     OH_Predicates *(*groupBy)(OH_Predicates *predicates, char const *const *fields, int length);
360 
361     /**
362      * @brief Function pointer.
363      * Configure the predicate to match the specified field and the value within the given array range.
364      *
365      * This method is similar IN the SQL statement.
366      *
367      * @param predicates Represents a pointer to an {@link OH_Predicates} instance.
368      * @param field Indicates the column name in the database table.
369      * @param valueObject Represents a pointer to an {@link OH_VObject} instance.
370      * @return Returns the self.
371      * @see OH_Predicates, OH_VObject.
372      * @since 10
373      */
374     OH_Predicates *(*in)(OH_Predicates *predicates, const char *field, OH_VObject *valueObject);
375 
376     /**
377      * @brief Function pointer.
378      * Configure the predicate to match the specified field and the value not within the given array range.
379      *
380      * This method is similar NOT IN the SQL statement.
381      *
382      * @param predicates Represents a pointer to an {@link OH_Predicates} instance.
383      * @param field Indicates the column name in the database table.
384      * @param valueObject Represents a pointer to an {@link OH_VObject} instance.
385      * @return Returns the self.
386      * @see OH_Predicates, OH_VObject.
387      * @since 10
388      */
389     OH_Predicates *(*notIn)(OH_Predicates *predicates, const char *field, OH_VObject *valueObject);
390 
391     /**
392      * @brief Function pointer. Initialize OH_Predicates object.
393      *
394      * @param predicates Represents a pointer to an {@link OH_Predicates} instance.
395      * @return Returns the self.
396      * @see OH_Predicates.
397      * @since 10
398      */
399     OH_Predicates *(*clear)(OH_Predicates *predicates);
400 
401     /**
402      * @brief Destroy the {@link OH_Predicates} object and reclaim the memory occupied by the object.
403      *
404      * @param predicates Represents a pointer to an {@link OH_Predicates} instance.
405      * @return Returns the status code of the execution..
406      * @see OH_Predicates.
407      * @since 10
408      */
409     int (*destroy)(OH_Predicates *predicates);
410 };
411 
412 #ifdef __cplusplus
413 };
414 #endif
415 
416 #endif // OH_PREDICATES_H
417