Setting version to 1.29.0.
[gammu.git] / docs / man / gammu-smsd-sql.7
blob033a04c5c027745f95ec324332faed6977490121
1 .TH "GAMMU-SMSD-SQL" "7" "January 19, 2011" "1.29.0" "Gammu"
2 .SH NAME
3 gammu-smsd-sql \- gammu-smsd(1) backend using SQL abstraction layer to use any supported database as a message storage
5 .nr rst2man-indent-level 0
7 .de1 rstReportMargin
8 \\$1 \\n[an-margin]
9 level \\n[rst2man-indent-level]
10 level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
12 \\n[rst2man-indent0]
13 \\n[rst2man-indent1]
14 \\n[rst2man-indent2]
16 .de1 INDENT
17 .\" .rstReportMargin pre:
18 . RS \\$1
19 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
20 . nr rst2man-indent-level +1
21 .\" .rstReportMargin post:
23 .de UNINDENT
24 . RE
25 .\" indent \\n[an-margin]
26 .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
27 .nr rst2man-indent-level -1
28 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
29 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
31 .\" Man page generated from reStructeredText.
33 .sp
34 SQL service stores all its data in database. It can use one of these SQL backends
35 (configuration option \fBDriver\fP in smsd section):
36 .INDENT 0.0
37 .IP \(bu 2
39 \fBnative_mysql\fP for \fIgammu\-smsd\-mysql\fP
40 .IP \(bu 2
42 \fBnative_pgsql\fP for \fIgammu\-smsd\-pgsql\fP
43 .IP \(bu 2
44 .INDENT 2.0
45 .TP
46 .B drivers supported by DBI for \fIgammu\-smsd\-dbi\fP, which include:
47 .INDENT 7.0
48 .IP \(bu 2
50 \fBsqlite3\fP \- for SQLite 3
51 .IP \(bu 2
53 \fBmysql\fP \- for MySQL
54 .IP \(bu 2
56 \fBpgsql\fP \- for PostgeSQL
57 .IP \(bu 2
59 \fBfreetds\fP \- for MS SQL Server or Sybase
60 .UNINDENT
61 .UNINDENT
62 .UNINDENT
63 .SH SQL CONNECTION PARAMETERS
64 .sp
65 Common for all backends:
66 .INDENT 0.0
67 .IP \(bu 2
69 \fBUser\fP \- user connecting to database
70 .IP \(bu 2
72 \fBPassword\fP \- password for connecting to database
73 .IP \(bu 2
75 \fBHost\fP \- database host
76 .IP \(bu 2
78 \fBDatabase\fP \- database name
79 .IP \(bu 2
81 \fBDriver\fP \- \fBnative_mysql\fP, \fBnative_pgsql\fP or DBI one
82 .UNINDENT
83 .sp
84 Specific for DBI:
85 .INDENT 0.0
86 .IP \(bu 2
88 \fBDriversPath\fP \- path to DBI drivers
89 .IP \(bu 2
91 \fBDBDir\fP \- sqlite/sqlite3 directory with database
92 .UNINDENT
93 .IP "See also"
94 .sp
95 The variables are fully described in \fIgammurc\fP documentation.
96 .RE
97 .SH SQL QUERIES
98 .sp
99 Almost all queries are configurable. You can edit them in
100 \fB[sql]\fP section. There are several variables used in SQL
101 queries. We can separate them into three groups:
102 .INDENT 0.0
103 .IP \(bu 2
105 phone specific, which can be used in every query, see \fI\%Phone Specific Parameters\fP
106 .IP \(bu 2
108 SMS specific, which can be used in queries which works with SMS messages, see \fI\%SMS Specific Parameters\fP
109 .IP \(bu 2
111 query specific, which are numeric and are specific only for given query (or set of queries), see \fI\%Configurable queries\fP
112 .UNINDENT
113 .SS Phone Specific Parameters
114 .INDENT 0.0
116 .B \fB%I\fP
118 IMEI of phone
120 .B \fB%P\fP
122 PHONE ID (hostname)
124 .B \fB%N\fP
126 client name (eg. Gammu 1.12.3)
127 .UNINDENT
128 .SS SMS Specific Parameters
129 .INDENT 0.0
131 .B \fB%R\fP
133 remote number [1]
135 .B \fB%C\fP
137 delivery datetime
139 .B \fB%e\fP
141 delivery status on receiving or status error on sending
143 .B \fB%t\fP
145 message reference
147 .B \fB%d\fP
149 receiving datetime for received sms
151 .B \fB%E\fP
153 encoded text of SMS
155 .B \fB%c\fP
157 SMS coding (ie 8bit or UnicodeNoCompression)
159 .B \fB%F\fP
161 sms centre number
163 .B \fB%u\fP
165 UDH header
167 .B \fB%x\fP
169 class
171 .B \fB%T\fP
173 decoded SMS text
175 .B \fB%A\fP
177 CreatorID of SMS (sending sms)
179 .B \fB%V\fP
181 relative validity
182 .UNINDENT
183 .IP [1] 5
185 Sender number for received messages (insert to inbox or delivery notifications), destination otherwise.
186 .SH CONFIGURABLE QUERIES
188 All configurable queries can be set in \fB[sql]\fP section. Sequence of rows in selects are mandatory.
190 All default queries noted here are noted for MySQL. Actual time and time addition
191 are selected for default queries during initialization.
192 .INDENT 0.0
194 .B delete_phone
196 Deletes phone from database.
198 Default value:
201 .ft C
202 DELETE FROM phones WHERE IMEI = %I
203 .ft P
205 .UNINDENT
206 .INDENT 0.0
208 .B insert_phone
210 Inserts phone to database.
212 Default value:
215 .ft C
216 INSERT INTO phones (IMEI, ID, Send, Receive, InsertIntoDB, TimeOut, Client, Battery, Signal)
217 VALUES (%I, %P, %1, %2, NOW(), (NOW() + INTERVAL 10 SECOND) + 0, %N, \-1, \-1)
218 .ft P
221 Query specific parameters:
222 .INDENT 7.0
224 .B \fB%1\fP
226 enable send (yes or no) \- configuration option Send
228 .B \fB%2\fP
230 enable receive (yes or no)  \- configuration option Receive
231 .UNINDENT
232 .UNINDENT
233 .INDENT 0.0
235 .B save_inbox_sms_select
237 Select message for update delivery status.
239 Default value:
242 .ft C
243 SELECT ID, Status, SendingDateTime, DeliveryDateTime, SMSCNumber FROM sentitems
244 WHERE DeliveryDateTime IS NULL AND SenderID = %P AND TPMR = %t AND DestinationNumber = %R
245 .ft P
247 .UNINDENT
248 .INDENT 0.0
250 .B save_inbox_sms_update_delivered
252 Update message delivery status if message was delivered.
254 Default value:
257 .ft C
258 UPDATE sentitems SET DeliveryDateTime = %C, Status = %1, StatusError = %e WHERE ID = %2 AND TPMR = %t
259 .ft P
262 Query specific parameters:
263 .INDENT 7.0
265 .B \fB%1\fP
267 delivery status returned by GSM network
269 .B \fB%2\fP
271 ID of message
272 .UNINDENT
273 .UNINDENT
274 .INDENT 0.0
276 .B save_inbox_sms_update
278 Update message if there is an delivery error.
280 Default value:
283 .ft C
284 UPDATE sentitems SET Status = %1, StatusError = %e WHERE ID = %2 AND TPMR = %t
285 .ft P
288 Query specific parameters:
289 .INDENT 7.0
291 .B \fB%1\fP
293 delivery status returned by GSM network
295 .B \fB%2\fP
297 ID of message
298 .UNINDENT
299 .UNINDENT
300 .INDENT 0.0
302 .B save_inbox_sms_insert
304 Insert received message.
306 Default value:
309 .ft C
310 INSERT INTO inbox (ReceivingDateTime, Text, SenderNumber, Coding, SMSCNumber, UDH,
311 Class, TextDecoded, RecipientID) VALUES (%d, %E, %R, %c, %F, %u, %x, %T, %P)
312 .ft P
314 .UNINDENT
315 .INDENT 0.0
317 .B update_received
319 Update statistics after receiving message.
321 Default value:
324 .ft C
325 UPDATE phones SET Received = Received + 1 WHERE IMEI = %I
326 .ft P
328 .UNINDENT
329 .INDENT 0.0
331 .B refresh_send_status
333 Update messages in outbox.
335 Default value:
338 .ft C
339 UPDATE outbox SET SendingTimeOut = (NOW() + INTERVAL locktime SECOND) + 0
340 WHERE ID = %1 AND (SendingTimeOut < NOW() OR SendingTimeOut IS NULL)
341 .ft P
344 Query specific parameters:
345 .INDENT 7.0
347 .B \fB%1\fP
349 ID of message
350 .UNINDENT
351 .UNINDENT
352 .INDENT 0.0
354 .B find_outbox_sms_id
356 Find sms messages for sending.
358 Default value:
361 .ft C
362 SELECT ID, InsertIntoDB, SendingDateTime, SenderID FROM outbox
363 WHERE SendingDateTime < NOW() AND SendingTimeOut <  NOW() AND
364 ( SenderID is NULL OR SenderID = \(aq\(aq OR SenderID = %P ) ORDER BY InsertIntoDB ASC LIMIT %1
365 .ft P
368 Query specific parameters:
369 .INDENT 7.0
371 .B \fB%1\fP
373 limit of sms messages sended in one walk in loop
374 .UNINDENT
375 .UNINDENT
376 .INDENT 0.0
378 .B find_outbox_body
380 Select body of message.
382 Default value:
385 .ft C
386 SELECT Text, Coding, UDH, Class, TextDecoded, ID, DestinationNumber, MultiPart,
387 RelativeValidity, DeliveryReport, CreatorID FROM outbox WHERE ID=%1
388 .ft P
391 Query specific parameters:
392 .INDENT 7.0
394 .B \fB%1\fP
396 ID of message
397 .UNINDENT
398 .UNINDENT
399 .INDENT 0.0
401 .B find_outbox_multipart
403 Select remaining parts of sms message.
405 Default value:
408 .ft C
409 SELECT Text, Coding, UDH, Class, TextDecoded, ID, SequencePosition
410 FROM outbox_multipart WHERE ID=%1 AND SequencePosition=%2
411 .ft P
414 Query specific parameters:
415 .INDENT 7.0
417 .B \fB%1\fP
419 ID of message
421 .B \fB%2\fP
423 Number of multipart message
424 .UNINDENT
425 .UNINDENT
426 .INDENT 0.0
428 .B delete_outbox
430 Remove messages from outbox after threir successful send.
432 Default value:
435 .ft C
436 DELETE FROM outbox WHERE ID=%1
437 .ft P
440 Query specific parameters:
441 .INDENT 7.0
443 .B \fB%1\fP
445 ID of message
446 .UNINDENT
447 .UNINDENT
448 .INDENT 0.0
450 .B delete_outbox_multipart
452 Remove messages from outbox_multipart after threir successful send.
454 Default value:
457 .ft C
458 DELETE FROM outbox_multipart WHERE ID=%1
459 .ft P
462 Query specific parameters:
463 .INDENT 7.0
465 .B \fB%1\fP
467 ID of message
468 .UNINDENT
469 .UNINDENT
470 .INDENT 0.0
472 .B create_outbox
474 Create message (insert to outbox).
476 Default value:
479 .ft C
480 INSERT INTO outbox (CreatorID, SenderID, DeliveryReport, MultiPart,
481 InsertIntoDB, Text, DestinationNumber, RelativeValidity, Coding, UDH, Class,
482 TextDecoded) VALUES (%1, %P, %2, %3, NOW(), %E, %R, %V, %c, %u, %x, %T)
483 .ft P
486 Query specific parameters:
487 .INDENT 7.0
489 .B \fB%1\fP
491 creator of message
493 .B \fB%2\fP
495 delivery status report \- yes/default
497 .B \fB%3\fP
499 multipart \- FALSE/TRUE
501 .B \fB%4\fP
503 Part (part number)
505 .B \fB%5\fP
507 ID of message
508 .UNINDENT
509 .UNINDENT
510 .INDENT 0.0
512 .B create_outbox_multipart
514 Create message remaining parts.
516 Default value:
519 .ft C
520 INSERT INTO outbox_multipart (SequencePosition, Text, Coding, UDH, Class,
521 TextDecoded, ID) VALUES (%4, %E, %c, %u, %x, %T, %5)
522 .ft P
525 Query specific parameters:
526 .INDENT 7.0
528 .B \fB%1\fP
530 creator of message
532 .B \fB%2\fP
534 delivery status report \- yes/default
536 .B \fB%3\fP
538 multipart \- FALSE/TRUE
540 .B \fB%4\fP
542 Part (part number)
544 .B \fB%5\fP
546 ID of message
547 .UNINDENT
548 .UNINDENT
549 .INDENT 0.0
551 .B add_sent_info
553 Insert to sentitems.
555 Default value:
558 .ft C
559 INSERT INTO sentitems (CreatorID,ID,SequencePosition,Status,SendingDateTime,
560 SMSCNumber, TPMR, SenderID,Text,DestinationNumber,Coding,UDH,Class,TextDecoded,
561 InsertIntoDB,RelativeValidity)
562 VALUES (%A, %1, %2, %3, NOW(), %F, %4, %P, %E, %R, %c, %u, %x, %T, %5, %V)
563 .ft P
566 Query specific parameters:
567 .INDENT 7.0
569 .B \fB%1\fP
571 ID of sms message
573 .B \fB%2\fP
575 part number (for multipart sms)
577 .B \fB%3\fP
579 message state (SendingError, Error, SendingOK, SendingOKNoReport)
581 .B \fB%4\fP
583 message reference (TPMR)
585 .B \fB%5\fP
587 time when inserted in db
588 .UNINDENT
589 .UNINDENT
590 .INDENT 0.0
592 .B update_sent
594 Update sent statistics after sending message.
596 Default value:
599 .ft C
600 UPDATE phones SET Sent= Sent + 1 WHERE IMEI = %I
601 .ft P
603 .UNINDENT
604 .INDENT 0.0
606 .B refresh_phone_status
608 Update phone status (battery, signal).
610 Default value:
613 .ft C
614 UPDATE phones SET TimeOut= (NOW() + INTERVAL 10 SECOND) + 0,
615 Battery = %1, Signal = %2 WHERE IMEI = %I
616 .ft P
619 Query specific parameters:
620 .INDENT 7.0
622 .B \fB%1\fP
624 battery percent
626 .B \fB%2\fP
628 signal percent
629 .UNINDENT
630 .UNINDENT
631 .SH AUTHOR
632 Michal Čihař <michal@cihar.com>
633 .SH COPYRIGHT
634 2009-2011, Michal Čihař <michal@cihar.com>
635 .\" Generated by docutils manpage writer.
636 .\"