libmp/include/database.h

56 lines
2.1 KiB
C
Raw Normal View History

2024-07-02 01:44:07 +00:00
#pragma once
#include "package.h"
#include <sqlite3.h>
#define HASH_LEN 32
2024-07-02 01:44:07 +00:00
typedef enum lm_query_index {
2024-07-06 00:48:23 +00:00
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,
2024-07-02 01:44:07 +00:00
} lm_query_index_t;
extern char *queries[];
typedef struct lm_database {
2024-07-06 00:48:23 +00:00
sqlite3 *packages_db;
sqlite3_stmt *packages_st;
sqlite3 *files_db;
sqlite3_stmt *files_st;
2024-07-02 01:44:07 +00:00
2024-07-06 00:48:23 +00:00
lm_pkg_t *pkg;
char *dir;
} lm_database_t;
2024-07-02 01:44:07 +00:00
lm_database_t *lm_database_new(char *path);
void lm_database_free(lm_database_t *db);
2024-07-06 00:48:23 +00:00
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_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);
bool lm_database_changes_del(lm_database_t *db, lm_pkg_t *pkg);