2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Diagnostics;
19 using FilterHandle = Interop.FilterHandle;
21 namespace Tizen.Content.MediaContent
24 /// The Base class for query arguments.
27 /// A filter is required for filtering information associated with Album, Folder, Tag, Bookmark, Playlist,
28 /// and MediaInfo on the basis of details like limit, order, and condition.
30 /// <since_tizen> 4 </since_tizen>
31 public class QueryArguments
33 private string _filter;
36 /// Gets or sets the filtering expression that is applied.
38 /// <value>A string that represents a filtering expression applied when data is retrieved.</value>
40 /// Expressions for the filter can be one of the following forms:<br/>
44 /// - <![CDATA[column < value]]>
45 /// - <![CDATA[column <= value]]>
48 /// - <![CDATA[value < column]]>
49 /// - <![CDATA[value <= column]]>
50 /// - column IN (value)
51 /// - column IN(value-list)
52 /// - column NOT IN(value)
53 /// - column NOT IN(value-list)
54 /// - column LIKE value
55 /// - expression COLLATE NOCASE
56 /// - expression COLLATE RTRIM
57 /// - expression COLLATE LOCALIZED
58 /// - expression1 AND expression2 OR expression3 ...
60 /// Note that if you want to set quotation (" ' " or " " ") as value of LIKE operator, you should use two times. (" '' " or " "" ").
61 /// And the optional ESCAPE clause is supported. Both percent symbol("%") and underscore symbol("_") are used in the LIKE pattern.
62 /// If these characters are used as values of the LIKE operation, then the expression following the ESCAPE clause of sqlite will be ignored.<br/>
64 /// For example, column LIKE ('#%') ESCAPE ('#') - "#" is an escape character, it will be ignored.
66 /// <exception cref="ArgumentException"><paramref name="value"/> is a zero-length string, contains only white space.</exception>
67 /// <seealso cref="MediaInfoColumns"/>
68 /// <seealso cref="AlbumColumns"/>
69 /// <seealso cref="FolderColumns"/>
70 /// <seealso cref="PlaylistColumns"/>
71 /// <seealso cref="TagColumns"/>
72 /// <seealso cref="BookmarkColumns"/>
73 /// <seealso cref="FaceInfoColumns"/>
74 /// <since_tizen> 4 </since_tizen>
75 public string FilterExpression
82 ValidationUtil.ValidateNotNullOrEmpty(value, nameof(value));
89 private string _storageId;
92 /// Gets or sets the storage ID for the given filter.
93 /// You can use this property when you want to search items only in the specific storage.
95 /// <value>The storage ID to restrict storage to search, or null for all storages.</value>
96 /// <exception cref="ArgumentException"><paramref name="value"/> is a zero-length string, contains only white space.</exception>
97 /// <since_tizen> 4 </since_tizen>
98 [Obsolete("Please do not use! this will be deprecated in level 6")]
99 public string StorageId
106 ValidationUtil.ValidateNotNullOrEmpty(value, nameof(value));
113 internal static FilterHandle ToNativeHandle(QueryArguments arguments)
115 if (arguments == null || arguments.IsEmpty())
117 return FilterHandle.Null;
120 Interop.Filter.Create(out var handle).ThrowIfError("Failed to apply arguments.");
124 arguments.FillHandle(handle);
135 internal static FilterHandle CreateNativeHandle(string filterExpression)
137 Debug.Assert(filterExpression != null);
139 Interop.Filter.Create(out var handle).ThrowIfError("Failed to apply arguments.");
141 Interop.Filter.SetCondition(handle, filterExpression, Collation.Default).
142 ThrowIfError("Failed to create filter handle.");
147 #pragma warning disable CS0618 // Type or member is obsolete
148 internal virtual bool IsEmpty()
150 return StorageId == null && FilterExpression == null;
153 internal virtual void FillHandle(FilterHandle handle)
155 if (FilterExpression != null)
157 Interop.Filter.SetCondition(handle, FilterExpression, Collation.Default).
158 ThrowIfError("Failed to create filter handle(condition)");
161 if (StorageId != null)
163 Interop.Filter.SetStorage(handle, StorageId).
164 ThrowIfError("Failed to create filter handle(storage id)"); ;
167 #pragma warning restore CS0618 // Type or member is obsolete
172 /// Provides the ability to filter the result of a Select command.
175 /// A filter is required for filtering information associated with Album, Folder, Tag, Bookmark, Playlist,
178 /// <since_tizen> 4 </since_tizen>
179 public class SelectArguments : QueryArguments
181 private int _startRowIndex;
184 /// Gets or sets the starting row position of a query (starting from zero).
186 /// <value>An integer value that indicates the starting row position of a query.</value>
187 /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than zero.<br/></exception>
188 /// <since_tizen> 4 </since_tizen>
189 public int StartRowIndex
191 get => _startRowIndex;
196 throw new ArgumentOutOfRangeException(nameof(value), value, "StartRowIndex can't be less than zero.");
199 _startRowIndex = value;
203 private int _totalRowCount;
206 /// Gets or sets the number of rows to be retrieved.
208 /// <value>An integer value that indicates the limit of rows of the result.</value>
209 /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than zero.</exception>
210 /// <since_tizen> 4 </since_tizen>
211 public int TotalRowCount
213 get => _totalRowCount;
218 throw new ArgumentOutOfRangeException(nameof(value), value, "TotalRowCount can't be less than zero.");
221 _totalRowCount = value;
225 private string _sortOrder;
228 /// Gets or sets the sort order of the results.
230 /// <value>The expression for the sort order.</value>
232 /// Expressions for the sort order can be:<br/>
233 /// column [COLLATE NOCASE/RTRIM/LOCALIZED] [ASC/DESC], column2 ...
235 /// <exception cref="ArgumentException"><paramref name="value"/> is a zero-length string, contains only white space.</exception>
236 /// <seealso cref="MediaInfoColumns"/>
237 /// <seealso cref="AlbumColumns"/>
238 /// <seealso cref="FolderColumns"/>
239 /// <seealso cref="PlaylistColumns"/>
240 /// <seealso cref="TagColumns"/>
241 /// <seealso cref="BookmarkColumns"/>
242 /// <seealso cref="FaceInfoColumns"/>
243 /// <since_tizen> 4 </since_tizen>
244 public string SortOrder
251 ValidationUtil.ValidateNotNullOrEmpty(value, nameof(value));
258 internal override bool IsEmpty()
260 return base.IsEmpty() && StartRowIndex == 0 && TotalRowCount == 0 && SortOrder == null;
263 internal override void FillHandle(FilterHandle handle)
265 base.FillHandle(handle);
267 if (StartRowIndex != 0 || TotalRowCount != 0)
269 Interop.Filter.SetOffset(handle, StartRowIndex, TotalRowCount).
270 ThrowIfError("Failed to create filter handle(limit)");
273 if (SortOrder != null)
275 Interop.Filter.SetOrder(handle, SortOrder).ThrowIfError("Failed to create filter handle(order)");
281 /// Provides the ability to filter the result of the Count command.
284 /// A filter is required for filtering information associated with Album, Folder, Tag, Bookmark, Playlist,
287 /// <since_tizen> 4 </since_tizen>
288 public class CountArguments : QueryArguments