drogonframework / drogonframework/drogon

How to enable for a client `PRAGMA foreign_keys = ON`?

Open
#1,425 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
14.3k
Forks
1.4k
Avg merge
1d 13h
Merged PRs (30d)
14

Description

**Is your feature request related to a problem? Please describe.**
If the tables are interconnected, then when deleting in one table, there is no deletion in the other.
```
CREATE TABLE IF NOT EXISTS "tokens" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
"token" TEXT NOT NULL,
"idUser" INTEGER NOT NULL,
FOREIGN KEY("idUser") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS "users" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
"login" TEXT NOT NULL UNIQUE,
"password" TEXT NOT NULL,
"name" TEXT NOT NULL
);
```

**Describe the solution you'd like**
Perhaps some method to change the parameters:
```
auto clientDb = drogon::orm::DbClient::newSqlite3Client("filename=./resources/dbBe.db", 10);
clientDb->setPragma("foreign_keys", true);
```

**Describe alternatives you've considered**
```
clientDb->execPragma("foreign_keys = ON");
```

**Additional context**
I found out that for a coherent deletion, you need to call the following command (but I still didn't understand exactly where to do it):
```
PRAGMA foreign_keys = ON
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.