Foreign key support in SQLite3 C++ ver.3.25.3
up vote
-1
down vote
favorite
EDIT
That worked:
std::string tab_B = R"(
CREATE TABLE B (
b INT NOT NULL PRIMARY KEY,
bb INT NOT NULL,
FOREIGN KEY(b) REFERENCES A(a)
);
)";
Pragma and config were not needed
END OF EDIT
I've tried pragma way:
std::string fk_on = "PRAGMA foreign_keys = ON;";
sqlite3_exec(DB, fk_on.c_str(), NULL, 0, &messaggeError);
and config one:
sqlite3_db_config(DB, SQLITE_DBCONFIG_ENABLE_FKEY, 1, &fkeyConstraintsEnabled);
Pragma gives me nothing, fkeyConstraintsEnabled gives 1.
What I am trying to do is to create B table:
std::string tab_A = R"(
CREATE TABLE A (
a INT NOT NULL PRIMARY KEY
);
)";
std::string tab_B = R"(
CREATE TABLE B (
b INT NOT NULL PRIMARY KEY,
bb INT NOT NULL FOREIGN_KEY REFERENCES A(a)
);
)";
sqlite3
add a comment |
up vote
-1
down vote
favorite
EDIT
That worked:
std::string tab_B = R"(
CREATE TABLE B (
b INT NOT NULL PRIMARY KEY,
bb INT NOT NULL,
FOREIGN KEY(b) REFERENCES A(a)
);
)";
Pragma and config were not needed
END OF EDIT
I've tried pragma way:
std::string fk_on = "PRAGMA foreign_keys = ON;";
sqlite3_exec(DB, fk_on.c_str(), NULL, 0, &messaggeError);
and config one:
sqlite3_db_config(DB, SQLITE_DBCONFIG_ENABLE_FKEY, 1, &fkeyConstraintsEnabled);
Pragma gives me nothing, fkeyConstraintsEnabled gives 1.
What I am trying to do is to create B table:
std::string tab_A = R"(
CREATE TABLE A (
a INT NOT NULL PRIMARY KEY
);
)";
std::string tab_B = R"(
CREATE TABLE B (
b INT NOT NULL PRIMARY KEY,
bb INT NOT NULL FOREIGN_KEY REFERENCES A(a)
);
)";
sqlite3
then accept my answer.
– johnathan
Nov 19 at 11:36
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
EDIT
That worked:
std::string tab_B = R"(
CREATE TABLE B (
b INT NOT NULL PRIMARY KEY,
bb INT NOT NULL,
FOREIGN KEY(b) REFERENCES A(a)
);
)";
Pragma and config were not needed
END OF EDIT
I've tried pragma way:
std::string fk_on = "PRAGMA foreign_keys = ON;";
sqlite3_exec(DB, fk_on.c_str(), NULL, 0, &messaggeError);
and config one:
sqlite3_db_config(DB, SQLITE_DBCONFIG_ENABLE_FKEY, 1, &fkeyConstraintsEnabled);
Pragma gives me nothing, fkeyConstraintsEnabled gives 1.
What I am trying to do is to create B table:
std::string tab_A = R"(
CREATE TABLE A (
a INT NOT NULL PRIMARY KEY
);
)";
std::string tab_B = R"(
CREATE TABLE B (
b INT NOT NULL PRIMARY KEY,
bb INT NOT NULL FOREIGN_KEY REFERENCES A(a)
);
)";
sqlite3
EDIT
That worked:
std::string tab_B = R"(
CREATE TABLE B (
b INT NOT NULL PRIMARY KEY,
bb INT NOT NULL,
FOREIGN KEY(b) REFERENCES A(a)
);
)";
Pragma and config were not needed
END OF EDIT
I've tried pragma way:
std::string fk_on = "PRAGMA foreign_keys = ON;";
sqlite3_exec(DB, fk_on.c_str(), NULL, 0, &messaggeError);
and config one:
sqlite3_db_config(DB, SQLITE_DBCONFIG_ENABLE_FKEY, 1, &fkeyConstraintsEnabled);
Pragma gives me nothing, fkeyConstraintsEnabled gives 1.
What I am trying to do is to create B table:
std::string tab_A = R"(
CREATE TABLE A (
a INT NOT NULL PRIMARY KEY
);
)";
std::string tab_B = R"(
CREATE TABLE B (
b INT NOT NULL PRIMARY KEY,
bb INT NOT NULL FOREIGN_KEY REFERENCES A(a)
);
)";
sqlite3
sqlite3
edited Nov 17 at 21:58
asked Nov 17 at 21:34
Marek Kowal
93
93
then accept my answer.
– johnathan
Nov 19 at 11:36
add a comment |
then accept my answer.
– johnathan
Nov 19 at 11:36
then accept my answer.
– johnathan
Nov 19 at 11:36
then accept my answer.
– johnathan
Nov 19 at 11:36
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
std::string tab_A = R"(
CREATE TABLE A (
a INT NOT NULL PRIMARY KEY
);
)";
std::string tab_B = R"(
CREATE TABLE B (
b INT NOT NULL PRIMARY KEY,
bb INT NOT NULL , FOREIGN_KEY(bb) REFERENCES A(a)
);
)";
That's how it's done according to the sqlite documentation. This is, btw, a sqlite problem not a c++ one.
It does not resolve the problem
– Marek Kowal
Nov 17 at 21:50
sqlitetutorial.net/sqlite-foreign-key
– johnathan
Nov 17 at 22:05
Drop the tables and use what I have in the answer and try it please. I had to make an edit on it to correct a missing comma issue when I first posted it. It's also identical to what the tutorial I linked you has.
– johnathan
Nov 18 at 0:17
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
std::string tab_A = R"(
CREATE TABLE A (
a INT NOT NULL PRIMARY KEY
);
)";
std::string tab_B = R"(
CREATE TABLE B (
b INT NOT NULL PRIMARY KEY,
bb INT NOT NULL , FOREIGN_KEY(bb) REFERENCES A(a)
);
)";
That's how it's done according to the sqlite documentation. This is, btw, a sqlite problem not a c++ one.
It does not resolve the problem
– Marek Kowal
Nov 17 at 21:50
sqlitetutorial.net/sqlite-foreign-key
– johnathan
Nov 17 at 22:05
Drop the tables and use what I have in the answer and try it please. I had to make an edit on it to correct a missing comma issue when I first posted it. It's also identical to what the tutorial I linked you has.
– johnathan
Nov 18 at 0:17
add a comment |
up vote
0
down vote
std::string tab_A = R"(
CREATE TABLE A (
a INT NOT NULL PRIMARY KEY
);
)";
std::string tab_B = R"(
CREATE TABLE B (
b INT NOT NULL PRIMARY KEY,
bb INT NOT NULL , FOREIGN_KEY(bb) REFERENCES A(a)
);
)";
That's how it's done according to the sqlite documentation. This is, btw, a sqlite problem not a c++ one.
It does not resolve the problem
– Marek Kowal
Nov 17 at 21:50
sqlitetutorial.net/sqlite-foreign-key
– johnathan
Nov 17 at 22:05
Drop the tables and use what I have in the answer and try it please. I had to make an edit on it to correct a missing comma issue when I first posted it. It's also identical to what the tutorial I linked you has.
– johnathan
Nov 18 at 0:17
add a comment |
up vote
0
down vote
up vote
0
down vote
std::string tab_A = R"(
CREATE TABLE A (
a INT NOT NULL PRIMARY KEY
);
)";
std::string tab_B = R"(
CREATE TABLE B (
b INT NOT NULL PRIMARY KEY,
bb INT NOT NULL , FOREIGN_KEY(bb) REFERENCES A(a)
);
)";
That's how it's done according to the sqlite documentation. This is, btw, a sqlite problem not a c++ one.
std::string tab_A = R"(
CREATE TABLE A (
a INT NOT NULL PRIMARY KEY
);
)";
std::string tab_B = R"(
CREATE TABLE B (
b INT NOT NULL PRIMARY KEY,
bb INT NOT NULL , FOREIGN_KEY(bb) REFERENCES A(a)
);
)";
That's how it's done according to the sqlite documentation. This is, btw, a sqlite problem not a c++ one.
answered Nov 17 at 21:43
johnathan
2,143818
2,143818
It does not resolve the problem
– Marek Kowal
Nov 17 at 21:50
sqlitetutorial.net/sqlite-foreign-key
– johnathan
Nov 17 at 22:05
Drop the tables and use what I have in the answer and try it please. I had to make an edit on it to correct a missing comma issue when I first posted it. It's also identical to what the tutorial I linked you has.
– johnathan
Nov 18 at 0:17
add a comment |
It does not resolve the problem
– Marek Kowal
Nov 17 at 21:50
sqlitetutorial.net/sqlite-foreign-key
– johnathan
Nov 17 at 22:05
Drop the tables and use what I have in the answer and try it please. I had to make an edit on it to correct a missing comma issue when I first posted it. It's also identical to what the tutorial I linked you has.
– johnathan
Nov 18 at 0:17
It does not resolve the problem
– Marek Kowal
Nov 17 at 21:50
It does not resolve the problem
– Marek Kowal
Nov 17 at 21:50
sqlitetutorial.net/sqlite-foreign-key
– johnathan
Nov 17 at 22:05
sqlitetutorial.net/sqlite-foreign-key
– johnathan
Nov 17 at 22:05
Drop the tables and use what I have in the answer and try it please. I had to make an edit on it to correct a missing comma issue when I first posted it. It's also identical to what the tutorial I linked you has.
– johnathan
Nov 18 at 0:17
Drop the tables and use what I have in the answer and try it please. I had to make an edit on it to correct a missing comma issue when I first posted it. It's also identical to what the tutorial I linked you has.
– johnathan
Nov 18 at 0:17
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53355775%2fforeign-key-support-in-sqlite3-c-ver-3-25-3%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
then accept my answer.
– johnathan
Nov 19 at 11:36