INSERT INTO data_web_conversation
(
ConversationCode,
Package,
ContactId,
ConversationGuid,
Senderid,
Timestamp,
Messagetype,
Message
)
VALUES
(
'{conversation_code}',
'{package}',
'{contact_id}',
'{conversation_guid}',
'{sender_id}',
UTC_TIMESTAMP(),
'{message_type}',
'{message}'
)
SELECT
Id,
Senderid,
Timestamp,
UNIX_TIMESTAMP(CONVERT_TZ(Timestamp, '+00:00', @@session.time_zone))
AS TimestampEpoch,
Messagetype,
Message
FROM data_web_conversation
WHERE UPPER(ConversationCode) = UPPER('{conversation_code}')
AND UPPER(ContactId) = UPPER('{contact_id}')
AND
(
({last_id} > 0 AND Id > {last_id})
OR
(
{last_id} <= 0
AND
(
Timestamp > '{last_stamp}'
OR (Timestamp = '{last_stamp}' AND Id > {last_id})
)
)
)
ORDER BY Id ASC