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:
parent
2ee1e90d1b
commit
d56b91425c
@ -7,10 +7,10 @@
|
|||||||
|
|
||||||
QDateTime CommonDataDAO::getLastScan() {
|
QDateTime CommonDataDAO::getLastScan() {
|
||||||
QSqlQuery query(DatabaseManager::instance().database());
|
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()) {
|
if (!query.exec()) {
|
||||||
qWarning() << "Ошибка при получении lastScan:" << query.lastError().text();
|
qWarning() << "Ошибка при получении update_time:" << query.lastError().text();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ QDateTime CommonDataDAO::getLastScan() {
|
|||||||
|
|
||||||
bool CommonDataDAO::updateLastScan(const QDateTime& newTime) {
|
bool CommonDataDAO::updateLastScan(const QDateTime& newTime) {
|
||||||
QSqlQuery query(DatabaseManager::instance().database());
|
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));
|
query.bindValue(":time", newTime.toString(Qt::ISODate));
|
||||||
|
|
||||||
if (!query.exec()) {
|
if (!query.exec()) {
|
||||||
@ -34,7 +34,7 @@ bool CommonDataDAO::updateLastScan(const QDateTime& newTime) {
|
|||||||
|
|
||||||
if (query.numRowsAffected() == 0) {
|
if (query.numRowsAffected() == 0) {
|
||||||
QSqlQuery insertQuery(DatabaseManager::instance().database());
|
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));
|
insertQuery.bindValue(":time", newTime.toString(Qt::ISODate));
|
||||||
|
|
||||||
if (!insertQuery.exec()) {
|
if (!insertQuery.exec()) {
|
||||||
|
|||||||
@ -9,7 +9,7 @@ QList<DeviceInfo> DeviceDAO::getAllDevices() {
|
|||||||
|
|
||||||
QSqlQuery query(DatabaseManager::instance().database());
|
QSqlQuery query(DatabaseManager::instance().database());
|
||||||
query.prepare(
|
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()) {
|
if (!query.exec()) {
|
||||||
qWarning() << "Ошибка при получении списка устройств:" << query.lastError().text();
|
qWarning() << "Ошибка при получении списка устройств:" << query.lastError().text();
|
||||||
@ -25,7 +25,7 @@ QList<DeviceInfo> DeviceDAO::getAllDevices() {
|
|||||||
device.screenWidth = query.value("screen_width").toInt();
|
device.screenWidth = query.value("screen_width").toInt();
|
||||||
device.screenHeight = query.value("screen_height").toInt();
|
device.screenHeight = query.value("screen_height").toInt();
|
||||||
device.battery = query.value("battery").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();
|
device.image = query.value("image").toByteArray();
|
||||||
|
|
||||||
devices.append(device);
|
devices.append(device);
|
||||||
@ -58,16 +58,16 @@ bool DeviceDAO::upsertDevice(const DeviceInfo &device) {
|
|||||||
screen_width = :width,
|
screen_width = :width,
|
||||||
screen_height = :height,
|
screen_height = :height,
|
||||||
battery = :battery,
|
battery = :battery,
|
||||||
updateTime = :updateTime
|
update_time = :update_time
|
||||||
WHERE id = :id
|
WHERE id = :id
|
||||||
)");
|
)");
|
||||||
} else {
|
} else {
|
||||||
// Вставка
|
// Вставка
|
||||||
query.prepare(R"(
|
query.prepare(R"(
|
||||||
INSERT INTO devices (
|
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 (
|
) 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(":width", device.screenWidth);
|
||||||
query.bindValue(":height", device.screenHeight);
|
query.bindValue(":height", device.screenHeight);
|
||||||
query.bindValue(":battery", device.battery);
|
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()) {
|
if (!query.exec()) {
|
||||||
qWarning() << "Ошибка при вставке/обновлении устройства:" << query.lastError().text();
|
qWarning() << "Ошибка при вставке/обновлении устройства:" << query.lastError().text();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user