CoffeePi
Coffee machine control for Raspberry Pi
Functions | Variables
database.cpp File Reference
#include <cstdio>
#include <stdlib.h>
#include <inttypes.h>
#include <cstdarg>
#include <cstring>
#include <string>
#include <stdexcept>
#include <pthread.h>
#include <sys/time.h>
#include "sqlite/sqlite3.h"
#include "global.h"
#include "database.h"
#include "logger.h"

Functions

std::string string_vsprintf (const char *format, std::va_list args)
 Helper function to allow the use of vsprintf() with a string See: http://codereview.stackexchange.com/questions/52522/mimic-sprintf-with-stdstring-output. More...
 
std::string string_sprintf (const char *format,...) __attribute__((format(printf
 Allows the format of printf but returns a string Source: http://codereview.stackexchange.com/questions/52522/mimic-sprintf-with-stdstring-output. More...
 
int sqlOpen ()
 Opens and initializes a sqlite3 database connection. More...
 
void sqlClose ()
 Closes the database connection. More...
 
int sqlExecute (string query)
 Executes a SQL statement. More...
 
int sqlExecute2 (char *query)
 
int sqlSetup ()
 Sets up the database and creates the needed structure. More...
 
uint64_t sqlGetConf (config_key_t id)
 Reads a configuration key from the database. More...
 
int sqlSetConf (config_key_t id, uint64_t value)
 Saves a configuration key to the database. More...
 
char * inttochar (uint8_t *guid)
 Converts the GUID from int to char array. More...
 
uint8_t * chartoint (const unsigned char *guid)
 Converts the GUID from char to int array. More...
 
uint8_t * int64to8bit (sqlite_int64 guid)
 Converts the GUID from int64 to int8 array. More...
 
sqlite_int64 int8to64bit (uint8_t *guid)
 
void sqltest ()
 

Variables

sqlite3 * db
 The database connector. More...
 

Function Documentation

uint8_t* chartoint ( const unsigned char *  guid)

Converts the GUID from char to int array.

Parameters
*guidPointer to the char GUID
Returns
pointer to the converted int array
uint8_t* int64to8bit ( sqlite_int64  guid)

Converts the GUID from int64 to int8 array.

Parameters
guid64bit GUID
Returns
pointer to the converted int array
sqlite_int64 int8to64bit ( uint8_t *  guid)
char* inttochar ( uint8_t *  guid)

Converts the GUID from int to char array.

Parameters
*guidPointer to the uint8_t GUID
Returns
pointer to the converted string
void sqlClose ( )

Closes the database connection.

int sqlExecute ( string  query)

Executes a SQL statement.

Parameters
*querySQL query string
Returns
0 on success
int sqlExecute2 ( char *  query)
uint64_t sqlGetConf ( config_key_t  id)

Reads a configuration key from the database.

Parameters
idConfig ID key
Returns
value as integer (up to 64bit), 0 for not found
int sqlOpen ( )

Opens and initializes a sqlite3 database connection.

Returns
0 on success
int sqlSetConf ( config_key_t  id,
uint64_t  value 
)

Saves a configuration key to the database.

Parameters
idConfig ID key
valueInteger value
Returns
0 on success
int sqlSetup ( )

Sets up the database and creates the needed structure.

Returns
0 on success
void sqltest ( )
std::string std::string string_sprintf ( const char *  format,
  ... 
)

Allows the format of printf but returns a string Source: http://codereview.stackexchange.com/questions/52522/mimic-sprintf-with-stdstring-output.

Returns
printf formatted string
Parameters
formatinput string as char array
std::string string_vsprintf ( const char *  format,
std::va_list  args 
)

Helper function to allow the use of vsprintf() with a string See: http://codereview.stackexchange.com/questions/52522/mimic-sprintf-with-stdstring-output.

Variable Documentation

sqlite3* db

The database connector.