Add description field to accounts table and related logic
Added a new `description` column to the `accounts` table in the database schema. Updated the model, DAO methods, and queries to handle the `description` field for both inserting and retrieving account data. This change ensures that account entries can now include descriptive information.
This commit is contained in:
parent
2ac5dcc5e5
commit
4f5229da0a
Binary file not shown.
@ -9,8 +9,8 @@ bool AccountDAO::upsertAccount(const AccountInfo &info) {
|
||||
QSqlQuery query(DatabaseManager::instance().database());
|
||||
|
||||
query.prepare(R"(
|
||||
INSERT INTO accounts (device_id, app_name, card_name, amount, update_time, status)
|
||||
VALUES (:device_id, :app_name, :card_name, :amount, :update_time, :status)
|
||||
INSERT INTO accounts (device_id, app_name, card_name, amount, update_time, status, description)
|
||||
VALUES (:device_id, :app_name, :card_name, :amount, :update_time, :status, :description)
|
||||
ON CONFLICT(device_id, app_name, card_name)
|
||||
DO UPDATE SET
|
||||
amount = excluded.amount,
|
||||
@ -24,6 +24,7 @@ bool AccountDAO::upsertAccount(const AccountInfo &info) {
|
||||
query.bindValue(":amount", info.amount);
|
||||
query.bindValue(":update_time", info.updateTime.toString(Qt::ISODate));
|
||||
query.bindValue(":status", info.status);
|
||||
query.bindValue(":description", info.description);
|
||||
|
||||
if (!query.exec()) {
|
||||
qWarning() << "Ошибка при вставке/обновлении account:" << query.lastError().text();
|
||||
@ -45,7 +46,7 @@ QList<AccountInfo> AccountDAO::getAccounts(const QString &deviceId, const QStrin
|
||||
QSqlQuery query(DatabaseManager::instance().database());
|
||||
|
||||
query.prepare(R"(
|
||||
SELECT id, device_id, app_name, card_name, amount, update_time, status
|
||||
SELECT id, device_id, app_name, card_name, amount, update_time, status, description
|
||||
FROM accounts
|
||||
WHERE device_id = :device_id AND app_name = :app_name
|
||||
)");
|
||||
@ -67,6 +68,7 @@ QList<AccountInfo> AccountDAO::getAccounts(const QString &deviceId, const QStrin
|
||||
acc.amount = query.value("amount").toDouble();
|
||||
acc.updateTime = QDateTime::fromString(query.value("update_time").toString(), Qt::ISODate);
|
||||
acc.status = query.value("status").toString();
|
||||
acc.description = query.value("description").toString();
|
||||
accounts.append(acc);
|
||||
}
|
||||
|
||||
|
||||
@ -18,6 +18,7 @@ CREATE TABLE IF NOT EXISTS accounts
|
||||
device_id TEXT,
|
||||
app_name TEXT,
|
||||
card_name TEXT,
|
||||
description TEXT,
|
||||
amount REAL,
|
||||
update_time DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
status TEXT,
|
||||
|
||||
@ -10,4 +10,5 @@ struct AccountInfo {
|
||||
double amount;
|
||||
QDateTime updateTime;
|
||||
QString status;
|
||||
QString description;
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user