diff options
author | justanothercatgirl <sotov@twistea.su> | 2025-03-31 15:44:36 +0300 |
---|---|---|
committer | justanothercatgirl <sotov@twistea.su> | 2025-03-31 15:44:36 +0300 |
commit | 08403b616f9dad83cb1204eec83ba1252e3eb129 (patch) | |
tree | 7d248c9db76d1b1bf9f303b9c0caadf1dd765a8d /include | |
parent | 82742d5d13dc7b0691a79c79f8e62782fcb16e10 (diff) |
Early working state.
TODO:
* /api/linkdel, /api/linkget
* finish website
Diffstat (limited to 'include')
-rw-r--r-- | include/sql.h | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/include/sql.h b/include/sql.h index e14167b..a90fde6 100644 --- a/include/sql.h +++ b/include/sql.h @@ -1,6 +1,48 @@ #ifndef SQL_H #define SQL_H +#include <stdbool.h> +#include <sqlite3.h> -extern const char *INIT_SQL, *INSERT_SQL, *DELETE_SQL; +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 |