2023-05-30 23:04:03 +00:00
|
|
|
|
module data;
|
|
|
|
|
|
|
|
|
|
import pgdb;
|
|
|
|
|
import singlog;
|
|
|
|
|
import structures;
|
|
|
|
|
|
|
|
|
|
import std.conv;
|
|
|
|
|
|
2023-06-01 21:36:21 +00:00
|
|
|
|
GroupDB[] sqlGetListGroups() {
|
2023-05-30 23:04:03 +00:00
|
|
|
|
GroupDB[] groups;
|
|
|
|
|
try {
|
|
|
|
|
auto queryResult = pgsql.sql(
|
|
|
|
|
"select distinct
|
2023-05-31 22:10:08 +00:00
|
|
|
|
dan.da_group,
|
|
|
|
|
dag.da_comment
|
|
|
|
|
from da_numbers dan
|
|
|
|
|
left join da_groups dag ON dag.da_name = dan.da_group"
|
2023-05-30 23:04:03 +00:00
|
|
|
|
);
|
|
|
|
|
foreach (row; queryResult) {
|
|
|
|
|
GroupDB data;
|
|
|
|
|
|
|
|
|
|
data.name = row["da_group"];
|
|
|
|
|
data.comment = row["da_comment"];
|
|
|
|
|
|
|
|
|
|
groups ~= data;
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.e("Не удалось выполнить запрос к БД. " ~ e.msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return groups;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-01 21:36:21 +00:00
|
|
|
|
NumberDB[] sqlGetListNumbers(string group) {
|
2023-05-30 23:04:03 +00:00
|
|
|
|
NumberDB[] numbers;
|
|
|
|
|
try {
|
|
|
|
|
auto queryResult = pgsql.sql(
|
|
|
|
|
"select
|
|
|
|
|
dan.da_number,
|
|
|
|
|
dal.da_comment da_list,
|
|
|
|
|
dan.da_all_cc,
|
|
|
|
|
dan.da_white_cc,
|
|
|
|
|
dan.da_black_cc,
|
|
|
|
|
dan.da_comment
|
|
|
|
|
from da_numbers dan
|
2023-05-31 22:10:08 +00:00
|
|
|
|
left join da_lists dal on dal.da_name = dan.da_list
|
2023-06-01 21:36:21 +00:00
|
|
|
|
where dan.da_group = ?
|
|
|
|
|
order by dan.da_number",
|
2023-05-30 23:04:03 +00:00
|
|
|
|
group
|
|
|
|
|
);
|
|
|
|
|
foreach (row; queryResult) {
|
|
|
|
|
NumberDB data;
|
|
|
|
|
|
|
|
|
|
data.number = row["da_number"];
|
|
|
|
|
data.list = row["da_list"];
|
|
|
|
|
data.all_cc = row["da_all_cc"].to!int;
|
|
|
|
|
data.white_cc = row["da_white_cc"].to!int;
|
|
|
|
|
data.black_cc = row["da_black_cc"].to!int;
|
|
|
|
|
data.comment = row["da_comment"];
|
|
|
|
|
|
|
|
|
|
numbers ~= data;
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.e("Не удалось выполнить запрос к БД. " ~ e.msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return numbers;
|
|
|
|
|
}
|
2023-05-31 22:10:08 +00:00
|
|
|
|
|
2023-06-01 21:36:21 +00:00
|
|
|
|
NumberDB sqlGetDataNumber(string number) {
|
2023-05-31 22:10:08 +00:00
|
|
|
|
NumberDB data;
|
|
|
|
|
try {
|
|
|
|
|
auto queryResult = pgsql.sql(
|
|
|
|
|
"select
|
|
|
|
|
da_number,
|
|
|
|
|
da_group,
|
|
|
|
|
da_list,
|
|
|
|
|
da_all_cc,
|
|
|
|
|
da_white_cc,
|
|
|
|
|
da_black_cc,
|
|
|
|
|
da_comment
|
|
|
|
|
from da_numbers
|
|
|
|
|
where da_number = ?",
|
|
|
|
|
number
|
|
|
|
|
);
|
|
|
|
|
foreach (row; queryResult) {
|
|
|
|
|
data.number = row["da_number"];
|
|
|
|
|
data.group = row["da_group"];
|
|
|
|
|
data.list = row["da_list"];
|
|
|
|
|
data.all_cc = row["da_all_cc"].to!int;
|
|
|
|
|
data.white_cc = row["da_white_cc"].to!int;
|
|
|
|
|
data.black_cc = row["da_black_cc"].to!int;
|
|
|
|
|
data.comment = row["da_comment"];
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.e("Не удалось выполнить запрос к БД. " ~ e.msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-01 21:36:21 +00:00
|
|
|
|
GroupDB[] sqlGetGroups() {
|
2023-05-31 22:10:08 +00:00
|
|
|
|
GroupDB[] groups;
|
|
|
|
|
try {
|
|
|
|
|
auto queryResult = pgsql.sql(
|
|
|
|
|
"select da_name, da_comment from da_groups"
|
|
|
|
|
);
|
|
|
|
|
foreach (row; queryResult) {
|
|
|
|
|
GroupDB data;
|
|
|
|
|
|
|
|
|
|
data.name = row["da_name"];
|
|
|
|
|
data.comment = row["da_comment"];
|
|
|
|
|
|
|
|
|
|
groups ~= data;
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.e("Не удалось выполнить запрос к БД. " ~ e.msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return groups;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-01 21:36:21 +00:00
|
|
|
|
ListDB[] sqlGetLists() {
|
2023-05-31 22:10:08 +00:00
|
|
|
|
ListDB[] lists;
|
|
|
|
|
try {
|
|
|
|
|
auto queryResult = pgsql.sql(
|
|
|
|
|
"select da_name, da_comment from da_lists"
|
|
|
|
|
);
|
|
|
|
|
foreach (row; queryResult) {
|
|
|
|
|
ListDB data;
|
|
|
|
|
|
|
|
|
|
data.name = row["da_name"];
|
|
|
|
|
data.comment = row["da_comment"];
|
|
|
|
|
|
|
|
|
|
lists ~= data;
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.e("Не удалось выполнить запрос к БД. " ~ e.msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return lists;
|
|
|
|
|
}
|
2023-06-01 21:36:21 +00:00
|
|
|
|
|
|
|
|
|
bool sqlUpdateNumber(NumberDB number) {
|
|
|
|
|
try {
|
|
|
|
|
pgsql.sql(
|
|
|
|
|
"update da_numbers set
|
|
|
|
|
da_group = ?,
|
|
|
|
|
da_list = ?,
|
|
|
|
|
da_all_cc = ?,
|
|
|
|
|
da_white_cc = ?,
|
|
|
|
|
da_black_cc = ?,
|
|
|
|
|
da_comment = ?
|
|
|
|
|
where da_number = ?",
|
|
|
|
|
number.group,
|
|
|
|
|
number.list,
|
|
|
|
|
number.all_cc,
|
|
|
|
|
number.white_cc,
|
|
|
|
|
number.black_cc,
|
|
|
|
|
number.comment,
|
|
|
|
|
number.number
|
|
|
|
|
);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.e("Ошибка обновления номера в БД. " ~ e.msg);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool sqlDeleteNumber(string number) {
|
|
|
|
|
try {
|
|
|
|
|
pgsql.sql(
|
|
|
|
|
"delete from da_numbers where da_number = ?", number
|
|
|
|
|
);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.e("Ошибка удаления номера в БД. " ~ e.msg);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool sqlInsertNumber(NumberDB number) {
|
|
|
|
|
try {
|
|
|
|
|
pgsql.sql(
|
|
|
|
|
"insert into da_numbers
|
|
|
|
|
(da_number, da_group, da_list, da_all_cc, da_white_cc, da_black_cc, da_comment)
|
|
|
|
|
values
|
|
|
|
|
(?, ?, ?, ?, ?, ?, ?)",
|
|
|
|
|
number.number,
|
|
|
|
|
number.group,
|
|
|
|
|
number.list,
|
|
|
|
|
number.all_cc,
|
|
|
|
|
number.white_cc,
|
|
|
|
|
number.black_cc,
|
|
|
|
|
number.comment
|
|
|
|
|
);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("Ошибка добавления номера телефона в БД. " ~ e.msg);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|