1
0
forked from BRT/arc

Rename database fields to use consistent snake_case format.

Updated all SQL queries and bindings to replace camelCase field names (e.g., `updateTime`, `lastScan`) with snake_case equivalents (e.g., `update_time`). Ensures uniformity across database schema and codebase.
This commit is contained in:
slava 2025-04-21 12:00:55 +07:00
parent 2ee1e90d1b
commit d56b91425c
2 changed files with 10 additions and 10 deletions

View File

@ -7,10 +7,10 @@
QDateTime CommonDataDAO::getLastScan() {
QSqlQuery query(DatabaseManager::instance().database());
query.prepare("SELECT lastScan FROM common_data WHERE id = 1");
query.prepare("SELECT update_time FROM common_data WHERE id = 1");
if (!query.exec()) {
qWarning() << "Ошибка при получении lastScan:" << query.lastError().text();
qWarning() << "Ошибка при получении update_time:" << query.lastError().text();
return {};
}
@ -24,7 +24,7 @@ QDateTime CommonDataDAO::getLastScan() {
bool CommonDataDAO::updateLastScan(const QDateTime& newTime) {
QSqlQuery query(DatabaseManager::instance().database());
query.prepare("UPDATE common_data SET lastScan = :time WHERE id = 1");
query.prepare("UPDATE common_data SET update_time = :time WHERE id = 1");
query.bindValue(":time", newTime.toString(Qt::ISODate));
if (!query.exec()) {
@ -34,7 +34,7 @@ bool CommonDataDAO::updateLastScan(const QDateTime& newTime) {
if (query.numRowsAffected() == 0) {
QSqlQuery insertQuery(DatabaseManager::instance().database());
insertQuery.prepare("INSERT INTO common_data (id, lastScan) VALUES (1, :time)");
insertQuery.prepare("INSERT INTO common_data (id, update_time) VALUES (1, :time)");
insertQuery.bindValue(":time", newTime.toString(Qt::ISODate));
if (!insertQuery.exec()) {

View File

@ -9,7 +9,7 @@ QList<DeviceInfo> DeviceDAO::getAllDevices() {
QSqlQuery query(DatabaseManager::instance().database());
query.prepare(
"SELECT id, status, name, android, screen_width, screen_height, battery, updateTime, image FROM devices WHERE image IS NOT NULL AND status = 'device'");
"SELECT id, status, name, android, screen_width, screen_height, battery, update_time, image FROM devices WHERE image IS NOT NULL AND status = 'device'");
if (!query.exec()) {
qWarning() << "Ошибка при получении списка устройств:" << query.lastError().text();
@ -25,7 +25,7 @@ QList<DeviceInfo> DeviceDAO::getAllDevices() {
device.screenWidth = query.value("screen_width").toInt();
device.screenHeight = query.value("screen_height").toInt();
device.battery = query.value("battery").toInt();
device.updateTime = QDateTime::fromString(query.value("updateTime").toString(), Qt::ISODate);
device.updateTime = QDateTime::fromString(query.value("update_time").toString(), Qt::ISODate);
device.image = query.value("image").toByteArray();
devices.append(device);
@ -58,16 +58,16 @@ bool DeviceDAO::upsertDevice(const DeviceInfo &device) {
screen_width = :width,
screen_height = :height,
battery = :battery,
updateTime = :updateTime
update_time = :update_time
WHERE id = :id
)");
} else {
// Вставка
query.prepare(R"(
INSERT INTO devices (
id, status, name, android, screen_width, screen_height, battery, updateTime
id, status, name, android, screen_width, screen_height, battery, update_time
) VALUES (
:id, :status, :name, :android, :width, :height, :battery, :updateTime
:id, :status, :name, :android, :width, :height, :battery, :update_time
)
)");
}
@ -79,7 +79,7 @@ bool DeviceDAO::upsertDevice(const DeviceInfo &device) {
query.bindValue(":width", device.screenWidth);
query.bindValue(":height", device.screenHeight);
query.bindValue(":battery", device.battery);
query.bindValue(":updateTime", device.updateTime.toString(Qt::ISODate));
query.bindValue(":update_time", device.updateTime.toString(Qt::ISODate));
if (!query.exec()) {
qWarning() << "Ошибка при вставке/обновлении устройства:" << query.lastError().text();