Hi, I'm having a bit of a problem with a chat application that stores data in an innoDB table. Here's the table:
CREATE TABLE IF NOT EXISTS axtChat (
senderId INT UNSIGNED NOT NULL,
receiverId INT UNSIGNED NOT NULL,
postTime DOUBLE UNSIGNED NOT NULL,
name VARCHAR(30) NOT NULL,
message VARCHAR(255) NOT NULL,
INDEX (senderId, receiverId, postTime)
) ENGINE = InnoDB DEFAULT CHARSET utf8 COLLATE utf8_general_ci
The chat application checks the database for new messages regularly by checking if its internal lastCheckTime < postTime. But sometimes it misses single messages.
When posting a new record, I'm getting postTime from the server (double with a 4 digit precision) before making an insert query, I wonder if there's a time lap between obtaining the system time and the time when the row is actually written. Because if the app checks the table in the meantime, it would not pick up the message that's about to be written, and then next time it would also not pick up that message because its lastCheckTime will already be greater than postTime of that particular message... I'm just guessing.
There must be a more reliable way to do this... Do you see an obvious problem here, could you suggest a better solution?
Thank you for your time.
CREATE TABLE IF NOT EXISTS axtChat (
senderId INT UNSIGNED NOT NULL,
receiverId INT UNSIGNED NOT NULL,
postTime DOUBLE UNSIGNED NOT NULL,
name VARCHAR(30) NOT NULL,
message VARCHAR(255) NOT NULL,
INDEX (senderId, receiverId, postTime)
) ENGINE = InnoDB DEFAULT CHARSET utf8 COLLATE utf8_general_ci
The chat application checks the database for new messages regularly by checking if its internal lastCheckTime < postTime. But sometimes it misses single messages.
When posting a new record, I'm getting postTime from the server (double with a 4 digit precision) before making an insert query, I wonder if there's a time lap between obtaining the system time and the time when the row is actually written. Because if the app checks the table in the meantime, it would not pick up the message that's about to be written, and then next time it would also not pick up that message because its lastCheckTime will already be greater than postTime of that particular message... I'm just guessing.
There must be a more reliable way to do this... Do you see an obvious problem here, could you suggest a better solution?
Thank you for your time.