strip added smb:// shares of their user/pass when adding, and instead store that...
[vuplus_xbmc] / xbmc / utils / DatabaseUtils.h
1 #pragma once
2 /*
3  *      Copyright (C) 2012 Team XBMC
4  *      http://www.xbmc.org
5  *
6  *  This Program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  *
11  *  This Program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with XBMC; see the file COPYING.  If not, see
18  *  <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 #include <map>
23 #include <memory>
24 #include <set>
25 #include <string>
26 #include <vector>
27
28 class CVariant;
29
30 namespace dbiplus
31 {
32   class Dataset;
33   class field_value;
34 }
35
36 typedef enum {
37   // special fields used during sorting
38   FieldNone = 0,
39   FieldSort,        // used to store the string to use for sorting
40   FieldSortSpecial, // whether the item needs special handling (0 = no, 1 = sort on top, 2 = sort on bottom)
41   FieldLabel,
42   FieldFolder,
43   FieldMediaType,
44   FieldRow,         // the row number in a dataset
45
46   // special fields not retrieved from the database
47   FieldSize,
48   FieldDate,
49   FieldDriveType,
50   FieldStartOffset,
51   FieldEndOffset,
52   FieldProgramCount,
53   FieldBitrate,
54   FieldListeners,
55   FieldPlaylist,
56   FieldSet,
57   FieldRandom,
58
59   // fields retrievable from the database
60   FieldId,
61   FieldGenre,
62   FieldAlbum,
63   FieldArtist,
64   FieldAlbumArtist,
65   FieldTitle,
66   FieldSortTitle,
67   FieldYear,
68   FieldTime,
69   FieldTrackNumber,
70   FieldFilename,
71   FieldPath,
72   FieldPlaycount,
73   FieldLastPlayed,
74   FieldInProgress,
75   FieldRating,
76   FieldComment,
77   FieldDateAdded,
78   FieldTvShowTitle,
79   FieldPlot,
80   FieldPlotOutline,
81   FieldTagline,
82   FieldTvShowStatus,
83   FieldVotes,
84   FieldDirector,
85   FieldActor,
86   FieldStudio,
87   FieldCountry,
88   FieldMPAA,
89   FieldTop250,
90   FieldNumberOfEpisodes,
91   FieldNumberOfWatchedEpisodes,
92   FieldWriter,
93   FieldAirDate,
94   FieldEpisodeNumber,
95   FieldSeason,
96   FieldEpisodeNumberSpecialSort,
97   FieldSeasonSpecialSort,
98   FieldReview,
99   FieldThemes,
100   FieldMoods,
101   FieldStyles,
102   FieldAlbumType,
103   FieldMusicLabel,
104   FieldTrailer,
105   FieldVideoResolution,
106   FieldVideoAspectRatio,
107   FieldVideoCodec,
108   FieldAudioChannels,
109   FieldAudioCodec,
110   FieldAudioLanguage,
111   FieldSubtitleLanguage,
112   FieldProductionCode
113 } Field;
114
115 typedef std::set<Field> Fields;
116 typedef std::vector<Field> FieldList;
117
118 typedef enum {
119   MediaTypeNone = 0,
120   MediaTypeMusic,
121   MediaTypeArtist,
122   MediaTypeAlbum,
123   MediaTypeSong,
124   MediaTypeVideo,
125   MediaTypeVideoCollection,
126   MediaTypeMusicVideo,
127   MediaTypeMovie,
128   MediaTypeTvShow,
129   MediaTypeEpisode
130 } MediaType;
131
132 typedef enum {
133   DatabaseQueryPartSelect,
134   DatabaseQueryPartWhere,
135   DatabaseQueryPartOrderBy,
136 } DatabaseQueryPart;
137
138 typedef std::map<Field, CVariant> DatabaseResult;
139 typedef std::vector<DatabaseResult> DatabaseResults;
140
141 class DatabaseUtils
142 {
143 public:
144   static std::string MediaTypeToString(MediaType mediaType);
145   static MediaType MediaTypeFromString(const std::string &strMediaType);
146
147   static std::string GetField(Field field, MediaType mediaType, DatabaseQueryPart queryPart);
148   static int GetFieldIndex(Field field, MediaType mediaType);
149   static bool GetSelectFields(const Fields &fields, MediaType mediaType, FieldList &selectFields);
150   
151   static bool GetFieldValue(const dbiplus::field_value &fieldValue, CVariant &variantValue);
152   static bool GetDatabaseResults(MediaType mediaType, const FieldList &fields, const std::auto_ptr<dbiplus::Dataset> &dataset, DatabaseResults &results);
153
154   static std::string BuildLimitClause(int end, int start = 0);
155 };