The enable_foreign_keys flag is added to deactivate foreign keys in sqlite3.
The appsvc.db doesn't use foreign keys.
Change-Id: I5f810e320592181674402440d2262a9b79e15969
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
int Step(T cb, std::tuple<ARGS...> args,
bool readonly, const std::string& query, uid_t uid) {
std::string path = Database::GetPath(APPSVC_DB, uid);
int Step(T cb, std::tuple<ARGS...> args,
bool readonly, const std::string& query, uid_t uid) {
std::string path = Database::GetPath(APPSVC_DB, uid);
+ Database db(path, false);
try {
db.Open(readonly ? SQLITE_OPEN_READONLY : SQLITE_OPEN_READWRITE);
} catch (Exception& e) {
try {
db.Open(readonly ? SQLITE_OPEN_READONLY : SQLITE_OPEN_READWRITE);
} catch (Exception& e) {
-Database::Database(std::string path) : path_(std::move(path)) {
+Database::Database(std::string path, bool enable_foreign_keys)
+ : path_(std::move(path)),
+ enable_foreign_keys_(enable_foreign_keys) {
}
Database::~Database() {
}
Database::~Database() {
- ret = sqlite3_exec(db, "PRAGMA foreign_keys=ON", nullptr, nullptr, nullptr);
- if (ret != SQLITE_OK) {
- _E("sqlite3_exec() is failed. error(%s:%d)", sqlite3_errmsg(db), ret);
- sqlite3_close_v2(db);
- THROW(-ret);
+ if (enable_foreign_keys_) {
+ ret = sqlite3_exec(db, "PRAGMA foreign_keys=ON", nullptr, nullptr, nullptr);
+ if (ret != SQLITE_OK) {
+ _E("sqlite3_exec() is failed. error(%s:%d)", sqlite3_errmsg(db), ret);
+ sqlite3_close_v2(db);
+ THROW(-ret);
+ }
- Database(std::string path);
+ Database(std::string path, bool enable_foreign_keys = true);
virtual ~Database();
void Open(int flags = SQLITE_OPEN_READWRITE);
virtual ~Database();
void Open(int flags = SQLITE_OPEN_READWRITE);
private:
std::string path_;
private:
std::string path_;
+ bool enable_foreign_keys_;
sqlite3* db_ = nullptr;
};
sqlite3* db_ = nullptr;
};