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)
);
)";









share|improve this question
























  • then accept my answer.
    – johnathan
    Nov 19 at 11:36















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)
);
)";









share|improve this question
























  • then accept my answer.
    – johnathan
    Nov 19 at 11:36













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)
);
)";









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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












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.






share|improve this answer





















  • 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











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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

























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.






share|improve this answer





















  • 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















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.






share|improve this answer





















  • 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













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.






share|improve this answer












 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.







share|improve this answer












share|improve this answer



share|improve this answer










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


















  • 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


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

If I really need a card on my start hand, how many mulligans make sense? [duplicate]

Alcedinidae

Can an atomic nucleus contain both particles and antiparticles? [duplicate]