libmp/include/database.h

75 lines
2.9 KiB
C
Raw Normal View History

2024-07-02 01:44:07 +00:00
#pragma once
2024-07-31 18:16:19 +00:00
#include "database.h"
2024-07-02 01:44:07 +00:00
#include "package.h"
2024-07-31 18:16:19 +00:00
2024-07-02 01:44:07 +00:00
#include <sqlite3.h>
2024-07-31 18:16:19 +00:00
#include <stdbool.h>
2024-08-14 23:16:16 +00:00
#include <stdio.h>
2024-07-31 18:16:19 +00:00
#include <sys/types.h>
2024-07-02 01:44:07 +00:00
#define HASH_LEN 32
2024-07-08 02:47:13 +00:00
enum lm_query_index {
2024-08-14 23:16:16 +00:00
QUERY_CREATE_TABLE = 0,
QUERY_INSERT_SINGLE = 1,
QUERY_SELECT_SINGLE_1 = 2,
QUERY_SELECT_SINGLE_2 = 3,
QUERY_DELETE_SINGLE = 4,
QUERY_SELECT_ALL = 5,
2024-07-08 02:47:13 +00:00
};
enum lm_columns {
2024-08-14 23:16:16 +00:00
COLUMN_NAME = 1,
COLUMN_VERSION = 2,
COLUMN_DESC = 3,
COLUMN_SIZE = 4,
COLUMN_DEPENDS = 5,
2024-07-08 02:47:13 +00:00
};
2024-07-02 01:44:07 +00:00
extern char *queries[];
2024-07-31 18:16:19 +00:00
typedef lm_pkg_data_t lm_entry_t;
2024-07-02 01:44:07 +00:00
typedef struct lm_database {
2024-08-14 23:16:16 +00:00
sqlite3 *sql;
sqlite3_stmt *st;
FILE *filesp;
char *dir;
2024-07-06 00:48:23 +00:00
} lm_database_t;
2024-07-02 01:44:07 +00:00
2024-07-31 18:16:19 +00:00
void lm_entry_init(lm_entry_t *entry);
void lm_entry_free(lm_entry_t *entry);
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-08 02:47:13 +00:00
bool lm_database_step_all(sqlite3_stmt *st);
2024-07-02 01:44:07 +00:00
2024-07-31 18:16:19 +00:00
bool lm_database_entry_find(
lm_database_t *db, lm_entry_t *out, char *name, char *version); // finds a entry by its name, entry stored in *pkg
bool lm_database_entry_next(lm_database_t *db, lm_entry_t *entry); // gets the next entry in the database
bool lm_database_entry_add(lm_database_t *db, lm_entry_t *entry); // adds a entry to the database
bool lm_database_entry_del(lm_database_t *db, lm_entry_t *entry); // delete a entry from the database
void lm_database_entry_next_free(
lm_database_t *db, lm_entry_t *entry); // frees resources used for lm_database_entry_next
2024-07-06 00:48:23 +00:00
2024-07-31 18:16:19 +00:00
ssize_t lm_database_files_count(
lm_database_t *db, lm_entry_t *entry); // returns the count of files associated with a entry
2024-07-08 02:47:13 +00:00
bool lm_database_files_contains(
2024-07-31 18:16:19 +00:00
lm_database_t *db, lm_entry_t *entry, char *path); // check if a entry contains the given file
2024-07-06 00:48:23 +00:00
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(
2024-07-31 18:16:19 +00:00
lm_database_t *db, lm_entry_t *entry, char **path, char **hash, bool *keep); // gets the next file of the entry
2024-07-06 00:48:23 +00:00
bool lm_database_files_add(
2024-07-31 18:16:19 +00:00
lm_database_t *db, lm_entry_t *entry, char *path, char *hash); // adds a file to the files database
2024-08-14 23:16:16 +00:00
bool lm_database_files_del(
lm_database_t *db, lm_entry_t *entry); // dels files belonging to an entry that is not set as KEEP
bool lm_database_files_del_all(lm_database_t *db, lm_entry_t *entry); // dels all files of belonging to an entry
2024-07-31 18:16:19 +00:00
void lm_database_files_next_free(lm_database_t *db, lm_entry_t *entry, char **path, char **hash,
2024-07-08 02:47:13 +00:00
bool *keep); // frees resources used for lm_database_files_next
2024-07-31 18:16:19 +00:00
bool lm_database_changes_update(lm_database_t *db, lm_entry_t *entry, char *file);
char *lm_database_changes_get(lm_database_t *db, lm_entry_t *entry);
bool lm_database_changes_del(lm_database_t *db, lm_entry_t *entry);