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