CoffeePi
Coffee machine control for Raspberry Pi
database.h
Go to the documentation of this file.
1 /*
2  * database.h
3  *
4  * Created on: Dec 4, 2015
5  * Author: Philipp Hinz
6  */
7 
8 #ifndef DATABASE_H_
9 #define DATABASE_H_
10 #include <string>
11 #include <stdexcept>
12 #include <cstdio>
13 #include <stdlib.h>
14 #include <inttypes.h>
15 #include <cstdarg>
16 #include "sqlite/sqlite3.h"
17 
18 using namespace std;
19 
20 // Config Keys
21 typedef enum {
25 } config_key_t;
26 
27 int sqlOpen();
28 void sqlClose();
29 int sqlSetup();
30 int sqlExecute(string query);
31 char *inttochar(uint8_t *guid);
32 uint8_t *chartoint(const unsigned char *guid);
33 uint8_t *int64to8bit(sqlite_int64 guid);
34 sqlite_int64 int8to64bit(uint8_t *guid);
35 void sqltest();
36 std::string string_sprintf(const char* format, ...);
37 uint64_t sqlGetConf(config_key_t id);
38 int sqlSetConf(config_key_t id, uint64_t value);
39 
40 #endif /* DATABASE_H_ */
int sqlSetConf(config_key_t id, uint64_t value)
Saves a configuration key to the database.
Definition: database.cpp:198
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
Definition: database.h:21
uint8_t * chartoint(const unsigned char *guid)
Converts the GUID from char to int array.
Definition: database.cpp:227
int sqlOpen()
Opens and initializes a sqlite3 database connection.
Definition: database.cpp:76
int sqlExecute(string query)
Executes a SQL statement.
Definition: database.cpp:103
void sqlClose()
Closes the database connection.
Definition: database.cpp:92
char * inttochar(uint8_t *guid)
Converts the GUID from int to char array.
Definition: database.cpp:212
void sqltest()
Definition: database.cpp:258
int sqlSetup()
Sets up the database and creates the needed structure.
Definition: database.cpp:150
Definition: database.h:24
uint64_t sqlGetConf(config_key_t id)
Reads a configuration key from the database.
Definition: database.cpp:163
sqlite_int64 int8to64bit(uint8_t *guid)
Definition: database.cpp:250
Definition: database.h:22
Definition: database.h:23
uint8_t * int64to8bit(sqlite_int64 guid)
Converts the GUID from int64 to int8 array.
Definition: database.cpp:241