aboutsummaryrefslogtreecommitdiffstats
path: root/include/sql.h
blob: a90fde6bb1e7bf1d606ec8bd332f4c7deaca3892 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef SQL_H
#define SQL_H
#include <stdbool.h>
#include <sqlite3.h>

struct slidid { sqlite3_int64 il, in, res; };
extern struct sql_state {
	sqlite3 *db;
} state;

enum statements_index {
	STMTIDX_INIT = 0,
	STMTIDX_INSERT,
	STMTIDX_DELETE,
	STMTIDX_SELECT,
	STMTIDX_RESET,
	STMTIDX_GETN,
	STMTIDX_SIZE,
};

enum dberror {
	DBERROR_SUCCESS = 0,
	DBERROR_ARGS,
	DBERROR_INVAL,
	DBERROR_OCCUPIED,
	DBERROR_SERVER,
	DBERROR_TOOBIG,
	DBERROR_UNKNOWN,
};

extern struct sqlite3_stmt *statements[STMTIDX_SIZE];

void sqlite_init(const char *db);
void sqlite_deinit(void);

enum dberror db_add_url(const char *url, const char *path, char **out);
bool db_del_url(const char *path);
// dong: output parameter
char *db_get_info(const char *path, long *dong);
// server should use this one. Memory must be freed.
char *db_get_url(const char *path);

static char *itou(register unsigned long i, register char *buf);
static unsigned long utoi(const char *s);

const char *db_error(enum dberror e);
int db_error_status(enum dberror e);
#endif