new: better way of handling files db
This commit is contained in:
@ -5,43 +5,50 @@
|
||||
#define HASH_LEN 32
|
||||
|
||||
typedef enum lm_query_index {
|
||||
QUERY_CREATE_TABLE = 0,
|
||||
QUERY_INSERT_PACKAGE = 1,
|
||||
QUERY_SELECT_PACKAGE = 2,
|
||||
QUERY_DELETE_PACKAGE = 3,
|
||||
QUERY_ALL_PACKAGE = 4,
|
||||
QUERY_CREATE_PACKAGE_TABLE = 0,
|
||||
QUERY_INSERT_PACKAGE_SINGLE = 1,
|
||||
QUERY_SELECT_PACKAGE_SINGLE = 2,
|
||||
QUERY_DELETE_PACKAGE_SINGLE = 3,
|
||||
QUERY_SELECT_PACKAGE_ALL = 4,
|
||||
QUERY_CREATE_FILE_TABLE = 5,
|
||||
QUERY_INSERT_FILE_SINGLE = 6,
|
||||
QUERY_DELETE_FILE_ALL = 7,
|
||||
QUERY_SELECT_FILE_SINGLE = 8,
|
||||
QUERY_SELECT_FILE_ALL = 9,
|
||||
QUERY_UPDATE_FILE_1 = 10,
|
||||
QUERY_UPDATE_FILE_2 = 11,
|
||||
} lm_query_index_t;
|
||||
|
||||
extern char *queries[];
|
||||
|
||||
typedef struct lm_database {
|
||||
sqlite3_stmt *st;
|
||||
sqlite3 *sql;
|
||||
char *dir;
|
||||
lm_pkg_t *pkg;
|
||||
} lm_database_t;
|
||||
sqlite3 *packages_db;
|
||||
sqlite3_stmt *packages_st;
|
||||
|
||||
typedef bool (*lm_database_files_eachfunc_t)(lm_pkg_t *pkg, char *path, char *hash, void *data);
|
||||
typedef bool (*lm_database_keeps_eachfunc_t)(lm_pkg_t *pkg, char *path, void *data);
|
||||
sqlite3 *files_db;
|
||||
sqlite3_stmt *files_st;
|
||||
|
||||
lm_pkg_t *pkg;
|
||||
char *dir;
|
||||
} lm_database_t;
|
||||
|
||||
lm_database_t *lm_database_new(char *path);
|
||||
void lm_database_free(lm_database_t *db);
|
||||
|
||||
bool lm_database_find(lm_database_t *db, lm_pkg_t *pkg, char *name);
|
||||
bool lm_database_next(lm_database_t *db, lm_pkg_t *pkg);
|
||||
bool lm_database_add(lm_database_t *db, lm_pkg_t *pkg);
|
||||
bool lm_database_del(lm_database_t *db, lm_pkg_t *pkg);
|
||||
bool lm_database_package_find(
|
||||
lm_database_t *db, lm_pkg_t *pkg, char *name); // finds a package by its name, package stored in *pkg
|
||||
bool lm_database_package_next(lm_database_t *db, lm_pkg_t *pkg); // gets the next package in the database
|
||||
bool lm_database_packege_add(lm_database_t *db, lm_pkg_t *pkg); // adds a package to the database
|
||||
bool lm_database_package_del(lm_database_t *db, lm_pkg_t *pkg); // delete a package from the database
|
||||
|
||||
bool lm_database_files_foreach(lm_database_t *db, lm_pkg_t *pkg, lm_database_files_eachfunc_t func, void *data);
|
||||
bool lm_database_files_matches(lm_database_t *db, lm_pkg_t *pkg, char *path, char *hash);
|
||||
bool lm_database_files_add(lm_database_t *db, lm_pkg_t *pkg, char *path, char *hash);
|
||||
bool lm_database_files_get(lm_database_t *db, lm_pkg_t *pkg, char *path, char *hash);
|
||||
bool lm_database_files_del(lm_database_t *db, lm_pkg_t *pkg);
|
||||
|
||||
bool lm_database_keeps_foreach(lm_database_t *db, lm_pkg_t *pkg, lm_database_keeps_eachfunc_t func, void *data);
|
||||
bool lm_database_keeps_load(lm_database_t *db, lm_pkg_t *pkg);
|
||||
bool lm_database_keeps_save(lm_database_t *db, lm_pkg_t *pkg);
|
||||
bool lm_database_keeps_del(lm_database_t *db, lm_pkg_t *pkg);
|
||||
bool lm_database_files_matches(
|
||||
lm_database_t *db, char *path, char *hash); // checks if the given file matches with the given hash
|
||||
bool lm_database_files_iskeep(lm_database_t *db, char *path); // checks if the given file is marked as keep
|
||||
bool lm_database_files_next(
|
||||
lm_database_t *db, lm_pkg_t *pkg, char **path, char **hash, bool *keep); // gets the next file of the package
|
||||
bool lm_database_files_add(
|
||||
lm_database_t *db, lm_pkg_t *pkg, char *path, char *hash); // adds a file to the files database
|
||||
bool lm_database_files_del(lm_database_t *db, lm_pkg_t *pkg); // dels all files of belonging to a package
|
||||
|
||||
bool lm_database_changes_update(lm_database_t *db, lm_pkg_t *pkg, char *file);
|
||||
char *lm_database_changes_get(lm_database_t *db, lm_pkg_t *pkg);
|
||||
|
@ -115,6 +115,9 @@ typedef enum lm_error {
|
||||
LM_ERR_SendReadFail = 107,
|
||||
LM_ERR_RecvBadSize = 108,
|
||||
LM_ERR_RecvNotCompleted = 109,
|
||||
LM_ERR_DbSqlSelectFail = 110,
|
||||
LM_ERR_DbSqlDeleteFail = 111,
|
||||
|
||||
} lm_error_t;
|
||||
|
||||
typedef struct lm_error_desc {
|
||||
|
Reference in New Issue
Block a user