Kinda new to helping out but here's what I would do. There's a lot of assumptions here, and you WILL need to tweak the code. First create a new table alarm_reason. We will create a relation for each "reason" to a specific alarm.
CREATE TABLE alarm_reasons (
reason_id INT AUTO_INCREMENT PRIMARY KEY,
alarm_id INT NOT NULL,
reason TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (alarm_id) REFERENCES alarms(alarm_id) #make sure the Foreign Key "alarm_id" and the alarm table "alarms" actually match your system.
);
Next create a Named Query to select data from both the alarms and alarm_reasons table. Something like this: (again you'll need to make sure the fields match the actual column names in your setup)
SELECT
a.alarm_id,
a.alarm_name,
r.reason
FROM
alarms a
LEFT JOIN
alarm_reasons r ON a.alarm_id = r.alarm_id;
Create a table on a view(i'm using Perspective). Bind the data prop to a query, and select the named query you just created. This will be how you display the data.
On the Columns prop, click the plus and add as many columns as you are displaying. Expand each column and in the "filed" add the name of the column as it exists in the actual table. Enable editing.
Create another named query that will update the alarm_reasons table.
INSERT INTO alarm_reasons (alarm_id, reason)
VALUES (:alarm_id, :reason)
ON DUPLICATE KEY UPDATE reason = :reason;
Right click on the Table > Configure Event > OnEditCellCommit > Add a script. Every time a user edits a cell and presses enter, this event fires. We can use this to call the query we just made.
def onCellEdited(self, event):
# Get the new value and the identifiers from the event
newValue = event.value
alarmID = self.props.data[event.row]["alarm_id"]
# Create a dictionary of parameters to pass to the Named Query
parameters = {
"alarm_id": alarmID,
"reason": newValue
}
# Run the Named Query
system.db.runNamedQuery("UpsertAlarmReason", parameters)
Post your actual fix so we can all learn! Thanks!