db_fifo.xml 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
  4. <section id="db_fifo" xmlns:xi="http://www.w3.org/2001/XInclude">
  5. <sectioninfo>
  6. <revhistory>
  7. <revision>
  8. <revnumber>$Revision$</revnumber>
  9. <date>$Date$</date>
  10. </revision>
  11. </revhistory>
  12. </sectioninfo>
  13. <title>Database FIFO interface</title>
  14. <section id="db_fifo_intro">
  15. <title>Introduction</title>
  16. <para>
  17. <application>SER</application> offers to its module developers a common
  18. DataBase(DB) interface, disregarding the database implementation (mysql,
  19. dbtext or postgres) that lays beneath it.
  20. </para>
  21. <para>
  22. This feature is now extended and offered also to the
  23. <application>SER</application> users/administrators by DataBase
  24. <acronym>FIFO</acronym> Interface (or DB FIFO interface). So,
  25. DB FIFO interface is an extension of the internal DB interface through the
  26. FIFO server. Everybody from outside <application>SER</application> can
  27. operate SER's database (for adding/removing users, for manipulating
  28. aliases, access control wrights, etc) using the same FIFO commands
  29. without caring about the database type that's used by SER.
  30. </para>
  31. </section>
  32. <section id="advantages">
  33. <title>Advantages</title>
  34. <para>
  35. All external applications that need to work with SER's database (like
  36. <application>serctl</application> or <application>serweb</application>)
  37. can do so via DB FIFO interface without depending of a specific database
  38. driver. No modifications will be required when a new type of database
  39. will be added to <application>SER</application>.
  40. </para>
  41. <para>
  42. Also, this approach, prevents any kind of confusion between the database
  43. type used by <application>SER</application> and the one used by these
  44. external applications. They will use automatically the same database as
  45. <application>SER</application> is configure to use.
  46. </para>
  47. </section>
  48. <section id="limitations">
  49. <title>Limitations</title>
  50. <para>
  51. DB FIFO interface is restricted to the limitation of the internal DB
  52. interface.
  53. </para>
  54. <para>
  55. Also the size (can fit on only one line) and the content (\n or \r
  56. characters must be escaped) of a BLOB value is restricted.
  57. </para>
  58. </section>
  59. <section id="db_fifo_config">
  60. <title>Configuration</title>
  61. <para>
  62. FIFO server presents is required, so configure in your config file the FIFO
  63. file to be used by the <application>SER</application> FIFO server:
  64. <programlisting>
  65. fifo="/tmp/ser_fifo"
  66. </programlisting>
  67. To enable the DB FIFO interface, it's required to load at least one
  68. database module (available for the moment are mysql, dbtext and postgres).
  69. </para>
  70. <para>
  71. The database module that you want to use and the database configuration are
  72. configured via parameter <varname>fifo_db_url</varname>:
  73. <programlisting>
  74. fifo_db_url="mysql:mysql_url"
  75. fifo_db_url="dbtext:dbtext_url"
  76. </programlisting>
  77. The format of the database URL depends of the used database implementation
  78. (see the documentation for each DB type).
  79. </para>
  80. <para><emphasis>
  81. NOTE: be sure to load the module the is specified into fifo_db_url!
  82. </emphasis></para>
  83. <para>
  84. If no fifo_db_url is specified or no appropriate DB module found, the
  85. DB FIFO interface will be disabled.
  86. </para>
  87. </section>
  88. <section id="db_fifo_commands">
  89. <title>DB FIFO commands</title>
  90. <para>
  91. From FIFO point of view, all DB FIFO commands are mapped with the
  92. same name: <emphasis>DB</emphasis>. The first line of the command must
  93. contain the name of the DB command. Available are:
  94. <itemizedlist>
  95. <listitem>
  96. <para>SELECT</para>
  97. </listitem>
  98. <listitem>
  99. <para>UPDATE</para>
  100. </listitem>
  101. <listitem>
  102. <para>INSERT</para>
  103. </listitem>
  104. <listitem>
  105. <para>DELETE</para>
  106. </listitem>
  107. <listitem>
  108. <para>RAW_QUERY</para>
  109. </listitem>
  110. <listitem>
  111. <para>EAW_QUERY_RES</para>
  112. </listitem>
  113. </itemizedlist>
  114. The grammar used in the commands definition can be found in next
  115. section "DB FIFO grammar". The presence of the
  116. <varname>reply_fifo_file</varname> in the FIFO command is
  117. <emphasis>required</emphasis> for all commands.
  118. </para>
  119. <section>
  120. <title><function>SELECT</function> command</title>
  121. <para>
  122. This function implements SELECT DB directive. Its syntax is:
  123. <programlisting>
  124. :DB:reply_fifo_file
  125. select
  126. [COLUMN]*
  127. .
  128. TABLE_NAME
  129. [CVP]
  130. .
  131. </programlisting>
  132. If no CVP line is present, the whole table.will be returned. If no
  133. COLUMN line is given, all table columns will be found in the result.
  134. </para>
  135. <para>
  136. The result of the query will be return via reply_fifo_file in one
  137. raw per line format (only requested columns), the first line being
  138. the head of the table. The <emphasis>NULL</emphasis> values will be
  139. printed as "NULL".
  140. </para>
  141. </section>
  142. <section id="insert">
  143. <title><function>INSERT</function> command</title>
  144. <para>
  145. This function implements INSERT DB directive - inserts one row in
  146. a table. Its syntax is:
  147. <programlisting>
  148. :DB:reply_fifo_file
  149. insert
  150. TABLE_NAME
  151. [EQUAL_CVP]+
  152. .
  153. </programlisting>
  154. </para>
  155. <para>
  156. Command returns nothing if success or, other way, an error message.
  157. </para>
  158. </section>
  159. <section id="update">
  160. <title><function>UPDATE</function> command</title>
  161. <para>
  162. The function implements UPDATE DB directive - it is possible to
  163. modify one or more rows in a table. Its syntax is:
  164. <programlisting>
  165. :DB:reply_fifo_file
  166. update
  167. [EQUAL_CVP]+
  168. .
  169. TABLE_NAME
  170. [CVP]*
  171. .
  172. </programlisting>
  173. </para>
  174. <para>
  175. Command returns nothing if success or, other way, an error message.
  176. </para>
  177. </section>
  178. <section id="delete">
  179. <title><function>DELETE</function> command</title>
  180. <para>
  181. This function implements DELETE DB directive - it is possible to
  182. delete one or more rows from a table. Its syntax is:
  183. <programlisting>
  184. :DB:reply_fifo_file
  185. delete
  186. TABLE_NAME
  187. [CVP]*
  188. .
  189. </programlisting>
  190. If CVP list contain <emphasis>no lines, all rows will be
  191. deleted</emphasis> (table will be empty).
  192. </para>
  193. <para>
  194. Command returns nothing if success or, other way, an error message.
  195. </para>
  196. </section>
  197. <section id="raw_query">
  198. <title><function>RAW_QUERY</function> command</title>
  199. <para>
  200. This function sends a raw query directly to the database driver
  201. without trying to understand the command. This command <emphasis>MUST
  202. NOT</emphasis> generate any response.Otherwise, the database driver
  203. can block or desynchronize (depending of the driver).
  204. Its syntax is:
  205. <programlisting>
  206. :DB:reply_fifo_file
  207. raw_query
  208. (ASCII)+
  209. </programlisting>
  210. </para>
  211. <para>
  212. Command returns nothing if success or, other way, an error message.
  213. </para>
  214. </section>
  215. <section id="raw_query_res">
  216. <title>
  217. <function>RAW_QUERY_RES</function> command
  218. </title>
  219. <para>
  220. This function sends a raw query directly to the database driver without
  221. trying to understand the command. This command <emphasis>MUST
  222. </emphasis> generate an response (even if an empty one). Otherwise,
  223. the database driver can block or desynchronize (depending of the
  224. driver). Its syntax is:
  225. <programlisting>
  226. :DB:reply_fifo_file
  227. raw_query_res
  228. (ASCII)+
  229. </programlisting>
  230. </para>
  231. <para>
  232. Command's output format is identical with the one from
  233. <function>SELECT</function> command.
  234. </para>
  235. </section>
  236. </section>
  237. <section id="db_fifo_grammar">
  238. <title>DB FIFO grammar</title>
  239. <programlisting>
  240. <![CDATA[
  241. COLUMN=(alfa-numeric|'_')+
  242. GAP=' '|'\t'
  243. DEF_OP='='|'<'|'>'|'>='|'<='
  244. UNDEF_OP=(ASCII)+
  245. CAST_OP="int"|"double"|"string"|"date"|"blob"|"bitmap"
  246. INT_VAL=integer number
  247. DOUBLE_VAL=float number
  248. STRING_VAL='"' ASCII* '"'
  249. DATE_VAL='<' YEAR '-' MONTH '-' DAY ' ' HOUR ':' MINS ':' SECS '>'
  250. BLOB_VAL=STRING_VAL
  251. BITMAP_VAL=INT_VAL
  252. NULL_VAL="null"
  253. VALUE=('['CAST_OP']')?(INT_VAL|DOUBLE_VAL|STRING_VAL|DATE_VAL|
  254. BLOB_VAL|BITMAP_VAL|NULL_VAL)
  255. CVP(column-value-pair)=
  256. (COLUMN GAP* DEF_OP GAP* VALUE) | (COLUMN GAP+ UNDEF_OP GAP+ VALUE)
  257. EQUAL-CVP(column-equal-value-pair)=
  258. (COLUMN GAP* '=' GAP* VALUE)
  259. ]]>
  260. </programlisting>
  261. </section>
  262. </section>