}
}
-int __open_read_db(const char *path, sqlite3 **db, int flags) {
+int __open_read_db(const char *path, sqlite3 **db) {
int ret;
- ret = sqlite3_open_v2(path, db, flags, NULL);
+ ret = sqlite3_open_v2(path, db,
+ SQLITE_OPEN_READONLY | SQLITE_OPEN_URI, NULL);
if (ret != SQLITE_OK) {
sqlite3_close_v2(*db);
return ret;
}
int __open_write_db(uid_t uid, const char* path,
- sqlite3** db, int flags) {
+ sqlite3** db) {
int ret;
- ret = sqlite3_open_v2(path, db, flags, NULL);
+ ret = sqlite3_open_v2(path, db, SQLITE_OPEN_READWRITE, NULL);
if (ret != SQLITE_OK) {
sqlite3_close_v2(*db);
return ret;
}
int __open_create_db(uid_t uid, const char* path,
- sqlite3** db, int flags) {
+ sqlite3** db) {
int ret;
- ret = sqlite3_open_v2(path, db, flags, NULL);
+ ret = sqlite3_open_v2(path, db,
+ SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
if (ret != SQLITE_OK) {
sqlite3_close_v2(*db);
return ret;
return false;
}
auto dbpath_list = GetDBPath();
- int ret = 0;
sqlite3* db;
for (auto& dbpath : dbpath_list) {
+ int ret = 0;
if (op_type_ == pkgmgr_common::DBOperationType::OPERATION_TYPE_READ) {
- ret = __open_read_db(dbpath.first.c_str(), &db, SQLITE_OPEN_READONLY |
- SQLITE_OPEN_URI);
+ ret = __open_read_db(dbpath.first.c_str(), &db);
} else if (op_type_ == pkgmgr_common::DBOperationType::OPERATION_TYPE_WRITE) {
if (ConvertUID(dbpath.second) != ConvertUID(uid_))
continue;
- ret = __open_write_db(uid_, dbpath.first.c_str(), &db,
- SQLITE_OPEN_READWRITE);
+ ret = __open_write_db(uid_, dbpath.first.c_str(), &db);
} else {
if (ConvertUID(dbpath.second) != ConvertUID(uid_))
continue;
_LOGE("Database for user %d is already exists", uid_);
return false;
}
- ret = __open_create_db(uid_, dbpath.first.c_str(), &db,
- SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
+ ret = __open_create_db(uid_, dbpath.first.c_str(), &db);
}
if (ret != SQLITE_OK)
op_type_ = type;
}
-const std::string& AbstractDBHandler::GetLocale() { return locale_; }
+const std::string& AbstractDBHandler::GetLocale() {
+ return locale_;
+}
-int AbstractDBHandler::GetPID() { return pid_; }
+int AbstractDBHandler::GetPID() {
+ return pid_;
+}
-uid_t AbstractDBHandler::GetUID() { return uid_; }
+uid_t AbstractDBHandler::GetUID() {
+ return uid_;
+}
void AbstractDBHandler::SetLocale(std::string locale) {
locale_ = std::move(locale);
}
-void AbstractDBHandler::SetDBType(pkgmgr_common::DBType type) { db_type_ = type; }
+void AbstractDBHandler::SetDBType(pkgmgr_common::DBType type) {
+ db_type_ = type;
+}
pkgmgr_common::DBOperationType AbstractDBHandler::GetOpType() {
return op_type_;
class EXPORT_API AbstractDBHandler {
public:
- AbstractDBHandler(uid_t uid, pid_t pid) : uid_(uid), pid_(pid) {};
+ AbstractDBHandler(uid_t uid, pid_t pid)
+ : db_type_(pkgmgr_common::DBType::DB_TYPE_NONE),
+ op_type_(pkgmgr_common::DBOperationType::OPERATION_TYPE_NONE),
+ uid_(uid), pid_(pid) {};
virtual ~AbstractDBHandler();
virtual int Execute() = 0;
void SetLocale(std::string locale);
virtual std::vector<std::pair<sqlite3*, uid_t>> GetConnection();
void ClearDBHandle();
const std::string& GetLocale();
+
static std::shared_timed_mutex lock_;
+
private:
std::vector<std::pair<std::string, uid_t>> GetDBPath();
- pkgmgr_common::DBType db_type_ = pkgmgr_common::DBType::DB_TYPE_NONE;
- pkgmgr_common::DBOperationType op_type_ =
- pkgmgr_common::DBOperationType::OPERATION_TYPE_NONE;
+
+ pkgmgr_common::DBType db_type_;
+ pkgmgr_common::DBOperationType op_type_;
uid_t uid_;
pid_t pid_;
std::string locale_;