So my problem is the following. I've got a timeStatus
column that will have one of two values on an INSERT
statement, 'pending' or 'never', depending on whether the column fromDate
is NULL or not.
I've made this prepared statement that doesn't work but represents what I intend. On the other hand I'm not sure if a constraint would be in order here, rather then having it specified on the statement. This way I could specify the status value for an insert or update and the table would know what to do. However I need some guidance as to what method to go with and where to go to learn it.
Here's the statement:
INSERT INTO Bservices (
servStatus, timeStatus,
fromDetails, fromDate, fromTime)
VALUES(
'pending', IF(ISNULL(`fromDate`)) 'pending' ELSE 'never',
'a', '', '')
The intended behavior is the following:
ON INSERT
if(fromDate == '') {
timeStatus = 'pending'
} else {
timeStatus = 'never'
}
ON UPDATE
if(timeStatus == 'pending' && fromDate != '') {
timeStatus = 'updated'
}