DVBCore  22.3.0
Open Source DVB Engine
Classes | Macros | Typedefs | Enumerations | Functions | Variables
database.h File Reference

Records can be created, updated and deleted in-memory, these operations may optionally be recorded so that changes can be compared with and saved into another database. More...

#include <sqlite3.h>
#include "stbllist.h"

Go to the source code of this file.

Classes

struct  S_DATA_TYPE
 
struct  S_COLUMN
 
struct  S_TABLE
 
struct  S_FIELD
 
struct  s_record
 

Macros

#define ARRAY_LENGTH(X)   (sizeof(X)/sizeof(*X))
 
#define INITIAL_VERSION   0
 

Typedefs

typedef struct s_record S_RECORD
 

Enumerations

enum  OPERATION_TYPE { OPERATION_NONE, OPERATION_UPDATE, OPERATION_CREATE, OPERATION_DELETE }
 

Functions

BOOLEAN Database_Initialise (void)
 Initialise runtime database. More...
 
void Database_Uninitialise (void)
 Uninitialise runtime database.
 
void Database_Clear (void)
 Clear runtime database.
 
const S_TABLEDatabase_GetTable (U32BIT record_type)
 Get table with given 'record_type'. More...
 
const S_COLUMNDatabase_GetColumn (const S_TABLE *table, U32BIT field_type)
 Get column in 'table' with given 'field_type'. More...
 
S_RECORDDatabase_GetRecord (const S_TABLE *table, const S_RECORD *prev, BOOLEAN exclude_deleted)
 Get record in 'table' after 'prev' or first record if 'prev' is NULL. More...
 
S_RECORDDatabase_FindRecord (const S_TABLE *table, sqlite3_int64 id)
 Find record in 'table' with given 'id'. More...
 
S_FIELDDatabase_GetField (S_RECORD *record, const S_COLUMN *column)
 Get field from 'column' in given 'record'. More...
 
S_RECORDDatabase_CreateRecord (const S_TABLE *table, S_RECORD *parent)
 Create database record of type 'table' with optional 'parent'. More...
 
BOOLEAN Database_DeleteRecord (S_RECORD *record)
 Free 'record' buffers and mark as deleted. If not created in SQLite 'record' is destroyed automatically, otherwise it must be manually destroyed once deleted from SQLite. More...
 
void Database_DestroyRecord (S_RECORD *record)
 Destroy deleted 'record'. More...
 
void Database_AddRecordOperation (S_RECORD *record, OPERATION_TYPE operation)
 Add record operation (except delete). Operations are merged. More...
 
void Database_ClearRecordOperation (S_RECORD *record)
 Clear the record operation. More...
 
S_RECORDDatabase_GetRecordParent (S_RECORD *record)
 Get parent of 'record'. More...
 
void Database_SetRecordParent (S_RECORD *record, S_RECORD *parent)
 Set the parent of 'record'. More...
 
U32BIT Database_GetRecordFieldUInt (S_FIELD *field)
 Get uint value of 'field'. More...
 
void Database_SetRecordFieldUInt (S_FIELD *field, U32BIT value)
 Set uint value of 'field'. More...
 
const char * Database_GetRecordFieldText (S_FIELD *field, U32BIT *size)
 Get text value of 'field'. More...
 
void Database_SetRecordFieldText (S_FIELD *field, const unsigned char *value, U32BIT size)
 Set text value of 'field'. More...
 
const void * Database_GetRecordFieldBlob (S_FIELD *field, U32BIT *size)
 Get blob value of 'field'. More...
 
void Database_SetRecordFieldBlob (S_FIELD *field, const void *value, U32BIT size)
 Set blob value of 'field'. More...
 

Variables

const S32BIT database_layout_version
 
const S_DATA_TYPE database_type_uint
 
const S_DATA_TYPE database_type_text
 
const S_DATA_TYPE database_type_blob
 
const S_TABLE database_layout []
 
const U32BIT database_layout_length
 

Detailed Description

Records can be created, updated and deleted in-memory, these operations may optionally be recorded so that changes can be compared with and saved into another database.

Date
01/01/2017
Author
Ocean Blue

Function Documentation

void Database_AddRecordOperation ( S_RECORD record,
OPERATION_TYPE  operation 
)

Add record operation (except delete). Operations are merged.

Parameters
recordDatabase record (must not be not deleted)
operationRecord operation (must not be delete)
void Database_ClearRecordOperation ( S_RECORD record)

Clear the record operation.

Parameters
recordDatabase record (must not be not deleted)
S_RECORD* Database_CreateRecord ( const S_TABLE table,
S_RECORD parent 
)

Create database record of type 'table' with optional 'parent'.

Parameters
tableDatabase table
parentParent database record (suitable for type 'table') or NULL
Returns
Database record, NULL on failure
BOOLEAN Database_DeleteRecord ( S_RECORD record)

Free 'record' buffers and mark as deleted. If not created in SQLite 'record' is destroyed automatically, otherwise it must be manually destroyed once deleted from SQLite.

Parameters
recordDatabase record
Returns
TRUE if 'record' destroyed automatically, FALSE otherwise
void Database_DestroyRecord ( S_RECORD record)

Destroy deleted 'record'.

Parameters
recordDatabase record (must be deleted but not already destroyed)
S_RECORD* Database_FindRecord ( const S_TABLE table,
sqlite3_int64  id 
)

Find record in 'table' with given 'id'.

Parameters
tableDatabase table
idRecord id
Returns
Database record, NULL if not found
const S_COLUMN* Database_GetColumn ( const S_TABLE table,
U32BIT  field_type 
)

Get column in 'table' with given 'field_type'.

Parameters
tableDatabase table
field_typeField type (see database/inc/dba.h)
Returns
Database column, NULL if not found
S_FIELD* Database_GetField ( S_RECORD record,
const S_COLUMN column 
)

Get field from 'column' in given 'record'.

Parameters
recordDatabase record (must not be deleted)
columnDatabase column (must exist in 'record')
Returns
Database field
S_RECORD* Database_GetRecord ( const S_TABLE table,
const S_RECORD prev,
BOOLEAN  exclude_deleted 
)

Get record in 'table' after 'prev' or first record if 'prev' is NULL.

Parameters
tableDatabase table
prevDatabase record or NULL
exclude_deleteExclude deleted records
Returns
Database record, NULL if not found
const void* Database_GetRecordFieldBlob ( S_FIELD field,
U32BIT *  size 
)

Get blob value of 'field'.

Parameters
fieldDatabase field
sizeSize out
Returns
Blob value
const char* Database_GetRecordFieldText ( S_FIELD field,
U32BIT *  size 
)

Get text value of 'field'.

Parameters
fieldDatabase field
sizeSize out
Returns
Text value
U32BIT Database_GetRecordFieldUInt ( S_FIELD field)

Get uint value of 'field'.

Parameters
fieldDatabase field
Returns
Uint Value
S_RECORD* Database_GetRecordParent ( S_RECORD record)

Get parent of 'record'.

Parameters
recordDatabase record (must not be not deleted)
Returns
Database record, NULL if no parent
const S_TABLE* Database_GetTable ( U32BIT  record_type)

Get table with given 'record_type'.

Parameters
record_typeRecord type (see database/inc/dba.h)
Returns
Database table, NULL if not found
BOOLEAN Database_Initialise ( void  )

Initialise runtime database.

Returns
TRUE on success, FALSE on failure
void Database_SetRecordFieldBlob ( S_FIELD field,
const void *  value,
U32BIT  size 
)

Set blob value of 'field'.

Parameters
fieldDatabase field
valueBlob value
sizeBlob value size
void Database_SetRecordFieldText ( S_FIELD field,
const unsigned char *  value,
U32BIT  size 
)

Set text value of 'field'.

Parameters
fieldDatabase field
valueText value
sizeText value size (including terminating null character)
void Database_SetRecordFieldUInt ( S_FIELD field,
U32BIT  value 
)

Set uint value of 'field'.

Parameters
fieldDatabase field
valueUint value
void Database_SetRecordParent ( S_RECORD record,
S_RECORD parent 
)

Set the parent of 'record'.

Parameters
recordDatabase record (must not be not deleted)
parentDatabase record (must not be not deleted) or NULL