/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Diagnostics; using FilterHandle = Interop.FilterHandle; namespace Tizen.Content.MediaContent { /// /// The Base class for query arguments. /// /// /// A filter is required for filtering information associated with Album, Folder, Tag, Bookmark, Playlist, /// and MediaInfo on the basis of details like limit, order, and condition. /// public class QueryArguments { private string _filter; /// /// Gets or sets the filtering expression that is applied. /// /// A string that represents a filtering expression applied when data is retrieved. /// /// Expressions for the filter can be one of the following forms:
/// - column = value /// - column > value /// - column >= value /// - /// - /// - value = column /// - value >= column /// - /// - /// - column IN (value) /// - column IN(value-list) /// - column NOT IN(value) /// - column NOT IN(value-list) /// - column LIKE value /// - expression COLLATE NOCASE /// - expression COLLATE RTRIM /// - expression COLLATE LOCALIZED /// - expression1 AND expression2 OR expression3 ... ///
/// Note that if you want to set quotation (" ' " or " " ") as value of LIKE operator, you should use two times. (" '' " or " "" "). /// And the optional ESCAPE clause is supported. Both percent symbol("%") and underscore symbol("_") are used in the LIKE pattern. /// If these characters are used as values of the LIKE operation, then the expression following the ESCAPE clause of sqlite will be ignored.
///
/// For example, column LIKE ('#%') ESCAPE ('#') - "#" is an escape character, it will be ignored. ///
/// is a zero-length string, contains only white space. /// /// /// /// /// /// /// public string FilterExpression { get => _filter; set { if (value != null) { ValidationUtil.ValidateNotNullOrEmpty(value, nameof(value)); } _filter = value; } } private string _storageId; /// /// Gets or sets the storage ID for the given filter. /// You can use this property when you want to search items only in the specific storage. /// /// The storage ID to restrict storage to search, or null for all storages. /// is a zero-length string, contains only white space. public string StorageId { get => _storageId; set { if (value != null) { ValidationUtil.ValidateNotNullOrEmpty(value, nameof(value)); } _storageId = value; } } internal static FilterHandle ToNativeHandle(QueryArguments arguments) { if (arguments == null || arguments.IsEmpty()) { return FilterHandle.Null; } Interop.Filter.Create(out var handle).ThrowIfError("Failed to apply arguments."); try { arguments.FillHandle(handle); } catch (Exception) { handle.Dispose(); throw; } return handle; } internal static FilterHandle CreateNativeHandle(string filterExpression) { Debug.Assert(filterExpression != null); Interop.Filter.Create(out var handle).ThrowIfError("Failed to apply arguments."); Interop.Filter.SetCondition(handle, filterExpression, Collation.Default). ThrowIfError("Failed to create filter handle."); return handle; } internal virtual bool IsEmpty() { return StorageId == null && FilterExpression == null; } internal virtual void FillHandle(FilterHandle handle) { if (FilterExpression != null) { Interop.Filter.SetCondition(handle, FilterExpression, Collation.Default). ThrowIfError("Failed to create filter handle(condition)"); } if (StorageId != null) { Interop.Filter.SetStorage(handle, StorageId). ThrowIfError("Failed to create filter handle(storage id)"); ; } } } /// /// Provides the ability to filter the result of a Select command. /// /// /// A filter is required for filtering information associated with Album, Folder, Tag, Bookmark, Playlist, /// and MediaInfo. /// public class SelectArguments : QueryArguments { private int _startRowIndex; /// /// Gets or sets the starting row position of a query (starting from zero). /// /// An integer value that indicates the starting row position of a query. /// is less than zero.
public int StartRowIndex { get => _startRowIndex; set { if (value < 0) { throw new ArgumentOutOfRangeException(nameof(value), value, "StartRowIndex can't be less than zero."); } _startRowIndex = value; } } private int _totalRowCount; /// /// Gets or sets the number of rows to be retrieved. /// /// An integer value that indicates the limit of rows of the result. /// is less than zero. public int TotalRowCount { get => _totalRowCount; set { if (value < 0) { throw new ArgumentOutOfRangeException(nameof(value), value, "TotalRowCount can't be less than zero."); } _totalRowCount = value; } } private string _sortOrder; /// /// Gets or sets the sort order of the results. /// /// The expression for the sort order. /// /// Expressions for the sort order can be:
/// column [COLLATE NOCASE/RTRIM/LOCALIZED] [ASC/DESC], column2 ... ///
/// is a zero-length string, contains only white space. /// /// /// /// /// /// /// public string SortOrder { get => _sortOrder; set { if (value != null) { ValidationUtil.ValidateNotNullOrEmpty(value, nameof(value)); } _sortOrder = value; } } internal override bool IsEmpty() { return base.IsEmpty() && StartRowIndex == 0 && TotalRowCount == 0 && SortOrder == null; } internal override void FillHandle(FilterHandle handle) { base.FillHandle(handle); if (StartRowIndex != 0 || TotalRowCount != 0) { Interop.Filter.SetOffset(handle, StartRowIndex, TotalRowCount). ThrowIfError("Failed to create filter handle(limit)"); } if (SortOrder != null) { Interop.Filter.SetOrder(handle, SortOrder).ThrowIfError("Failed to create filter handle(order)"); } } } /// /// Provides the ability to filter the result of the Count command. /// /// /// A filter is required for filtering information associated with Album, Folder, Tag, Bookmark, Playlist, /// and MediaInfo. /// public class CountArguments : QueryArguments { } }