database.h
Go to the documentation of this file.
/*
* database.h
*
* Created on: Dec 4, 2015
* Author: Philipp Hinz
*/
#ifndef DATABASE_H_
#define DATABASE_H_
#include <string>
#include <stdexcept>
#include <cstdio>
#include <stdlib.h>
#include <inttypes.h>
#include <cstdarg>
#include "sqlite/sqlite3.h"
using namespace std;
// Config Keys
typedef enum {
CFGbrewcounter = 1,
CFGHeatingTime = 2,
CFGdisplaylang = 3
} config_key_t;
int sqlOpen();
void sqlClose();
int sqlSetup();
int sqlExecute(string query);
char *inttochar(uint8_t *guid);
uint8_t *chartoint(const unsigned char *guid);
uint8_t *int64to8bit(sqlite_int64 guid);
sqlite_int64 int8to64bit(uint8_t *guid);
void sqltest();
std::string string_sprintf(const char* format, ...);
uint64_t sqlGetConf(config_key_t id);
int sqlSetConf(config_key_t id, uint64_t value);
#endif /* DATABASE_H_ */
sqlSetConf
int sqlSetConf(config_key_t id, uint64_t value)
Saves a configuration key to the database.
Definition: database.cpp:198
string_sprintf
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.
Definition: database.cpp:54
config_key_t
config_key_t
Definition: database.h:21
std
chartoint
uint8_t * chartoint(const unsigned char *guid)
Converts the GUID from char to int array.
Definition: database.cpp:227
sqlOpen
int sqlOpen()
Opens and initializes a sqlite3 database connection.
Definition: database.cpp:76
sqlExecute
int sqlExecute(string query)
Executes a SQL statement.
Definition: database.cpp:103
sqlClose
void sqlClose()
Closes the database connection.
Definition: database.cpp:92
inttochar
char * inttochar(uint8_t *guid)
Converts the GUID from int to char array.
Definition: database.cpp:212
sqltest
void sqltest()
Definition: database.cpp:258
sqlSetup
int sqlSetup()
Sets up the database and creates the needed structure.
Definition: database.cpp:150
CFGdisplaylang
Definition: database.h:24
sqlGetConf
uint64_t sqlGetConf(config_key_t id)
Reads a configuration key from the database.
Definition: database.cpp:163
int8to64bit
sqlite_int64 int8to64bit(uint8_t *guid)
Definition: database.cpp:250
CFGbrewcounter
Definition: database.h:22
CFGHeatingTime
Definition: database.h:23
int64to8bit
uint8_t * int64to8bit(sqlite_int64 guid)
Converts the GUID from int64 to int8 array.
Definition: database.cpp:241