2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <SensorRecorderTypes.h>
19 #include "TypesInternal.h"
21 #include "SensorLogger.h"
25 SensorLogger::SensorLogger() :
30 SensorLogger::~SensorLogger()
34 void SensorLogger::flushCache(bool force)
38 bool SensorLogger::executeQuery(const char *query)
40 return __dbMgr.execute(0, query, NULL);
43 void SensorLogger::removeExpired(const char *subject, const char *tableName, const char *timeKey)
45 uint64_t timestamp = TimeUtil::getTime();
47 if (timestamp - __lastRemovalTime < SEC_TO_MS(SECONDS_PER_HOUR))
50 char *query = sqlite3_mprintf(
51 "DELETE FROM %s WHERE %s < " \
52 "%llu - (SELECT MAX(" KEY_RETENTION ") * 1000 FROM " CLIENT_INFO \
53 " WHERE " KEY_SUBJECT "='%s')",
54 tableName, timeKey, timestamp, subject);
56 __dbMgr.execute(0, query, NULL);
59 __lastRemovalTime = timestamp;