I am using Gammu on my server to setup a SMS gateway, but I ran into a problem, when I was moving from receiving IDs to just get any non-processed SMS’es from Gammu’s DB (in MySQL)
A bit of the inbox table looks like this
| UDH | TextDecoded | ID | Processed |
| 0500034A0201 | Some long text (156 l.) | 1 | false |
| 0500034A0202 | Some continuing text | 2 | false |
| | An SMS (less than 160 l) | 3 | false |
If an SMS is over 160 letters the SMS is splitted over multiple entries indicated by UDH.
The UDH is created by
- part of the
UDH(050003) indicates it is an SMS. - part of the
UDH(4A02) is a unique identifier. - part of the
UDH(01) is the part-number of the SMS.
I can check if the SMS is fully received, if the TextDecoded (of the last entry with the long SMS (with UDH)) is less than 156 letters long or TheRecevingDateTime is later than 3 minutes.
I need to create Stored Procedures to Get a SMS (here a SMS can be over 160 letters long) and Get All New SMSes (if the Processed is false).
I have already created an example of how to Get a SMS, that looks like
DELIMITER €€
CREATE PROCEDURE `GetSMS`(IN smsid int(10))
BEGIN
DECLARE smsudh TEXT;
SELECT `UDH` INTO smsudh FROM `inbox` WHERE `ID`=smsid;
IF (STRCMP(smsudh, '') < 1) THEN
SELECT * FROM `inbox` WHERE `ID`=smsid;
ELSE
SELECT * FROM `inbox` WHERE `UDH` LIKE CONCAT(LEFT(smsudh, (LENGTH(smsudh)-2)), "%") GROUP BY `ID` ORDER BY `UDH`;
END IF;
END €€
DELIMITER ;
But I can not figure out how to create a Stored Procedure to Get All New SMSes.
** EDIT **
- It should get all new SMSes
- A long SMS is received when the last entry (with
UDH) is received later than 3 minutes due toTheReceivingDateTimeor theTextDecodedis shorter than 156 letters - An SMS without
UDHis just received (it should not be combined with other SMSes withoutUDH)
I hope you understand my question
Since we can’t filter by
wherefor a time interval, we use it as a group function and filter byhavingThis will give back a list of id’s, that you can run through your
GetSMS