• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "media_column.h"
17 
18 #include <string>
19 #include <vector>
20 
21 #include "base_column.h"
22 #include "medialibrary_db_const.h"
23 #include "userfile_manager_types.h"
24 
25 namespace OHOS {
26 namespace Media {
27 const std::string MediaColumn::MEDIA_ID = "file_id";
28 const std::string MediaColumn::MEDIA_FILE_PATH = "data";
29 const std::string MediaColumn::MEDIA_SIZE = "size";
30 const std::string MediaColumn::MEDIA_TITLE = "title";
31 const std::string MediaColumn::MEDIA_NAME = "display_name";
32 const std::string MediaColumn::MEDIA_TYPE = "media_type";
33 const std::string MediaColumn::MEDIA_MIME_TYPE = "mime_type";
34 const std::string MediaColumn::MEDIA_OWNER_PACKAGE = "owner_package";
35 const std::string MediaColumn::MEDIA_OWNER_APPID = "owner_appid";
36 const std::string MediaColumn::MEDIA_PACKAGE_NAME = "package_name";
37 const std::string MediaColumn::MEDIA_DEVICE_NAME = "device_name";
38 const std::string MediaColumn::MEDIA_DATE_MODIFIED = "date_modified";
39 const std::string MediaColumn::MEDIA_DATE_ADDED = "date_added";
40 const std::string MediaColumn::MEDIA_DATE_TAKEN = "date_taken";
41 const std::string MediaColumn::MEDIA_DURATION = "duration";
42 const std::string MediaColumn::MEDIA_TIME_PENDING = "time_pending";
43 const std::string MediaColumn::MEDIA_IS_FAV = "is_favorite";
44 const std::string MediaColumn::MEDIA_DATE_TRASHED = "date_trashed";
45 const std::string MediaColumn::MEDIA_DATE_DELETED = "date_deleted";
46 const std::string MediaColumn::MEDIA_HIDDEN = "hidden";
47 const std::string MediaColumn::MEDIA_PARENT_ID = "parent";
48 const std::string MediaColumn::MEDIA_RELATIVE_PATH = "relative_path";
49 const std::string MediaColumn::MEDIA_VIRTURL_PATH = "virtual_path";
50 const std::set<std::string> MediaColumn::MEDIA_COLUMNS = {
51     MEDIA_ID, MEDIA_FILE_PATH, MEDIA_SIZE, MEDIA_TITLE, MEDIA_NAME, MEDIA_TYPE, MEDIA_MIME_TYPE,
52     MEDIA_OWNER_PACKAGE, MEDIA_OWNER_APPID, MEDIA_PACKAGE_NAME, MEDIA_DEVICE_NAME, MEDIA_DATE_MODIFIED,
53     MEDIA_DATE_ADDED, MEDIA_DATE_TAKEN, MEDIA_DURATION, MEDIA_TIME_PENDING, MEDIA_IS_FAV, MEDIA_DATE_TRASHED,
54     MEDIA_DATE_DELETED, MEDIA_HIDDEN, MEDIA_PARENT_ID, MEDIA_RELATIVE_PATH, MEDIA_VIRTURL_PATH
55 };
56 const std::set<std::string> MediaColumn::DEFAULT_FETCH_COLUMNS = {
57     MEDIA_ID, MEDIA_FILE_PATH, MEDIA_NAME, MEDIA_TYPE
58 };
59 
60 const std::string PhotoColumn::PHOTO_DIRTY = "dirty";
61 const std::string PhotoColumn::PHOTO_CLOUD_ID = "cloud_id";
62 const std::string PhotoColumn::PHOTO_META_DATE_MODIFIED = "meta_date_modified";
63 const std::string PhotoColumn::PHOTO_SYNC_STATUS = "sync_status";
64 const std::string PhotoColumn::PHOTO_CLOUD_VERSION = "cloud_version";
65 const std::string PhotoColumn::PHOTO_ORIENTATION = "orientation";
66 const std::string PhotoColumn::PHOTO_LATITUDE = "latitude";
67 const std::string PhotoColumn::PHOTO_LONGITUDE = "longitude";
68 const std::string PhotoColumn::PHOTO_HEIGHT = "height";
69 const std::string PhotoColumn::PHOTO_WIDTH = "width";
70 const std::string PhotoColumn::PHOTO_LCD_VISIT_TIME = "lcd_visit_time";
71 const std::string PhotoColumn::PHOTO_EDIT_TIME = "edit_time";
72 const std::string PhotoColumn::PHOTO_POSITION = "position";
73 const std::string PhotoColumn::PHOTO_SUBTYPE = "subtype";
74 const std::string PhotoColumn::CAMERA_SHOT_KEY = "camera_shot_key";
75 const std::string PhotoColumn::PHOTO_USER_COMMENT = "user_comment";
76 const std::string PhotoColumn::PHOTO_SHOOTING_MODE = "shooting_mode";
77 const std::string PhotoColumn::PHOTO_SHOOTING_MODE_TAG = "shooting_mode_tag";
78 const std::string PhotoColumn::PHOTO_ALL_EXIF = "all_exif";
79 const std::string PhotoColumn::PHOTO_DATE_YEAR = "date_year";
80 const std::string PhotoColumn::PHOTO_DATE_MONTH = "date_month";
81 const std::string PhotoColumn::PHOTO_DATE_DAY = "date_day";
82 const std::string PhotoColumn::PHOTO_LAST_VISIT_TIME = "last_visit_time";
83 const std::string PhotoColumn::PHOTO_HIDDEN_TIME = "hidden_time";
84 const std::string PhotoColumn::PHOTO_THUMB_STATUS = "thumb_status";
85 const std::string PhotoColumn::PHOTO_CLEAN_FLAG = "clean_flag";
86 const std::string PhotoColumn::PHOTO_ID = "photo_id";
87 const std::string PhotoColumn::PHOTO_QUALITY = "photo_quality";
88 const std::string PhotoColumn::PHOTO_FIRST_VISIT_TIME = "first_visit_time";
89 const std::string PhotoColumn::PHOTO_DEFERRED_PROC_TYPE = "deferred_proc_type";
90 const std::string PhotoColumn::PHOTO_DYNAMIC_RANGE_TYPE = "dynamic_range_type";
91 const std::string PhotoColumn::MOVING_PHOTO_EFFECT_MODE = "moving_photo_effect_mode";
92 const std::string PhotoColumn::PHOTO_LCD_SIZE = "lcd_size";
93 const std::string PhotoColumn::PHOTO_THUMB_SIZE = "thumb_size";
94 const std::string PhotoColumn::PHOTO_HAS_ASTC = "has_astc"; // This attribute has been replaced by "thumbnail_ready"
95 const std::string PhotoColumn::PHOTO_IS_TEMP = "is_temp";
96 const std::string PhotoColumn::PHOTO_THUMBNAIL_READY = "thumbnail_ready";
97 const std::string PhotoColumn::PHOTO_COVER_POSITION = "cover_position";
98 const std::string PhotoColumn::PHOTO_THUMBNAIL_VISIBLE = "thumbnail_visible";
99 const std::string PhotoColumn::PHOTO_FRONT_CAMERA = "front_camera";
100 const std::string PhotoColumn::PHOTO_BURST_COVER_LEVEL = "burst_cover_level";
101 const std::string PhotoColumn::PHOTO_BURST_KEY = "burst_key";
102 const std::string PhotoColumn::PHOTO_ORIGINAL_SUBTYPE = "original_subtype";
103 
104 const std::string PhotoColumn::PHOTO_CE_AVAILABLE = "ce_available";
105 const std::string PhotoColumn::PHOTO_CE_STATUS_CODE = "ce_status_code";
106 const std::string PhotoColumn::PHOTO_STRONG_ASSOCIATION = "strong_association";
107 const std::string PhotoColumn::PHOTO_ASSOCIATE_FILE_ID = "associate_file_id";
108 const std::string PhotoColumn::PHOTO_HAS_CLOUD_WATERMARK = "has_cloud_watermark";
109 const std::string PhotoColumn::PHOTO_DETAIL_TIME = "detail_time";
110 
111 const std::string PhotoColumn::PHOTO_OWNER_ALBUM_ID = "owner_album_id";
112 const std::string PhotoColumn::PHOTO_ORIGINAL_ASSET_CLOUD_ID = "original_asset_cloud_id";
113 const std::string PhotoColumn::PHOTO_SOURCE_PATH = "source_path";
114 const std::string PhotoColumn::PHOTO_CLOUD_ID_INDEX = "cloud_id_index";
115 const std::string PhotoColumn::PHOTO_DATE_YEAR_INDEX = "date_year_index";
116 const std::string PhotoColumn::PHOTO_DATE_MONTH_INDEX = "date_month_index";
117 const std::string PhotoColumn::PHOTO_DATE_DAY_INDEX = "date_day_index";
118 const std::string PhotoColumn::PHOTO_SCHPT_ADDED_INDEX = "idx_schpt_date_added";
119 const std::string PhotoColumn::PHOTO_SCHPT_MEDIA_TYPE_INDEX = "idx_schpt_media_type";
120 const std::string PhotoColumn::PHOTO_SCHPT_DAY_INDEX = "idx_schpt_date_day";
121 const std::string PhotoColumn::PHOTO_HIDDEN_TIME_INDEX = "hidden_time_index";
122 const std::string PhotoColumn::PHOTO_SCHPT_HIDDEN_TIME_INDEX = "idx_schpt_hidden_time";
123 const std::string PhotoColumn::PHOTO_FAVORITE_INDEX = "idx_photo_is_favorite";
124 const std::string PhotoColumn::PHOTO_DISPLAYNAME_INDEX = "idx_display_name";
125 const std::string PhotoColumn::PHOTO_SCHPT_READY_INDEX = "idx_schpt_thumbnail_ready";
126 const std::string PhotoColumn::PHOTO_BURSTKEY_INDEX = "idx_burstkey";
127 
128 const std::string PhotoColumn::PHOTO_DATE_YEAR_FORMAT = "%Y";
129 const std::string PhotoColumn::PHOTO_DATE_MONTH_FORMAT = "%Y%m";
130 const std::string PhotoColumn::PHOTO_DATE_DAY_FORMAT = "%Y%m%d";
131 const std::string PhotoColumn::PHOTO_DETAIL_TIME_FORMAT = "%Y:%m:%d %H:%M:%S";
132 
133 const std::string PhotoColumn::PHOTOS_TABLE = "Photos";
134 
135 const std::string PhotoColumn::PHOTO_URI_PREFIX = "file://media/Photo/";
136 const std::string PhotoColumn::DEFAULT_PHOTO_URI = "file://media/Photo";
137 const std::string PhotoColumn::PHOTO_CACHE_URI_PREFIX = "file://media/Photo/cache/";
138 const std::string PhotoColumn::PHOTO_TYPE_URI = "/Photo";
139 const std::string PhotoColumn::HIGHTLIGHT_COVER_URI = "/highlight";
140 const std::string PhotoColumn::HIGHTLIGHT_URI = "/highlight/video";
141 
142 const std::string PhotoColumn::PHOTO_CLOUD_URI_PREFIX = "file://cloudsync/Photo/";
143 
144 const std::string PhotoColumn::PHOTO_HEIGHT_ERROR_URI_PREFIX = "file://cloudsync/Photo/HeightError/";
145 const std::string PhotoColumn::PHOTO_DOWNLOAD_SUCCEED_URI_PREFIX = "file://cloudsync/Photo/DownloadSucceed/";
146 
147 const std::string PhotoColumn::PHOTO_REQUEST_PICTURE = "file://media/Photo/picture/";
148 const std::string PhotoColumn::PHOTO_REQUEST_PICTURE_BUFFER = "file://media/Photo/pictureBuffer/";
149 
150 const std::set<std::string> PhotoColumn::DEFAULT_FETCH_COLUMNS = {
151     PHOTO_SUBTYPE, PHOTO_BURST_KEY,
152 };
153 
154 const std::string PhotoColumn::CREATE_PHOTO_TABLE = "CREATE TABLE IF NOT EXISTS " +
155     PHOTOS_TABLE + " (" +
156     MEDIA_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
157     MEDIA_FILE_PATH + " TEXT, " +
158     MEDIA_SIZE + " BIGINT, " +
159     MEDIA_TITLE + " TEXT, " +
160     MEDIA_NAME + " TEXT, " +
161     MEDIA_TYPE + " INT, " +
162     MEDIA_MIME_TYPE + " TEXT, " +
163     MEDIA_OWNER_PACKAGE + " TEXT, " +
164     MEDIA_OWNER_APPID + " TEXT, " +
165     MEDIA_PACKAGE_NAME + " TEXT, " +
166     MEDIA_DEVICE_NAME + " TEXT, " +
167     MEDIA_DATE_ADDED + " BIGINT, " +
168     MEDIA_DATE_MODIFIED + " BIGINT, " +
169     MEDIA_DATE_TAKEN + " BIGINT DEFAULT 0, " +
170     MEDIA_DURATION + " INT, " +
171     MEDIA_TIME_PENDING + " BIGINT DEFAULT 0, " +
172     MEDIA_IS_FAV + " INT DEFAULT 0, " +
173     MEDIA_DATE_TRASHED + " BIGINT DEFAULT 0, " +
174     MEDIA_DATE_DELETED + " BIGINT DEFAULT 0, " +
175     MEDIA_HIDDEN + " INT DEFAULT 0, " +
176     MEDIA_PARENT_ID + " INT DEFAULT 0, " +
177     MEDIA_RELATIVE_PATH + " TEXT, " +
178     MEDIA_VIRTURL_PATH + " TEXT UNIQUE, " +
179     PHOTO_DIRTY + " INT DEFAULT 1, " +
180     PHOTO_CLOUD_ID + " TEXT, " +
181     PHOTO_META_DATE_MODIFIED + "  BIGINT DEFAULT 0, " +
182     PHOTO_SYNC_STATUS + "  INT DEFAULT 0, " +
183     PHOTO_CLOUD_VERSION + " BIGINT DEFAULT 0, " +
184     PHOTO_ORIENTATION + " INT DEFAULT 0, " +
185     PHOTO_LATITUDE + " DOUBLE DEFAULT 0, " +
186     PHOTO_LONGITUDE + " DOUBLE DEFAULT 0, " +
187     PHOTO_HEIGHT + " INT, " +
188     PHOTO_WIDTH + " INT, " +
189     PHOTO_EDIT_TIME + " BIGINT DEFAULT 0, " +
190     PHOTO_LCD_VISIT_TIME + " BIGINT DEFAULT 0, " +
191     PHOTO_POSITION + " INT DEFAULT 1, " +
192     PHOTO_SUBTYPE + " INT DEFAULT 0, " +
193     PHOTO_ORIGINAL_SUBTYPE + " INT," +
194     CAMERA_SHOT_KEY + " TEXT, " +
195     PHOTO_USER_COMMENT + " TEXT, " +
196     PHOTO_ALL_EXIF  + " TEXT, " +
197     PHOTO_DATE_YEAR + " TEXT, " +
198     PHOTO_DATE_MONTH + " TEXT, " +
199     PHOTO_DATE_DAY + " TEXT, " +
200     PHOTO_SHOOTING_MODE + " TEXT, " +
201     PHOTO_SHOOTING_MODE_TAG + " TEXT, " +
202     PHOTO_LAST_VISIT_TIME + " BIGINT DEFAULT 0, " +
203     PHOTO_HIDDEN_TIME + " BIGINT DEFAULT 0, " +
204     PHOTO_THUMB_STATUS + " INT DEFAULT 0, " +
205     PHOTO_CLEAN_FLAG + " INT DEFAULT 0, " +
206     PHOTO_ID + " TEXT, " +
207     PHOTO_QUALITY + " INT, " +
208     PHOTO_FIRST_VISIT_TIME + " BIGINT DEFAULT 0, " +
209     PHOTO_DEFERRED_PROC_TYPE + " INT DEFAULT 0, " +
210     PHOTO_DYNAMIC_RANGE_TYPE + " INT DEFAULT 0, " +
211     MOVING_PHOTO_EFFECT_MODE + " INT DEFAULT 0, " +
212     PHOTO_COVER_POSITION + " BIGINT DEFAULT 0, " +
213     PHOTO_THUMBNAIL_READY + " BIGINT DEFAULT 0, " +
214     PHOTO_LCD_SIZE + " TEXT, " +
215     PHOTO_THUMB_SIZE + " TEXT," +
216     PHOTO_FRONT_CAMERA + " TEXT, " +
217     PHOTO_IS_TEMP + " INT DEFAULT 0," +
218     PHOTO_BURST_COVER_LEVEL + " INT DEFAULT 1, " +
219     PHOTO_BURST_KEY + " TEXT, " +
220     PHOTO_CE_AVAILABLE + " INT DEFAULT 0, " +
221     PHOTO_CE_STATUS_CODE + " INT, " +
222     PHOTO_STRONG_ASSOCIATION + " INT DEFAULT 0, " +
223     PHOTO_ASSOCIATE_FILE_ID + " INT DEFAULT 0, " +
224     PHOTO_HAS_CLOUD_WATERMARK + " INT DEFAULT 0, " +
225     PHOTO_DETAIL_TIME + " TEXT, " +
226     PHOTO_OWNER_ALBUM_ID + " INT DEFAULT 0, " +
227     PHOTO_ORIGINAL_ASSET_CLOUD_ID + " TEXT, " +
228     PHOTO_THUMBNAIL_VISIBLE + " INT DEFAULT 0, " +
229     PHOTO_SOURCE_PATH + " TEXT)";
230 
231 const std::string PhotoColumn::CREATE_CLOUD_ID_INDEX = BaseColumn::CreateIndex() +
232     PHOTO_CLOUD_ID_INDEX + " ON " + PHOTOS_TABLE + " (" + PHOTO_CLOUD_ID + " DESC)";
233 
234 const std::string PhotoColumn::CREATE_YEAR_INDEX = BaseColumn::CreateIndex() +
235     PHOTO_DATE_YEAR_INDEX + " ON " + PHOTOS_TABLE + " (" + PHOTO_DATE_YEAR + " DESC)";
236 
237 const std::string PhotoColumn::CREATE_MONTH_INDEX = BaseColumn::CreateIndex() +
238     PHOTO_DATE_MONTH_INDEX + " ON " + PHOTOS_TABLE + " (" + PHOTO_DATE_MONTH + " DESC)";
239 
240 const std::string PhotoColumn::CREATE_DAY_INDEX = BaseColumn::CreateIndex() +
241     PHOTO_DATE_DAY_INDEX + " ON " + PHOTOS_TABLE + " (" + PHOTO_DATE_DAY + " DESC)";
242 
243 const std::string PhotoColumn::CREATE_SCHPT_DAY_INDEX = BaseColumn::CreateIndex() +
244     PHOTO_SCHPT_DAY_INDEX + " ON " + PHOTOS_TABLE +
245     " (" + PHOTO_SYNC_STATUS + "," + PHOTO_CLEAN_FLAG + "," + MEDIA_HIDDEN + "," + MEDIA_TIME_PENDING +
246     "," + MEDIA_DATE_TRASHED + "," + PHOTO_IS_TEMP + "," + PHOTO_BURST_COVER_LEVEL + "," + PHOTO_DATE_DAY + " DESC);";
247 
248 const std::string PhotoColumn::DROP_SCHPT_DAY_INDEX = BaseColumn::DropIndex() + PHOTO_SCHPT_DAY_INDEX;
249 
250 const std::string PhotoColumn::DROP_SCHPT_MEDIA_TYPE_INDEX = "DROP INDEX IF EXISTS " + PHOTO_SCHPT_MEDIA_TYPE_INDEX;
251 
252 const std::string PhotoColumn::CREATE_SCHPT_MEDIA_TYPE_INDEX = BaseColumn::CreateIndex() +
253     PHOTO_SCHPT_MEDIA_TYPE_INDEX + " ON " + PHOTOS_TABLE +
254     " (" + PHOTO_SYNC_STATUS + "," + PHOTO_CLEAN_FLAG + "," + MEDIA_DATE_TRASHED + "," + MEDIA_HIDDEN +
255     "," + MEDIA_TIME_PENDING + ", " + PHOTO_IS_TEMP + "," + MEDIA_TYPE + "," + PHOTO_BURST_COVER_LEVEL +
256     "," + MEDIA_DATE_ADDED + " DESC);";
257 
258 const std::string PhotoColumn::CREATE_HIDDEN_TIME_INDEX = BaseColumn::CreateIndex() +
259     PHOTO_HIDDEN_TIME_INDEX + " ON " + PHOTOS_TABLE + " (" + PHOTO_HIDDEN_TIME + " DESC)";
260 
261 const std::string PhotoColumn::CREATE_SCHPT_HIDDEN_TIME_INDEX =
262     BaseColumn::CreateIndex() + PHOTO_SCHPT_HIDDEN_TIME_INDEX + " ON " + PHOTOS_TABLE +
263     " (" + PHOTO_SYNC_STATUS + "," + PHOTO_CLEAN_FLAG + "," + MEDIA_HIDDEN + "," + MEDIA_TIME_PENDING +
264     "," + MEDIA_DATE_TRASHED + "," + PHOTO_IS_TEMP + "," + PHOTO_BURST_COVER_LEVEL +
265     "," + PHOTO_HIDDEN_TIME + " DESC);";
266 
267 const std::string PhotoColumn::DROP_SCHPT_HIDDEN_TIME_INDEX = BaseColumn::DropIndex() + PHOTO_SCHPT_HIDDEN_TIME_INDEX;
268 
269 const std::string PhotoColumn::CREATE_PHOTO_FAVORITE_INDEX =
270     BaseColumn::CreateIndex() + PHOTO_FAVORITE_INDEX + " ON " + PHOTOS_TABLE +
271     " (" + PHOTO_SYNC_STATUS + "," + PHOTO_CLEAN_FLAG + "," + MEDIA_HIDDEN + "," + MEDIA_TIME_PENDING +
272     "," + MEDIA_DATE_TRASHED + "," + PHOTO_IS_TEMP + "," + MEDIA_IS_FAV + "," + PHOTO_BURST_COVER_LEVEL +
273     "," + MEDIA_DATE_TAKEN + " DESC);";
274 
275 const std::string PhotoColumn::DROP_PHOTO_FAVORITE_INDEX = BaseColumn::DropIndex() + PHOTO_FAVORITE_INDEX;
276 
277 const std::string PhotoColumn::CREATE_PHOTO_DISPLAYNAME_INDEX = BaseColumn::CreateIndex() +
278     PHOTO_DISPLAYNAME_INDEX + " ON " + PHOTOS_TABLE + " (" + MediaColumn::MEDIA_NAME + ")";
279 
280 const std::string PhotoColumn::CREATE_PHOTO_BURSTKEY_INDEX = BaseColumn::CreateIndex() + PHOTO_BURSTKEY_INDEX +
281     " ON " + PHOTOS_TABLE + " (" + PHOTO_BURST_KEY + "," + MEDIA_TIME_PENDING  + "," +
282     MediaColumn::MEDIA_NAME + " ASC);";
283 
284 const std::string PhotoColumn::QUERY_MEDIA_VOLUME = "SELECT sum(" + MediaColumn::MEDIA_SIZE + ") AS " +
285     MediaColumn::MEDIA_SIZE + "," +
286     MediaColumn::MEDIA_TYPE + " FROM " +
287     PhotoColumn::PHOTOS_TABLE + " WHERE " +
288     "(" + MediaColumn::MEDIA_TYPE + " = " + std::to_string(MEDIA_TYPE_IMAGE) + " OR " +
289     MediaColumn::MEDIA_TYPE + " = " + std::to_string(MEDIA_TYPE_VIDEO) + ") AND " +
290     PhotoColumn::PHOTO_POSITION + " != 2" + " GROUP BY " +
291     MediaColumn::MEDIA_TYPE;
292 
293 // Create indexes
294 const std::string PhotoColumn::INDEX_SCTHP_ADDTIME =
295     BaseColumn::CreateIndex() + PHOTO_SCHPT_ADDED_INDEX + " ON " + PHOTOS_TABLE +
296     " (" + PHOTO_SYNC_STATUS + "," + PHOTO_CLEAN_FLAG + "," + MEDIA_DATE_TRASHED + "," + MEDIA_HIDDEN + "," +
297     MEDIA_TIME_PENDING + "," + PHOTO_IS_TEMP + "," + PHOTO_BURST_COVER_LEVEL + "," + MEDIA_DATE_TAKEN + " DESC, " +
298     MEDIA_ID + " DESC);";
299 
300 const std::string PhotoColumn::DROP_INDEX_SCTHP_ADDTIME = BaseColumn::DropIndex() + PHOTO_SCHPT_ADDED_INDEX;
301 
302 const std::string PhotoColumn::INDEX_CAMERA_SHOT_KEY =
303     BaseColumn::CreateIndex() + "idx_camera_shot_key" + " ON " + PHOTOS_TABLE +
304     " (" + CAMERA_SHOT_KEY + ");";
305 
306 const std::string PhotoColumn::INDEX_SCHPT_READY =
307     BaseColumn::CreateIndex() + PHOTO_SCHPT_READY_INDEX + " ON " + PHOTOS_TABLE +
308     " (" + PHOTO_SYNC_STATUS + "," + PHOTO_CLEAN_FLAG + "," + PHOTO_THUMBNAIL_VISIBLE + "," + MEDIA_DATE_TRASHED +
309     "," + MEDIA_TIME_PENDING + ", " + MEDIA_HIDDEN + "," + PHOTO_IS_TEMP + "," + PHOTO_BURST_COVER_LEVEL +
310     "," + MEDIA_DATE_TAKEN + " DESC, " + MEDIA_ID + " DESC);";
311 
312 const std::string PhotoColumn::DROP_INDEX_SCHPT_READY = BaseColumn::DropIndex() + PHOTO_SCHPT_READY_INDEX;
313 
314 const std::string PhotoColumn::CREATE_PHOTOS_DELETE_TRIGGER =
315                         "CREATE TRIGGER IF NOT EXISTS photos_delete_trigger AFTER UPDATE ON " +
316                         PhotoColumn::PHOTOS_TABLE + " FOR EACH ROW WHEN new." + PhotoColumn::PHOTO_DIRTY +
317                         " = " + std::to_string(static_cast<int32_t>(DirtyTypes::TYPE_DELETED)) +
318                         " AND OLD." + PhotoColumn::PHOTO_CLOUD_ID + " is NULL AND is_caller_self_func() = 'true'" +
319                         " BEGIN DELETE FROM " + PhotoColumn::PHOTOS_TABLE +
320                         " WHERE " + PhotoColumn::MEDIA_ID + " = old." + PhotoColumn::MEDIA_ID + "; END;";
321 
322 const std::string PhotoColumn::CREATE_PHOTOS_FDIRTY_TRIGGER =
323                         "CREATE TRIGGER IF NOT EXISTS photos_fdirty_trigger AFTER UPDATE ON " +
324                         PhotoColumn::PHOTOS_TABLE + " FOR EACH ROW WHEN OLD.cloud_id IS NOT NULL AND" +
325                         " new.date_modified <> old.date_modified " +
326                         " AND new.dirty = old.dirty AND is_caller_self_func() = 'true'" +
327                         " BEGIN " +
328                         " UPDATE " + PhotoColumn::PHOTOS_TABLE + " SET dirty = " +
329                         std::to_string(static_cast<int32_t>(DirtyTypes::TYPE_FDIRTY)) +
330                         " WHERE file_id = old.file_id;" +
331                         " SELECT cloud_sync_func(); " +
332                         " END;";
333 
334 const std::string PhotoColumn::CREATE_PHOTOS_MDIRTY_TRIGGER =
335                         "CREATE TRIGGER IF NOT EXISTS photos_mdirty_trigger AFTER UPDATE ON " +
336                         PhotoColumn::PHOTOS_TABLE + " FOR EACH ROW WHEN OLD.cloud_id IS NOT NULL" +
337                         " AND new.date_modified = old.date_modified AND ( old.dirty = " +
338                         std::to_string(static_cast<int32_t>(DirtyTypes::TYPE_SYNCED)) + " OR old.dirty =" +
339                         std::to_string(static_cast<int32_t>(DirtyTypes::TYPE_SDIRTY)) +
340                         ") AND new.dirty = old.dirty AND is_caller_self_func() = 'true'" +
341                         " AND " + PhotoColumn::CheckUploadPhotoColumns() +
342                         " BEGIN " +
343                         " UPDATE " + PhotoColumn::PHOTOS_TABLE + " SET dirty = " +
344                         std::to_string(static_cast<int32_t>(DirtyTypes::TYPE_MDIRTY)) +
345                         " WHERE file_id = old.file_id;" +
346                         " SELECT cloud_sync_func(); " +
347                         " END;";
348 
349 const std::string  PhotoColumn::CREATE_PHOTOS_INSERT_CLOUD_SYNC =
350                         " CREATE TRIGGER IF NOT EXISTS photo_insert_cloud_sync_trigger AFTER INSERT ON " +
351                         PhotoColumn::PHOTOS_TABLE + " BEGIN SELECT cloud_sync_func(); END;";
352 
353 const std::string PhotoColumn::CREATE_PHOTOS_UPDATE_CLOUD_SYNC =
354                         " CREATE TRIGGER IF NOT EXISTS photo_update_cloud_sync_trigger AFTER UPDATE ON " +
355                         PhotoColumn::PHOTOS_TABLE + " FOR EACH ROW WHEN OLD.dirty IN (1,2,3,5) AND new.dirty != " +
356                         std::to_string(static_cast<int32_t>(DirtyTypes::TYPE_SYNCED)) +
357                         " BEGIN SELECT cloud_sync_func(); END;";
358 
359 const std::string PhotoColumn::UPDATE_READY_ON_THUMBNAIL_UPGRADE =
360                         " UPDATE " + PhotoColumn::PHOTOS_TABLE + " SET " + PhotoColumn::PHOTO_THUMBNAIL_READY +
361                         " = 6 " + " WHERE " + PhotoColumn::PHOTO_THUMBNAIL_READY + " != 0; END;";
362 
363 const std::string PhotoColumn::UPDATA_PHOTOS_DATA_UNIQUE = "CREATE UNIQUE INDEX IF NOT EXISTS photo_data_index ON " +
364     PhotoColumn::PHOTOS_TABLE + " (" + MEDIA_FILE_PATH + ");";
365 
366 const std::set<std::string> PhotoColumn::PHOTO_COLUMNS = {
367     PhotoColumn::PHOTO_ORIENTATION, PhotoColumn::PHOTO_LATITUDE, PhotoColumn::PHOTO_LONGITUDE,
368     PhotoColumn::PHOTO_HEIGHT, PhotoColumn::PHOTO_WIDTH, PhotoColumn::PHOTO_LCD_VISIT_TIME, PhotoColumn::PHOTO_POSITION,
369     PhotoColumn::PHOTO_DIRTY, PhotoColumn::PHOTO_CLOUD_ID, PhotoColumn::CAMERA_SHOT_KEY, PhotoColumn::PHOTO_ALL_EXIF,
370     PhotoColumn::PHOTO_USER_COMMENT, PhotoColumn::PHOTO_DATE_YEAR, PhotoColumn::PHOTO_DATE_MONTH,
371     PhotoColumn::PHOTO_DATE_DAY, PhotoColumn::PHOTO_EDIT_TIME, PhotoColumn::PHOTO_CLEAN_FLAG,
372     PhotoColumn::PHOTO_SHOOTING_MODE, PhotoColumn::PHOTO_SHOOTING_MODE_TAG, PhotoColumn::PHOTO_THUMB_STATUS,
373     PhotoColumn::PHOTO_SUBTYPE, PhotoColumn::PHOTO_DYNAMIC_RANGE_TYPE, PhotoColumn::PHOTO_LCD_SIZE,
374     PhotoColumn::PHOTO_THUMB_SIZE, PhotoColumn::MOVING_PHOTO_EFFECT_MODE, PhotoColumn::PHOTO_COVER_POSITION,
375     PhotoColumn::PHOTO_FRONT_CAMERA, PhotoColumn::PHOTO_BURST_COVER_LEVEL, PhotoColumn::PHOTO_BURST_KEY,
376     PhotoColumn::PHOTO_THUMBNAIL_READY, PhotoColumn::PHOTO_ORIGINAL_SUBTYPE, PhotoColumn::PHOTO_CE_AVAILABLE,
377     PhotoColumn::PHOTO_DETAIL_TIME, PhotoColumn::PHOTO_OWNER_ALBUM_ID, PhotoColumn::PHOTO_THUMBNAIL_VISIBLE,
378 };
379 
IsPhotoColumn(const std::string & columnName)380 bool PhotoColumn::IsPhotoColumn(const std::string &columnName)
381 {
382     if (columnName == "count(*)") {
383         return true;
384     }
385     return (PHOTO_COLUMNS.find(columnName) != PHOTO_COLUMNS.end()) ||
386         (MEDIA_COLUMNS.find(columnName) != MEDIA_COLUMNS.end());
387 }
388 
CheckUploadPhotoColumns()389 std::string PhotoColumn::CheckUploadPhotoColumns()
390 {
391     // Since date_modified has been checked in mdirty and fdirty, omit it here.
392     const std::vector<std::string> uploadPhotoColumns = {
393         MEDIA_FILE_PATH,
394         MEDIA_SIZE,
395         MEDIA_NAME,
396         MEDIA_TYPE,
397         MEDIA_MIME_TYPE,
398         MEDIA_OWNER_PACKAGE,
399         MEDIA_OWNER_APPID,
400         MEDIA_DEVICE_NAME,
401         MEDIA_DATE_ADDED,
402         MEDIA_DATE_TAKEN,
403         MEDIA_DURATION,
404         MEDIA_IS_FAV,
405         MEDIA_DATE_TRASHED,
406         MEDIA_DATE_DELETED,
407         MEDIA_HIDDEN,
408         PHOTO_META_DATE_MODIFIED,
409         PHOTO_ORIENTATION,
410         PHOTO_LATITUDE,
411         PHOTO_LONGITUDE,
412         PHOTO_HEIGHT,
413         PHOTO_WIDTH,
414         PHOTO_SUBTYPE,
415         PHOTO_USER_COMMENT,
416         PHOTO_DATE_YEAR,
417         PHOTO_DATE_MONTH,
418         PHOTO_DATE_DAY,
419         PHOTO_SHOOTING_MODE,
420         PHOTO_SHOOTING_MODE_TAG,
421         MOVING_PHOTO_EFFECT_MODE,
422         PHOTO_COVER_POSITION,
423         PHOTO_ORIGINAL_SUBTYPE,
424         PHOTO_OWNER_ALBUM_ID,
425         PHOTO_SOURCE_PATH,
426     };
427 
428     std::string result = "(";
429     size_t size = uploadPhotoColumns.size();
430     for (size_t i = 0; i < size; i++) {
431         std::string column = uploadPhotoColumns[i];
432         if (i != size - 1) {
433             result += "new." + column + " <> old." + column + " OR ";
434         } else {
435             result += "new." + column + " <> old." + column + ")";
436         }
437     }
438     return result;
439 }
440 
441 const std::string AudioColumn::AUDIO_ALBUM = "audio_album";
442 const std::string AudioColumn::AUDIO_ARTIST = "artist";
443 
444 const std::string AudioColumn::AUDIOS_TABLE = "Audios";
445 
446 const std::string AudioColumn::AUDIO_URI_PREFIX = "file://media/Audio/";
447 const std::string AudioColumn::DEFAULT_AUDIO_URI = "file://media/Audio";
448 const std::string AudioColumn::AUDIO_TYPE_URI = "/Audio";
449 
450 const std::string AudioColumn::CREATE_AUDIO_TABLE = "CREATE TABLE IF NOT EXISTS " +
451     AUDIOS_TABLE + " (" +
452     MEDIA_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
453     MEDIA_FILE_PATH + " TEXT, " +
454     MEDIA_SIZE + " BIGINT, " +
455     MEDIA_TITLE + " TEXT, " +
456     MEDIA_NAME + " TEXT, " +
457     MEDIA_TYPE + " INT, " +
458     MEDIA_MIME_TYPE + " TEXT, " +
459     MEDIA_OWNER_PACKAGE + " TEXT, " +
460     MEDIA_OWNER_APPID + " TEXT, " +
461     MEDIA_PACKAGE_NAME + " TEXT, " +
462     MEDIA_DEVICE_NAME + " TEXT, " +
463     AUDIO_ARTIST + " TEXT, " +
464     MEDIA_DATE_ADDED + " BIGINT, " +
465     MEDIA_DATE_MODIFIED + " BIGINT, " +
466     MEDIA_DATE_TAKEN + " BIGINT DEFAULT 0, " +
467     MEDIA_DURATION + " INT, " +
468     MEDIA_TIME_PENDING + " BIGINT DEFAULT 0, " +
469     MEDIA_IS_FAV + " INT DEFAULT 0, " +
470     MEDIA_DATE_TRASHED + " BIGINT DEFAULT 0, " +
471     MEDIA_DATE_DELETED + " BIGINT DEFAULT 0, " +
472     MEDIA_PARENT_ID + " INT DEFAULT 0, " +
473     MEDIA_RELATIVE_PATH + " TEXT, " +
474     MEDIA_VIRTURL_PATH + " TEXT UNIQUE, " +
475     AUDIO_ALBUM + " TEXT)";
476 
477 const std::string AudioColumn::QUERY_MEDIA_VOLUME = "SELECT sum(" + MediaColumn::MEDIA_SIZE + ") AS " +
478     MediaColumn::MEDIA_SIZE + "," +
479     MediaColumn::MEDIA_TYPE + " FROM " +
480     AudioColumn::AUDIOS_TABLE + " WHERE " +
481     MediaColumn::MEDIA_TYPE + " = " + std::to_string(MEDIA_TYPE_AUDIO) + " GROUP BY " +
482     MediaColumn::MEDIA_TYPE;
483 
484 const std::set<std::string> AudioColumn::AUDIO_COLUMNS = {
485     AudioColumn::AUDIO_ALBUM, AudioColumn::AUDIO_ARTIST
486 };
487 
IsAudioColumn(const std::string & columnName)488 bool AudioColumn::IsAudioColumn(const std::string &columnName)
489 {
490     return (AUDIO_COLUMNS.find(columnName) != AUDIO_COLUMNS.end()) ||
491         (MEDIA_COLUMNS.find(columnName) != MEDIA_COLUMNS.end());
492 }
493 
494 const std::string MediaColumn::ASSETS_QUERY_FILTER =
495     PhotoColumn::PHOTO_SYNC_STATUS + " = 0" + " AND " +
496     MediaColumn::MEDIA_DATE_TRASHED + " = 0" + " AND " +
497     MediaColumn::MEDIA_HIDDEN + " = 0" + " AND " +
498     MediaColumn::MEDIA_TIME_PENDING + " = 0 ";
499 
500 const std::string PhotoExtColumn::PHOTOS_EXT_TABLE = "tab_photos_ext";
501 
502 const std::string PhotoExtColumn::PHOTO_ID = "photo_id";
503 const std::string PhotoExtColumn::THUMBNAIL_SIZE = "thumbnail_size";
504 
505 const std::string PhotoExtColumn::CREATE_PHOTO_EXT_TABLE =
506     "CREATE TABLE IF NOT EXISTS " +
507     PHOTOS_EXT_TABLE + " (" +
508     PHOTO_ID + " INTEGER PRIMARY KEY, " +
509     THUMBNAIL_SIZE + " BIGINT DEFAULT 0)";
510 
511 // For Photos table query filter
512 const std::string PhotoColumn::PHOTOS_QUERY_FILTER =
513     MediaColumn::MEDIA_DATE_TRASHED + " = 0" + " AND " +
514     MediaColumn::MEDIA_HIDDEN + " = 0" + " AND " +
515     MediaColumn::MEDIA_TIME_PENDING + " = 0" + " AND " +
516     PhotoColumn::PHOTO_IS_TEMP + " = 0" + " AND " +
517     PhotoColumn::PHOTO_BURST_COVER_LEVEL + " = 1 ";
518 }  // namespace Media
519 }  // namespace OHOS
520