1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
/*
* Copyright (C) 2012-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#pragma once
#include "media/MediaType.h"
#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>
class CVariant;
enum class VideoDbContentType;
namespace dbiplus
{
class Dataset;
class field_value;
}
typedef enum
{
// special fields used during sorting
FieldUnknown = -1,
FieldNone = 0,
FieldSort, // used to store the string to use for sorting
FieldSortSpecial, // whether the item needs special handling (0 = no, 1 = sort on top, 2 = sort on bottom)
FieldLabel,
FieldFolder,
FieldMediaType,
FieldRow, // the row number in a dataset
// special fields not retrieved from the database
FieldSize,
FieldDate,
FieldDriveType,
FieldStartOffset,
FieldEndOffset,
FieldProgramCount,
FieldBitrate,
FieldListeners,
FieldPlaylist,
FieldVirtualFolder,
FieldRandom,
FieldDateTaken,
FieldAudioCount,
FieldSubtitleCount,
FieldInstallDate,
FieldLastUpdated,
FieldLastUsed,
// fields retrievable from the database
FieldId,
FieldGenre,
FieldAlbum,
FieldDiscTitle,
FieldIsBoxset,
FieldTotalDiscs,
FieldOrigYear,
FieldOrigDate,
FieldArtist,
FieldArtistSort,
FieldAlbumArtist,
FieldTitle,
FieldSortTitle,
FieldOriginalTitle,
FieldYear,
FieldTime,
FieldTrackNumber,
FieldFilename,
FieldPath,
FieldPlaycount,
FieldLastPlayed,
FieldInProgress,
FieldRating,
FieldComment,
FieldRole,
FieldDateAdded,
FieldDateModified,
FieldDateNew,
FieldTvShowTitle,
FieldPlot,
FieldPlotOutline,
FieldTagline,
FieldTvShowStatus,
FieldVotes,
FieldDirector,
FieldActor,
FieldStudio,
FieldCountry,
FieldMPAA,
FieldTop250,
FieldSet,
FieldNumberOfEpisodes,
FieldNumberOfWatchedEpisodes,
FieldWriter,
FieldAirDate,
FieldEpisodeNumber,
FieldUniqueId,
FieldSeason,
FieldEpisodeNumberSpecialSort,
FieldSeasonSpecialSort,
FieldReview,
FieldThemes,
FieldMoods,
FieldStyles,
FieldAlbumType,
FieldMusicLabel,
FieldCompilation,
FieldSource,
FieldTrailer,
FieldVideoResolution,
FieldVideoAspectRatio,
FieldVideoCodec,
FieldAudioChannels,
FieldAudioCodec,
FieldAudioLanguage,
FieldSubtitleLanguage,
FieldProductionCode,
FieldTag,
FieldChannelName,
FieldChannelNumber,
FieldInstruments,
FieldBiography,
FieldArtistType,
FieldGender,
FieldDisambiguation,
FieldBorn,
FieldBandFormed,
FieldDisbanded,
FieldDied,
FieldStereoMode,
FieldUserRating,
FieldRelevance, // Used for actors' appearances
FieldClientChannelOrder,
FieldBPM,
FieldMusicBitRate,
FieldSampleRate,
FieldNoOfChannels,
FieldAlbumStatus,
FieldAlbumDuration,
FieldHdrType,
FieldProvider,
FieldUserPreference,
FieldMax
} Field;
typedef std::set<Field> Fields;
typedef std::vector<Field> FieldList;
typedef enum {
DatabaseQueryPartSelect,
DatabaseQueryPartWhere,
DatabaseQueryPartOrderBy,
} DatabaseQueryPart;
typedef std::map<Field, CVariant> DatabaseResult;
typedef std::vector<DatabaseResult> DatabaseResults;
class DatabaseUtils
{
public:
static MediaType MediaTypeFromVideoContentType(VideoDbContentType videoContentType);
static std::string GetField(Field field, const MediaType &mediaType, DatabaseQueryPart queryPart);
static int GetField(Field field, const MediaType &mediaType);
static int GetFieldIndex(Field field, const MediaType &mediaType);
static bool GetSelectFields(const Fields &fields, const MediaType &mediaType, FieldList &selectFields);
static bool GetFieldValue(const dbiplus::field_value &fieldValue, CVariant &variantValue);
static bool GetDatabaseResults(const MediaType &mediaType, const FieldList &fields, const std::unique_ptr<dbiplus::Dataset> &dataset, DatabaseResults &results);
static std::string BuildLimitClause(int end, int start = 0);
static std::string BuildLimitClauseOnly(int end, int start = 0);
static size_t GetLimitCount(int end, int start);
private:
static int GetField(Field field, const MediaType &mediaType, bool asIndex);
};
|