dm_db_api Module

Database API module for CRUD operations, based on the core module dm_db. 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)
call 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 (rc == E_DB_DONE) exit
    if (dm_is_ok(rc)) print '(a)', trim(observ%name)
end do

rc = dm_db_finalize(db_stmt)
call dm_db_close(db)

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


Uses

  • module~~dm_db_api~~UsesGraph module~dm_db_api dm_db_api iso_c_binding iso_c_binding module~dm_db_api->iso_c_binding module~dm_db dm_db module~dm_db_api->module~dm_db module~dm_db_count dm_db_count module~dm_db_api->module~dm_db_count module~dm_db_pragma dm_db_pragma module~dm_db_api->module~dm_db_pragma module~dm_db_query dm_db_query module~dm_db_api->module~dm_db_query module~dm_db_row dm_db_row module~dm_db_api->module~dm_db_row module~dm_db_table dm_db_table module~dm_db_api->module~dm_db_table module~dm_error dm_error module~dm_db_api->module~dm_error module~dm_id dm_id module~dm_db_api->module~dm_id module~dm_kind dm_kind module~dm_db_api->module~dm_kind module~dm_sql dm_sql module~dm_db_api->module~dm_sql module~dm_time dm_time module~dm_db_api->module~dm_time module~dm_util dm_util module~dm_db_api->module~dm_util module~dm_uuid dm_uuid module~dm_db_api->module~dm_uuid sqlite3 sqlite3 module~dm_db_api->sqlite3 module~dm_db->iso_c_binding module~dm_db->module~dm_db_query module~dm_db->module~dm_error module~dm_db->module~dm_kind module~dm_db->module~dm_util module~dm_db->sqlite3 module~dm_db_count->module~dm_db module~dm_db_count->module~dm_error module~dm_db_count->module~dm_kind module~dm_db_count->module~dm_sql module~dm_db_pragma->module~dm_db module~dm_db_pragma->module~dm_error module~dm_db_pragma->module~dm_kind module~dm_db_query->module~dm_error module~dm_db_query->module~dm_kind module~dm_db_row->module~dm_db module~dm_db_row->module~dm_error module~dm_db_row->module~dm_util module~dm_db_table->module~dm_db module~dm_db_table->module~dm_db_query module~dm_db_table->module~dm_error module~dm_db_table->module~dm_sql module~dm_db_table->module~dm_util 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_time->module~dm_error module~dm_time->module~dm_kind module~dm_time->module~dm_util unix unix module~dm_time->unix module~dm_util->module~dm_error module~dm_util->module~dm_kind

Used by

  • module~~dm_db_api~~UsedByGraph module~dm_db_api dm_db_api module~dmpack dmpack module~dmpack->module~dm_db_api

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_JOURNAL_WAL2 = 6

Use Write-Ahead Log 2 (WAL2) journal.

integer, public, parameter :: DB_JOURNAL_LAST = 6

Never use this.

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_APPLICATION_ID = int(z'444D31')

Application id of DMPACK databases (DM1 in ASCII).

integer, public, parameter :: DB_SCHEMA_VERSION = 3

Database schema version, increased on updates.

integer, public, parameter :: DB_TIMEOUT_DEFAULT = 1000

Default SQLite 3 busy timeout [msec].


Interfaces

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_image(db, image, validate) result(rc)

    Adds given image to database. The image 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 image 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(image_type), intent(inout) :: image

    Image to insert.

    logical, intent(in), optional :: validate

    Validate image.

    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 function dm_db_insert_transfer(db, transfer, validate) result(rc)

    Adds given transfer to database. The transfer 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 transfer 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(transfer_type), intent(inout) :: transfer

    Transfer to insert.

    logical, intent(in), optional :: validate

    Validate transfer.

    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_DONE if statement finished.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.
    • E_INVALID if id is invalid.

    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_image(db, image, image_id) result(rc)

    Returns image data associated with given image id from images table.

    The function returns the following error codes:

    • E_DB_BIND if value binding failed.
    • E_DB_DONE if statement finished.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.
    • E_INVALID if image id or type id is not passed or invalid.

    Arguments

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

    Database type.

    type(image_type), intent(out) :: image

    Returned image data.

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

    Image 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_DONE if statement finished.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.
    • E_INVALID if id is invalid.

    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_DONE if statement finished.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.
    • E_INVALID if id is invalid.

    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_DONE if statement finished.
    • E_DB_FINALIZE if statement finalisation failed.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.
    • E_INVALID if id is invalid.

    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_DONE if statement finished.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.
    • E_INVALID if id is invalid.

    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_DONE if statement finished.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.
    • E_INVALID if id is invalid.

    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_select_transfer(db, transfer, transfer_id, type_id) result(rc)

    Returns transfer data associated with given transfer id and/or type_id from transfer database.

    The function returns the following error codes:

    • E_DB_BIND if value binding failed.
    • E_DB_DONE if statement finished.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.
    • E_INVALID if transfer id or type id is not passed or invalid.

    Arguments

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

    Database type.

    type(transfer_type), intent(out) :: transfer

    Returned transfer data.

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

    Transfer id.

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

    Transfer type 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, validate) 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_DONE if statement finished.
    • 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.

    logical, intent(in), optional :: validate

    Validate column types.

    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, ndps) 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_STEP if step execution 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 :: ndps

    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, validate) 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_DONE if statement finished.
    • 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.

    logical, intent(in), optional :: validate

    Validate column types.

    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, observ_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 :: observ_id

    Observation 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, observ_id, source, from, to, min_level, max_level, error, desc, limit, validate) 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_DONE if statement finished.
    • 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 :: observ_id

    Observation 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.

    logical, intent(in), optional :: validate

    Validate column types.

    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, validate) 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_DONE if statement finished.
    • 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.

    logical, intent(in), optional :: validate

    Validate column types.

    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.

    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, validate) 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_DONE if statement finished.
    • 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.

    logical, intent(in), optional :: validate

    Validate column types.

    Return Value integer

public interface dm_db_select_sensors

Generic sensors select function.

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

    Returns all sensors in allocatable array sensors. If argument node_id is passed, returns only sensors of this node.

    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.
    • E_INVALID if node id is empty.

    Arguments

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

    Database type.

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

    Returned sensor data array.

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

    Node id.

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

    Number of returned sensors.

    Return Value integer

  • private function db_select_sensors_iter(db, db_stmt, sensor, node_id, validate) 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_DONE if statement finished.
    • E_DB_PREPARE if statement preparation failed.
    • E_DB_TYPE if returned columns are unexpected.
    • E_INVALID if node id is empty.

    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.

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

    Node id.

    logical, intent(in), optional :: validate

    Validate column types.

    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, validate) 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_DONE if statement finished.
    • 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.

    logical, intent(in), optional :: validate

    Validate column types.

    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


Functions

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_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_image(db, image_id) result(rc)

Deletes image from database.

Read more…

Arguments

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

Database type.

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

Image 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_delete_transfer(db, transfer_id) result(rc)

Deletes transfer from database.

Read more…

Arguments

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

Database type.

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

Transfer id.

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 enumerator.

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_schema_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 of passed 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 of passed 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 of passed 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_sensor(db, sensor_id) result(exists)

Returns .true. if sensor of passed 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_has_target(db, target_id) result(has)

Returns .true. if target of passed 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_has_transfer(db, transfer_id) result(has)

Returns .true. if transfer of passed id exists.

Arguments

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

Database type.

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

Transfer id.

Return Value logical

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_image(db, image, validate) result(rc)

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

Read more…

Arguments

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

Database type.

type(image_type), intent(inout) :: image

Image to insert.

logical, intent(in), optional :: validate

Validate image.

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_insert_transfer(db, transfer, validate) result(rc)

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

Read more…

Arguments

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

Database type.

type(transfer_type), intent(inout) :: transfer

Transfer to insert.

logical, intent(in), optional :: validate

Validate transfer.

Return Value integer

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_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_image(db, image, image_id) result(rc)

Returns image data associated with given image id from images table.

Read more…

Arguments

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

Database type.

type(image_type), intent(out) :: image

Returned image data.

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

Image 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_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=OBSERV_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_id, before_id, limit, stub, nobservs) result(rc)

Returns observations of a given id range in observs. The argument after_id is the id of the observation after which the range starts, before_id 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

Id of observation with timestamp before first of range.

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

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_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_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_select_transfer(db, transfer, transfer_id, type_id) result(rc)

Returns transfer data associated with given transfer id and/or type_id from transfer database.

Read more…

Arguments

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

Database type.

type(transfer_type), intent(out) :: transfer

Returned transfer data.

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

Transfer id.

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

Transfer type id.

Return Value integer

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_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. Argument mode has to be one of:

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_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_schema_version(db, version) result(rc)

Sets database schema 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_size(db, nbyte) result(rc)

Returns SQLite database size in bytes.

Read more…

Arguments

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

Database type.

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

Database size [byte].

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_update_transfer(db, transfer_id, timestamp, state, error, validate) result(rc)

Updates attributes of transfer with passed transfer id. The arguments are validated by default. This function is not thread-safe. If executed by multiple threads, E_NOT_FOUND may be returned even on a successful transfer update.

Read more…

Arguments

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

Database type.

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

Transfer id (UUIDv4).

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

Transfer time stamp (ISO 8601).

integer, intent(in), optional :: state

Transfer state (TRANSFER_STATE_*).

integer, intent(in), optional :: error

Error code.

logical, intent(in), optional :: validate

Validate arguments.

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_SCHEMA_VERSION.

Read more…

Arguments

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

Database type.

Return Value integer


Subroutines

public subroutine dm_db_close(db, optimize, error)

Closes connection to SQLite database. Optimises the database if argument optimize is .true..

Read more…

Arguments

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

Database type.

logical, intent(in), optional :: optimize

Optimise on close.

integer, intent(out), optional :: error

Error code.