diff options
Diffstat (limited to 'core/src/Model')
-rw-r--r-- | core/src/Model/TransactionsModel.cpp | 27 | ||||
-rw-r--r-- | core/src/Model/TransactionsModel.hpp | 3 |
2 files changed, 21 insertions, 9 deletions
diff --git a/core/src/Model/TransactionsModel.cpp b/core/src/Model/TransactionsModel.cpp index 6d0989e..3df7990 100644 --- a/core/src/Model/TransactionsModel.cpp +++ b/core/src/Model/TransactionsModel.cpp @@ -11,7 +11,9 @@ SalesTable::SalesTable(TransactionModel& db) // language=SQLite : GetRowCount(db.GetSQLite(), "SELECT Count(*) FROM Sales") // language=SQLite - , GetRows(db.GetSQLite(), "SELECT * FROM Sales WHERE rowid >= ? AND rowid < ?") + , GetRows(db.GetSQLite(), "SELECT * FROM Sales WHERE Id >= ? AND Id < ?") + // language=SQLite + , GetItems(db.GetSQLite(), "SELECT * FROM SalesItems WHERE SaleId == ?") { } @@ -19,13 +21,17 @@ PurchasesTable::PurchasesTable(TransactionModel& db) // language=SQLite : GetRowCount(db.GetSQLite(), "SELECT Count(*) FROM Purchases") // language=SQLite - , GetRows(db.GetSQLite(), "SELECT * FROM Purchases WHERE rowid >= ? AND rowid < ?") + , GetRows(db.GetSQLite(), "SELECT * FROM Purchases WHERE Id >= ? AND Id < ?") + // language=SQLite + , GetItems(db.GetSQLite(), "SELECT * FROM PurchasesItems WHERE PurchaseId == ?") { } DeliveryTable::DeliveryTable(TransactionModel& db) // language=SQLite : FilterByTypeAndId(db.GetSQLite(), "SELECT * FROM Deliveries WHERE AssociatedOrder == ? AND Outgoing = ?") + // language=SQLite + , GetItems(db.GetSQLite(), "SELECT * FROM DeliveriesItems WHERE DeliveryId == ?") { } @@ -40,7 +46,7 @@ static std::string GetDatabaseFilePath(const Project& project) /// Wrapper for SQLite::Database that creates the default tables TransactionModel::DatabaseWrapper::DatabaseWrapper(TransactionModel& self) - : mSqlite(GetDatabaseFilePath(*self.mProject), SQLite::OPEN_READWRITE) + : mSqlite(GetDatabaseFilePath(*self.mProject), SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE) { // If this table doesn't exist, the database probably just got initialized if (mSqlite.tableExists("Sales")) { @@ -58,15 +64,18 @@ TransactionModel::DatabaseWrapper::DatabaseWrapper(TransactionModel& self) // - DeliveryTime: the time this order was completed (through a set of deliveries) // 'Deliveries' schema - // - ShipmentTime: unix epoch time of sending to delivery - // - ArrivalTime: unix epoch time of delivery arrived at warehouse; 0 if not arrived yet - // - AssociatedOrder: rowid of the order that this delivery is completing (which table: Outgoing=true -> Sales, Outgoing=false -> Purchases) + // - ShipmentTime: unix epoch time stamp of sending to delivery + // - ArrivalTime: unix epoch time stamp of delivery arrived at warehouse; 0 if not arrived yet + // - AssociatedOrder: Id of the order that this delivery is completing (which table: Outgoing=true -> Sales, Outgoing=false -> Purchases) // - Outgoing: true if the delivery is from warehouse to customer; false if the delivery is from factory to warehouse + // Note: the 'Id' key would be unique (not recycled after row deletion) because it's explicit + // https://www.sqlite.org/rowidtable.html + // language=SQLite mSqlite.exec(R"""( CREATE TABLE IF NOT EXISTS Sales( - INT PRIMARY KEY, + Id INT PRIMARY KEY, Customer INT, Deadline DATETIME, DeliveryTime DATETIME @@ -78,7 +87,7 @@ CREATE TABLE IF NOT EXISTS SalesItems( ); CREATE TABLE IF NOT EXISTS Purchases( - INT PRIMARY KEY, + Id INT PRIMARY KEY, Factory INT, OrderTime DATETIME, DeliveryTime DATETIME @@ -90,7 +99,7 @@ CREATE TABLE IF NOT EXISTS PurchasesItems( ); CREATE TABLE IF NOT EXISTS Deliveries( - INT PRIMARY KEY, + Id INT PRIMARY KEY, ShipmentTime DATETIME, ArrivalTime DATETIME, AssociatedOrder INT, diff --git a/core/src/Model/TransactionsModel.hpp b/core/src/Model/TransactionsModel.hpp index 86611cf..cd19241 100644 --- a/core/src/Model/TransactionsModel.hpp +++ b/core/src/Model/TransactionsModel.hpp @@ -11,6 +11,7 @@ class SalesTable public: SQLite::Statement GetRowCount; SQLite::Statement GetRows; + SQLite::Statement GetItems; public: SalesTable(TransactionModel& db); @@ -21,6 +22,7 @@ class PurchasesTable public: SQLite::Statement GetRowCount; SQLite::Statement GetRows; + SQLite::Statement GetItems; public: PurchasesTable(TransactionModel& db); @@ -30,6 +32,7 @@ class DeliveryTable { public: SQLite::Statement FilterByTypeAndId; + SQLite::Statement GetItems; public: DeliveryTable(TransactionModel& db); |