dm_db Module

Database abstraction layer over SQLite 3. The SQL statements are stored in module dm_sql.

Load the last 10 observations into allocatable array observs:

integer       :: rc
type(db_type) :: db
type(observ_type), allocatable :: observs(:)

rc = dm_db_open(db, '/var/dmpack/observ.sqlite')
rc = dm_db_select_observs(db, observs, desc=.true., limit=10)
rc = dm_db_close(db)

Using the iterator interface instead:

integer            :: rc      ! Return code.
type(db_type)      :: db      ! Database handle.
type(db_stmt_type) :: db_stmt ! Database statement.
type(observ_type)  :: observ  ! Returned observation.

rc = dm_db_open(db, '/var/dmpack/observ.sqlite')

do while (dm_is_ok(rc))
    rc = dm_db_select_observs(db, db_stmt, observ, desc=.true., limit=10)
    if (dm_is_ok(rc)) print '(a)', trim(observ%name)
end do

rc = dm_db_finalize(db_stmt)
rc = dm_db_close(db)

The database functions return E_NONE if the respective operation was successful.


Uses

  • module~~dm_db~~UsesGraph module~dm_db dm_db iso_c_binding iso_c_binding module~dm_db->iso_c_binding module~dm_error dm_error module~dm_db->module~dm_error module~dm_id dm_id module~dm_db->module~dm_id module~dm_kind dm_kind module~dm_db->module~dm_kind module~dm_sql dm_sql module~dm_db->module~dm_sql module~dm_string dm_string module~dm_db->module~dm_string module~dm_time dm_time module~dm_db->module~dm_time module~dm_util dm_util module~dm_db->module~dm_util module~dm_uuid dm_uuid module~dm_db->module~dm_uuid sqlite3 sqlite3 module~dm_db->sqlite3 module~dm_error->module~dm_kind module~dm_ascii dm_ascii module~dm_error->module~dm_ascii iso_fortran_env iso_fortran_env module~dm_kind->iso_fortran_env module~dm_sql->module~dm_ascii module~dm_string->module~dm_error module~dm_string->module~dm_kind module~dm_time->module~dm_error module~dm_time->module~dm_kind module~dm_time->module~dm_util module~dm_util->module~dm_error module~dm_util->module~dm_kind

Used by

  • module~~dm_db~~UsedByGraph module~dm_db dm_db module~dmpack dmpack module~dmpack->module~dm_db

Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: DB_JOURNAL_OFF = 0

No rollback journals.

integer, public, parameter :: DB_JOURNAL_DELETE = 1

Delete journal (default).

integer, public, parameter :: DB_JOURNAL_TRUNCATE = 2

Delete journal by truncating (may be faster than DB_JOURNAL_DELETE).

integer, public, parameter :: DB_JOURNAL_PERSIST = 3

Overwrite journal instead of deleting (may be faster than deleting or truncating).

integer, public, parameter :: DB_JOURNAL_MEMORY = 4

Store journal in memory (fast, volatile).

integer, public, parameter :: DB_JOURNAL_WAL = 5

Use Write-Ahead Log (WAL) journal.

integer, public, parameter :: DB_AUTO_VACUUM_NONE = 0

No auto-vacuum (default).

integer, public, parameter :: DB_AUTO_VACUUM_FULL = 1

Enable auto-vacuum.

integer, public, parameter :: DB_AUTO_VACUUM_INCREMENTAL = 2

Vacuum requires additional PRAGMA.

integer, public, parameter :: DB_TRANS_DEFERRED = 0

Deferred transaction (default).

integer, public, parameter :: DB_TRANS_IMMEDIATE = 1

Start a new write immediately (may fail with E_DB_BUSY).

integer, public, parameter :: DB_TRANS_EXCLUSIVE = 2

No reading while transactions are underway.

integer, public, parameter :: DB_APPLICATION_ID = int(z'444D31')

Application id of DMPACK databases (DM1 in ASCII).

integer, public, parameter :: DB_USER_VERSION = 1

Database schema version, increased on updates.

integer, public, parameter :: DB_TIMEOUT_DEFAULT = 1000

Default SQLite 3 busy timeout in mseconds.


Interfaces

public interface dm_db_begin

Starts a transaction. Public alias for db_begin().

Optional argument mode may be one of:

  • DB_TRANS_DEFERRED
  • DB_TRANS_IMMEDIATE
  • DB_TRANS_EXCLUSIVE

The default mode is DB_TRANS_DEFERRED.

  • private function db_begin(db, mode) result(rc)

    Starts a transactions in IMMEDIATE mode. Mode shall be either DB_TRANS_DEFERRED, DB_TRANS_IMMEDIATE, or DB_TRANS_EXLCUSIVE. Default is DB_TRANS_IMMEDIATE.

    The function returns the following error codes:

    • E_DB_TRANSACTION if the transaction failed.
    • E_INVALID if the transaction mode is invalid.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    integer, intent(in), optional :: mode

    Transaction mode.

    Return Value integer

public interface dm_db_insert

Generic database insert function.

  • public function dm_db_insert_beat(db, beat, db_stmt, validate) result(rc)

    Adds the given heartbeat to database. The beat data is validated by default.

    The function returns the following error codes:

    • E_DB if statement reset failed.
    • E_DB_BIND if value binding failed.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_STEP if step execution failed or no write permission.
    • E_INVALID if argument beat is invalid.
    • E_READ_ONLY if database is opened read-only.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(beat_type), intent(inout) :: beat

    Beat to insert.

    type(db_stmt_type), intent(inout), optional :: db_stmt

    Database statement type.

    logical, intent(in), optional :: validate

    Validate beat.

    Return Value integer

  • public function dm_db_insert_beats(db, beats, transaction, validate) result(rc)

    Adds array of beats to database. A transaction is used unless transaction is .false.. The beat data is validated by default.

    The function returns the following error codes:

    • E_DB if statement reset failed.
    • E_DB_BIND if value binding failed.
    • E_DB_EXEC if execution of transaction statement failed.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_ROLLBACK if transaction rollback failed.
    • E_DB_STEP if step execution failed or no write permission.
    • E_DB_TRANSACTION if transaction failed.
    • E_EMPTY if array beats is empty.
    • E_INVALID if an element in beats is invalid.
    • E_READ_ONLY if database is opened read-only.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(beat_type), intent(inout) :: beats(:)

    Beat type array.

    logical, intent(in), optional :: transaction

    Use SQL transaction.

    logical, intent(in), optional :: validate

    Validate beats.

    Return Value integer

  • public function dm_db_insert_log(db, log, validate) result(rc)

    Adds the given log to database. The log data is validated by default.

    The function returns the following error codes:

    • E_DB_BIND if value binding failed.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_STEP if step execution failed or no write permission.
    • E_INVALID if argument log is invalid.
    • E_READ_ONLY if database is opened read-only.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(log_type), intent(inout) :: log

    Log message to insert.

    logical, intent(in), optional :: validate

    Validate log.

    Return Value integer

  • public function dm_db_insert_node(db, node, validate) result(rc)

    Adds the given node to database. The node data is validated by default.

    The function returns the following error codes:

    • E_DB_BIND if value binding failed.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_STEP if step execution failed or no write permission.
    • E_INVALID if argument node is invalid.
    • E_READ_ONLY if database is opened read-only.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(node_type), intent(inout) :: node

    Node to insert.

    logical, intent(in), optional :: validate

    Validate node.

    Return Value integer

  • public function dm_db_insert_observ(db, observ, db_stmt, validate) result(rc)

    Adds single observation to database, including receivers, requests, and responses. If the insert query fails, the transaction will be rolled back, i.e., no part of the observation is written to the database on error. The observation data is validated by default.

    The function returns the following error codes:

    • E_DB if statement reset failed.
    • E_DB_BIND if value binding failed.
    • E_DB_EXEC if execution of transaction statement failed.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_ROLLBACK if transaction rollback failed.
    • E_DB_STEP if step execution failed or no write permission.
    • E_DB_TRANSACTION if transaction failed.
    • E_INVALID if argument observ is invalid.
    • E_READ_ONLY if database is opened read-only.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(observ_type), intent(inout) :: observ

    Observation type.

    type(db_stmt_type), intent(inout), optional :: db_stmt

    Database statement type.

    logical, intent(in), optional :: validate

    Validate observation.

    Return Value integer

  • public function dm_db_insert_observs(db, observs, transaction, validate) result(rc)

    Adds array of observations to database. A transaction is used unless transaction is .false.. The observation data is validated by default.

    The function returns the following error codes:

    • E_DB if statement reset failed.
    • E_DB_BIND if value binding failed.
    • E_DB_EXEC if execution of transaction statement failed.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_ROLLBACK if transaction rollback failed.
    • E_DB_STEP if step execution failed or no write permission.
    • E_DB_TRANSACTION if transaction failed.
    • E_EMPTY if array observs is empty.
    • E_INVALID if an element in observs is invalid.
    • E_READ_ONLY if database is opened read-only.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(observ_type), intent(inout) :: observs(:)

    Observation type array.

    logical, intent(in), optional :: transaction

    Use SQL transaction.

    logical, intent(in), optional :: validate

    Validate observations.

    Return Value integer

  • public function dm_db_insert_sensor(db, sensor, validate) result(rc)

    Adds given sensor to database. The sensor data is validated by default.

    The function returns the following error codes:

    • E_DB_BIND if value binding failed.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_STEP if step execution failed or no write permission.
    • E_INVALID if argument sensor is invalid.
    • E_READ_ONLY if database is opened read-only.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(sensor_type), intent(inout) :: sensor

    Sensor to insert.

    logical, intent(in), optional :: validate

    Validate sensor.

    Return Value integer

  • public function dm_db_insert_target(db, target, validate) result(rc)

    Adds given target to database. The target data is validated by default.

    The function returns the following error codes:

    • E_DB_BIND if value binding failed.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_STEP if step execution failed or no write permission.
    • E_INVALID if argument target is invalid.
    • E_READ_ONLY if database is opened read-only.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(target_type), intent(inout) :: target

    Target to insert.

    logical, intent(in), optional :: validate

    Validate target.

    Return Value integer

public interface dm_db_select

Generic database select function.

  • public function dm_db_select_beat(db, beat, node_id) result(rc)

    Returns heartbeat associated with given node id in beat.

    The function returns the following error codes:

    • E_DB_BIND if value binding failed.
    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(beat_type), intent(out) :: beat

    Returned beat type.

    character(len=*), intent(in) :: node_id

    Node id.

    Return Value integer

  • public function dm_db_select_log(db, log, log_id) result(rc)

    Returns log associated with given id in log.

    The function returns the following error codes:

    • E_DB_BIND if value binding failed.
    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(log_type), intent(out) :: log

    Returned log data.

    character(len=*), intent(in) :: log_id

    Log id.

    Return Value integer

  • public function dm_db_select_node(db, node, node_id) result(rc)

    Returns node data associated with given id in node.

    The function returns the following error codes:

    • E_DB_BIND if value binding failed.
    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(node_type), intent(out) :: node

    Returned node data.

    character(len=*), intent(in) :: node_id

    Node id.

    Return Value integer

  • public function dm_db_select_observ(db, observ, observ_id) result(rc)

    Returns observation referenced by the given id from database.

    The function returns the following error codes:

    • E_DB_BIND if value binding failed.
    • E_DB_FINALIZE if statement finalisation failed.
    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(observ_type), intent(out) :: observ

    Selected observation.

    character(len=*), intent(in) :: observ_id

    Observation id (UUID).

    Return Value integer

  • public function dm_db_select_sensor(db, sensor, sensor_id) result(rc)

    Returns sensor data associated with given sensor id from database.

    The function returns the following error codes:

    • E_DB_BIND if value binding failed.
    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(sensor_type), intent(out) :: sensor

    Returned sensor data.

    character(len=*), intent(in) :: sensor_id

    Sensor id.

    Return Value integer

  • public function dm_db_select_target(db, target, target_id) result(rc)

    Returns target data associated with given target id from database.

    The function returns the following error codes:

    • E_DB_BIND if value binding failed.
    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(target_type), intent(out) :: target

    Returned target data.

    character(len=*), intent(in) :: target_id

    Target id.

    Return Value integer

public interface dm_db_select_beats

Generic beats select function.

  • private function db_select_beats_array(db, beats, limit, nbeats) result(rc)

    Returns heatbeats from database in array beats. An optional limit may be passed in limit.

    The function returns the following error codes:

    • E_ALLOC if memory allocation failed.
    • E_DB_BIND if value binding failed.
    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(beat_type), intent(out), allocatable :: beats(:)

    Returned beat types.

    integer(kind=i8), intent(in), optional :: limit

    Max. number of beats.

    integer(kind=i8), intent(out), optional :: nbeats

    Total number of beats in database.

    Return Value integer

  • private function db_select_beats_iter(db, db_stmt, beat, limit) result(rc)

    Iterator function that returns heatbeats from database in beat. An optional limit may be passed in limit. The statement db_stmt must be finalised once finished.

    The function returns the following error codes:

    • E_DB_BIND if value binding failed.
    • E_DB_NO_ROWS if no more rows are available.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(db_stmt_type), intent(inout) :: db_stmt

    Database statement type.

    type(beat_type), intent(out) :: beat

    Returned beat type.

    integer(kind=i8), intent(in), optional :: limit

    Max. number of beats.

    Return Value integer

public interface dm_db_select_data_points

Generic data points select function.

  • private function db_select_data_points_array(db, dps, node_id, sensor_id, target_id, response_name, from, to, error, limit, npoints) result(rc)

    Returns data points from observations database in dps. This function selects only responses of error E_NONE, unless argument error is passed, then only of the given error code.

    The function returns the following error codes:

    • E_ALLOC if memory allocation failed.
    • E_DB_BIND if value binding failed.
    • E_DB_FINALIZE if statement finalisation failed.
    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(dp_type), intent(out), allocatable :: dps(:)

    Returned data points.

    character(len=*), intent(in) :: node_id

    Node id.

    character(len=*), intent(in) :: sensor_id

    Sensor id.

    character(len=*), intent(in) :: target_id

    Target id.

    character(len=*), intent(in) :: response_name

    Response name.

    character(len=*), intent(in) :: from

    Beginning of time span.

    character(len=*), intent(in) :: to

    End of time span.

    integer, intent(in), optional :: error

    Response error code.

    integer(kind=i8), intent(in), optional :: limit

    Max. number of data points.

    integer(kind=i8), intent(out), optional :: npoints

    Number of data points.

    Return Value integer

  • private function db_select_data_points_iter(db, db_stmt, dp, node_id, sensor_id, target_id, response_name, from, to, error, limit) result(rc)

    Iterator function that returns data points from observations database in dp. This function selects only responses of error E_NONE, unless argument error is passed, then only of the given error code. The statement db_stmt must be finalised once finished.

    The function returns the following error codes:

    • E_DB_BIND if value binding failed.
    • E_DB_NO_ROWS if no more rows are available.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(db_stmt_type), intent(inout) :: db_stmt

    Database statement type.

    type(dp_type), intent(out) :: dp

    Returned data point.

    character(len=*), intent(in) :: node_id

    Node id.

    character(len=*), intent(in) :: sensor_id

    Sensor id.

    character(len=*), intent(in) :: target_id

    Target id.

    character(len=*), intent(in) :: response_name

    Response name.

    character(len=*), intent(in) :: from

    Beginning of time span.

    character(len=*), intent(in) :: to

    End of time span.

    integer, intent(in), optional :: error

    Response error code.

    integer(kind=i8), intent(in), optional :: limit

    Max. number of data points.

    Return Value integer

public interface dm_db_select_json_beats

Generic JSON logs select function.

  • private function db_select_json_beats_array(db, strings, limit, nbeats) result(rc)

    Returns beats in JSON format in allocatable string type array strings.

    If no beats have been found, the array will be empty, and the function returns E_DB_NO_ROWS.

    The function returns the following error codes:

    • E_ALLOC if memory allocation failed.
    • E_DB_BIND if value binding failed.
    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(string_type), intent(out), allocatable :: strings(:)

    Returned JSON array.

    integer(kind=i8), intent(in), optional :: limit

    Max. number of beats.

    integer(kind=i8), intent(out), optional :: nbeats

    Number of beats.

    Return Value integer

  • private function db_select_json_beats_iter(db, db_stmt, json, limit) result(rc)

    Iterator function that returns beats in JSON format in allocatable string json. The statement db_stmt must be finalised once finished.

    If no beats have been found, the string will be empty, and the function returns E_DB_NO_ROWS.

    The function returns the following error codes:

    • E_DB_BIND if value binding failed.
    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(db_stmt_type), intent(inout) :: db_stmt

    Database statement type.

    character(len=:), intent(out), allocatable :: json

    Returned JSON.

    integer(kind=i8), intent(in), optional :: limit

    Max. number of beats.

    Return Value integer

public interface dm_db_select_json_logs

Generic JSON logs select function.

  • private function db_select_json_logs_array(db, strings, node_id, sensor_id, target_id, source, from, to, min_level, max_level, error, desc, limit, nlogs) result(rc)

    Returns logs in JSON format in allocatable string type array strings.

    If no logs have been found, the array will be empty, and the function returns E_DB_NO_ROWS.

    The function returns the following error codes:

    • E_ALLOC if memory allocation failed.
    • E_DB_BIND if value binding failed.
    • E_DB_FINALIZE if statement finalisation failed.
    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(string_type), intent(out), allocatable :: strings(:)

    Returned JSON array.

    character(len=*), intent(in), optional :: node_id

    Node id.

    character(len=*), intent(in), optional :: sensor_id

    Sensor id.

    character(len=*), intent(in), optional :: target_id

    Target id.

    character(len=*), intent(in), optional :: source

    Source name.

    character(len=*), intent(in), optional :: from

    Begin of time range.

    character(len=*), intent(in), optional :: to

    End of time range.

    integer, intent(in), optional :: min_level

    Minimum log level.

    integer, intent(in), optional :: max_level

    Maximum log level.

    integer, intent(in), optional :: error

    Error code.

    logical, intent(in), optional :: desc

    Descending order.

    integer(kind=i8), intent(in), optional :: limit

    Max. numbers of logs.

    integer(kind=i8), intent(out), optional :: nlogs

    Number of logs.

    Return Value integer

  • private function db_select_json_logs_iter(db, db_stmt, json, node_id, sensor_id, target_id, source, from, to, min_level, max_level, error, desc, limit) result(rc)

    Iterator function that returns logs in JSON format in allocatable character json. The statement db_stmt must be finalised once finished.

    If no logs have been found, the string will be empty, and the function returns E_DB_NO_ROWS.

    The function returns the following error codes:

    • E_DB_BIND if value binding failed.
    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(db_stmt_type), intent(inout) :: db_stmt

    Database statement type.

    character(len=:), intent(out), allocatable :: json

    Returned JSON.

    character(len=*), intent(in), optional :: node_id

    Node id.

    character(len=*), intent(in), optional :: sensor_id

    Sensor id.

    character(len=*), intent(in), optional :: target_id

    Target id.

    character(len=*), intent(in), optional :: source

    Source name.

    character(len=*), intent(in), optional :: from

    Begin of time range.

    character(len=*), intent(in), optional :: to

    End of time range.

    integer, intent(in), optional :: min_level

    Minimum log level.

    integer, intent(in), optional :: max_level

    Maximum log level.

    integer, intent(in), optional :: error

    Error code.

    logical, intent(in), optional :: desc

    Descending order.

    integer(kind=i8), intent(in), optional :: limit

    Max. numbers of logs.

    Return Value integer

public interface dm_db_select_json_nodes

Generic JSON nodes select function.

  • private function db_select_json_nodes_array(db, strings, limit, nnodes) result(rc)

    Returns nodes in JSON format in allocatable string type array strings.

    If no nodes have been found, the array will be empty, and the function returns E_DB_NO_ROWS.

    The function returns the following error codes:

    • E_ALLOC if memory allocation failed.
    • E_DB_BIND if value binding failed.
    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(string_type), intent(out), allocatable :: strings(:)

    Returned JSON array.

    integer(kind=i8), intent(in), optional :: limit

    Max. number of nodes.

    integer(kind=i8), intent(out), optional :: nnodes

    Number of nodes.

    Return Value integer

  • private function db_select_json_nodes_iter(db, db_stmt, json, limit) result(rc)

    Iterator function that returns nodes in JSON format in allocatable string json. The statement db_stmt must be finalised once finished.

    If no nodes have been found, the string will be empty, and the function returns E_DB_NO_ROWS.

    The function returns the following error codes:

    • E_DB_BIND if value binding failed.
    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(db_stmt_type), intent(inout) :: db_stmt

    Database statement type.

    character(len=:), intent(out), allocatable :: json

    Returned JSON.

    integer(kind=i8), intent(in), optional :: limit

    Max. number of nodes.

    Return Value integer

public interface dm_db_select_logs

Generic logs select function.

  • private function db_select_logs_array(db, logs, node_id, sensor_id, target_id, source, from, to, min_level, max_level, error, desc, limit, nlogs) result(rc)

    Returns logs in allocatable array logs.

    The function returns the following error codes:

    • E_ALLOC if memory allocation failed.
    • E_DB_BIND if value binding failed.
    • E_DB_FINALIZE if statement finalisation failed.
    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(log_type), intent(out), allocatable :: logs(:)

    Returned log data array.

    character(len=*), intent(in), optional :: node_id

    Node id.

    character(len=*), intent(in), optional :: sensor_id

    Sensor id.

    character(len=*), intent(in), optional :: target_id

    Target id.

    character(len=*), intent(in), optional :: source

    Source name.

    character(len=*), intent(in), optional :: from

    Begin of time range.

    character(len=*), intent(in), optional :: to

    End of time range.

    integer, intent(in), optional :: min_level

    Minimum log level.

    integer, intent(in), optional :: max_level

    Maximum log level.

    integer, intent(in), optional :: error

    Error code.

    logical, intent(in), optional :: desc

    Descending order.

    integer(kind=i8), intent(in), optional :: limit

    Max. numbers of logs.

    integer(kind=i8), intent(out), optional :: nlogs

    Total number of logs.

    Return Value integer

  • private function db_select_logs_iter(db, db_stmt, log, node_id, sensor_id, target_id, source, from, to, min_level, max_level, error, desc, limit) result(rc)

    Iterator function that returns logs in logs. The statement db_stmt must be finalised once finished.

    The function returns the following error codes:

    • E_DB_BIND if value binding failed.
    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(db_stmt_type), intent(inout) :: db_stmt

    Database statement type.

    type(log_type), intent(out) :: log

    Returned log type.

    character(len=*), intent(in), optional :: node_id

    Node id.

    character(len=*), intent(in), optional :: sensor_id

    Sensor id.

    character(len=*), intent(in), optional :: target_id

    Target id.

    character(len=*), intent(in), optional :: source

    Source name.

    character(len=*), intent(in), optional :: from

    Begin of time range.

    character(len=*), intent(in), optional :: to

    End of time range.

    integer, intent(in), optional :: min_level

    Minimum log level.

    integer, intent(in), optional :: max_level

    Maximum log level.

    integer, intent(in), optional :: error

    Error code.

    logical, intent(in), optional :: desc

    Descending order.

    integer(kind=i8), intent(in), optional :: limit

    Max. numbers of logs.

    Return Value integer

public interface dm_db_select_nodes

Generic nodes select function.

  • private function db_select_nodes_array(db, nodes, nnodes) result(rc)

    Returns all sensor nodes in allocatable array nodes.

    The function returns the following error codes:

    • E_ALLOC if memory allocation failed.
    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(node_type), intent(out), allocatable :: nodes(:)

    Returned node data array.

    integer(kind=i8), intent(out), optional :: nnodes

    Number of nodes.

    Return Value integer

  • private function db_select_nodes_iter(db, db_stmt, node) result(rc)

    Iterator function that returns all sensor nodes in node. The statement db_stmt must be finalised once finished.

    The function returns the following error codes:

    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(db_stmt_type), intent(inout) :: db_stmt

    Database statement type.

    type(node_type), intent(out) :: node

    Returned node data.

    Return Value integer

public interface dm_db_select_observs

Generic observations select function.

  • private function db_select_observs_array(db, observs, node_id, sensor_id, target_id, from, to, desc, limit, stub, nobservs) result(rc)

    Returns observations in observs, with optional node id, sensor id, target id, from, to. By default, observations are returned in ascending order, unless desc is passed and .true.. The maximum number of observations may be passed in limit.

    The stub is .true., neither receivers nor requests are read from database.

    The total number of observations is returned in optional argument nobservs.

    Calling this function is usually slower than db_select_observs_by_id() or db_select_observs_by_time().

    The function returns the following error codes:

    • E_ALLOC if memory allocation failed.
    • E_DB_BIND if value binding failed.
    • E_DB_FINALIZE if statement finalisation failed.
    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(observ_type), intent(out), allocatable :: observs(:)

    Returned observation data.

    character(len=*), intent(in), optional :: node_id

    Node id.

    character(len=*), intent(in), optional :: sensor_id

    Sensor id.

    character(len=*), intent(in), optional :: target_id

    Target id.

    character(len=*), intent(in), optional :: from

    Beginning of time span.

    character(len=*), intent(in), optional :: to

    End of time span.

    logical, intent(in), optional :: desc

    Descending order.

    integer(kind=i8), intent(in), optional :: limit

    Max. number of observations.

    logical, intent(in), optional :: stub

    Without receivers, requests, responses.

    integer(kind=i8), intent(out), optional :: nobservs

    Total number of observations (may be greater than limit).

    Return Value integer

  • private function db_select_observs_iter(db, db_stmt, observ, node_id, sensor_id, target_id, from, to, desc, limit, stub) result(rc)

    Iterator function that returns observations in observ, with optional node id, sensor id, target id, from, to. By default, observations are returned in ascending order, unless desc is passed and .true.. The maximum number of observations may be passed in limit. The statement db_stmt must be finalised once finished.

    The stub is .true., neither receivers nor requests are read from database.

    The function returns the following error codes:

    • E_DB_BIND if value binding failed.
    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(db_stmt_type), intent(inout) :: db_stmt

    Database statement type.

    type(observ_type), intent(out) :: observ

    Returned observation type.

    character(len=*), intent(in), optional :: node_id

    Node id.

    character(len=*), intent(in), optional :: sensor_id

    Sensor id.

    character(len=*), intent(in), optional :: target_id

    Target id.

    character(len=*), intent(in), optional :: from

    Beginning of time span.

    character(len=*), intent(in), optional :: to

    End of time span.

    logical, intent(in), optional :: desc

    Descending order.

    integer(kind=i8), intent(in), optional :: limit

    Max. number of observations.

    logical, intent(in), optional :: stub

    Without receivers, requests, responses.

    Return Value integer

public interface dm_db_select_sensors

Generic sensors select function.

  • private function db_select_sensors_array(db, sensors, nsensors) result(rc)

    Returns all sensors in allocatable array sensors.

    The function returns the following error codes:

    • E_ALLOC if memory allocation failed.
    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(sensor_type), intent(out), allocatable :: sensors(:)

    Returned sensor data array.

    integer(kind=i8), intent(out), optional :: nsensors

    Number of returned sensors.

    Return Value integer

  • private function db_select_sensors_iter(db, db_stmt, sensor) result(rc)

    Iterator function that returns all sensors in sensor. The statement db_stmt must be finalised once finished.

    The function returns the following error codes:

    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(db_stmt_type), intent(inout) :: db_stmt

    Database statement type.

    type(sensor_type), intent(out) :: sensor

    Returned sensor data.

    Return Value integer

  • private function db_select_sensors_by_node_array(db, node_id, sensors, nsensors) result(rc)

    Returns all sensors of node node_id in allocatable array sensors.

    The function returns the following error codes:

    • E_ALLOC if memory allocation failed.
    • E_INVALID if node id is empty.
    • E_DB_BIND if value binding failed.
    • E_DB_FINALIZE if statement finalisation failed.
    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    character(len=*), intent(in) :: node_id

    Node id.

    type(sensor_type), intent(out), allocatable :: sensors(:)

    Returned sensor data array.

    integer(kind=i8), intent(out), optional :: nsensors

    Number of returned sensors.

    Return Value integer

  • private function db_select_sensors_by_node_iter(db, db_stmt, node_id, sensor) result(rc)

    Iterator function that returns all sensors of node node_id in sensor. The statement db_stmt must be finalised once finished.

    The function returns the following error codes:

    • E_INVALID if node id is empty.
    • E_DB_BIND if value binding failed.
    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(db_stmt_type), intent(inout) :: db_stmt

    Database statement type.

    character(len=*), intent(in) :: node_id

    Node id.

    type(sensor_type), intent(out) :: sensor

    Returned sensor data.

    Return Value integer

public interface dm_db_select_targets

Generic targets select function.

  • private function db_select_targets_array(db, targets, ntargets) result(rc)

    Returns number of targets and array of target data in allocatable array targets, if query was successful.

    The function returns the following error codes:

    • E_ALLOC if memory allocation failed.
    • E_DB_NO_ROWS if no rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(target_type), intent(out), allocatable :: targets(:)

    Target data array.

    integer(kind=i8), intent(out), optional :: ntargets

    Number of selected targets.

    Return Value integer

  • private function db_select_targets_iter(db, db_stmt, target) result(rc)

    Iterator function that returns all targets in target. The statement db_stmt must be finalised once finished.

    The function returns the following error codes:

    • E_DB_NO_ROWS if no more rows are returned.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(db_stmt_type), intent(inout) :: db_stmt

    Database statement type.

    type(target_type), intent(out) :: target

    Target data.

    Return Value integer

public interface dm_db_update

Generic database update function.

  • public function dm_db_update_node(db, node, validate) result(rc)

    Updates the given node in database. The node data is validated by default.

    The function returns the following error codes:

    • E_DB_BIND if value binding failed.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_STEP if step execution failed or no write permission.
    • E_INVALID if node is invalid.
    • E_READ_ONLY if database is opened read-only.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(node_type), intent(inout) :: node

    Node to update.

    logical, intent(in), optional :: validate

    Validate node.

    Return Value integer

  • public function dm_db_update_sensor(db, sensor, validate) result(rc)

    Updates given sensor in database. The sensor data is validated by default.

    The function returns the following error codes:

    • E_DB_BIND if value binding failed.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_STEP if step execution failed or no write permission.
    • E_INVALID if sensor is invalid.
    • E_READ_ONLY if database is opened read-only.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(sensor_type), intent(inout) :: sensor

    Sensor to update.

    logical, intent(in), optional :: validate

    Validate sensor.

    Return Value integer

  • public function dm_db_update_target(db, target, validate) result(rc)

    Updates the given target in database. The target data is validated by default.

    The function returns the following error codes:

    • E_DB_BIND if value binding failed.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_STEP if step execution failed or no write permission.
    • E_INVALID if target is invalid.
    • E_READ_ONLY if database is opened read-only.

    Arguments

    Type IntentOptional Attributes Name
    type(db_type), intent(inout) :: db

    Database type.

    type(target_type), intent(inout) :: target

    Target to update.

    logical, intent(in), optional :: validate

    Validate target.

    Return Value integer


Abstract Interfaces

abstract interface

  • public function dm_db_busy_callback(client_data, n) bind(c)

    C-interoperable callback function that is invoked on error SQL_BUSY. May return 0 to signal that no more invocations are desired.

    Arguments

    Type IntentOptional Attributes Name
    type(c_ptr), intent(in), value :: client_data

    Client data.

    integer(kind=c_int), intent(in), value :: n

    Number of times the busy callback has been invoked previously.

    Return Value integer(kind=c_int)

    Returns value.

abstract interface

  • public subroutine dm_db_backup_callback(remaining, page_count)

    Callback routine that is invoked if passed to dm_db_backup().

    Arguments

    Type IntentOptional Attributes Name
    integer, intent(in) :: remaining

    Remaining pages.

    integer, intent(in) :: page_count

    Total number of pages.

abstract interface

  • public subroutine dm_db_log_callback(client_data, err_code, err_msg_ptr) bind(c)

    C-interoperable callback routine that is invoked for each created SQLite log.

    Arguments

    Type IntentOptional Attributes Name
    type(c_ptr), intent(in), value :: client_data

    Client data.

    integer(kind=c_int), intent(in), value :: err_code

    SQLite error code.

    type(c_ptr), intent(in), value :: err_msg_ptr

    SQLite error message.

abstract interface

  • public subroutine dm_db_update_callback(client_data, type, db_name, table_name, row_id) bind(c)

    C-interoperable callback routine that is invoked on database updates.

    Arguments

    Type IntentOptional Attributes Name
    type(c_ptr), intent(in), value :: client_data

    Client data.

    integer(kind=c_int), intent(in), value :: type

    Database operation.

    type(c_ptr), intent(in), value :: db_name

    Database name.

    type(c_ptr), intent(in), value :: table_name

    Table name.

    integer(kind=c_int64_t), intent(in), value :: row_id

    Row id.


Derived Types

type, public ::  db_type

Opaque SQLite database connectivity type.

type, public ::  db_stmt_type

Opaque SQLite database statement type.


Functions

public function dm_db_attach(db, path, name) result(rc)

Attaches the database at path to the current connection. If no name is passed for the attached database, the name will be set to attached. The function trims the given path and name strings.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

character(len=*), intent(in) :: path

Path of database to attach.

character(len=*), intent(in), optional :: name

Name of attached database.

Return Value integer

public function dm_db_backup(db, path, wal, callback, nsteps, sleep_time) result(rc)

Creates online backup of given database. The functions assumes 500 steps and a sleep time of 250 msec by default, if the arguments are not passed.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

character(len=*), intent(in) :: path

File path of backup database to be created.

logical, intent(in), optional :: wal

Enable WAL mode for backup.

procedure(dm_db_backup_callback), optional :: callback

Progress callback routine.

integer, intent(in), optional :: nsteps

Number of steps per iteration (default: 500).

integer, intent(in), optional :: sleep_time

Sleep time per iteration in msec (default: 250 msec).

Return Value integer

public function dm_db_close(db, optimize) result(rc)

Closes connection to SQLite database. Optimises the database if optimize is .true.. Returns E_DB on error.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

logical, intent(in), optional :: optimize

Optimise on close.

Return Value integer

public function dm_db_commit(db) result(rc)

Ends transaction and commits changes to database. On error, does a rollback automatically. Returns E_DB_ROLLBACK if the rollback failed.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

Return Value integer

public function dm_db_count_beats(db, n) result(rc)

Returns number of rows in table beats.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer(kind=i8), intent(out) :: n

Number of rows in table.

Return Value integer

public function dm_db_count_logs(db, n) result(rc)

Returns number of rows in table logs.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer(kind=i8), intent(out) :: n

Number of rows in table.

Return Value integer

public function dm_db_count_nodes(db, n) result(rc)

Returns number of rows in table nodes.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer(kind=i8), intent(out) :: n

Number of rows in table.

Return Value integer

public function dm_db_count_observs(db, n) result(rc)

Returns number of rows in table observs.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer(kind=i8), intent(out) :: n

Number of rows in table.

Return Value integer

public function dm_db_count_receivers(db, n) result(rc)

Returns number of rows in table receivers.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer(kind=i8), intent(out) :: n

Number of rows in table.

Return Value integer

public function dm_db_count_requests(db, n) result(rc)

Returns number of rows in table requests.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer(kind=i8), intent(out) :: n

Number of rows in table.

Return Value integer

public function dm_db_count_responses(db, n) result(rc)

Returns number of rows in table responses.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer(kind=i8), intent(out) :: n

Number of rows in table.

Return Value integer

public function dm_db_count_sensors(db, n) result(rc)

Returns number of rows in table sensors.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer(kind=i8), intent(out) :: n

Number of rows in table.

Return Value integer

public function dm_db_count_targets(db, n) result(rc)

Returns number of rows in table sensors.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer(kind=i8), intent(out) :: n

Number of rows in table.

Return Value integer

public function dm_db_count_sync_logs(db, n) result(rc)

Returns number of rows in table sync_logs.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer(kind=i8), intent(out) :: n

Number of rows in table.

Return Value integer

public function dm_db_count_sync_nodes(db, n) result(rc)

Returns number of rows in table sync_nodes.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer(kind=i8), intent(out) :: n

Number of rows in table.

Return Value integer

public function dm_db_count_sync_observs(db, n) result(rc)

Returns number of rows in table sync_observs.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer(kind=i8), intent(out) :: n

Number of rows in table.

Return Value integer

public function dm_db_count_sync_sensors(db, n) result(rc)

Returns number of rows in table sync_sensors.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer(kind=i8), intent(out) :: n

Number of rows in table.

Return Value integer

public function dm_db_count_sync_targets(db, n) result(rc)

Returns number of rows in table sync_sensors.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer(kind=i8), intent(out) :: n

Number of rows in table.

Return Value integer

public function dm_db_create_beats(db) result(rc)

Creates logs table in given database.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

Return Value integer

public function dm_db_create_logs(db, sync) result(rc)

Creates logs table in given database.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

logical, intent(in), optional :: sync

Create synchronisation tables.

Return Value integer

public function dm_db_create_observs(db, sync) result(rc)

Initialises a connected SQLite 3 database by creating all necessary tables if they do not exist already. The function also creates additional indices and triggers on the tables.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

logical, intent(in), optional :: sync

Create synchronisation tables.

Return Value integer

public function dm_db_delete_beat(db, node_id) result(rc)

Deletes heartbeat from database.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

character(len=*), intent(in) :: node_id

Node id.

Return Value integer

public function dm_db_delete_log(db, log_id) result(rc)

Deletes log from database.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

character(len=*), intent(in) :: log_id

Log id.

Return Value integer

public function dm_db_delete_node(db, node_id) result(rc)

Deletes node from database.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

character(len=*), intent(in) :: node_id

Node id.

Return Value integer

public function dm_db_delete_observ(db, observ_id) result(rc)

Deletes observation from database. The function expects the SQLite trigger delete_observ_trigger as defined in module dm_sql to be present in the database, in order to delete receivers, requests, and responses automatically.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

character(len=*), intent(in) :: observ_id

Observation id.

Return Value integer

public function dm_db_delete_sensor(db, sensor_id) result(rc)

Deletes sensor of given id from database.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

character(len=*), intent(in) :: sensor_id

Sensor id.

Return Value integer

public function dm_db_delete_target(db, target_id) result(rc)

Deletes target from database.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

character(len=*), intent(in) :: target_id

Target id.

Return Value integer

public function dm_db_detach(db, name) result(rc)

Detaches database from the current connection. If no name is passed for the attached database, the name is assumed to be attached. The function trims the given name string. Returns E_DB_DETACH on error.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

character(len=*), intent(in), optional :: name

Name of attached database.

Return Value integer

public function dm_db_error(db, sqlite_error) result(rc)

Returns last database error as DMPACK error code, optionally the SQLite error code in argument sqlite_error. This function matches an SQLite error code to the corresponding DMPACK error code. For example, if the last SQLite error is SQLITE_OK, the function returns E_NONE.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer, intent(out), optional :: sqlite_error

SQLite error code.

Return Value integer

public function dm_db_error_message(db) result(message)

Returns last SQLite error message.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

Return Value character(len=:), allocatable

Error message.

public function dm_db_finalize(db_stmt) result(rc)

Finalises given database statement. Returns E_DB_FINALIZE on error.

Arguments

Type IntentOptional Attributes Name
type(db_stmt_type), intent(inout) :: db_stmt

Database statement type.

Return Value integer

public function dm_db_get_application_id(db, id) result(rc)

Returns application id of database in id.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer, intent(out) :: id

Database application id.

Return Value integer

public function dm_db_get_data_version(db, version) result(rc)

Returns data version in version.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer, intent(out) :: version

Data version.

Return Value integer

public function dm_db_get_foreign_keys(db, enabled) result(rc)

Returns status of foreign keys contraint in enabled.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

logical, intent(out) :: enabled

Foreign keys constraint is enabled.

Return Value integer

public function dm_db_get_journal_mode(db, mode, name) result(rc)

Returns journal mode of database in mode. The name of the mode is optionally passed in name.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer, intent(out) :: mode

Journal mode.

character(len=:), intent(out), optional, allocatable :: name

Journal mode name.

Return Value integer

public function dm_db_get_query_only(db, enabled) result(rc)

Returns status of query-only pragma in enabled.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

logical, intent(out) :: enabled

Query-only mode is enabled.

Return Value integer

public function dm_db_get_user_version(db, version) result(rc)

Returns user version of database in version.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer, intent(out) :: version

Database user version.

Return Value integer

public function dm_db_has_log(db, log_id) result(has)

Returns .true. if log id exists.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

character(len=*), intent(in) :: log_id

Log id (UUID).

Return Value logical

public function dm_db_has_node(db, node_id) result(has)

Returns .true. if node id exists.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

character(len=*), intent(in) :: node_id

Node id.

Return Value logical

public function dm_db_has_observ(db, observ_id) result(has)

Returns .true. if observation id exists.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

character(len=*), intent(in) :: observ_id

Observation id (UUID).

Return Value logical

public function dm_db_has_table(db, table) result(has)

Returns .true. if given table exists in database.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer, intent(in) :: table

Table enumerator.

Return Value logical

public function dm_db_has_target(db, target_id) result(has)

Returns .true. if target id exists.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

character(len=*), intent(in) :: target_id

Target id.

Return Value logical

public function dm_db_init() result(rc)

Initialises SQLite backend. Returns E_DB on error.

Arguments

None

Return Value integer

public function dm_db_insert_beat(db, beat, db_stmt, validate) result(rc)

Adds the given heartbeat to database. The beat data is validated by default.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(beat_type), intent(inout) :: beat

Beat to insert.

type(db_stmt_type), intent(inout), optional :: db_stmt

Database statement type.

logical, intent(in), optional :: validate

Validate beat.

Return Value integer

public function dm_db_insert_beats(db, beats, transaction, validate) result(rc)

Adds array of beats to database. A transaction is used unless transaction is .false.. The beat data is validated by default.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(beat_type), intent(inout) :: beats(:)

Beat type array.

logical, intent(in), optional :: transaction

Use SQL transaction.

logical, intent(in), optional :: validate

Validate beats.

Return Value integer

public function dm_db_insert_log(db, log, validate) result(rc)

Adds the given log to database. The log data is validated by default.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(log_type), intent(inout) :: log

Log message to insert.

logical, intent(in), optional :: validate

Validate log.

Return Value integer

public function dm_db_insert_node(db, node, validate) result(rc)

Adds the given node to database. The node data is validated by default.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(node_type), intent(inout) :: node

Node to insert.

logical, intent(in), optional :: validate

Validate node.

Return Value integer

public function dm_db_insert_observ(db, observ, db_stmt, validate) result(rc)

Adds single observation to database, including receivers, requests, and responses. If the insert query fails, the transaction will be rolled back, i.e., no part of the observation is written to the database on error. The observation data is validated by default.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(observ_type), intent(inout) :: observ

Observation type.

type(db_stmt_type), intent(inout), optional :: db_stmt

Database statement type.

logical, intent(in), optional :: validate

Validate observation.

Return Value integer

public function dm_db_insert_observs(db, observs, transaction, validate) result(rc)

Adds array of observations to database. A transaction is used unless transaction is .false.. The observation data is validated by default.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(observ_type), intent(inout) :: observs(:)

Observation type array.

logical, intent(in), optional :: transaction

Use SQL transaction.

logical, intent(in), optional :: validate

Validate observations.

Return Value integer

public function dm_db_insert_sensor(db, sensor, validate) result(rc)

Adds given sensor to database. The sensor data is validated by default.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(sensor_type), intent(inout) :: sensor

Sensor to insert.

logical, intent(in), optional :: validate

Validate sensor.

Return Value integer

public function dm_db_insert_sync(db, sync) result(rc)

Wrapper function that inserts or replaces given sync data into database. Sync data must have a valid type.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(sync_type), intent(inout) :: sync

Sync data to insert.

Return Value integer

public function dm_db_insert_sync_log(db, sync) result(rc)

Inserts or replaces given log sync data into database.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(sync_type), intent(inout) :: sync

Sync data to insert.

Return Value integer

public function dm_db_insert_sync_node(db, sync) result(rc)

Inserts or replaces given node sync data into database.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(sync_type), intent(inout) :: sync

Sync data to insert.

Return Value integer

public function dm_db_insert_sync_observ(db, sync) result(rc)

Inserts or replaces given observation sync data into database.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(sync_type), intent(inout) :: sync

Sync data to insert.

Return Value integer

public function dm_db_insert_sync_sensor(db, sync) result(rc)

Inserts or replaces given sensor sync data into database.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(sync_type), intent(inout) :: sync

Sync data to insert.

Return Value integer

public function dm_db_insert_sync_target(db, sync) result(rc)

Inserts or replaces given target sync data into database.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(sync_type), intent(inout) :: sync

Sync data to insert.

Return Value integer

public function dm_db_insert_target(db, target, validate) result(rc)

Adds given target to database. The target data is validated by default.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(target_type), intent(inout) :: target

Target to insert.

logical, intent(in), optional :: validate

Validate target.

Return Value integer

public function dm_db_is_connected(db) result(connected)

Returns .true. if database type has associated pointer.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

Return Value logical

public function dm_db_is_read_only(db) result(read_only)

Returns .true. if database is in read-only mode. This function checks only the opaque database type for the read-only flag. It is still possible to enable ready-only access by calling dm_db_set_query_only(). The function dm_db_get_query_only() returns the status of the query_only pragma.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

Return Value logical

public function dm_db_is_threadsafe() result(safe)

Returns true if SQLite 3 was compiled threadsafe.

Arguments

None

Return Value logical

public function dm_db_open(db, path, create, foreign_keys, read_only, threaded, timeout, validate, wal) result(rc)

Opens connection to the SQLite database at path, or creates a new database with given file path if create is passed and .true.. The foreign key constraint is enabled unless foreign_keys is .false..

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

character(len=*), intent(in) :: path

File path of database.

logical, intent(in), optional :: create

Create flag (off by default).

logical, intent(in), optional :: foreign_keys

Foreign keys contraint flag (on by default).

logical, intent(in), optional :: read_only

Read-only mode (off by default).

logical, intent(in), optional :: threaded

Threaded access flag (off by default).

integer, intent(in), optional :: timeout

Busy timeout in mseconds (0 by default).

logical, intent(in), optional :: validate

Validate application id (off by default).

logical, intent(in), optional :: wal

WAL journal mode flag (off by default).

Return Value integer

public function dm_db_optimize(db) result(rc)

Attempts to optimise the database. All schemas are optimised.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

Return Value integer

public function dm_db_prepared(db_stmt) result(prepared)

Returns .true. if given statement has been prepared.

Arguments

Type IntentOptional Attributes Name
type(db_stmt_type), intent(inout) :: db_stmt

Return Value logical

public function dm_db_rollback(db) result(rc)

Rolls a transaction back. Returns E_DB_ROLLBACK on error.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

Return Value integer

public function dm_db_select_beat(db, beat, node_id) result(rc)

Returns heartbeat associated with given node id in beat.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(beat_type), intent(out) :: beat

Returned beat type.

character(len=*), intent(in) :: node_id

Node id.

Return Value integer

public function dm_db_select_json_beat(db, json, node_id) result(rc)

Returns heartbeat associated with given node id as allocatable character json in JSON format.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

character(len=:), intent(out), allocatable :: json

Returned JSON.

character(len=*), intent(in) :: node_id

Node id.

Return Value integer

public function dm_db_select_json_log(db, json, log_id) result(rc)

Returns log associated with given id as allocatable character in JSON format in json. If no log has been found, the string will be empty and the function returns E_DB_NO_ROWS.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

character(len=:), intent(out), allocatable :: json

Returned JSON.

character(len=*), intent(in) :: log_id

Log id.

Return Value integer

public function dm_db_select_json_node(db, json, node_id) result(rc)

Returns nodes associated with given node id as allocatable character json in JSON format.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

character(len=:), intent(out), allocatable :: json

Returned JSON.

character(len=*), intent(in) :: node_id

Node id.

Return Value integer

public function dm_db_select_log(db, log, log_id) result(rc)

Returns log associated with given id in log.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(log_type), intent(out) :: log

Returned log data.

character(len=*), intent(in) :: log_id

Log id.

Return Value integer

public function dm_db_select_logs_by_observ(db, logs, observ_id, nlogs) result(rc)

Returns logs by observation id in allocatable array logs.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(log_type), intent(out), allocatable :: logs(:)

Returned log data array.

character(len=*), intent(in) :: observ_id

Observation id.

integer(kind=i8), intent(out), optional :: nlogs

Number of logs.

Return Value integer

public function dm_db_select_node(db, node, node_id) result(rc)

Returns node data associated with given id in node.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(node_type), intent(out) :: node

Returned node data.

character(len=*), intent(in) :: node_id

Node id.

Return Value integer

public function dm_db_select_observ(db, observ, observ_id) result(rc)

Returns observation referenced by the given id from database.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(observ_type), intent(out) :: observ

Selected observation.

character(len=*), intent(in) :: observ_id

Observation id (UUID).

Return Value integer

public function dm_db_select_observ_ids(db, ids, node_id, sensor_id, target_id, from, to, desc, limit, nids) result(rc)

Returns observation ids in ids, with optional node id, sensor id, target id, from, to. By default, ids are returned ordered by ascending observation timestamp, unless desc is passed and .true.. The maximum number of ids may be passed in limit.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

character(len=ID_LEN), intent(out), allocatable :: ids(:)

Returned observation ids.

character(len=*), intent(in), optional :: node_id

Node id.

character(len=*), intent(in), optional :: sensor_id

Sensor id.

character(len=*), intent(in), optional :: target_id

Target id.

character(len=*), intent(in), optional :: from

Beginning of time span.

character(len=*), intent(in), optional :: to

End of time span.

logical, intent(in), optional :: desc

Descending order.

integer(kind=i8), intent(in), optional :: limit

Max. number of observations.

integer(kind=i8), intent(out), optional :: nids

Total number of observation ids (may be greater than limit).

Return Value integer

public function dm_db_select_observ_views(db, views, node_id, sensor_id, target_id, response_name, from, to, limit, nviews) result(rc)

Returns observation views of the given time range from database.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(observ_view_type), intent(out), allocatable :: views(:)

Returned observation views.

character(len=*), intent(in) :: node_id

Node id.

character(len=*), intent(in) :: sensor_id

Sensor id.

character(len=*), intent(in) :: target_id

Target id.

character(len=*), intent(in) :: response_name

Response name.

character(len=*), intent(in) :: from

Beginning of time span.

character(len=*), intent(in) :: to

End of time span.

integer(kind=i8), intent(in), optional :: limit

Max. number of views.

integer(kind=i8), intent(out), optional :: nviews

Total number of views (may be greater than limit).

Return Value integer

public function dm_db_select_observs_by_id(db, observs, after, before, limit, stub, nobservs) result(rc)

Returns observations of a given id range in observs. The argument after is the id of the observation after which the range starts, before the id of the observation that limits the range.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(observ_type), intent(out), allocatable :: observs(:)

Returned observation data.

character(len=*), intent(in) :: after

Id of observation with timestamp before first of range.

character(len=*), intent(in), optional :: before

Id of observation with timestamp after last of range.

integer(kind=i8), intent(in), optional :: limit

Max. number of observations.

logical, intent(in), optional :: stub

Without receivers, requests, responses.

integer(kind=i8), intent(out), optional :: nobservs

Total number of observations (may be greater than limit).

Return Value integer

public function dm_db_select_observs_by_time(db, observs, node_id, sensor_id, target_id, from, to, limit, stub, nobservs) result(rc)

Returns observations of a given time span in observs.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(observ_type), intent(out), allocatable :: observs(:)

Returned observation data.

character(len=*), intent(in) :: node_id

Node id.

character(len=*), intent(in) :: sensor_id

Sensor id.

character(len=*), intent(in) :: target_id

Target id.

character(len=*), intent(in) :: from

Beginning of time span.

character(len=*), intent(in) :: to

End of time span.

integer(kind=i8), intent(in), optional :: limit

Max. number of observations.

logical, intent(in), optional :: stub

No receivers, requests, responses.

integer(kind=i8), intent(out), optional :: nobservs

Total number of observations (may be greater than limit).

Return Value integer

public function dm_db_select_sensor(db, sensor, sensor_id) result(rc)

Returns sensor data associated with given sensor id from database.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(sensor_type), intent(out) :: sensor

Returned sensor data.

character(len=*), intent(in) :: sensor_id

Sensor id.

Return Value integer

public function dm_db_select_sync_log(db, sync) result(rc)

Returns log synchronisation data (oldest not transmitted log).

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(sync_type), intent(out) :: sync

Returned sync data.

Return Value integer

public function dm_db_select_sync_logs(db, syncs, nsyncs, limit) result(rc)

Returns log synchronisation data.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(sync_type), intent(out), allocatable :: syncs(:)

Returned sync data.

integer(kind=i8), intent(out), optional :: nsyncs

Array size.

integer(kind=i8), intent(in), optional :: limit

Max. number of sync data to fetch.

Return Value integer

public function dm_db_select_sync_node(db, sync) result(rc)

Returns node synchronisation data (oldest not transmitted node).

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(sync_type), intent(out) :: sync

Returned sync data.

Return Value integer

public function dm_db_select_sync_nodes(db, syncs, nsyncs, limit) result(rc)

Returns node synchronisation data.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(sync_type), intent(out), allocatable :: syncs(:)

Returned sync data.

integer(kind=i8), intent(out), optional :: nsyncs

Array size.

integer(kind=i8), intent(in), optional :: limit

Max. number of sync data to fetch.

Return Value integer

public function dm_db_select_sync_observ(db, sync) result(rc)

Returns observation synchronisation data (oldest not transmitted observation).

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(sync_type), intent(out) :: sync

Returned sync data.

Return Value integer

public function dm_db_select_sync_observs(db, syncs, nsyncs, limit) result(rc)

Returns observation synchronisation data.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(sync_type), intent(out), allocatable :: syncs(:)

Returned sync data.

integer(kind=i8), intent(out), optional :: nsyncs

Array size.

integer(kind=i8), intent(in), optional :: limit

Max. number of sync data to fetch.

Return Value integer

public function dm_db_select_sync_sensor(db, sync) result(rc)

Returns sensor synchronisation data (oldest not transmitted sensor).

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(sync_type), intent(out) :: sync

Returned sync data.

Return Value integer

public function dm_db_select_sync_sensors(db, syncs, nsyncs, limit) result(rc)

Returns sensor synchronisation data.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(sync_type), intent(out), allocatable :: syncs(:)

Returned sync data.

integer(kind=i8), intent(out), optional :: nsyncs

Array size.

integer(kind=i8), intent(in), optional :: limit

Max. number of sync data to fetch.

Return Value integer

public function dm_db_select_sync_target(db, sync) result(rc)

Returns target synchronisation data (oldest not transmitted target).

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(sync_type), intent(out) :: sync

Returned sync data.

Return Value integer

public function dm_db_select_sync_targets(db, syncs, nsyncs, limit) result(rc)

Returns sensor synchronisation data.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(sync_type), intent(out), allocatable :: syncs(:)

Returned sync data.

integer(kind=i8), intent(out), optional :: nsyncs

Array size.

integer(kind=i8), intent(in), optional :: limit

Max. number of sync data to fetch.

Return Value integer

public function dm_db_select_tables(db, tables) result(rc)

Returns an array containing the names of all tables in the given database.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

character(len=SQL_TABLE_NAME_LEN), intent(out), allocatable :: tables(:)

Array of tables.

Return Value integer

public function dm_db_select_target(db, target, target_id) result(rc)

Returns target data associated with given target id from database.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(target_type), intent(out) :: target

Returned target data.

character(len=*), intent(in) :: target_id

Target id.

Return Value integer

public function dm_db_has_sensor(db, sensor_id) result(exists)

Returns .true. if sensor id exists.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

character(len=*), intent(in) :: sensor_id

Sensor id.

Return Value logical

public function dm_db_set_application_id(db, id) result(rc)

Set the 32-bit signed big-endian “Application ID” integer located at offset 68 into the database header.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer, intent(in) :: id

Application id.

Return Value integer

public function dm_db_set_auto_vacuum(db, mode) result(rc)

Auto-vacuuming is only possible if the database stores some additional information that allows each database page to be traced backwards to its referrer. Therefore, auto-vacuuming must be turned on before any tables are created. It is not possible to enable or disable auto-vacuum after a table has been created.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer, intent(in) :: mode

Database auto vacuum mode.

Return Value integer

public function dm_db_set_busy_callback(db, callback, client_data) result(rc)

Sets SQLite busy callback that is invoked whenever the database is busy.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

procedure(dm_db_busy_callback) :: callback

Callback function.

type(c_ptr), intent(in) :: client_data

C pointer to client data.

Return Value integer

public function dm_db_set_busy_timeout(db, msec) result(rc)

Sets SQLite busy timeout in msec. Returns E_DB on error.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer, intent(in) :: msec

Timeout in mseconds.

Return Value integer

public function dm_db_set_foreign_keys(db, enabled) result(rc)

Sets foreign keys constraint.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

logical, intent(in) :: enabled

Enable foreign keys constraint.

Return Value integer

public function dm_db_set_journal_mode(db, mode) result(rc)

Sets journal mode.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer, intent(in) :: mode

Journal mode.

Return Value integer

public function dm_db_set_log_callback(callback, client_data) result(rc)

Sets SQLite error log callback. The dummy argument client_data is passed to the callback routine. The function returns E_DB on error.

Arguments

Type IntentOptional Attributes Name
procedure(dm_db_log_callback) :: callback

Callback routine.

type(c_ptr), intent(in), optional :: client_data

C pointer to client data.

Return Value integer

public function dm_db_set_query_only(db, enabled) result(rc)

Sets query-only pragma.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

logical, intent(in) :: enabled

Enable query-only mode.

Return Value integer

public function dm_db_set_update_callback(db, callback, client_data) result(rc)

Sets SQLite error log callback. The dummy argument client_data is passed to the callback routine. The function returns E_DB on error.

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

procedure(dm_db_update_callback) :: callback

Callback routine.

type(c_ptr), intent(in), optional :: client_data

C pointer to client data.

Return Value integer

public function dm_db_set_user_version(db, version) result(rc)

Sets database user version.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

integer, intent(in) :: version

Database user version.

Return Value integer

public function dm_db_shutdown() result(rc)

Finalises SQLite handle. Returns E_DB on error.

Arguments

None

Return Value integer

public function dm_db_update_node(db, node, validate) result(rc)

Updates the given node in database. The node data is validated by default.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(node_type), intent(inout) :: node

Node to update.

logical, intent(in), optional :: validate

Validate node.

Return Value integer

public function dm_db_update_sensor(db, sensor, validate) result(rc)

Updates given sensor in database. The sensor data is validated by default.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(sensor_type), intent(inout) :: sensor

Sensor to update.

logical, intent(in), optional :: validate

Validate sensor.

Return Value integer

public function dm_db_update_target(db, target, validate) result(rc)

Updates the given target in database. The target data is validated by default.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

type(target_type), intent(inout) :: target

Target to update.

logical, intent(in), optional :: validate

Validate target.

Return Value integer

public function dm_db_vacuum(db, into) result(rc)

Vacuums database schema main, or, if into is passed, vacuums it into new database at given path.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

character(len=*), intent(in), optional :: into

File path to vacuum database.

Return Value integer

public function dm_db_validate(db) result(rc)

Validates an opened DMPACK database. The application id must match the constant DB_APPLICATION_ID, and the user version must be equal to DB_USER_VERSION.

Read more…

Arguments

Type IntentOptional Attributes Name
type(db_type), intent(inout) :: db

Database type.

Return Value integer

public function dm_db_version(name) result(version)

Returns SQLite 3 library version as allocatable string.

Arguments

Type IntentOptional Attributes Name
logical, intent(in), optional :: name

Add prefix `libsqlite/'.

Return Value character(len=:), allocatable


Subroutines

public subroutine dm_db_log(err_code, err_msg)

Sends log message to SQLite error log handler. The callback has to be set through dm_db_set_log_callback() initially.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: err_code

Error code.

character(len=*), intent(in) :: err_msg

Error message.

public subroutine dm_db_sleep(msec)

Delays execution for given duration in msec.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: msec

Time in [msec].