Chapter 1. Admin Guide

1.1. Overview

The module implements a simplified database engine based on text
files. It can be used by OpenSIPS DB interface instead of other
database module (like MySQL).

The module is meant for use in demos or small devices that do not
support other DB modules. It keeps everything in memory and if you deal
with large amount of data you may run quickly out of memory. Also, it
has not implemented all standard database facilities (like order by),
it includes minimal functionality to work properly (who knows ?!?)
with OpenSIPS.

NOTE: the timestamp is printed in an integer value from time_t
structure. If you use it in a system that cannot do this conversion,
it will fail (support for such situation is in to-do list).

NOTE: even when is in non-caching mode, the module does not write
back to hard drive after changes. In this mode, the module checks if
the corresponding file on disk has changed, and reloads it. The write
on disk happens at OpenSIPS shut down.

1.1.1. Design of dbtext engine

The dbtext database system architecture:

a database is represented by a directory in the local file
system.
NOTE: when you use dbtext in OpenSIPS,
the database URL for modules must be the path to the directory
where the table-files are located, prefixed by
“dbtext://”, e.g.,
“dbtext:///var/dbtext/ser”. If there is no
“/” after “dbtext://” then
“CFG_DIR/” is inserted at the beginning of the
database path. So, either you provide an absolute path to
database directory or a relative one to “CFG_DIR”
directory.

a table is represented by a text file inside database directory.

1.1.2. Internal format of a dbtext table

First line is the definition of the columns. Each column must be
declared as follows:

the name of column must not include white spaces.

the format of a column definition is:
name(type,attr).

between two column definitions must be a white space, e.g.,
“first_name(str) last_name(str)”.

the type of a column can be:

int - integer numbers.

double - real numbers with two
decimals.

str - strings with maximum size of 4KB.

a column can have one of the attributes:

auto - only for 'int' columns,
the maximum value in that column is incremented and stored
in this field if it is not provided in queries.

null - accept null values in column
fields.

if no attribute is set, the fields of the column cannot have
null value.

each other line is a row with data. The line ends with
“\n”.

the fields are separated by “:”.

no value between two ':' (or between ':' and start/end of a row)
means “null” value.

1.1.3. Existing limitations

This database interface don't support the data insertion with
default values. All such values specified in the database template
are ignored. So its advisable to specify all data for a column at
insertion operations.

1.2. Dependencies

1.2.1. OpenSIPS modules

The next modules must be loaded before this module:

none.

1.2.2. External libraries or applications

The next libraries or applications must be installed before running
OpenSIPS with this module:

none.

1.3. Exported Parameters

None.

1.3.1. db_mode (integer)

Set caching mode (0) or non-caching mode (1). In caching mode, data
is loaded at startup. In non-caching mode, the module check every time
a table is requested whether the corresponding file on disk has
changed, and if yes, will re-load table from file.

Default value is “0”.

Example 1.4. Set db_mode parameter

...
modparam("db_text", "db_mode", 1)
...

1.4. Exported Functions

None.

1.5. Installation and Running

Compile the module and load it instead of mysql or other DB modules.

REMINDER: when you use dbtext in OpenSIPS,
the database URL for modules must be the path to the directory
where the table-files are located, prefixed by
“dbtext://”, e.g.,
“dbtext:///var/dbtext/ser”. If there is no “/”
after “dbtext://” then “CFG_DIR/” is inserted
at the beginning of the database path. So, either you provide an
absolute path to database directory or a relative one to
“CFG_DIR” directory.

1.5.1. Using dbtext with basic OpenSIPS configuration

Here are the definitions for most important table as well as a basic
configuration file to use dbtext with OpenSIPS. The table structures
may change in time and you will have to adjust next examples. These are
know to work with upcoming OpenSIPS v0.9.x

You have to populate the table 'subscriber' by hand with user profiles
in order to have authentication. To use with the given configuration
file, the table files must be placed in the '/tmp/serdb' directory.