Database Management


Defines

#define STATEMENT_INIT   int rc; sqlite3_stmt *stmt=NULL
 Macro to define the varaiable required for executing an sql statement, Only 1 call to STATEMENT_INIT per function is supported!
#define DBASE_CONNECTION_GET   DBaseConnectionGet
 Macro for the function to call to get a database connection.
#define STATEMENT_PREPARE(_statement)   rc = sqlite3_prepare( DBASE_CONNECTION_GET(), _statement, -1, &stmt, NULL)
 Macro to prepare an sql statement.
#define STATEMENT_PREPAREVA(_statement, _args...)
 Macro to prepare an sql statement with arguments.
#define STATEMENT_STEP()   rc = sqlite3_step(stmt)
 Macro to perform a 'step' on an sql statement.
#define STATEMENT_COLUMN_INT(_index)   sqlite3_column_int(stmt, _index)
 Macro to retrieve an int value from the result of a 'step'.
#define STATEMENT_COLUMN_DOUBLE(_index)   sqlite3_column_double(stmt, _index)
 Macro to retrieve a double value from the result of a 'step'.
#define STATEMENT_COLUMN_TEXT(_index)   (char*)sqlite3_column_text( stmt, _index)
 Macro to retrieve a string from the result of a 'step'.
#define STATEMENT_FINALIZE()   rc = sqlite3_finalize(stmt)
 Macro to finalise an sql statement.
#define PRINTLOG_SQLITE3ERROR()
 Macro to log the last SQLite error.
#define RETURN_ON_ERROR(_result)
 Macro to tidy up an sql statement and return the specified value if an error occured.
#define RETURN_RC_ON_ERROR   RETURN_ON_ERROR(rc)
 Macro to tidy up an sql statemente and return the last result from an sqlite call.

Functions

int DBaseInit (int adapter)
void DBaseDeInit ()
sqlite3 * DBaseConnectionGet (void)
 Get the sqlite3 connection object for this thread.
int DBaseTransactionBegin (void)
 Start a transaction on the database.
int DBaseTransactionCommit (void)
 Commit a transaction on the database.
int DBaseMetadataGet (char *name, char **value)
 Retrieve the specified metadata property.
int DBaseMetadataSet (char *name, char *value)
 Set the specified metadata property to the string specified.
int DBaseMetadataGetInt (char *name, int *value)
 Retrieve the specified metadata property.
int DBaseMetadataSetInt (char *name, int value)
 Set the specified metadata property to the int specified.
int DBaseMetadataGetDouble (char *name, double *value)
 Retrieve the specified metadata property.
int DBaseMetadataSetDouble (char *name, double value)
 Set the specified metadata property to the double specified.
int DBaseMetadataDelete (char *name)
 Delete the specified metadata property.

Define Documentation

 
#define PRINTLOG_SQLITE3ERROR (  ) 

Value:

do{\
        LogModule(LOG_DEBUG, "dbase", "%s(%d): Failed with error code 0x%x=%s\n",\
            __FUNCTION__,__LINE__, rc, sqlite3_errmsg(DBASE_CONNECTION_GET()));\
    }while(0)
Macro to log the last SQLite error.

This macro logs at the LOG_ERROR level.

#define RETURN_ON_ERROR ( _result   ) 

Value:

do{\
        if ((rc != SQLITE_OK) && (rc != SQLITE_ROW) && (rc != SQLITE_DONE))\
        {\
            PRINTLOG_SQLITE3ERROR();\
            if (stmt)\
            {\
                STATEMENT_FINALIZE();\
            }\
            return _result;\
        }\
    }while(0)
Macro to tidy up an sql statement and return the specified value if an error occured.

This macro logs the sqlite error, finalises the sql statement and returns if the error was not SQLITE_OK, SQLITE_ROW or SQLITE_DONE.

Parameters:
_result The value to return from the current function.

#define STATEMENT_COLUMN_DOUBLE ( _index   )     sqlite3_column_double(stmt, _index)

Macro to retrieve a double value from the result of a 'step'.

Parameters:
_index Column index of the result to retrieve.

#define STATEMENT_COLUMN_INT ( _index   )     sqlite3_column_int(stmt, _index)

Macro to retrieve an int value from the result of a 'step'.

Parameters:
_index Column index of the result to retrieve.

#define STATEMENT_COLUMN_TEXT ( _index   )     (char*)sqlite3_column_text( stmt, _index)

Macro to retrieve a string from the result of a 'step'.

The string should be free'd using the sqlite_free function when it is no longer required.

Parameters:
_index Column index of the result to retrieve.

#define STATEMENT_PREPARE ( _statement   )     rc = sqlite3_prepare( DBASE_CONNECTION_GET(), _statement, -1, &stmt, NULL)

Macro to prepare an sql statement.

Parameters:
_statement The sql statement to prepare.

#define STATEMENT_PREPAREVA ( _statement,
_args...   ) 

Value:

do{\
        char *sqlstring;\
        sqlstring = sqlite3_mprintf(_statement, _args);\
        if (sqlstring)\
        {\
            STATEMENT_PREPARE(sqlstring);\
            sqlite3_free(sqlstring);\
        }\
        else\
        {\
            rc = SQLITE_NOMEM;\
        }\
    }while(0)
Macro to prepare an sql statement with arguments.

Parameters:
_statement The sql statement to prepare.
_args The arguments to be inserted into the statement.


Function Documentation

sqlite3* DBaseConnectionGet ( void   ) 

Get the sqlite3 connection object for this thread.

Returns:
An sqlite3 connection object or NULL if the database could not be opened.

void DBaseDeInit (  ) 

For internal use only.

De-initialise the database.

int DBaseInit ( int  adapter  ) 

For internal use only.

Initialise the database for the given adapter. This function will create the database if one doesn't exist, and upgrade the database if it is a different version to the one being used by the application.

Parameters:
adapter The DVB adapter number to open the database of.
Returns:
0 on success, otherwise an SQLite error code.

int DBaseMetadataDelete ( char *  name  ) 

Delete the specified metadata property.

Parameters:
name The name of the property.
Returns:
0 on success, otherwise an SQLite error code.

int DBaseMetadataGet ( char *  name,
char **  value 
)

Retrieve the specified metadata property.

Parameters:
name The name of the property.
value The location to store the value in. This should must be free'd once finished with.
Returns:
0 on success, otherwise an SQLite error code.

int DBaseMetadataGetDouble ( char *  name,
double *  value 
)

Retrieve the specified metadata property.

Parameters:
name The name of the property.
value The location to store the value in.
Returns:
0 on success, otherwise an SQLite error code.

int DBaseMetadataGetInt ( char *  name,
int *  value 
)

Retrieve the specified metadata property.

Parameters:
name The name of the property.
value The location to store the value in.
Returns:
0 on success, otherwise an SQLite error code.

int DBaseMetadataSet ( char *  name,
char *  value 
)

Set the specified metadata property to the string specified.

Parameters:
name The name of the property.
value The value to set it to.
Returns:
0 on success, otherwise an SQLite error code.

int DBaseMetadataSetDouble ( char *  name,
double  value 
)

Set the specified metadata property to the double specified.

Parameters:
name The name of the property.
value The value to set it to.
Returns:
0 on success, otherwise an SQLite error code.

int DBaseMetadataSetInt ( char *  name,
int  value 
)

Set the specified metadata property to the int specified.

Parameters:
name The name of the property.
value The value to set it to.
Returns:
0 on success, otherwise an SQLite error code.

int DBaseTransactionBegin ( void   ) 

Start a transaction on the database.

Can be used to increase the speed when reading from multiple tables.

Returns:
0 on success, otherwise an SQLite error code.

int DBaseTransactionCommit ( void   ) 

Commit a transaction on the database.

Returns:
0 on success, otherwise an SQLite error code.


Generated on Thu Jun 26 12:58:31 2008 for DVBStreamer by  doxygen 1.5.5