52 lines
1.5 KiB
D
52 lines
1.5 KiB
D
module source.sql;
|
||
|
||
import singlog;
|
||
import std.conv;
|
||
|
||
import source.dblite;
|
||
|
||
int sqlAddNewTheme(string topic) {
|
||
try {
|
||
auto queryResult = dblite.sql(
|
||
"insert into topics (name) values (?) returning id",
|
||
topic
|
||
);
|
||
if (!queryResult.empty())
|
||
return queryResult.front()["id"].to!int;
|
||
} catch (Exception e) {
|
||
log.e("Не удалось выполнить запрос к БД. " ~ e.msg);
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
|
||
int sqlAddNewQuestion(int topic_id, int question_number, string question_text) {
|
||
try {
|
||
auto queryResult = dblite.sql(
|
||
"insert into questions (topic_id, number, text) values (?, ?, ?) returning id",
|
||
topic_id, question_number, question_text
|
||
);
|
||
if (!queryResult.empty())
|
||
return queryResult.front()["id"].to!int;
|
||
} catch (Exception e) {
|
||
log.e("Не удалось выполнить запрос к БД. " ~ e.msg);
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
|
||
int sqlAddNewAnswer(int question_id, int answer_number, string answer_text, int answer_truth) {
|
||
try {
|
||
auto queryResult = dblite.sql(
|
||
"insert into answers (question_id, number, text, truth) values (?, ?, ?, ?) returning id",
|
||
question_id, answer_number, answer_text, answer_truth
|
||
);
|
||
if (!queryResult.empty())
|
||
return queryResult.front()["id"].to!int;
|
||
} catch (Exception e) {
|
||
log.e("Не удалось выполнить запрос к БД. " ~ e.msg);
|
||
}
|
||
|
||
return 0;
|
||
}
|