2024-02-13 00:44:54 +00:00
|
|
|
|
module source.sql;
|
|
|
|
|
|
|
|
|
|
import singlog;
|
|
|
|
|
import std.conv;
|
2024-02-17 18:47:20 +00:00
|
|
|
|
import arsd.sqlite;
|
2024-02-13 00:44:54 +00:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-17 18:47:20 +00:00
|
|
|
|
int sqlAddNewQuestion(
|
|
|
|
|
int topic_id,
|
|
|
|
|
int question_number,
|
|
|
|
|
string question_text,
|
|
|
|
|
bool question_has_picture,
|
|
|
|
|
ubyte[] question_picture,
|
|
|
|
|
string question_picture_name
|
|
|
|
|
) {
|
|
|
|
|
SqliteResult queryResult;
|
2024-02-13 00:44:54 +00:00
|
|
|
|
try {
|
2024-02-17 18:47:20 +00:00
|
|
|
|
if (question_has_picture)
|
|
|
|
|
queryResult = dblite.sql(
|
|
|
|
|
"insert into questions (topic_id, number, text, picture_name, picture)
|
|
|
|
|
values (?, ?, ?, ?, ?) returning id",
|
|
|
|
|
topic_id, question_number, question_text, question_picture_name, question_picture
|
|
|
|
|
);
|
|
|
|
|
else
|
|
|
|
|
queryResult = dblite.sql(
|
|
|
|
|
"insert into questions (topic_id, number, text) values (?, ?, ?) returning id",
|
|
|
|
|
topic_id, question_number, question_text
|
|
|
|
|
);
|
|
|
|
|
|
2024-02-13 00:44:54 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|