summaryrefslogtreecommitdiff
path: root/docs/manual/smsd/tables.rst
blob: b4219be45a325c581c52ada849731cb869f02269 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
.. _gammu-smsd-tables:

SMSD Database Structure
=======================

The backends themselves are described in their sections, this document
describes general database structure and required tables.

More SMS daemons can share single database. If you do not specify PhoneID in
their configuration, all are treated equally and you have no guarantee which
one sends outgoing message. If you configure PhoneID and use it when inserting
message to the ``outbox`` table (:ref:`gammu-smsd-inject` does this), each SMS
daemon will have separate outbox queue.

Receiving of messages
---------------------

Received messages are stored in :ref:`inbox` table.

Transmitting of messages
------------------------

Transmitted messages are read from table :ref:`outbox` and possible subsequent parts
of the same message from :ref:`outbox_multipart`.

Description of tables
---------------------

daemons
+++++++

Information about running daemons.

gammu
+++++

Table holding single field ``Version`` - version of a database schema. See
:ref:`smsd-tables-history` for details what has changed.

.. _inbox:

inbox
+++++

Table where received messages will be stored.

Fields description:

``UpdatedInDB`` (timestamp)
    when somebody (daemon, user, etc.) updated it

``ReceivingDateTime`` (timestamp)
    when SMS was received

``Text`` (text)
    encoded SMS text (for all SMS)

``SenderNumber`` (varchar(20))
    decoded SMS sender number

``Coding`` (enum('Default_No_Compression', 'Unicode_No_Compression', '8bit', 'Default_Compression', 'Unicode_Compression'))
    SMS text coding

``UDH`` (text)
    encoded User Data Header text

``SMSCNumber`` (varchar(20))
    decoded SMSC number

``Class`` (integer)
    SMS class or \-1 (0 is flash SMS, 1 is normal one)

``TextDecoded`` (varchar(160))
    decoded SMS text (for Default Alphabet/Unicode SMS)

``ID`` (integer unsigned)
    SMS identificator (for using with external applications)

``RecipientID`` (text)
    which Gammu daemon has added it

``Processed`` (enum('false', 'true'))
    you can use for marking, whether SMS was processed or not


.. _outbox:

outbox
++++++

Messages enqueued for sending should be placed in this table. If message
is multipart, subsequent parts are stored in table :ref:`outbox_multipart`.

Fields description:

``UpdatedInDB`` (timestamp)
    when somebody (daemon, user, etc.) updated it

``InsertIntoDB`` (timestamp)
    when message was inserted into database

``SendingDateTime`` (timestamp)
    set it to some value, when want to force sending after some planned time

``SendBefore`` (time)
    Send message before specified time, can be used to limit messages from
    being sent in night. Default value is 23:59:59

``SendAfter`` (time)
    Send message after specified time, can be used to limit messages from
    being sent in night. Default value is 00:00:00

    .. versionadded:: 1.29.90

``Text`` (text)
    SMS text encoded using hex values in proper coding. If you want to use
    TextDecoded field, keep this NULL (or empty).

    .. versionadded:: 1.29.90

``DestinationNumber`` (varchar(20))
    recipient number

``Coding`` (enum('Default_No_Compression', 'Unicode_No_Compression', '8bit', 'Default_Compression', 'Unicode_Compression'))
    SMS text coding

``UDH`` (text)
    User Data Header encoded using hex values which will be used for constructing
    the message. Without this, message will be sent as plain text.

``Class`` (integer)
    SMS class or \-1 (0 is normal SMS, 1 is flash one)

``TextDecoded`` (varchar(160))
    SMS text in "human readable" form

``ID`` (integer unsigned)
    SMS/SMS sequence ID

    Please note that this number has to be unique also for sentitems table, so
    reusing message IDs might not be a good idea.

``MultiPart`` (enum('false','true'))
    info, whether there are more SMS from this sequence in outbox_multipart

``RelativeValidity`` (integer)
    SMS relative validity like encoded using GSM specs

``SenderID`` (text)
    which SMSD instance should send this one sequence, see :config:option:`PhoneID`

``SendingTimeOut`` (timestamp)
    used by SMSD instance for own targets

``DeliveryReport`` (enum('default','yes','no'))
    when default is used, Delivery Report is used or not according to SMSD instance settings; yes forces Delivery Report.

``CreatorID`` (text)
    sender identification, it has to match PhoneID in SMSD configuration to make
    SMSD process this message

.. _outbox_multipart:

outbox_multipart
++++++++++++++++

Data for outgoing multipart messages.

Fields description:

``ID`` (integer unsigned)
    the same meaning as values in outbox table
``Text`` (text)
    the same meaning as values in outbox table
``Coding`` (enum('Default_No_Compression', 'Unicode_No_Compression', '8bit', 'Default_Compression', 'Unicode_Compression'))
    the same meaning as values in outbox table
``UDH`` (text)
    the same meaning as values in outbox table
``Class`` (integer)
    the same meaning as values in outbox table
``TextDecoded`` (varchar(160))
    the same meaning as values in outbox table
``ID`` (integer unsigned)
    the same meaning as values in outbox table

``SequencePosition`` (integer)
    info, what is SMS number in SMS sequence (start at 2, first part is in :ref:`outbox`
    table).


phones
++++++

Information about connected phones. This table is periodically refreshed and
you can get information such as battery or signal level from here.

Fields description:

``ID`` (text)
    PhoneID value

``UpdatedInDB`` (timestamp)
    when this record has been updated

``InsertIntoDB`` (timestamp)
    when this record has been created (when phone has been connected)

``TimeOut`` (timestamp)
    when this record expires

``Send`` (boolean)
    indicates whether SMSD is sending messages, depends on configuration directive :config:option:`Send`

``Receive`` (boolean)
    indicates whether SMSD is receiving messages, depends on configuration directive :config:option:`Receive`

``IMEI`` (text)
    IMEI of phone

``Client`` (text)
    client name, usually string Gammu with version

``Battery`` (integer)
    battery level in percent (or \-1 if unknown)

``SignalStrength`` (integer)
    signal level in percent (or \-1 if unknown)

    .. versionchanged:: 1.29.90
        This used to be called ``Signal``. Renamed because ``SIGNAL`` is
        reserved word in MySQL 5.5.

``Sent`` (integer)
    Number of sent SMS messages (SMSD does not reset this counter, so it might
    overflow).

``Received`` (integer)
    Number of received SMS messages (SMSD does not reset this counter, so it might
    overflow).

sentitems
+++++++++

Log of sent messages (and unsent ones with error code). Also if delivery
reports are enabled, message state is updated after receiving delivery report.

Fields description:

``UpdatedInDB`` (timestamp)
    when somebody (daemon, user, etc.) updated it

``InsertIntoDB`` (timestamp)
    when message was inserted into database

``SendingDateTime`` (timestamp)
    when message has been sent

``DeliveryDateTime`` (timestamp)
    Time of receiving delivery report (if it has been enabled).

``Status`` (enum('SendingOK', 'SendingOKNoReport', 'SendingError', 'DeliveryOK', 'DeliveryFailed', 'DeliveryPending', 'DeliveryUnknown', 'Error'))
    Status of message sending. SendingError mens that phone failed to send the
    message, Error indicates some other error while processing message.

    ``SendingOK``
        Message has been sent, waiting for delivery report.
    ``SendingOKNoReport``
        Message has been sent without asking for delivery report.
    ``SendingError``
        Sending has failed.
    ``DeliveryOK``
        Delivery report arrived and reported success.
    ``DeliveryFailed``
        Delivery report arrived and reports failure.
    ``DeliveryPending``
        Delivery report announced pending deliver.
    ``DeliveryUnknown``
        Delivery report reported unknown status.
    ``Error``
        Some other error happened during sending (usually bug in SMSD).

``StatusError`` (integer)
    Status of delivery from delivery report message, codes are defined in GSM
    specification 03.40 section 9.2.3.15 (TP-Status).

``Text`` (text)
    SMS text encoded using hex values

``DestinationNumber`` (varchar(20))
    decoded destination number for SMS

``Coding`` (enum('Default_No_Compression', 'Unicode_No_Compression', '8bit', 'Default_Compression', 'Unicode_Compression'))
    SMS text coding

``UDH`` (text)
    User Data Header encoded using hex values

``SMSCNumber`` (varchar(20))
    decoded number of SMSC, which sent SMS

``Class`` (integer)
    SMS class or \-1 (0 is normal SMS, 1 is flash one)

``TextDecoded`` (varchar(160))
    SMS text in "human readable" form

``ID`` (integer unsigned)
    SMS ID

``SenderID`` (text)
    which SMSD instance sent this one sequence, see :config:option:`PhoneID`

``SequencePosition`` (integer)
    SMS number in SMS sequence

``TPMR`` (integer)
    Message Reference like in GSM specs

``RelativeValidity`` (integer)
    SMS relative validity like encoded using GSM specs

``CreatorID`` (text)
    copied from CreatorID from outbox table, matches PhoneID


pbk
+++

Not used by SMSD currently, included only for application usage.

pbk_groups
++++++++++

Not used by SMSD currently, included only for application usage.

.. _smsd-tables-history:

History of database structure
-----------------------------

History of schema versions:

13
    Changed name of ``Signal`` field to ``SignalStrength`` to avoid problems
    with database which have ``SIGNAL`` as reserved word. Added ``SendBefore``
    and ``SendAfter`` fields.

    .. versionchanged:: 1.29.90
12
    the changes only affect MySQL structure changing default values for
    timestamps from ``0000-00-00 00:00:00`` to ``CURRENT_TIMESTAMP()`` by
    using triggers, to update to this version, just execute triggers
    definition at the end of SQL file.

    .. versionchanged:: 1.28.94
11
    all fields for storing message text are no longer limited to 160 chars,
    but are arbitrary length text fields.
    
    .. versionchanged:: 1.25.92
10
    ``DeliveryDateTime`` is now NULL when message is not delivered, added several
    indexes

    .. versionchanged:: 1.22.95
9
    added sent/received counters to phones table

    .. versionchanged:: 1.22.93
8
    Signal and battery state are now stored in database.

    .. versionchanged:: 1.20.94
7
    Added ``CreatorID`` to several tables.

    .. versionchanged:: 1.07.00
6
    Many fields in outbox can now be NULL.

    .. versionchanged:: 1.06.00
5
    Introduced daemons table and various other changes.

    .. versionchanged:: 1.03.00
3
    Introduced phones table and various other changes.

    .. versionchanged:: 0.98.0


Examples
--------

Creating tables
+++++++++++++++

SQL scripts to create all needed tables for most databases are included in
Gammu documentation (docs/sql). As well as some PHP scripts interacting with
the database.

For example to create SQLite tables, issue following command:

.. code-block:: sh

    sqlite3 smsd.db < docs/sql/sqlite.sql

Injecting a message using SQL
+++++++++++++++++++++++++++++

To send a message, you can either use :ref:`gammu-smsd-inject`, which does all the
magic for you, or you can insert the message manually. The simplest example is
short text message:

.. code-block:: sql

    INSERT INTO outbox (
        DestinationNumber,
        TextDecoded,
        CreatorID,
        Coding
    ) VALUES (
        '800123465',
        'This is a SQL test message',
        'Program',
        'Default_No_Compression'
    );

Injecting long message using SQL
++++++++++++++++++++++++++++++++

Inserting multipart messages is a bit more tricky, you need to construct also
UDH header and store it hexadecimally written into UDH field. Unless you have
a good reason to do this manually, use :ref:`gammu-smsd-inject`.

For long text message, the UDH starts with ``050003`` followed by byte as a
message reference (you can put anything there, but it should be different for
each message, ``D3`` in following example), byte for number of messages (``02``
in example, it should be unique for each message you send to same phone number)
and byte for number of current message (``01`` for first message, ``02`` for
second, etc.).

For example long text message of two parts could look like following:

.. code-block:: sql

    INSERT INTO outbox (
        CreatorID,
        MultiPart,
        DestinationNumber,
        UDH,
        TextDecoded,
        Coding
    ) VALUES (
        'Gammu 1.23.91',
        'true',
        '123465',
        '050003D30201',
        'Mqukqirip ya konej eqniu rejropocejor hugiygydewl tfej nrupxujob xuemymiyliralj. Te tvyjuh qaxumur ibewfoiws zuucoz tdygu gelum L ejqigqesykl kya jdytbez',
        'Default_No_Compression'
    )

    INSERT INTO outbox_multipart (
        SequencePosition,
        UDH,
        Class,
        TextDecoded,
        ID,
        Coding
    ) VALUES (
        2,
        '050003D30202',
        'u xewz qisubevumxyzk ufuylehyzc. Nse xobq dfolizygqysj t bvowsyhyhyemim ovutpapeaempye giuuwbib.',
        <ID_OF_INSERTED_RECORD_IN_OUBOX_TABLE>,
        'Default_No_Compression'
    )

.. note::

    Adding UDH means that you have less space for text, in above example you
    can use only 153 characters in single message.