2024-07-02 01:44:07 +00:00
|
|
|
#pragma once
|
|
|
|
#include "package.h"
|
|
|
|
#include <sqlite3.h>
|
|
|
|
|
2024-07-03 00:40:52 +00:00
|
|
|
#define HASH_LEN 32
|
|
|
|
|
2024-07-08 02:47:13 +00:00
|
|
|
enum lm_query_index {
|
2024-07-08 09:49:22 +00:00
|
|
|
QUERY_CREATE_PACKAGE_TABLE = 0,
|
|
|
|
QUERY_INSERT_PACKAGE_SINGLE = 1,
|
|
|
|
QUERY_SELECT_PACKAGE_SINGLE_1 = 2,
|
|
|
|
QUERY_SELECT_PACKAGE_SINGLE_2 = 3,
|
|
|
|
QUERY_DELETE_PACKAGE_SINGLE = 4,
|
|
|
|
QUERY_SELECT_PACKAGE_ALL = 5,
|
|
|
|
QUERY_CREATE_FILE_TABLE = 6,
|
|
|
|
QUERY_INSERT_FILE_SINGLE = 7,
|
|
|
|
QUERY_DELETE_FILE_ALL = 8,
|
|
|
|
QUERY_SELECT_FILE_SINGLE = 9,
|
|
|
|
QUERY_SELECT_FILE_ALL = 10,
|
|
|
|
QUERY_UPDATE_FILE_1 = 11,
|
|
|
|
QUERY_UPDATE_FILE_2 = 12,
|
2024-07-08 02:47:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum lm_columns {
|
|
|
|
FILES_COLUMN_PATH = 1,
|
|
|
|
FILES_COLUMN_HASH = 2,
|
|
|
|
FILES_COLUMN_KEEP = 3,
|
|
|
|
FILES_COLUMN_PACKAGE = 4,
|
|
|
|
|
|
|
|
PACKAGES_COLUMN_NAME = 1,
|
2024-07-08 09:49:22 +00:00
|
|
|
PACKAGES_COLUMN_VERSION = 2,
|
|
|
|
PACKAGES_COLUMN_DESC = 3,
|
2024-07-08 02:47:13 +00:00
|
|
|
PACKAGES_COLUMN_SIZE = 4,
|
|
|
|
PACKAGES_COLUMN_DEPENDS = 5,
|
|
|
|
};
|
2024-07-02 01:44:07 +00:00
|
|
|
|
|
|
|
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-08 02:47:13 +00:00
|
|
|
bool lm_database_step_all(sqlite3_stmt *st);
|
2024-07-02 01:44:07 +00:00
|
|
|
|
2024-07-06 00:48:23 +00:00
|
|
|
bool lm_database_package_find(
|
2024-07-08 09:49:22 +00:00
|
|
|
lm_database_t *db, lm_pkg_t *pkg, char *name, char *version); // 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_package_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
|
2024-07-08 02:47:13 +00:00
|
|
|
void lm_database_package_next_free(
|
|
|
|
lm_database_t *db, lm_pkg_t *pkg); // frees resources used for lm_database_package_next
|
2024-07-06 00:48:23 +00:00
|
|
|
|
2024-07-08 02:47:13 +00:00
|
|
|
size_t lm_database_files_count(
|
|
|
|
lm_database_t *db, lm_pkg_t *pkg); // returns the count of files associated with a package
|
|
|
|
bool lm_database_files_contains(
|
|
|
|
lm_database_t *db, lm_pkg_t *pkg, char *path); // check if a package 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(
|
|
|
|
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
|
2024-07-08 02:47:13 +00:00
|
|
|
void lm_database_files_next_free(lm_database_t *db, lm_pkg_t *pkg, char **path, char **hash,
|
|
|
|
bool *keep); // frees resources used for lm_database_files_next
|
2024-07-04 22:44:42 +00:00
|
|
|
|
|
|
|
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);
|