Overview
When you configure shopMaster, it creates:- A
ChangeLogtable to store all product changes - Three triggers on your product table:
trgAfterInsert,trgAfterUpdate, andtrgAfterDelete - Automatic logging of all INSERT, UPDATE, and DELETE operations
Change tracking is configured automatically when you click the Configure button in Settings. The
create_change_log_and_triggers() function (helper.py:30) handles the entire setup.ChangeLog table structure
The ChangeLog table is created with this schema (helper.py:41-51):| Column | Purpose |
|---|---|
| LogID | Auto-incrementing primary key |
| ChangeType | INSERT, UPDATE, or DELETE |
| ProductID | The product’s unique identifier |
| ProductName | Product name at time of change |
| SellPrice | Product price at time of change |
| QrCode | Product QR code |
| Status | Product status flag |
| ChangeDateTime | Timestamp of the change |
Database triggers
shopMaster installs three triggers on your local product table:- INSERT trigger
- UPDATE trigger
- DELETE trigger
The The trigger only logs the change if no existing INSERT record exists for that ProductID, preventing duplicates.
trgAfterInsert trigger (helper.py:56-69) fires when new products are added:How triggers capture changes
SQL Server provides special tables during trigger execution:- inserted: Contains new/updated row data
- deleted: Contains old/deleted row data
- Access the affected product data
- Check for duplicate log entries
- Insert change records into ChangeLog
The
SET NOCOUNT ON statement at the start of each trigger prevents row count messages from interfering with your application.Configuration process
When you configure shopMaster (main.py:227):Create ChangeLog table
The function checks if the ChangeLog table exists using
sysobjects. If not, it creates the table (helper.py:38-52).Duplicate prevention
Each trigger includes duplicate prevention logic:- Multiple changes to the same product don’t create duplicate log entries
- The ChangeLog remains clean and efficient
- Sync operations don’t send duplicate data
Once a change is synced, the
sync_data() function clears processed records from ChangeLog (helper.py:334), allowing new changes to the same product to be tracked.Sync integration
The sync process reads from the ChangeLog table:- Fetches all pending INSERT and UPDATE changes
- Ignores DELETE operations
- Provides data for the sync workflow
Troubleshooting
Triggers not firing
- Verify the triggers were created successfully during configuration
- Check SQL Server permissions - the database user needs CREATE TRIGGER rights
- Ensure triggers are enabled on the table
Duplicate entries in ChangeLog
- This shouldn’t happen due to duplicate prevention logic
- If it occurs, reconfigure shopMaster to recreate the triggers
Changes not appearing in ChangeLog
- Verify the triggers exist:
SELECT * FROM sys.triggers WHERE parent_id = OBJECT_ID('YourTableName') - Check if the triggers are disabled
- Ensure the product table name matches your configuration
Performance considerations
The change tracking system is designed for efficiency:- Triggers execute immediately after each operation
- Duplicate checks use indexed columns (ProductID)
- ChangeLog is regularly cleared by sync operations
- Minimal overhead on normal database operations
create_change_log_and_triggers() implementation.